How to Configure OpenHands Kubernetes Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up openhands kubernetes least privilege, bind a single-namespace role to the agent identity. You must limit that role to exact verbs and resources instead of cluster-wide rights. Teams often start by giving AI coding agents broad cluster permissions to avoid permission errors. That shortcut lets an automated agent change or delete workloads across every namespace. How openhands kubernetes least privilege works in RBAC Kubernetes role-based access control uses additive rules to grant pe

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 openhands kubernetes least privilege, bind a single-namespace role to the agent identity. You must limit that role to exact verbs and resources instead of cluster-wide rights. Teams often start by giving AI coding agents broad cluster permissions to avoid permission errors. That shortcut lets an automated agent change or delete workloads across every namespace.

How openhands kubernetes least privilege works in RBAC

Kubernetes role-based access control uses additive rules to grant permissions. There are no deny rules in this system. You start with zero access and add only the exact actions the agent needs. A Role sets permissions inside one specific namespace. A ClusterRole sets permissions across the whole cluster or for cluster-scoped items like nodes.

For an AI agent, you should create a Role inside one target namespace. Then you link that Role to the agent service account with a RoleBinding. A RoleBinding grants permissions inside that single namespace only. Even if you reference a reusable ClusterRole, the RoleBinding keeps access inside that namespace. Avoid using a ClusterRoleBinding because it grants access across the entire cluster.

You also need to control subresources in your role rules. Kubernetes APIs use subresources for actions like reading pod logs or running commands inside pods. In role rules, you write these with a slash, such as pods and log. If the agent only needs to read logs, grant read rights on the log subresource. Do not grant pod exec subresource rights unless the agent must run shell commands.

Where native RBAC stops and runtime risks begin

Native Kubernetes roles solve the first step of access control. They decide which service account or user can call a specific API endpoint. They also keep an agent inside its assigned namespace and block cluster-wide changes. This setup stops an agent from touching other teams or reading secrets in other namespaces.

Still, native role rules only check the API verb and the resource type. Once you grant pod exec or secret read permissions, RBAC steps out of the way. It does not inspect the actual shell commands the agent runs inside a container. It also does not filter the data returned from a log stream or command output. If pod logs contain customer emails, phone numbers, or card numbers, the raw text flows back. A scoped role decides who can enter the pod, not what commands run in flight.

Least Privilege Principle + Kubernetes RBAC: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Scoping subresources and service accounts for agents

When you build the role for your agent, separate read actions from write actions. Start by listing only the core resources the agent must inspect, such as pods. Grant read-only verbs like get, list, and watch on those items first. If the agent must debug a failing app, add the pod log subresource. Keep write verbs like create, update, patch, and delete out of the base role.

Watch out for how Kubernetes handles resource names in role rules. You can limit a role to specific resource names for standard read and update verbs. Still, resource name restrictions on create actions apply only to top-level resources, not subresources. Because pod exec uses a subresource, you must manage exec permissions with extra care. Give each agent task its own service account so you can revoke access fast.

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 HTTP proxy, a sidecar for your Kubernetes API. The kubectl client changes only the server address it talks to while RBAC stays in place.

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. On the way back, hoop.dev data masking walks JSON responses by key and masks matched values in Secrets, ConfigMaps, and pod logs. Every request and verdict is logged without storing bearer tokens. View the project on GitHub.

Frequently asked questions

Should I use a RoleBinding or a ClusterRoleBinding for OpenHands?

Always use a RoleBinding for the agent service account. A RoleBinding keeps permissions inside one namespace, while a ClusterRoleBinding exposes the whole cluster.

Can I use deny rules in Kubernetes RBAC to block specific pods?

No, Kubernetes RBAC permissions are purely additive and do not support deny rules. You must grant only the exact resources and verbs the agent needs to use.

How do I let OpenHands read pod logs without full pod control?

Grant read permissions on the pods log subresource in your namespace Role. Leave out the pods exec subresource and write verbs so the agent only reads logs.

The query runs. The emails stay hidden.