Back to Policies

Restrict Seccomp in ValidatingPolicy

The seccomp profile must not be explicitly set to Unconfined. This policy, requiring Kubernetes v1.30 or later, ensures that seccomp is unset or set to `RuntimeDefault` or `Localhost`.

View on GitHub

Policy Definition

apiVersion: policies.kyverno.io/v1alpha1
kind: ValidatingPolicy
metadata:
name: restrict-seccomp
annotations:
policies.kyverno.io/title: Restrict Seccomp in ValidatingPolicy
policies.kyverno.io/category: Pod Security Standards (Baseline) in ValidatingPolicy
policies.kyverno.io/severity: medium
policies.kyverno.io/subject: Pod
policies.kyverno.io/minversion: 1.14.0
kyverno.io/kyverno-version: 1.14.0
kyverno.io/kubernetes-version: 1.30+
policies.kyverno.io/description: The seccomp profile must not be explicitly set to Unconfined. This policy, requiring Kubernetes v1.30 or later, ensures that seccomp is unset or set to `RuntimeDefault` or `Localhost`.
spec:
validationActions:
- Audit
evaluation:
background:
enabled: true
matchConstraints:
resourceRules:
- apiGroups:
- ""
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- pods
variables:
- name: allContainers
expression: object.spec.containers + object.spec.?initContainers.orValue([]) + object.spec.?ephemeralContainers.orValue([])
- name: allowedProfileTypes
expression: "['RuntimeDefault', 'Localhost']"
- name: hasValidSeccompProfile
expression: object.spec.?securityContext.?seccompProfile.?type.orValue('Localhost') in variables.allowedProfileTypes
validations:
- expression: |-
variables.hasValidSeccompProfile && variables.allContainers.all(container,
container.?securityContext.?seccompProfile.?type.orValue('Localhost') in variables.allowedProfileTypes)
message: Use of custom Seccomp profiles is disallowed. The field `securityContext.seccompProfile.type` must be unset or set to `RuntimeDefault` or `Localhost`.

Related Policies