Skip to content

Commit

Permalink
feat(apparmor/host): cleanup profiles on gracefult termination
Browse files Browse the repository at this point in the history
This will avoid lingering enforcement of policies on running processes during uninstallation of kubearmor

Signed-off-by: daemon1024 <[email protected]>
  • Loading branch information
daemon1024 committed Dec 17, 2024
1 parent 410ea7a commit 9ffb121
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions KubeArmor/enforcer/appArmorEnforcer.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,29 +443,9 @@ func (ae *AppArmorEnforcer) UnregisterAppArmorHostProfile() bool {
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 := 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
}

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 := kl.RunCommandAndWaitWithErr("aa-remove-unknown", []string{}); err != nil {
ae.Logger.Warnf("Unable to cleanup the KubeArmor host profile in %s", cfg.GlobalCfg.Host)

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 9ffb121

Please sign in to comment.