How to Configure K3s Exec Into Pod

Published
Length
3 min read

Luis Felipe Dias

All posts

To run a k3s exec into pod session, you grant role permissions for the pod exec subresource. Then your client talks to the cluster API server to open a shell inside the container. Teams often share broad admin keys so engineers can debug live apps fast. This common habit gives every user full control over all workloads on the node. How a native k3s exec into pod workflow operates K3s packs the core Kubernetes control plane into a single small binary. When an engineer starts a shell session, t

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 run a k3s exec into pod session, you grant role permissions for the pod exec subresource. Then your client talks to the cluster API server to open a shell inside the container. Teams often share broad admin keys so engineers can debug live apps fast. This common habit gives every user full control over all workloads on the node.

How a native k3s exec into pod workflow operates

K3s packs the core Kubernetes control plane into a single small binary. When an engineer starts a shell session, the client sends a request to the API server. The server checks the user identity and looks up the matching role rules. You must define a role that allows creating the pod exec subresource in that namespace.

A role binding links that specific role to a user or a team group. Once the API server approves the request, it talks to the local node agent. The node agent opens an interactive stream to the target container runtime. Standard input and output then flow between the user terminal and the running container process.

To keep this setup clean, admins scope roles down to single namespaces. You can also limit the role to specific pod names in your rule definitions. Still, pod names change every time you deploy a new version of an app. Because of this, most teams allow shell sessions across all pods in a given namespace.

What native role rules solve and what they miss

Native role rules do a great job of deciding who can enter a container. They stop unauthorized users from opening a shell in namespaces they do not own. They also let you separate read-only log viewers from engineers who need interactive shells. Cluster audit logs will record the exact time a user starts a pod session.

Still, native role controls stop working the moment the shell session opens. The cluster API server knows who started the session, but not what they type next. Native audit logs only show that an exec connection happened on a specific pod. They do not capture the individual commands run inside that shell or the output returned.

Inside the container, the user assumes the full rights of the container process. If the container runs as root, the user gets root power inside that space. They can read local secret files, change app settings, or query attached databases. A simple check of a failing app can turn into an untracked production change.

K8s Pod Security Standards + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Why static cluster keys create extra risk for teams

K3s creates a master admin file on the host when the server starts up. Many teams copy this file to developer laptops to speed up daily debugging work. Once that file leaves the server, you cannot track who uses it to run commands. Every action looks like it came from the same system admin account.

Revoking that master key requires a cluster restart and breaks existing automation scripts. Even when teams create individual user keys, those files often stay valid for months. If a laptop goes missing, anyone with that file can open a pod shell. Teams need a way to inspect commands in flight and mask sensitive output data.

For example, a support engineer might check a pod log that prints user emails. A live shell might also return phone numbers, card numbers, or national IDs on screen. Native cluster roles cannot rewrite those matched fields in results before they reach the user.

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

How do I let a user run commands in just one namespace?

Create a namespace role that grants create and get verbs on pods and pod exec resources. Then link that role to the user account with a role binding in that same namespace.

Why does my pod shell session fail even when I can view pods?

Viewing pods only requires the get and list verbs on the main pod resource. Opening a shell requires extra permission to create the pod exec subresource in your role rules.

Does K3s log the commands someone types inside a container shell?

No, native cluster audit logs only record that a user opened an exec stream to a pod. The cluster does not log the shell commands or screen output inside that stream.

The query runs. The emails stay hidden.