In some cases you would need to trust custom CA certificates for all the containers of a Pod. It makes sense to be in a ConfigMap so that you can automount them by only setting an annotation. This policy adds a volume to all containers in a Pod containing the certificate if the annotation called `inject-certs` with value `enabled` is found.
apiVersion: policies.kyverno.io/v1alpha1kind: MutatingPolicymetadata:name: add-certificates-volumeannotations:policies.kyverno.io/title: Add Certificates as a Volumepolicies.kyverno.io/category: Samplepolicies.kyverno.io/subject: Pod,Volumekyverno.io/kyverno-version: 1.6.0kyverno.io/kubernetes-version: "1.21"policies.kyverno.io/minversion: 1.5.0policies.kyverno.io/description: In some cases you would need to trust custom CA certificates for all the containers of a Pod. It makes sense to be in a ConfigMap so that you can automount them by only setting an annotation. This policy adds a volume to all containers in a Pod containing the certificate if the annotation called `inject-certs` with value `enabled` is found.spec:autogen:podControllers:controllers:- daemonsets- deployments- jobs- statefulsetsevaluation:admission:enabled: truematchConstraints:resourceRules:- apiGroups:- ""apiVersions:- v1operations:- CREATE- UPDATEresources:- podsmatchConditions:- name: check-inject-certs-annotationexpression: has(object.metadata.annotations) && "inject-certs" in object.metadata.annotations && object.metadata.annotations["inject-certs"] == "enabled"mutations:- patchType: ApplyConfigurationapplyConfiguration:expression: |Object{spec: Object.spec{containers: object.spec.containers.map(container, Object.spec.containers{name: container.name,volumeMounts: (has(container.volumeMounts) && container.volumeMounts.exists(vm, vm.name == "etc-ssl-certs"))? container.volumeMounts: ((has(container.volumeMounts) ? container.volumeMounts : []) + [Object.spec.containers.volumeMounts{name: "etc-ssl-certs",mountPath: "/etc/ssl/certs"}])}),volumes: (has(object.spec.volumes) && object.spec.volumes.exists(v, v.name == "etc-ssl-certs"))? object.spec.volumes: ((has(object.spec.volumes) ? object.spec.volumes : []) + [Object.spec.volumes{name: "etc-ssl-certs",configMap: Object.spec.volumes.configMap{name: "ca-pemstore"}}])}}
The Kubernetes cluster autoscaler does not evict pods that use hostPath or emptyDir volumes. To allow eviction of these pods, the annotation cluster-autoscaler.kubernetes.io/safe-to-evict=true must be added to the pods.
Tiller, found in Helm v2, has known security challenges. It requires administrative privileges and acts as a shared resource accessible to any authenticated user. Tiller can lead to privilege escalation as restricted users can impact other users. It is recommended to use Helm v3+ which does not contain Tiller for these reasons. This policy validates that there is not an image containing the name `tiller`.
The Kubernetes cluster autoscaler does not evict pods that use hostPath or emptyDir volumes. To allow eviction of these pods, the annotation cluster-autoscaler.kubernetes.io/safe-to-evict=true must be added to the pods.