Description
pods/exec permits running commands inside a running container. In production namespaces, grant it only to accounts that need it for debugging.
Potential impact
The container’s runtime user and permissions limit what is accessible. Exposure can be greater when a workload uses a powerful service account or handles sensitive environment variables, files or tokens.
Remediation
Remove pods/exec from roles used by ordinary accounts. Use approved debugging procedures and accounts, and check the account’s other bindings for the same permission in that namespace.
Examples
The examples define two differently named Roles in my-namespace. Their RoleBindings are omitted.
Before
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: my-namespace
name: allow-exec
rules:
- apiGroups: [""]
resources: ["pods", "pods/exec"]
verbs: ["get", "list", "create"]
After
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
namespace: my-namespace
name: allow-exec-neg
rules:
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "create"]
The second role permits only get, list and create on Pods. Check that existing bindings no longer grant unwanted exec access and that Pod creation is still needed.