All Policies
Restrict Auto-Mount of Service Account Tokens
Kubernetes automatically mounts ServiceAccount credentials in each Pod. The ServiceAccount may be assigned roles allowing Pods to access API resources. Blocking this ability is an extension of the least privilege best practice and should be followed if Pods do not need to speak to the API server to function. This policy ensures that mounting of these ServiceAccount tokens is blocked.
Policy Definition
/other/restrict_automount_sa_token.yaml
1apiVersion: kyverno.io/v1
2kind: ClusterPolicy
3metadata:
4 name: restrict-automount-sa-token
5 annotations:
6 policies.kyverno.io/title: Restrict Auto-Mount of Service Account Tokens
7 policies.kyverno.io/category: Sample
8 policies.kyverno.io/severity: medium
9 policies.kyverno.io/subject: Pod
10 policies.kyverno.io/description: >-
11 Kubernetes automatically mounts ServiceAccount credentials in each Pod.
12 The ServiceAccount may be assigned roles allowing Pods to access API resources.
13 Blocking this ability is an extension of the least privilege best practice and should
14 be followed if Pods do not need to speak to the API server to function.
15 This policy ensures that mounting of these ServiceAccount tokens is blocked.
16spec:
17 rules:
18 - name: validate-automountServiceAccountToken
19 match:
20 resources:
21 kinds:
22 - Pod
23 validate:
24 message: "Auto-mounting of Service Account tokens is not allowed."
25 pattern:
26 spec:
27 automountServiceAccountToken: false