How to Configure LangChain Kubernetes Prevent Delete
You set up a langchain kubernetes prevent delete rule by limiting the agent role verbs. You leave out the delete action when you write the cluster role for the agent. Many teams start by giving their AI agent a broad admin role to test tasks. This broad role lets the agent drop pods, services, or whole namespaces by mistake. A prompt error or model loop can wipe out live apps in seconds. How to set up langchain kubernetes prevent delete with roles Kubernetes uses role-based rules to control w
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 a langchain kubernetes prevent delete rule by limiting the agent role verbs. You leave out the delete action when you write the cluster role for the agent. Many teams start by giving their AI agent a broad admin role to test tasks. This broad role lets the agent drop pods, services, or whole namespaces by mistake. A prompt error or model loop can wipe out live apps in seconds.
How to set up langchain kubernetes prevent delete with roles
Kubernetes uses role-based rules to control what a user or service account can do. Every rule in this system is additive, which means there are no deny rules. You cannot attach a block rule on top of an existing admin role. Instead, you must build a fresh role from zero and list only safe actions.
First, you create a dedicated service account for your LangChain app or tool runner. Next, you define a Role for one namespace or a ClusterRole for the whole cluster. Inside that role, you list the exact resources the agent needs to check. Then you add read verbs like get, list, and watch to those resources. You leave delete and deletecollection out of the verb list so the API rejects removals.
Finally, you link the service account to the role with a RoleBinding or ClusterRoleBinding. Your LangChain tool uses this service account token when it talks to the cluster API. When the model tries to remove a pod, the API server blocks the call.
Why role rules alone miss risky agent actions
Native role rules decide which API calls a service account can make at login. They do a great job of blocking direct delete calls against top-level cluster objects. Still, AI agents often need more than basic read verbs to fix real issues. Teams often grant subresource permissions like pod exec so the agent can run checks inside containers.
Once an agent can run commands inside a pod, role verbs no longer inspect the commands. The API server only checks if the account can open the exec subresource session. It does not read the shell script or command string that LangChain sends next. An agent can still wipe local files or drop data inside the running container.
Kubernetes RBAC + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
The same gap appears when an agent can update or patch a live deployment. Changing a replica count to zero or breaking an image tag takes an app down. Static role files also force teams to maintain dozens of custom roles across many clusters. You cannot require a human check for one risky command while allowing safe commands in the same role.
How to separate read checks from write actions in agents
A safer pattern splits your LangChain tools into read tools and change tools. Give your default agent tool a role that only holds get, list, and watch verbs. This setup lets the chat model inspect logs and events without touching live state. Keep any write or patch verbs in a separate path that demands human review.
You should also limit roles to a single namespace with a RoleBinding whenever possible. Avoid ClusterRoleBindings unless the agent must read node status across the whole cluster. Also, watch out for secret read rules when agents inspect namespaces. If an agent reads cluster secrets or pod logs, sensitive emails or card numbers can leak into prompts.
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 runs as an open-source proxy, a sidecar for your Kubernetes API, checking requests and responses without replacing RBAC.
First, hoop.dev guardrails refuse banned methods, paths, or headers before they run. 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 to stop an admin LangChain agent from deleting pods?
No, Kubernetes permissions are only additive and do not support explicit deny rules. To block deletes, you must remove the admin binding and grant a new role without delete verbs.
What happens if a LangChain agent has pod exec access but no delete verb?
The agent cannot delete the pod object through the cluster API. Still, it can still run shell commands inside the container that erase files or stop processes.
Should I use a Role or a ClusterRole for a LangChain tool?
Use a Role and RoleBinding when the agent only works in one namespace. Use a ClusterRole only when the agent must inspect cluster-wide items like nodes or all namespaces.
Related guides
In this post