mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
Allow kyverno-policies to have preconditions defined (#3606)
* Allow kyverno-policies to have preconditions defined Signed-off-by: Trey Dockendorf <tdockendorf@osc.edu> * Fix docs Signed-off-by: Trey Dockendorf <tdockendorf@osc.edu>
This commit is contained in:
parent
a0d3f31851
commit
1cfc80d32a
21 changed files with 112 additions and 8 deletions
|
@ -70,6 +70,7 @@ The command removes all the Kubernetes components associated with the chart and
|
||||||
| validationFailureAction | string | `"audit"` | Validation failure action (`audit`, `enforce`). For more info https://kyverno.io/docs/writing-policies/validate. |
|
| validationFailureAction | string | `"audit"` | Validation failure action (`audit`, `enforce`). For more info https://kyverno.io/docs/writing-policies/validate. |
|
||||||
| validationFailureActionOverrides | object | `{"all":[]}` | Define validationFailureActionOverrides for specific policies. The overrides for `all` will apply to all policies. |
|
| validationFailureActionOverrides | object | `{"all":[]}` | Define validationFailureActionOverrides for specific policies. The overrides for `all` will apply to all policies. |
|
||||||
| policyExclude | object | `{}` | Exclude resources from individual policies. Policies with multiple rules can have individual rules excluded by using the name of the rule as the key in the `policyExclude` map. |
|
| policyExclude | object | `{}` | Exclude resources from individual policies. Policies with multiple rules can have individual rules excluded by using the name of the rule as the key in the `policyExclude` map. |
|
||||||
|
| policyPreconditions | object | `{}` | Add preconditions to individual policies. Policies with multiple rules can have individual rules excluded by using the name of the rule as the key in the `policyPreconditions` map. |
|
||||||
| nameOverride | string | `nil` | Name override. |
|
| nameOverride | string | `nil` | Name override. |
|
||||||
| customLabels | object | `{}` | Additional labels. |
|
| customLabels | object | `{}` | Additional labels. |
|
||||||
| background | bool | `true` | Policies background mode |
|
| background | bool | `true` | Policies background mode |
|
||||||
|
|
14
charts/kyverno-policies/ci/test-preconditions.yaml
Normal file
14
charts/kyverno-policies/ci/test-preconditions.yaml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
podSecurityStandard: restricted
|
||||||
|
includeOtherPolicies:
|
||||||
|
- require-non-root-groups
|
||||||
|
policyPreconditions:
|
||||||
|
require-run-as-non-root-user:
|
||||||
|
any:
|
||||||
|
- key: "{{ request.object.metadata.name }}"
|
||||||
|
operator: NotEquals
|
||||||
|
value: "dcgm-exporter*"
|
||||||
|
adding-capabilities-strict:
|
||||||
|
any:
|
||||||
|
- key: "{{ request.object.metadata.name }}"
|
||||||
|
operator: NotEquals
|
||||||
|
value: "dcgm-exporter*"
|
|
@ -34,6 +34,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with index .Values "policyPreconditions" $name }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Any capabilities added beyond the allowed list (AUDIT_WRITE, CHOWN, DAC_OVERRIDE, FOWNER,
|
Any capabilities added beyond the allowed list (AUDIT_WRITE, CHOWN, DAC_OVERRIDE, FOWNER,
|
||||||
|
|
|
@ -35,6 +35,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with index .Values "policyPreconditions" $name }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Sharing the host namespaces is disallowed. The fields spec.hostNetwork,
|
Sharing the host namespaces is disallowed. The fields spec.hostNetwork,
|
||||||
|
|
|
@ -34,6 +34,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with index .Values "policyPreconditions" $name }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
HostPath volumes are forbidden. The field spec.volumes[*].hostPath must be unset.
|
HostPath volumes are forbidden. The field spec.volumes[*].hostPath must be unset.
|
||||||
|
|
|
@ -34,6 +34,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with index .Values "policyPreconditions" $name }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Use of host ports is disallowed. The fields spec.containers[*].ports[*].hostPort
|
Use of host ports is disallowed. The fields spec.containers[*].ports[*].hostPort
|
||||||
|
|
|
@ -35,6 +35,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with index .Values "policyPreconditions" $name }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
HostProcess containers are disallowed. The fields spec.securityContext.windowsOptions.hostProcess,
|
HostProcess containers are disallowed. The fields spec.securityContext.windowsOptions.hostProcess,
|
||||||
|
|
|
@ -33,6 +33,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with index .Values "policyPreconditions" $name }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Privileged mode is disallowed. The fields spec.containers[*].securityContext.privileged
|
Privileged mode is disallowed. The fields spec.containers[*].securityContext.privileged
|
||||||
|
|
|
@ -35,6 +35,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with index .Values "policyPreconditions" $name }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Changing the proc mount from the default is not allowed. The fields
|
Changing the proc mount from the default is not allowed. The fields
|
||||||
|
|
|
@ -33,6 +33,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with merge (index .Values "policyPreconditions" "selinux-type") (index .Values "policyPreconditions" $name) }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Setting the SELinux type is restricted. The fields
|
Setting the SELinux type is restricted. The fields
|
||||||
|
@ -66,6 +70,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with merge (index .Values "policyPreconditions" "selinux-user-role") (index .Values "policyPreconditions" $name) }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Setting the SELinux user or role is forbidden. The fields
|
Setting the SELinux user or role is forbidden. The fields
|
||||||
|
|
|
@ -36,6 +36,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with index .Values "policyPreconditions" $name }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Specifying other AppArmor profiles is disallowed. The annotation
|
Specifying other AppArmor profiles is disallowed. The annotation
|
||||||
|
|
|
@ -34,6 +34,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with index .Values "policyPreconditions" $name }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Use of custom Seccomp profiles is disallowed. The fields
|
Use of custom Seccomp profiles is disallowed. The fields
|
||||||
|
|
|
@ -37,6 +37,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with index .Values "policyPreconditions" $name }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Setting additional sysctls above the allowed type is disallowed.
|
Setting additional sysctls above the allowed type is disallowed.
|
||||||
|
|
|
@ -35,6 +35,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with merge (index .Values "policyPreconditions" "check-runasgroup") (index .Values "policyPreconditions" $name) }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Running with root group IDs is disallowed. The fields
|
Running with root group IDs is disallowed. The fields
|
||||||
|
@ -75,6 +79,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with merge (index .Values "policyPreconditions" "check-supplementalgroups") (index .Values "policyPreconditions" $name) }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Containers cannot run with a root primary or supplementary GID. The field
|
Containers cannot run with a root primary or supplementary GID. The field
|
||||||
|
|
|
@ -35,11 +35,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with merge (index .Values "policyPreconditions" "require-drop-all") (index .Values "policyPreconditions" $name) }}
|
||||||
preconditions:
|
preconditions:
|
||||||
all:
|
{{- toYaml . | nindent 8 }}
|
||||||
- key: "{{`{{ request.operation }}`}}"
|
{{- end }}
|
||||||
operator: NotEquals
|
|
||||||
value: DELETE
|
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Containers must drop `ALL` capabilities.
|
Containers must drop `ALL` capabilities.
|
||||||
|
@ -61,11 +60,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with merge (index .Values "policyPreconditions" "adding-capabilities-strict") (index .Values "policyPreconditions" $name) }}
|
||||||
preconditions:
|
preconditions:
|
||||||
all:
|
{{- toYaml . | nindent 8 }}
|
||||||
- key: "{{`{{ request.operation }}`}}"
|
{{- end }}
|
||||||
operator: NotEquals
|
|
||||||
value: DELETE
|
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Any capabilities added other than NET_BIND_SERVICE are disallowed.
|
Any capabilities added other than NET_BIND_SERVICE are disallowed.
|
||||||
|
|
|
@ -33,6 +33,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with index .Values "policyPreconditions" $name }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Privilege escalation is disallowed. The fields
|
Privilege escalation is disallowed. The fields
|
||||||
|
|
|
@ -33,6 +33,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with index .Values "policyPreconditions" $name }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Running as root is not allowed. The fields spec.securityContext.runAsUser,
|
Running as root is not allowed. The fields spec.securityContext.runAsUser,
|
||||||
|
|
|
@ -34,6 +34,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with index .Values "policyPreconditions" $name }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Running as root is not allowed. Either the field spec.securityContext.runAsNonRoot
|
Running as root is not allowed. Either the field spec.securityContext.runAsNonRoot
|
||||||
|
|
|
@ -36,6 +36,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with index .Values "policyPreconditions" $name }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Use of custom Seccomp profiles is disallowed. The fields
|
Use of custom Seccomp profiles is disallowed. The fields
|
||||||
|
|
|
@ -36,6 +36,10 @@ spec:
|
||||||
exclude:
|
exclude:
|
||||||
{{- toYaml . | nindent 8 }}
|
{{- toYaml . | nindent 8 }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
|
{{- with index .Values "policyPreconditions" $name }}
|
||||||
|
preconditions:
|
||||||
|
{{- toYaml . | nindent 8 }}
|
||||||
|
{{- end }}
|
||||||
validate:
|
validate:
|
||||||
message: >-
|
message: >-
|
||||||
Only the following types of volumes may be used: configMap, csi, downwardAPI,
|
Only the following types of volumes may be used: configMap, csi, downwardAPI,
|
||||||
|
|
|
@ -48,6 +48,21 @@ policyExclude: {}
|
||||||
# - Pod
|
# - Pod
|
||||||
# namespaces:
|
# namespaces:
|
||||||
# - kube-system
|
# - kube-system
|
||||||
|
# -- Add preconditions to individual policies.
|
||||||
|
# Policies with multiple rules can have individual rules excluded by using the name of the rule as the key in the `policyPreconditions` map.
|
||||||
|
policyPreconditions: {}
|
||||||
|
# # Exclude resources from individual policies
|
||||||
|
# require-run-as-non-root-user:
|
||||||
|
# any:
|
||||||
|
# - key: "{{ request.object.metadata.name }}"
|
||||||
|
# operator: NotEquals
|
||||||
|
# value: "dcgm-exporter*"
|
||||||
|
# # Policies with multiple rules can have individual rules excluded
|
||||||
|
# adding-capabilities-strict:
|
||||||
|
# any:
|
||||||
|
# - key: "{{ request.object.metadata.name }}"
|
||||||
|
# operator: NotEquals
|
||||||
|
# value: "dcgm-exporter*"
|
||||||
|
|
||||||
# -- Name override.
|
# -- Name override.
|
||||||
nameOverride:
|
nameOverride:
|
||||||
|
|
Loading…
Add table
Reference in a new issue