Skip to content

Commit

Permalink
fix: fail for irrelevant resources
Browse files Browse the repository at this point in the history
reported in aquasecurity/trivy#4922
since the failRootGroupId rule is given a default value, it doesn't fail
the deny rule and results in a false detection. added an explicit check for
the failRootGropuId truthiness to resolve.

also fixed the sad path test
  • Loading branch information
itaysk committed Jan 10, 2024
1 parent 8b3cedc commit c54c2ec
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ failRootGroupId {
}

deny[res] {
failRootGroupId
output := failRootGroupId
msg := kubernetes.format(sprintf("%s %s in %s namespace should set spec.securityContext.runAsGroup, spec.securityContext.supplementalGroups[*] and spec.securityContext.fsGroup to integer greater than 0", [lower(kubernetes.kind), kubernetes.name, kubernetes.namespace]))
res := result.new(msg, output)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,15 @@ test_failRootGroupId_failed {
}},
}

count(r) > 0
count(r) = 0
}

test_failRootGroupId_irrelevant {
r := deny with input as {
"apiVersion": "v1",
"kind": "ClusterRole",
"metadata": {"name": "hello"}
}

count(r) = 0
}

0 comments on commit c54c2ec

Please sign in to comment.