mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-09 17:37:12 +00:00
59 lines
2 KiB
YAML
59 lines
2 KiB
YAML
|
{{- $name := "disallow-capabilities" }}
|
||
|
{{- if eq (include "kyverno-policies.podSecurityBaseline" (merge (dict "name" $name) .)) "true" }}
|
||
|
{{- include "kyverno-policies.supportedKyvernoCheck" (dict "top" . "ver" ">= 1.6.0-0") }}
|
||
|
apiVersion: kyverno.io/v1
|
||
|
kind: ClusterPolicy
|
||
|
metadata:
|
||
|
name: {{ $name }}
|
||
|
annotations:
|
||
|
policies.kyverno.io/title: Disallow Capabilities
|
||
|
policies.kyverno.io/category: Pod Security Standards (Baseline)
|
||
|
{{- if .Values.podSecuritySeverity }}
|
||
|
policies.kyverno.io/severity: {{ .Values.podSecuritySeverity }}
|
||
|
{{- end }}
|
||
|
kyverno.io/kyverno-version: 1.6.0
|
||
|
policies.kyverno.io/minversion: 1.6.0
|
||
|
kyverno.io/kubernetes-version: "1.22-1.23"
|
||
|
policies.kyverno.io/subject: Pod
|
||
|
policies.kyverno.io/description: >-
|
||
|
Adding capabilities beyond those listed in the policy must be disallowed.
|
||
|
spec:
|
||
|
validationFailureAction: {{ .Values.validationFailureAction }}
|
||
|
background: true
|
||
|
rules:
|
||
|
- name: adding-capabilities
|
||
|
match:
|
||
|
any:
|
||
|
- resources:
|
||
|
kinds:
|
||
|
- Pod
|
||
|
{{- with index .Values "policyExclude" $name }}
|
||
|
exclude:
|
||
|
{{- toYaml . | nindent 8 }}
|
||
|
{{- end }}
|
||
|
validate:
|
||
|
message: >-
|
||
|
Any capabilities added beyond the allowed list (AUDIT_WRITE, CHOWN, DAC_OVERRIDE, FOWNER,
|
||
|
FSETID, KILL, MKNOD, NET_BIND_SERVICE, SETFCAP, SETGID, SETPCAP, SETUID, SYS_CHROOT)
|
||
|
are disallowed.
|
||
|
deny:
|
||
|
conditions:
|
||
|
all:
|
||
|
- key: "{{`{{ request.object.spec.[ephemeralContainers, initContainers, containers][].securityContext.capabilities.add[] }}`}}"
|
||
|
operator: AnyNotIn
|
||
|
value:
|
||
|
- AUDIT_WRITE
|
||
|
- CHOWN
|
||
|
- DAC_OVERRIDE
|
||
|
- FOWNER
|
||
|
- FSETID
|
||
|
- KILL
|
||
|
- MKNOD
|
||
|
- NET_BIND_SERVICE
|
||
|
- SETFCAP
|
||
|
- SETGID
|
||
|
- SETPCAP
|
||
|
- SETUID
|
||
|
- SYS_CHROOT
|
||
|
{{- end }}
|