How to Configure Kubernetes Role Binding

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a kubernetes role binding by linking a role to a user or group. This link gives those users permission to act inside one specific namespace. Many teams start by giving broad cluster roles to speed up work. Broad permissions let one bad command break apps or expose secret data across the cluster. How a kubernetes role binding works Kubernetes uses its built-in role system to control who can talk to the API server. You turn this mode on at the API server level. The system uses four m

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 a kubernetes role binding by linking a role to a user or group. This link gives those users permission to act inside one specific namespace. Many teams start by giving broad cluster roles to speed up work. Broad permissions let one bad command break apps or expose secret data across the cluster.

How a kubernetes role binding works

Kubernetes uses its built-in role system to control who can talk to the API server. You turn this mode on at the API server level. The system uses four main objects to manage permissions across your cluster. First, a role holds a list of rules for one single namespace. Second, a cluster role holds rules that work across the whole cluster. Cluster roles can cover cluster-wide items like nodes, or namespaced items like pods.

Rules in this system only add permissions. There are no deny rules in Kubernetes role setups. Every user starts with zero permissions until you bind them to a role. A kubernetes role binding connects a role to a subject, like a user or service account. This binding only gives permissions inside the namespace where you create it.

You can also point a namespace role binding at a cluster role. That trick lets you write one common rule set and reuse it in many namespaces. Each binding still keeps the user locked to that one single namespace. If a user needs permissions in every namespace at once, you use a cluster role binding instead.

Setting up rules for pods and subresources

When you write role rules, you name the exact API objects and actions allowed. Standard actions include reading, creating, updating, or deleting objects like pods and services. Kubernetes also splits some features into smaller parts called subresources. For example, reading pod logs or running a shell inside a pod uses subresources.

If you only allow reading pods, the user still cannot view logs or open a shell. You must list the log or exec subresource in the role rules too. Admins can also limit rules to specific object names using the resource names field. That way, a team can only touch the exact pods they own.

Session Binding to Device + Role-Based Access Control (RBAC): architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native bindings solve and what they miss

Native role bindings do a great job of gating entry at the API server door. They check who the user is and which API paths they can call. This setup stops developers from deleting namespaces or reading secrets they do not own. It keeps teams in their own lanes during normal daily work.

Still, native bindings stop checking once the API call opens a live session. When a role allows the pod exec subresource, the user gets an open shell inside the container. Kubernetes does not check the individual shell commands that run inside that session. It also does not filter the data that prints back to the user screen.

If a container holds database keys or customer emails, the user can read them in full. Native audit logs record that an exec session started, not what happened inside it. Teams often need fine control over live sessions and sensitive output fields like phone numbers or card numbers.

Add request guardrails and response masking beside Kubernetes

Cluster roles and service accounts govern who reaches the Kubernetes API. Still, a broad role or agent can delete workloads or print sensitive values from ConfigMaps and logs. In practice, hoop.dev sits inline beside the API server as a sidecar for your Kubernetes API. For every production API call an agent or human sends, hoop.dev decides whether to pass, mask, block, or escalate it for review alongside RBAC.

With hoop.dev Kubernetes controls, guardrails allow listing Secret names while refusing reads of Secret data before execution, and data masking redacts matched keys in returned JSON responses and log streams in memory. Furthermore, hoop.dev holds SOC 2 Type II and is MIT licensed on GitHub.

Frequently asked questions

What is the difference between a role binding and a cluster role binding?

A role binding grants permissions inside one specific namespace only. A cluster role binding grants permissions across all namespaces and cluster-wide nodes at once.

Can I use a deny rule in a Kubernetes role?

No, Kubernetes role permissions are purely additive and never use deny rules. To block an action, you must remove the rule or delete the binding.

How do I let a user run commands inside a pod?

You must add the pod exec subresource to the role rules, then bind that role to the user. Giving basic pod read permissions alone does not allow shell sessions.

The query runs. The emails stay hidden.