How to Configure Kubernetes Exec Into Pod

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up kubernetes exec into pod access, you grant a role on the pod exec subresource. You then bind that role to a user or group in your target namespace. Many teams take a shortcut and grant broad cluster admin roles during an outage. That approach gives engineers full control over every container and secret in the cluster. A safer design scopes permissions to one namespace and only the needed subresources. How kubernetes exec into pod permissions work in RBAC Kubernetes uses role-based a

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.

To set up kubernetes exec into pod access, you grant a role on the pod exec subresource. You then bind that role to a user or group in your target namespace. Many teams take a shortcut and grant broad cluster admin roles during an outage. That approach gives engineers full control over every container and secret in the cluster. A safer design scopes permissions to one namespace and only the needed subresources.

How kubernetes exec into pod permissions work in RBAC

Kubernetes uses role-based access control to check every request to the API server. Rules in this system are purely additive. There are no deny rules in native role definitions. You start with zero access and add specific verbs on specific resources.

A Role sets permissions inside a single namespace. A ClusterRole sets permissions across the whole cluster. To let an engineer run commands in a container, you do not grant full pod write rights. Instead, you target the exec subresource of the pod resource. Kubernetes writes subresources with a slash in the rule definition.

The user also needs permission to read the pod itself before starting a session. You create a Role that allows reading pods and creating the pod exec subresource. Next, you create a RoleBinding in that same namespace. The RoleBinding links your Role to a specific user, group, or service account. If you bind a ClusterRole with a RoleBinding, the access stays inside that one namespace. If you use a ClusterRoleBinding, the user gets exec access across every namespace in the cluster.

Why you should avoid broad roles for container debugging

Teams often attach built-in edit or admin roles when developers need to debug a live app. Those roles include permissions far beyond running a shell in a single container. They often allow deleting workloads, changing network rules, or reading sensitive store objects.

Because rules are additive, you cannot give a broad role and then subtract secret access. You must build a tight role from the ground up. Even within a single namespace, you may want to limit access to specific pod names. Kubernetes lets you list specific resource names on a pod exec subresource rule. This prevents an engineer from jumping into sibling pods that handle billing or auth tasks.

Kubernetes RBAC + K8s Pod Security Standards: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native RBAC solves and what it leaves open

Native role bindings do a great job deciding who can start a container session. The API server checks the user identity, checks the namespace role, and opens the stream. That stops unauthorized users at the front door of the cluster.

Still, RBAC stops checking once the exec stream opens. Native roles do not inspect what individual commands do inside the container during the session. An engineer with exec rights gets the same local permissions as the container process itself. They can read local files, dump memory, or print environment variables holding database keys. They can also query internal services and view unmasked emails, phone numbers, or card numbers. Standard cluster audit logs record that an exec session started on a pod. They do not capture the actual shell commands or output inside that stream. Teams that need command checks or data masking must look beyond native cluster roles.

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

Can I deny kubernetes exec into pod access for one specific container?

No, native Kubernetes RBAC rules are purely additive and do not support deny rules. You must grant access only to the exact namespaces and pod names the user needs.

What is the difference between a RoleBinding and a ClusterRoleBinding for exec access?

A RoleBinding limits pod exec permissions to a single namespace. A ClusterRoleBinding grants those pod exec permissions across every namespace in the entire cluster.

Does Kubernetes RBAC log the commands run inside an exec session?

No, native RBAC only checks if a user can open the pod exec subresource stream. It does not inspect or log the individual shell commands run inside the container.

The query runs. The emails stay hidden.