How to Configure Claude Code Kubernetes Prevent Delete

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up claude code kubernetes prevent delete rules by scoping cluster roles and shell permissions. You must omit delete verbs from the role that the agent uses to run commands. Many teams start by letting the coding agent use a local admin profile on a developer laptop. When a role is too broad, one bad prompt can wipe out live pods or namespaces. How claude code kubernetes prevent delete works in native RBAC Claude Code reaches external systems through its Bash tool or through Model Cont

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 claude code kubernetes prevent delete rules by scoping cluster roles and shell permissions. You must omit delete verbs from the role that the agent uses to run commands. Many teams start by letting the coding agent use a local admin profile on a developer laptop. When a role is too broad, one bad prompt can wipe out live pods or namespaces.

How claude code kubernetes prevent delete works in native RBAC

Claude Code reaches external systems through its Bash tool or through Model Context Protocol servers. When it uses the Bash tool, it runs shell commands from your local machine. Those shell commands use whatever cluster credentials sit on the host machine at that moment. If you use an MCP server, the server connects to your tools and APIs for the agent.

On the cluster side, native Kubernetes RBAC controls what a user or service account can do. A Role sets rules inside one namespace, while a ClusterRole covers resources across the whole cluster. A RoleBinding grants those rules inside one namespace, and a ClusterRoleBinding grants them across the cluster. In Kubernetes RBAC, rules are additive only, and there are no deny rules at all.

Because there are no deny rules, you cannot add a block rule on top of admin access. Instead, you must build a fresh Role or ClusterRole from scratch for the coding agent. You list only read verbs or safe write verbs and leave out delete verbs across all resources. Then you bind that restricted role to the identity that the agent uses for cluster calls.

Where native shell approvals and cluster roles help

In Manual mode, the Claude Code Bash tool asks for human approval before it runs shell commands. It only skips approval for a small built-in set of read-only commands like listing files. This manual step lets an engineer check a cluster command before the agent runs it. Combining manual shell approval with a scoped cluster role stops many basic mistakes during daily work.

Scoped roles also help when the agent reads subresources to debug a broken app. In Kubernetes RBAC, subresources like pod logs or pod exec use a slash in the resource name. You can grant read rules on pod logs without granting write or delete rules on pods. This lets the agent read logs and check status while keeping destructive actions off limits.

Claude Code Security + Kubernetes RBAC: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Operational gaps in static roles and local approvals

Static RBAC roles and local shell prompts still leave big gaps during real incidents. First, local shell prompts rely on a human reading every command string before clicking approve. During a long session, engineers get tired and approve shell commands out of habit. If the local kubeconfig holds broad rights, one missed flag can still drop a live workload.

Second, static roles are hard to tune when an agent needs to fix a live bug. If you lock the role down to read-only, the agent cannot restart a stuck pod or patch a config. If you grant write verbs so it can fix bugs, those rights keeps the session active all day. Native RBAC decides who can log in and call an API, not whether one command is safe now.

Third, pod exec rules let a user run commands inside a running container. Even without cluster delete rights, a shell inside a pod can delete files or drop data. Static cluster roles cannot inspect what happens inside an exec stream or mask sensitive fields like emails. Teams also struggle to audit which prompt caused which cluster command across many developer machines.

Govern kubectl and API calls in flight

Identity providers and Kubernetes RBAC decide who logs into a cluster. They cannot redact keys inside returned JSON objects or hold a risky delete call for review. By design, hoop.dev sits inline as an open-source proxy, a sidecar for your Kubernetes API, without replacing RBAC. On every production call from an engineer or AI agent, hoop.dev decides to pass, mask, block, or hold it for human approval.

First, hoop.dev guardrails refuse banned methods, paths, or headers before they run or hold risky deletes for review. Next, hoop.dev data masking rewrites sensitive keys in returned Secret, ConfigMap, and log responses in memory, and writes each decision to the audit trail. Explore the repo on GitHub.

Frequently asked questions

Can I add a deny rule in Kubernetes RBAC to block delete commands?

No, Kubernetes RBAC rules are additive only and do not support deny rules. To stop deletes, you must assign a new role that leaves out delete verbs.

How does Claude Code run Kubernetes commands on my cluster?

The agent runs cluster commands through its Bash tool or through a connected MCP server. In Manual mode, the Bash tool asks for your approval before running non-read shell commands.

Does blocking pod delete also block running commands inside a pod?

No, pod exec is a separate subresource in Kubernetes RBAC. You must omit the pod exec subresource from the role if you want to block container shells.

The query runs. The emails stay hidden.