|
1 | | -apiVersion: policies.kyverno.io/v1 |
2 | | -kind: MutatingPolicy |
| 1 | +apiVersion: kyverno.io/v1 |
| 2 | +kind: ClusterPolicy |
3 | 3 | metadata: |
4 | 4 | name: inject-coco-initdata |
5 | 5 | annotations: |
6 | 6 | policies.kyverno.io/title: Inject CoCo InitData |
7 | 7 | policies.kyverno.io/category: Confidential Computing |
8 | 8 | policies.kyverno.io/severity: medium |
9 | | - policies.kyverno.io/subject: Deployment |
| 9 | + policies.kyverno.io/subject: Pod,Deployment |
10 | 10 | policies.kyverno.io/description: >- |
11 | | - Injects cc_init_data annotation into Deployment pod templates with a kata |
12 | | - runtime class by reading from a ConfigMap specified via the |
13 | | - coco.io/initdata-configmap annotation on the pod template. |
14 | | - Adapted from upstream kyverno inject-coco-initdata policy. |
| 11 | + Injects cc_init_data annotation into pods with a kata runtime class |
| 12 | + by reading from a ConfigMap specified via the coco.io/initdata-configmap |
| 13 | + annotation. Kyverno autogen extends this to Deployments, StatefulSets, |
| 14 | + DaemonSets, and Jobs automatically. |
15 | 15 | argocd.argoproj.io/sync-wave: "1" |
| 16 | + pod-policies.kyverno.io/autogen-controllers: Deployment,StatefulSet,DaemonSet,Job |
16 | 17 | spec: |
17 | | - matchConstraints: |
18 | | - resourceRules: |
19 | | - - apiGroups: ["apps"] |
20 | | - apiVersions: ["v1"] |
21 | | - operations: ["CREATE", "UPDATE"] |
22 | | - resources: ["deployments"] |
23 | | - matchConditions: |
24 | | - - name: has-kata-runtime |
25 | | - expression: >- |
26 | | - has(object.spec.template.spec.runtimeClassName) && |
27 | | - (object.spec.template.spec.runtimeClassName == "kata" || object.spec.template.spec.runtimeClassName == "kata-cc") |
28 | | - - name: has-initdata-configmap-annotation |
29 | | - expression: >- |
30 | | - has(object.spec.template.metadata.annotations) && |
31 | | - 'coco.io/initdata-configmap' in object.spec.template.metadata.annotations && |
32 | | - object.spec.template.metadata.annotations['coco.io/initdata-configmap'] != '' |
33 | | - - name: no-existing-cc-init-data |
34 | | - expression: >- |
35 | | - !has(object.spec.template.metadata.annotations) || |
36 | | - !('io.katacontainers.config.hypervisor.cc_init_data' in object.spec.template.metadata.annotations) |
37 | | - variables: |
38 | | - - name: configMapName |
39 | | - expression: "object.spec.template.metadata.annotations['coco.io/initdata-configmap']" |
40 | | - - name: configMap |
41 | | - expression: >- |
42 | | - namespaceObject.get('configmaps', variables.configMapName) |
43 | | - mutations: |
44 | | - - patchType: JSONPatch |
45 | | - jsonPatch: |
46 | | - expression: >- |
47 | | - [ |
48 | | - JSONPatch{ |
49 | | - op: "add", |
50 | | - path: "/spec/template/metadata/annotations/io.katacontainers.config.hypervisor.cc_init_data", |
51 | | - value: variables.configMap.data['INITDATA'] |
52 | | - } |
53 | | - ] |
| 18 | + rules: |
| 19 | + - name: inject-initdata |
| 20 | + match: |
| 21 | + any: |
| 22 | + - resources: |
| 23 | + kinds: |
| 24 | + - Pod |
| 25 | + operations: |
| 26 | + - CREATE |
| 27 | + preconditions: |
| 28 | + all: |
| 29 | + - key: "{{ "{{" }}request.object.spec.runtimeClassName || '' {{ "}}" }}" |
| 30 | + operator: AnyIn |
| 31 | + value: ["kata", "kata-cc"] |
| 32 | + - key: "{{ "{{" }}request.object.metadata.annotations.\"coco.io/initdata-configmap\" || '' {{ "}}" }}" |
| 33 | + operator: NotEquals |
| 34 | + value: "" |
| 35 | + - key: "{{ "{{" }}request.object.metadata.annotations.\"io.katacontainers.config.hypervisor.cc_init_data\" || '' {{ "}}" }}" |
| 36 | + operator: Equals |
| 37 | + value: "" |
| 38 | + context: |
| 39 | + - name: initdata |
| 40 | + configMap: |
| 41 | + name: "{{ "{{" }}request.object.metadata.annotations.\"coco.io/initdata-configmap\"{{ "}}" }}" |
| 42 | + namespace: "{{ "{{" }}request.namespace{{ "}}" }}" |
| 43 | + mutate: |
| 44 | + patchStrategicMerge: |
| 45 | + metadata: |
| 46 | + annotations: |
| 47 | + io.katacontainers.config.hypervisor.cc_init_data: "{{ "{{" }}initdata.data.INITDATA{{ "}}" }}" |
0 commit comments