Users may be able to specify any ServiceAccount which exists in their Namespace without restrictions. Confining Pods to a list of authorized ServiceAccounts can be useful to ensure applications in those Pods do not have more privileges than they should. This policy verifies that in the `staging` Namespace the ServiceAccount being specified is matched based on the image and name of the container. For example: 'sa-name: ["registry/image-name"]'
apiVersion: kyverno.io/v1kind: ClusterPolicymetadata:name: restrict-service-accountannotations:policies.kyverno.io/title: Restrict Service Accountpolicies.kyverno.io/category: Samplepolicies.kyverno.io/severity: mediumpolicies.kyverno.io/subject: Pod,ServiceAccountpolicies.kyverno.io/minversion: 1.6.0kyverno.io/kyverno-version: 1.6.2kyverno.io/kubernetes-version: "1.23"policies.kyverno.io/description: "Users may be able to specify any ServiceAccount which exists in their Namespace without restrictions. Confining Pods to a list of authorized ServiceAccounts can be useful to ensure applications in those Pods do not have more privileges than they should. This policy verifies that in the `staging` Namespace the ServiceAccount being specified is matched based on the image and name of the container. For example: 'sa-name: [\"registry/image-name\"]'"spec:validationFailureAction: Auditbackground: truerules:- name: validate-service-accountcontext:- name: saMapconfigMap:name: sa-mapnamespace: stagingmatch:any:- resources:kinds:- Podnamespaces:- stagingvalidate:message: Invalid service account {{ request.object.spec.serviceAccountName }} for image {{ images.containers.*.registry | [0] }}/{{ images.containers.*.name | [0] }}deny:conditions:any:- key: "{{ images.containers.*.registry | [0] }}/{{ images.containers.*.name | [0] }}"operator: AnyNotInvalue: "{{ saMap.data.\"{{ request.object.spec.serviceAccountName }}\" }}"
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.