Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create deny-exec-by-pod-label #160

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions rbac-best-practices/deny-exec-by-pod-label
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: deny-exec-by-pod-label
annotations:
policies.kyverno.io/title: Block Pod Exec by Pod Label
policies.kyverno.io/category: Sample
policies.kyverno.io/minversion: 1.6.0
policies.kyverno.io/subject: Pod
policies.kyverno.io/description: >-
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 having the label `exec=false`.
spec:
validationFailureAction: enforce
background: false
rules:
- name: deny-exec-by-label
match:
any:
- resources:
kinds:
- Pod/exec
context:
- name: podexeclabel
apiCall:
urlPath: "/api/v1/namespaces/{{request.namespace}}/pods/{{request.name}}"
jmesPath: "metadata.labels.exec || ''"
preconditions:
all:
- key: "{{ request.operation || 'BACKGROUND' }}"
operator: Equals
value: CONNECT
validate:
message: Exec'ing into Pods protected with the label `exec=false` is forbidden.
deny:
conditions:
all:
- key: "{{ podexeclabel }}"
operator: Equals
value: "false"
Loading