forked from open-policy-agent/gatekeeper-library
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(k8sPSPHostFilesystem): null-check on volumes
A K8sNativeValidation implementation of this template was added in open-policy-agent#547. When testing it, I found that a Pod lacking the `volumes` field would yield a null-pointer style error on the CEL expression: ``` unexpected number of violations: got 1 violations but want none: got messages [expression '(has(request.operation) && request.operation == "UPDATE") || size(variables.badHostPaths) == 0' resulted in error: composited variable "badHostPaths" fails to evaluate: composited variable "volumes" fails to evaluate: no such key: volumes] ``` This PR adds a `has(` check to prevent that null pointer, and adds a suite test case that fails without the code change. Signed-off-by: juliankatz <[email protected]>
- Loading branch information
1 parent
598df74
commit b0d012c
Showing
5 changed files
with
32 additions
and
3 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
library/pod-security-policy/host-filesystem/samples/no-host-paths/constraint.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: constraints.gatekeeper.sh/v1beta1 | ||
kind: K8sPSPHostFilesystem | ||
metadata: | ||
name: no-host-paths | ||
spec: | ||
match: | ||
kinds: | ||
- apiGroups: [""] | ||
kinds: ["Pod"] |
8 changes: 8 additions & 0 deletions
8
...pod-security-policy/host-filesystem/samples/no-host-paths/example_allowed_no_volumes.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: nginx-no-volumes | ||
spec: | ||
containers: | ||
- name: nginx | ||
image: nginx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters