How to Configure OpenHands Kubernetes Prevent Delete

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up an openhands kubernetes prevent delete workflow by scoping down cluster roles. You must remove delete verbs from the agent role and bind only safe actions. Many teams start by giving their AI agent broad cluster admin rights for testing. When an agent holds broad rights, one bad prompt can wipe out production pods. Even a minor loop in the agent logic can drop whole namespaces by mistake. Fixing this requires strict role rules before the agent ever runs a command. How openhands kube

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 an openhands kubernetes prevent delete workflow by scoping down cluster roles. You must remove delete verbs from the agent role and bind only safe actions. Many teams start by giving their AI agent broad cluster admin rights for testing. When an agent holds broad rights, one bad prompt can wipe out production pods. Even a minor loop in the agent logic can drop whole namespaces by mistake. Fixing this requires strict role rules before the agent ever runs a command.

How openhands kubernetes prevent delete works with native roles

Kubernetes uses role-based access control to check every API call an agent makes. In this model, a Role or ClusterRole holds a list of allowed rules. These rules are purely additive, which means there are no explicit deny rules. You cannot attach a block rule on top of an existing admin role. Instead, you must build a fresh role from scratch for the OpenHands agent.

To stop deletions, you list only read, create, or update verbs in the role. You leave out the delete and deletecollection verbs on pods, deployments, and services. A Role sets these rules inside one single namespace to limit the blast radius. A ClusterRole works across the whole cluster and covers cluster-scoped items like nodes. You then connect the agent identity to the role with a RoleBinding or ClusterRoleBinding. When the API server gets a request, it checks the rbac.authorization.k8s.io API group. If the agent tries to remove a pod, the server blocks the call.

Managing subresources and agent execution paths

Preventing resource deletion through the main API is only the first step for teams. AI agents often need to read pod logs or run commands inside containers. Kubernetes treats these deeper actions as subresources that sit under the main pod object. The RBAC system names each subresource using a slash, such as pods/log for logs. Another common subresource allows running commands inside a running container.

If you grant access to that execution subresource, the agent can open a shell. While RBAC stops the agent from deleting the pod itself, the shell keeps the session active. Inside that container shell, the agent can still delete files or stop processes. Also, restricting specific resource names on create calls only works for top-level resources. It does not restrict subresources in the same way during creation calls. Teams must be very careful when granting subresource permissions to automated coding agents.

Kubernetes RBAC + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native RBAC solves and what it leaves open

Native Kubernetes roles do a great job of locking down the cluster API boundary. They verify who can log in and which API endpoints that user can call. If an agent lacks the delete verb, it cannot drop a deployment via API. This stops the most obvious accidents before they harm your cluster state.

Still, static role setup leaves a big operational gap during daily engineering work. Sometimes an agent needs to restart a stuck pod or clean up test jobs. With additive RBAC, you must either grant delete rights all the time or never. Native roles also cannot inspect the exact commands an agent sends inside a session. They do not mask sensitive data like emails, phone numbers, or card numbers. If a pod log holds national IDs, standard RBAC returns the raw log text. Teams need a way to check individual commands in flight and rewrite sensitive results.

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 add a deny rule to block delete actions in Kubernetes RBAC?

No, Kubernetes RBAC permissions are purely additive and do not support deny rules. To block deletions, you must create a new role that leaves out delete verbs.

Should I use a Role or a ClusterRole for an OpenHands agent?

Use a Role with a RoleBinding to keep the agent inside one single namespace. Use a ClusterRole only when the agent must read resources across all namespaces.

Does removing the delete verb stop an agent from breaking an app?

No, an agent with update or subresource execution rights can still change live state. It can scale replicas to zero or run destructive shell commands inside a pod.

The query runs. The emails stay hidden.