From c86e28815e7f8c1e43e00306652226e67226373e Mon Sep 17 00:00:00 2001 From: Anubhav Sharma <40705688+anubhav888@users.noreply.github.com> Date: Fri, 6 Sep 2024 13:46:56 -0700 Subject: [PATCH] Create restrict-add-other-users-to-rolebinding --- .../restrict-add-other-users-to-rolebinding | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 rbac-best-practices/restrict-add-other-users-to-rolebinding diff --git a/rbac-best-practices/restrict-add-other-users-to-rolebinding b/rbac-best-practices/restrict-add-other-users-to-rolebinding new file mode 100644 index 00000000..fdc5ed1c --- /dev/null +++ b/rbac-best-practices/restrict-add-other-users-to-rolebinding @@ -0,0 +1,38 @@ +apiVersion: kyverno.io/v1 +kind: ClusterPolicy +metadata: + name: restrict-add-other-users-to-rolebinding + annotations: + policies.kyverno.io/title: Restrict Users from Adding other User to their Rolebinding + policies.kyverno.io/category: Security, EKS Best Practices + policies.kyverno.io/severity: medium + policies.kyverno.io/subject: ClusterRole, Role, RBAC + kyverno.io/kyverno-version: 1.7.0 + policies.kyverno.io/minversion: 1.6.0 + kyverno.io/kubernetes-version: "1.23" + policies.kyverno.io/description: >- + Restrict users from adding other users to their rolebindings. +spec: + validationFailureAction: audit + rules: + - name: restrict-add-rolebinding + match: + any: + - resources: + kinds: + - Role + validate: + deny: + conditions: + all: + - key: "{{ request.object.rules[].resources[] }}" + operator: AnyIn + value: rolebindings + - key: "{{ request.object.rules[].verbs[] }}" + operator: AnyIn + value: + - get + - patch + - key: "{{ contains(request.object.rules[].apiGroups[], '*') }}" + operator: Equals + value: true