ServiceAccounts which have the ability to edit/patch workloads which they created may potentially use that privilege to update to a different ServiceAccount with higher privileges. This policy, intended to be run in `enforce` mode, blocks updates to Pod controllers if those updates modify the serviceAccountName field. Updates to Pods directly for this field are not possible as it is immutable once set.
apiVersion: kyverno.io/v1kind: ClusterPolicymetadata:name: restrict-pod-controller-serviceaccount-updatesannotations:policies.kyverno.io/title: Restrict Pod Controller ServiceAccount Updatespolicies.kyverno.io/category: Otherpolicies.kyverno.io/severity: Mediumpolicies.kyverno.io/subject: Podkyverno.io/kyverno-version: 1.9.0kyverno.io/kubernetes-version: "1.24"policies.kyverno.io/description: ServiceAccounts which have the ability to edit/patch workloads which they created may potentially use that privilege to update to a different ServiceAccount with higher privileges. This policy, intended to be run in `enforce` mode, blocks updates to Pod controllers if those updates modify the serviceAccountName field. Updates to Pods directly for this field are not possible as it is immutable once set.spec:validationFailureAction: Auditbackground: truerules:- name: block-serviceaccount-updatesmatch:any:- resources:kinds:- DaemonSet- Deployment- Job- StatefulSet- ReplicaSet- ReplicationControllerpreconditions:all:- key: "{{ request.operation }}"operator: Equalsvalue: UPDATEvalidate:message: The serviceAccountName field may not be changed once created.deny:conditions:all:- key: "{{ request.object.spec.template.spec.serviceAccountName || 'empty'}}"operator: NotEqualsvalue: "{{ request.oldObject.spec.template.spec.serviceAccountName || 'empty'}}"- name: block-serviceaccount-updates-cronjobmatch:any:- resources:kinds:- CronJobpreconditions:all:- key: "{{ request.operation }}"operator: Equalsvalue: UPDATEvalidate:message: The serviceAccountName field may not be changed once created.deny:conditions:all:- key: "{{ request.object.spec.jobTemplate.spec.template.spec.serviceAccountName || 'empty'}}"operator: NotEqualsvalue: "{{ request.oldObject.spec.jobTemplate.spec.template.spec.serviceAccountName || 'empty'}}"
This policy performs some best practices validation on Application fields. Path or chart must be specified but never both. And destination.name or destination.server must be specified but never both.
This policy prevents the use of the default project in an Application.
This policy prevents updates to the project field after an Application is created.