Back to Policies

Restrict ClusterRole with Nodes Proxy in ValidatingPolicy

A ClusterRole with nodes/proxy resource access allows a user to perform anything the kubelet API allows. It also allows users to bypass the API server and talk directly to the kubelet potentially circumventing audits and admission controllers. See https://blog.aquasec.com/privilege-escalation-kubernetes-rbac for more info. This policy prevents the creation of a ClusterRole if it contains the nodes/proxy resource.

View on GitHub

Policy Definition

apiVersion: policies.kyverno.io/v1alpha1
kind: ValidatingPolicy
metadata:
name: restrict-clusterrole-nodesproxy
annotations:
policies.kyverno.io/title: Restrict ClusterRole with Nodes Proxy in ValidatingPolicy
policies.kyverno.io/category: Sample in Vpol
policies.kyverno.io/severity: medium
policies.kyverno.io/subject: ClusterRole, RBAC
kyverno.io/kyverno-version: 1.14.0
policies.kyverno.io/minversion: 1.14.0
kyverno.io/kubernetes-version: "1.30"
policies.kyverno.io/description: "A ClusterRole with nodes/proxy resource access allows a user to perform anything the kubelet API allows. It also allows users to bypass the API server and talk directly to the kubelet potentially circumventing audits and admission controllers. See https://blog.aquasec.com/privilege-escalation-kubernetes-rbac for more info. This policy prevents the creation of a ClusterRole if it contains the nodes/proxy resource. "
spec:
validationActions:
- Audit
evaluation:
background:
enabled: true
matchConstraints:
resourceRules:
- apiGroups:
- rbac.authorization.k8s.io
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- clusterroles
validations:
- expression: object.rules == null || !object.rules.exists(rule, rule.resources.exists(resource, resource == 'nodes/proxy') && rule.apiGroups.exists(apiGroup, apiGroup == ''))
message: A ClusterRole containing the nodes/proxy resource is not allowed.

Related Policies