How to Configure OpenHands Kubernetes Guardrails

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up openhands kubernetes guardrails by giving the agent a strict role in one namespace. You then bind that role to the service account of the agent. Many teams start by giving their automated coding agent broad cluster rights to fix build bugs. When a role is too wide, the agent can delete pods or read secret keys across the whole cluster. A bad prompt or a simple mistake can take down live apps. How openhands kubernetes guardrails work with native roles To lock down an agent, you use

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 set up openhands kubernetes guardrails by giving the agent a strict role in one namespace. You then bind that role to the service account of the agent. Many teams start by giving their automated coding agent broad cluster rights to fix build bugs. When a role is too wide, the agent can delete pods or read secret keys across the whole cluster. A bad prompt or a simple mistake can take down live apps.

How openhands kubernetes guardrails work with native roles

To lock down an agent, you use native role-based access control on your cluster API server. In this system, a Role or a ClusterRole holds a set of rules. All rules are additive, which means there are no deny rules at all. You only state what the agent is allowed to do.

A standard Role sets rules inside one single namespace. A ClusterRole is not tied to one namespace. It can cover cluster-wide items like nodes, or resources across every namespace. For an automated agent, you should start with a standard Role in a test namespace. You then create a RoleBinding to link that Role to the user identity of the agent. If you used a ClusterRoleBinding instead, you would grant the agent access across the whole cluster.

You also have to control subresources in your rules. The cluster API uses a slash to name subresources, like the log subresource or the exec subresource of a pod. If an agent needs to read app output, you grant access to the log subresource. If the agent needs to run commands inside a container, it needs the exec subresource. You must add each subresource by name in the Role.

What native roles solve and what they miss

Native roles and bindings are great at controlling who can talk to the cluster API. They stop an agent in a test namespace from touching pods in a live namespace. They also block the agent from reading node data or changing cluster roles. If the agent tries to call an API route outside its Role, the API server blocks the request.

Kubernetes RBAC + AI Guardrails: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Still, native cluster rules only check the start of an API request. They do not inspect what happens inside a session once it opens. When you give an agent access to the pod exec subresource, the API server only checks if the agent can open the exec stream. Once that stream opens, the cluster does not check the shell commands that run inside the container. The agent can wipe local files, dump memory, or read app keys from the container disk.

Data exposure is another big gap with native roles. If an agent has permission to read pod logs, it receives the full text stream. Those logs might contain customer emails, phone numbers, card numbers, or national IDs. Native cluster roles cannot mask those fields in flight. A human review flow is also missing from standard roles. You cannot pause a single risky command for team approval without blocking all exec access. To close these gaps, teams need controls that work at the command and data level.

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

Can I write a deny rule in a Kubernetes Role for OpenHands?

No, native cluster roles do not support deny rules. Every permission rule is additive, so you must build a role from scratch and only include the exact actions the agent needs.

Should I use a RoleBinding or a ClusterRoleBinding for an AI agent?

You should use a RoleBinding in a single namespace. A RoleBinding keeps the agent inside that one namespace, while a ClusterRoleBinding gives the agent permissions across the entire cluster.

How do I let OpenHands read pod logs without giving it shell access?

You grant permission to the pod log subresource in your Role and leave out the pod exec subresource. This lets the agent read output streams without running commands inside the container.

The query runs. The emails stay hidden.