Skip to content

Commit

Permalink
Merge pull request #610 from achrefbensaad/fix-policy-gen
Browse files Browse the repository at this point in the history
make disocvered policies work
  • Loading branch information
achrefbensaad committed Nov 28, 2022
2 parents 3131f7e + fd306ee commit 29ca624
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
k8s.io/api v0.23.5
k8s.io/apimachinery v0.23.5
k8s.io/client-go v0.23.5
k8s.io/utils v0.0.0-20211116205334-6203023598ed
sigs.k8s.io/yaml v1.3.0
)

Expand Down Expand Up @@ -125,7 +126,6 @@ require (
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.2.1 // indirect
)
28 changes: 28 additions & 0 deletions src/systempolicy/systemPolicy.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/clarketm/json"
"k8s.io/utils/strings/slices"
"sigs.k8s.io/yaml"

"github.com/accuknox/auto-policy-discovery/src/cluster"
Expand Down Expand Up @@ -340,6 +341,33 @@ func extractK8SSystemPolicies(namespace, clustername, labels, fromsource string,
if !includeNetwork {
pol.Spec.Network = types.NetworkRule{}
}
// if a binary is a global binary, convert file access to global

globalbinaries := []string{}
for _, binary := range pol.Spec.Process.MatchPaths {
if len(binary.FromSource) == 0 && !slices.Contains(globalbinaries, binary.Path) {
globalbinaries = append(globalbinaries, binary.Path)
}
}

for i, matchpath := range pol.Spec.File.MatchPaths {
for _, binary := range matchpath.FromSource {
if slices.Contains(globalbinaries, binary.Path) {
pol.Spec.File.MatchPaths[i].FromSource = []types.KnoxFromSource{}
break
}
}
}

for i, matchDir := range pol.Spec.File.MatchDirectories {
for _, binary := range matchDir.FromSource {
if slices.Contains(globalbinaries, binary.Path) {
pol.Spec.File.MatchDirectories[i].FromSource = []types.KnoxFromSource{}
break
}
}
}

result = append(result, pol)
}
}
Expand Down

0 comments on commit 29ca624

Please sign in to comment.