How to Configure Kubernetes Least Privilege
You set up kubernetes least privilege by creating narrow RBAC roles and binding them to specific namespaces. You grant only the exact API actions and resources each person or service needs. Most teams start by handing out broad cluster admin roles during early testing. Those wide permissions often stay in place when workloads move to production. When roles are too broad, one bad command can affect every namespace in the cluster. How native kubernetes least privilege works Kubernetes controls
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You set up kubernetes least privilege by creating narrow RBAC roles and binding them to specific namespaces. You grant only the exact API actions and resources each person or service needs. Most teams start by handing out broad cluster admin roles during early testing. Those wide permissions often stay in place when workloads move to production. When roles are too broad, one bad command can affect every namespace in the cluster.
How native kubernetes least privilege works
Kubernetes controls permissions through its native Role-Based Access Control system. The API server checks these rules every time a user or service sends a request. Permissions in this system are additive, which means there are no deny rules. You start with zero rights and add only the rules required for a task.
To keep rights narrow, you choose between two types of roles. A standard Role sets permissions inside a single namespace. A ClusterRole sets permissions across the whole cluster. A ClusterRole can cover cluster-wide objects like nodes or namespaced objects across all namespaces.
Once you define a role, you attach it to a user or group with a binding. A RoleBinding grants permissions inside one namespace. You can point a RoleBinding at a standard Role in that same namespace. You can also point a RoleBinding at a shared ClusterRole. When you do this, the user gets those ClusterRole rights only inside that one namespace. This pattern lets admins maintain one common set of read or edit rules while keeping teams isolated. By contrast, a ClusterRoleBinding grants rights across the entire cluster and should be rare.
Fine-grained setup also requires attention to subresources. The API server treats actions like reading pod logs or running commands inside a pod as subresources. In RBAC rules, you write these with a slash, such as pods and log or pods and exec. Giving a team permission to view pods does not let them read logs or open a shell. You must list those subresources in the role if the user needs them. Keeping exec rights out of standard developer roles stops users from opening shells in live containers.
Least Privilege Principle + Kubernetes RBAC: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native RBAC solves and what it misses
Native RBAC is great at deciding who can call which API endpoint in a given namespace. It blocks unauthorized users from deleting workloads, reading secret objects, or touching other teams' namespaces. Setting up namespace roles and subresource rules removes most standing cluster admin rights.
Still, native RBAC stops at the API check. Once a user has permission to run pod exec, Kubernetes does not inspect the shell commands they run inside the container. In the same way, if a role allows reading secrets or logs, RBAC returns the full payload. It cannot mask sensitive values like emails, phone numbers, card numbers, or national IDs inside command output. Native roles also remain static until someone edits or deletes the binding. When engineers need temporary shell rights to fix an outage, teams must manually create and later clean up bindings. Without controls on active commands and output data, valid roles can still expose sensitive records or allow risky shell actions.
Check Kubernetes API requests and responses on the wire
Kubernetes RBAC decides who may call the API server. RBAC does not check response payloads or split listing Secret names from reading Secret values when a role grants get access. With hoop.dev, you run an open-source proxy, a sidecar for your Kubernetes API, inline on the API connection. On every kubectl or API call an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
On each call, hoop.dev guardrails read the method, normalized path, and headers to refuse bad deletes or full Secret reads with a 403 error, or hold risky calls for approval. On the way back, hoop.dev data masking walks JSON responses by key and masks matched values in Secrets, ConfigMaps, and pod logs in memory. View the project on GitHub.
Frequently asked questions
What is the difference between a RoleBinding and a ClusterRoleBinding?
A RoleBinding grants permissions inside a single namespace. A ClusterRoleBinding grants permissions across all namespaces and cluster-wide objects. For least privilege, use RoleBindings whenever a team only works in specific namespaces.
Can I write a deny rule in Kubernetes RBAC?
No, Kubernetes RBAC rules are only additive. You cannot write a rule that subtracts permissions from a broader role. Instead, you must build smaller roles from scratch and grant only the required verbs and resources.
How do I stop users from running shell commands in pods?
Remove the pods and exec subresource from their Role or ClusterRole definitions. Users can still view pod status and read logs if you grant the pods resource and the pods and log subresource.
Related guides
In this post