Kubectl Exec Interactive

Published
Length
3 min read

Luis Felipe Dias

All posts

You run a kubectl exec interactive session to open a live shell inside a pod. This lets your team check running apps, read local files, and fix live bugs. Most teams grant this right through native role rules in the cluster. Still, broad role rules often let users run any command inside every container. That level of control creates clear operational and safety risks for your cluster. How a kubectl exec interactive session works When an engineer starts a kubectl exec interactive session, the

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 run a kubectl exec interactive session to open a live shell inside a pod. This lets your team check running apps, read local files, and fix live bugs. Most teams grant this right through native role rules in the cluster. Still, broad role rules often let users run any command inside every container. That level of control creates clear operational and safety risks for your cluster.

How a kubectl exec interactive session works

When an engineer starts a kubectl exec interactive session, the request hits the API server. The API server checks if the user has the right role to run commands. Kubernetes uses roles and bindings to manage these rights across the cluster. A standard role sets rules within a single namespace. A cluster role can set rules across every namespace at once. Both role types are purely additive, which means there are no deny rules.

To open a shell in a pod, a user needs permission on a subresource. Kubernetes names this subresource by joining the pod resource and the exec action. The role must allow the user to create an exec request on that subresource. A role binding then links that role to a specific user or group. Once the API server approves the request, it upgrades the network link. The user then gets a live stream for standard input and output.

How teams scope pod shell permissions

Good cluster admins do not give cluster-wide shell rights to every developer. Instead, they create separate roles for each team and each namespace. A role binding in a dev namespace keeps developers inside their own test pods. Admins can also restrict a role to specific pod names in that namespace. This stops a user from opening a shell in a neighbor pod.

Still, pod names change every time a deployment rolls out a new version. Because pod names change so often, name rules are hard to maintain. Most teams end up granting shell rights to all pods in a namespace. They rely on namespace walls to keep production data safe from mistakes.

Exec Interactive: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native role rules leave open

Native role rules do a great job of deciding who can enter a pod. They check the user identity and check the subresource rule before the shell starts. Still, the API server stops checking actions once the live shell is open. Native rules cannot tell a safe read command from a destructive delete command.

Inside an open shell, a user has the same rights as the container process. They can read local env vars, dump memory, or change app files on disk. They can also query internal databases if the pod holds database keys. Native cluster logs show that a user opened a shell on a pod. They do not show the exact shell commands or the text returned on screen. To control in-flight commands and mask sensitive fields like emails, teams need deeper controls.

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 runs beside the API server as a sidecar for your Kubernetes API and checks every request and response alongside RBAC.

With hoop.dev Kubernetes controls, guardrails can allow listing Secret names while refusing reads of Secret data before execution. 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 RBAC rule allows a user to open a pod shell?

A role must include the pods resource and the pods exec subresource. The user also needs permission to read the pod and create the exec session. You then link this role to the user with a role binding.

Can I block specific shell commands with Kubernetes RBAC?

No, Kubernetes RBAC only checks if a user can start the exec session. It cannot inspect or block individual shell commands typed inside the open stream. Also, RBAC is purely additive and has no deny rules for commands.

Why do pod name limits fail for exec rules?

Kubernetes adds random text to pod names when a deployment creates new pods. If you lock a role to a fixed pod name, the rule breaks after deploys. Teams must update the role every time a pod restarts with a new name.

The query runs. The emails stay hidden.