-
Notifications
You must be signed in to change notification settings - Fork 339
Open
Description
The Pod Security Standard Restricted policy requires that runAsNonRoot is set to true. https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
Containers must be required to run as non-root users.
Restricted Fields
spec.securityContext.runAsNonRootspec.containers[*].securityContext.runAsNonRootspec.initContainers[*].securityContext.runAsNonRootspec.ephemeralContainers[*].securityContext.runAsNonRootAllowed Values
trueThe container fields may be undefined/
nilif the pod-levelspec.securityContext.runAsNonRootis set totrue.
Therefore, a manifest such as this should violate the policy.
apiVersion: v1
kind: Pod
metadata:
name: no-nonroot
labels:
app: nginx-users
spec:
securityContext:
supplementalGroups:
- 199
fsGroup: 199
containers:
- name: nginx
image: nginx
securityContext:
runAsUser: 1
runAsGroup: 199
allowPrivilegeEscalation: false
seccompProfile:
type: RuntimeDefault
capabilities:
drop:
- ALLThe above manifest is blocked by the Pod Security admission controller in restricted mode.
$ k apply -n yes-pss -f reject-unset-runasnonroot.yaml
Error from server (Forbidden): error when creating "reject-unset-runasnonroot.yaml": pods "no-nonroot" is forbidden: violates PodSecurity "restricted:v1.33": runAsNonRoot != true (pod or container "nginx" must set securityContext.runAsNonRoot=true)
But OPA does not show a violation:
$ gator verify -v suite.yaml
=== RUN allowed-users
=== RUN reject-unset-runasnonroot
--- FAIL: reject-unset-runasnonroot (0.007s)
unexpected number of violations: got 0 violations but want exactly 1: got messages []
--- FAIL: allowed-users (0.015s)
FAIL suite.yaml 0.015s
FAIL
Error: FAIL
suite.yaml:
kind: Suite
apiVersion: test.gatekeeper.sh/v1alpha1
tests:
- name: allowed-users
template: constrainttemplate.yaml
constraint: constraint.yaml
cases:
- name: reject-unset-runasnonroot
object: reject-unset-runasnonroot.yaml
assertions:
- violations: 1constraint.yaml
apiVersion: constraints.gatekeeper.sh/v1beta1
kind: K8sPSPAllowedUsers
metadata:
name: psp-pods-allowed-user-ranges
spec:
match:
kinds:
- apiGroups: [""]
kinds: ["Pod"]
parameters:
runAsUser:
rule: MustRunAsNonRoot # MustRunAsNonRoot # RunAsAny
runAsGroup:
rule: MustRunAs # MayRunAs # RunAsAny
ranges:
- min: 1
max: 65535
supplementalGroups:
rule: MayRunAs # MayRunAs # RunAsAny
ranges:
- min: 1
max: 65535
fsGroup:
rule: MayRunAs # MayRunAs # RunAsAny
ranges:
- min: 1
max: 65535The template is https://github.com/open-policy-agent/gatekeeper-library/blob/master/library/pod-security-policy/users/template.yaml as it was in version 1.0.2.
Metadata
Metadata
Assignees
Labels
No labels