How to Configure OpenHands Kubernetes Credentials
You set up openhands kubernetes credentials by mounting a scoped cluster token into the agent container. You then bind that token to a narrow role inside one target namespace. Most teams start by giving the agent a broad admin file to test tasks fast. That shortcut creates risk because an autonomous agent can change or delete live workloads across namespaces. A safer setup gives the agent only the exact API rules it needs for its task. How openhands kubernetes credentials work with native role
Ephemeral Credentials + Kubernetes RBAC: the complete guide
Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.
You set up openhands kubernetes credentials by mounting a scoped cluster token into the agent container. You then bind that token to a narrow role inside one target namespace. Most teams start by giving the agent a broad admin file to test tasks fast. That shortcut creates risk because an autonomous agent can change or delete live workloads across namespaces. A safer setup gives the agent only the exact API rules it needs for its task.
How openhands kubernetes credentials work with native roles
OpenHands runs tasks inside a sandbox container that acts like a developer workstation. When the agent needs to check pods or deploy apps, it uses standard cluster tools. You pass credentials into this workspace as a file or environment variable. The cluster API server reads this token on every call the agent makes.
Kubernetes role-based access control uses pure additive rules to manage what that token can do. There are no deny rules in this system. You start with zero rights and add allowed verbs for each resource type. A Role sets permissions inside one single namespace. A ClusterRole sets permissions across the whole cluster or for cluster-wide items like nodes.
To keep the agent contained, you create a Role in the target workspace namespace. You then link that Role to the agent service account with a RoleBinding. If you use a ClusterRoleBinding instead, the agent gets rights across every namespace in the cluster. For most coding and debugging tasks, a single namespace RoleBinding is the right choice.
You also have to watch out for subresources in the API. Reading pod logs or running commands inside a pod uses subresources like pod logs or exec. In Kubernetes rules, you write these with a slash after the main resource name. If you grant exec rights, the agent can open a shell inside any pod allowed by that rule.
Why static role files leave a runtime gap
Native roles do a great job of deciding who can call a cluster endpoint. They block an agent from touching namespaces or resource types outside its RoleBinding. Still, native roles only check the resource type and the action verb at the API door. They do not inspect the payload of a command or the contents of a log stream.
Once an agent has rights to run exec commands in a pod, it can run anything inside. A static role cannot tell a safe status check apart from a destructive shell command. The same gap happens when the agent reads pod logs or config maps during a fix. Those outputs often hold emails, phone numbers, card numbers, or national IDs from live traffic. Native cluster roles send that raw text straight into the agent workspace and model prompt.
Ephemeral Credentials + Kubernetes RBAC: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Storing a static credential file inside the agent sandbox also creates a secret management problem. Because the agent can run shell scripts in its own workspace, it can read its own token file. If a prompt goes wrong, the agent might print that token into a log or pull request. Teams need a way to keep raw keys out of the sandbox and inspect commands in flight.
Scoping agent permissions for daily tasks
Start by splitting agent tasks into read-only checks and write actions. For an agent that only investigates bugs, grant read verbs on pods, events, and pod logs. Leave out rights to read secrets or run exec commands inside running containers. This stops the agent from pulling database keys or running arbitrary code in live pods.
When an agent needs to deploy code, scope its RoleBinding to a staging namespace first. Grant rights to update deployments and services only in that test space. Rotate the service account token often and remove the binding when the task finishes. Clear boundaries let your team use coding agents without risking the whole cluster.
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
Can I restrict an OpenHands agent to a single Kubernetes namespace?
Yes, you can restrict the agent by creating a Role and a RoleBinding inside one namespace. Avoid using a ClusterRoleBinding so the agent token has no rights in other namespaces.
How do I let OpenHands read pod logs without giving it shell access?
Grant the get and list verbs on the pods log subresource in your Role rules. Leave the pods exec subresource out of the Role so the agent cannot open container shells.
Why should I avoid mounting a static admin config file into the agent container?
An agent can read files inside its own workspace and might leak a static token in logs. Using an admin file also lets a bad command delete resources across the whole cluster.
Related guides
In this post