Skip to content

Commit

Permalink
Merge pull request #1915 from daemon1024/apparmor-cleanup-graceful
Browse files Browse the repository at this point in the history
feat(apparmor/host): cleanup profiles on gracefult termination
  • Loading branch information
DelusionalOptimist authored Dec 19, 2024
2 parents dc0bb33 + 98bc591 commit c472718
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions KubeArmor/enforcer/appArmorEnforcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,32 +440,37 @@ func (ae *AppArmorEnforcer) UnregisterAppArmorHostProfile() bool {
return true
}

ae.Logger.Printf("Unregistering the KubeArmor host profile from %s", cfg.GlobalCfg.Host)

ae.AppArmorProfilesLock.Lock()
defer ae.AppArmorProfilesLock.Unlock()

if err := ae.CreateAppArmorHostProfile(); err != nil {
ae.Logger.Warnf("Unable to reset the KubeArmor host profile in %s", cfg.GlobalCfg.Host)
if err := kl.RunCommandAndWaitWithErr("aa-remove-unknown", []string{}); err != nil {
ae.Logger.Warnf("Unable to cleanup the KubeArmor host profile in %s", cfg.GlobalCfg.Host)

if err := os.Remove(appArmorHostFile); err != nil {
ae.Logger.Warnf("Unable to remove the KubeArmor host profile from %s (%s)", cfg.GlobalCfg.Host, err.Error())
if err := ae.CreateAppArmorHostProfile(); err != nil {
ae.Logger.Warnf("Unable to reset the KubeArmor host profile in %s", cfg.GlobalCfg.Host)

if err := os.Remove(appArmorHostFile); err != nil {
ae.Logger.Warnf("Unable to remove the KubeArmor host profile from %s (%s)", cfg.GlobalCfg.Host, err.Error())
}

return false
}

return false
}
if err := kl.RunCommandAndWaitWithErr("apparmor_parser", []string{"-r", "-W", "-C", appArmorHostFile}); err != nil {
ae.Logger.Warnf("Unable to reset the KubeArmor host profile in %s", cfg.GlobalCfg.Host)

if err := kl.RunCommandAndWaitWithErr("apparmor_parser", []string{"-r", "-W", "-C", appArmorHostFile}); err != nil {
ae.Logger.Warnf("Unable to reset the KubeArmor host profile in %s", cfg.GlobalCfg.Host)
if err := os.Remove(appArmorHostFile); err != nil {
ae.Logger.Warnf("Unable to remove the KubeArmor host profile from %s (%s)", cfg.GlobalCfg.Host, err.Error())
}

}

if err := os.Remove(appArmorHostFile); err != nil {
ae.Logger.Warnf("Unable to remove the KubeArmor host profile from %s (%s)", cfg.GlobalCfg.Host, err.Error())
return false
}

return false
}

if err := os.Remove(appArmorHostFile); err != nil {
ae.Logger.Warnf("Unable to remove the KubeArmor host profile from %s (%s)", cfg.GlobalCfg.Host, err.Error())
return false
}

ae.Logger.Printf("Unregistered the KubeArmor host profile from %s", cfg.GlobalCfg.Host)
Expand Down

0 comments on commit c472718

Please sign in to comment.