Kubectl Exec Interactive Shell
You open a kubectl exec interactive shell by asking the API server for a terminal inside a running pod. The API server checks your role and streams your input and output to the container. Teams often grant broad cluster roles so developers can fix broken apps fast. When roles are too broad, anyone can run commands inside live pods and read private keys. How a kubectl exec interactive shell works in Kubernetes Kubernetes uses Role-Based Access Control to manage who can enter a container. The 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.
You open a kubectl exec interactive shell by asking the API server for a terminal inside a running pod. The API server checks your role and streams your input and output to the container. Teams often grant broad cluster roles so developers can fix broken apps fast. When roles are too broad, anyone can run commands inside live pods and read private keys.
How a kubectl exec interactive shell works in Kubernetes
Kubernetes uses Role-Based Access Control to manage who can enter a container. The API server checks rules inside its authorization group before starting any session. A Role sets permissions inside one single namespace. A ClusterRole sets permissions across the whole cluster and covers all namespaces. You link these rules to users or groups with a RoleBinding or a ClusterRoleBinding.
All permissions in Kubernetes are additive, which means there are no deny rules. You start with zero access and add rules for each action you need. To open a shell, a user needs permission for the pod exec subresource. Kubernetes names subresources with a slash to match the API path, like pod logs or pod exec.
When a user asks for a shell, the client sends a request to the API server. The server checks if the user's bound role allows actions on the pod exec subresource. If the rule matches, the server upgrades the connection and opens a stream to the node. The user can now type commands right into the running container.
What native RBAC solves and what it leaves open
Native Kubernetes roles are great at deciding who can start a container session. You can lock down a namespace so only one team can enter its pods. You can also use a RoleBinding to limit a ClusterRole to one namespace. This stops engineers from jumping into pods owned by other teams.
Still, native RBAC stops checking once the shell stream opens. The API server knows who started the session, but it does not inspect what happens next. Inside the container, the user runs with the permissions of the container process itself. If that process runs as root, the user has root power inside the pod.
Exec Interactive Shell: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Also, RBAC rules cannot restrict subresource creation to a single named pod very well. The resource names filter on create actions works only on top-level resources, not subresources. Once a user has pod exec rights in a namespace, they can often enter any pod there. Also, the shell stream can print sensitive data like emails, phone numbers, or card numbers right to the screen.
Why teams limit open shell sessions in production
An open shell lets an engineer run any binary installed inside the container image. A user might read mounted secret files or query an internal database from the pod. Native audit logs record that an exec session started, along with the user and pod name. They do not record the exact shell commands typed or the text printed back.
When an outage happens, teams cannot tell which shell command changed a file or broke a process. Security teams also worry about raw customer data appearing in terminal output. Without command inspection or data masking that rewrites matched fields in results, every interactive session carries high risk. Teams need control over individual commands and output in flight, not just initial login checks.
Govern kubectl and API calls in flight
Identity providers and Kubernetes RBAC decide who logs into a cluster. They cannot redact keys inside returned JSON objects or hold a risky delete call for review. By design, hoop.dev runs as an open-source proxy, a sidecar for your Kubernetes API, checking requests and responses without replacing RBAC.
First, hoop.dev guardrails refuse banned methods, paths, or headers before they run. Next, hoop.dev data masking rewrites sensitive keys in returned Secret, ConfigMap, and log responses in memory, and writes each decision to the audit trail. Explore the repo on GitHub.
Frequently asked questions
What RBAC rule grants access to open a pod shell?
You must grant permission for the pods exec subresource inside a Role or ClusterRole. Then you bind that role to the user with a RoleBinding or ClusterRoleBinding.
Can I write a deny rule in Kubernetes RBAC to block shell access?
No, Kubernetes RBAC permissions are purely additive and do not support deny rules. To block shell access, you must remove the pods exec rule from the user's bound roles.
Does Kubernetes log the commands typed inside an interactive shell?
No, the Kubernetes API server only logs the initial request to open the exec subresource. It does not capture the standard input or output stream after the session starts.
Related guides
In this post