Skip to content

Commit

Permalink
fix(hsp/systemd): parse both matchpaths and matchdir together on hsp …
Browse files Browse the repository at this point in the history
…event

Signed-off-by: daemon1024 <[email protected]>
  • Loading branch information
daemon1024 committed Mar 7, 2024
1 parent 407c8ca commit 429a21b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
8 changes: 6 additions & 2 deletions KubeArmor/core/kubeUpdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,9 @@ func (dm *KubeArmorDaemon) ParseAndUpdateHostSecurityPolicy(event tp.K8sKubeArmo
}
}
}
} else if len(secPolicy.Spec.Process.MatchDirectories) > 0 {
}

if len(secPolicy.Spec.Process.MatchDirectories) > 0 {
for idx, dir := range secPolicy.Spec.Process.MatchDirectories {
if dir.Severity == 0 {
if secPolicy.Spec.Process.Severity != 0 {
Expand Down Expand Up @@ -1602,7 +1604,9 @@ func (dm *KubeArmorDaemon) ParseAndUpdateHostSecurityPolicy(event tp.K8sKubeArmo
}
}
}
} else if len(secPolicy.Spec.Process.MatchPatterns) > 0 {
}

if len(secPolicy.Spec.Process.MatchPatterns) > 0 {
for idx, pat := range secPolicy.Spec.Process.MatchPatterns {
if pat.Severity == 0 {
if secPolicy.Spec.Process.Severity != 0 {
Expand Down
13 changes: 6 additions & 7 deletions KubeArmor/core/unorchestratedUpdates.go
Original file line number Diff line number Diff line change
Expand Up @@ -677,21 +677,20 @@ func (dm *KubeArmorDaemon) restoreKubeArmorPolicies() {
}

} else { // HostSecurityPolicy
var hostPolicy tp.HostSecurityPolicy
var hostPolicy tp.K8sKubeArmorHostPolicy
if err := json.Unmarshal(data, &hostPolicy); err == nil {
dm.HostSecurityPolicies = append(dm.HostSecurityPolicies, hostPolicy)
dm.ParseAndUpdateHostSecurityPolicy(tp.K8sKubeArmorHostPolicyEvent{
Type: "ADDED",
Object: hostPolicy,
})
} else {
kg.Errf("Failed to unmarshal host policy: %v", err)
}
}
}
}

if len(policyFiles) != 0 {
if len(dm.HostSecurityPolicies) != 0 {
dm.UpdateHostSecurityPolicies()
}
} else {
if len(policyFiles) == 0 {
kg.Warn("No policies found for restoration")
}
}
Expand Down

0 comments on commit 429a21b

Please sign in to comment.