All Policies
Block Pod Exec by Namespace Name
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 to Pods in a Namespace called `pci`.
Policy Definition
/other/block-pod-exec-by-namespace.yaml
1apiVersion: kyverno.io/v1
2kind: ClusterPolicy
3metadata:
4 name: deny-exec-by-namespace-name
5 annotations:
6 policies.kyverno.io/title: Block Pod Exec by Namespace Name
7 policies.kyverno.io/category: Sample
8 policies.kyverno.io/minversion: 1.6.0
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 to Pods in a Namespace called `pci`.
14spec:
15 validationFailureAction: enforce
16 background: false
17 rules:
18 - name: deny-exec-ns-pci
19 match:
20 any:
21 - resources:
22 kinds:
23 - PodExecOptions
24 preconditions:
25 all:
26 - key: "{{ request.operation || 'BACKGROUND' }}"
27 operator: Equals
28 value: CONNECT
29 validate:
30 message: Pods in this namespace may not be exec'd into.
31 deny:
32 conditions:
33 any:
34 - key: "{{ request.namespace }}"
35 operator: Equals
36 value: pci