All Policies
Block Pod Exec by Namespace Label
The `exec` command may be used to gain shell access, or run other commands, in a Pod's container. While this can be useful for troubleshooting purposes, it could represent an attack vector and is discouraged. This policy blocks Pod exec commands based upon a Namespace label `exec=false`.
Policy Definition
/other/block-pod-exec-by-namespace-label.yaml
1apiVersion: kyverno.io/v1
2kind: ClusterPolicy
3metadata:
4 name: deny-exec-by-namespace-label
5 annotations:
6 policies.kyverno.io/title: Block Pod Exec by Namespace Label
7 policies.kyverno.io/category: Sample
8 policies.kyverno.io/minversion: 1.4.2
9 policies.kyverno.io/subject: Pod
10 policies.kyverno.io/description: >-
11 The `exec` command may be used to gain shell access, or run other commands, in a Pod's container. While this can
12 be useful for troubleshooting purposes, it could represent an attack vector and is discouraged.
13 This policy blocks Pod exec commands based upon a Namespace label `exec=false`.
14spec:
15 validationFailureAction: audit
16 background: false
17 rules:
18 - name: deny-exec-by-ns-label
19 match:
20 resources:
21 kinds:
22 - PodExecOptions
23 context:
24 - name: nslabelexec
25 apiCall:
26 urlPath: "/api/v1/namespaces/{{request.namespace}}"
27 jmesPath: "metadata.labels.exec"
28 preconditions:
29 - key: "{{ request.operation }}"
30 operator: Equals
31 value: CONNECT
32 validate:
33 message: Executing a command in a container is forbidden for Pods running in Namespaces protected with the label "exec=false".
34 deny:
35 conditions:
36 - key: "{{ nslabelexec }}"
37 operator: Equals
38 value: "false"
39