2022-11-28 09:04:21 -05:00
|
|
|
apiVersion: kyverno.io/v1
|
|
|
|
kind: ClusterPolicy
|
|
|
|
metadata:
|
|
|
|
name: check-trustable-images
|
|
|
|
spec:
|
2023-04-03 15:36:30 +02:00
|
|
|
validationFailureAction: Enforce
|
2022-11-28 09:04:21 -05:00
|
|
|
rules:
|
|
|
|
- name: only-allow-trusted-images
|
|
|
|
match:
|
|
|
|
any:
|
|
|
|
- resources:
|
|
|
|
kinds:
|
|
|
|
- Pod
|
|
|
|
preconditions:
|
|
|
|
- key: "{{request.operation}}"
|
|
|
|
operator: NotEquals
|
|
|
|
value: DELETE
|
|
|
|
validate:
|
|
|
|
message: "images with root user are not allowed"
|
|
|
|
foreach:
|
|
|
|
- list: "request.object.spec.containers"
|
|
|
|
context:
|
|
|
|
- name: imageData
|
|
|
|
imageRegistry:
|
|
|
|
reference: "{{ element.image }}"
|
|
|
|
jmesPath: "{user: configData.config.User || '', registry: registry}"
|
|
|
|
deny:
|
|
|
|
conditions:
|
|
|
|
all:
|
|
|
|
- key: "{{ imageData.user }}"
|
|
|
|
operator: Equals
|
|
|
|
value: ""
|
|
|
|
- key: "{{ imageData.registry }}"
|
|
|
|
operator: NotEquals
|
|
|
|
value: "ghcr.io"
|