Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Require runAsNonRoot" policy with "initContainers: null" #1197

Open
jplitza opened this issue Nov 11, 2024 · 1 comment
Open

"Require runAsNonRoot" policy with "initContainers: null" #1197

jplitza opened this issue Nov 11, 2024 · 1 comment

Comments

@jplitza
Copy link

jplitza commented Nov 11, 2024

The sample policy Require runAsNonRoot fails with the following Pod spec:

apiVersion: v1
kind: Pod
metadata:
  name: null-initcontainers
spec:
  securityContext:
    runAsNonRoot: true
  containers:
  - image: alpine:latest
  initContainers:

Without the last line (which is equivalent to initContainers: null), the policy succeeds.

This situation is common with Helm charts, where list keys are always templated, followed by a loop for the items. It is valid according to the Kubernetes schemas, too.

@realshuting
Copy link
Member

Not sure if this is something we can "fix" in Kyverno. With =(initContainers): declaration, it means if the initContainers exists, check the following XYZ.

An alternative is to use PSS policies in CEL:

https://kyverno.io/policies/?policytypes=Pod%2520Security%2520Standards%2520%28Baseline%29%2520in%2520CEL%2BPod%2520Security%2520Standards%2520%28Restricted%29%2520in%2520CEL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants