How to Configure Dify Kubernetes Prevent Delete
To set up dify kubernetes prevent delete rules, give Dify a custom role without delete verbs. You bind this role to the Dify account in one namespace. Many teams start by giving Dify broad cluster rights to move fast. Broad roles let automated workflows or bad prompts wipe out live pods and data. Scoping down permissions stops Dify from removing cluster objects by mistake. How native dify kubernetes prevent delete rules work Kubernetes uses Role-Based Access Control, or RBAC, to check every A
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 dify kubernetes prevent delete rules, give Dify a custom role without delete verbs. You bind this role to the Dify account in one namespace. Many teams start by giving Dify broad cluster rights to move fast. Broad roles let automated workflows or bad prompts wipe out live pods and data. Scoping down permissions stops Dify from removing cluster objects by mistake.
How native dify kubernetes prevent delete rules work
Kubernetes uses Role-Based Access Control, or RBAC, to check every API request. In this system, permissions only add rights to an account. There are no explicit deny rules in native Kubernetes RBAC. If you want to block deletes, you must build a role from scratch. You list only the safe actions that Dify needs to run.
First, you create a dedicated service account for your Dify app. Next, you define a Role inside the target namespace. A Role always sets rules within one single namespace. For cluster-wide objects like nodes, you would use a ClusterRole instead. Most teams keep Dify inside one namespace to limit blast radius.
In your Role definition, you name the resources Dify can touch, such as pods. Then you list the allowed verbs, like get, list, watch, create, and update. You leave out the delete and deletecollection verbs on purpose. Finally, you create a RoleBinding in that same namespace. The RoleBinding links your Dify service account to the restricted Role. When Dify sends a delete request, the API server sees no matching verb and blocks it.
What native RBAC solves and what it misses
Native RBAC is great at blocking direct API calls that remove whole objects. If a Dify workflow tries to delete a pod, the API server rejects it. It also blocks Dify from wiping out services or config maps through the API. This stops the most obvious kind of cluster loss.
Still, RBAC only checks who makes the call and which API verb they use. It cannot inspect what happens inside an allowed request in flight. For example, Dify often needs rights to run commands inside pods or update configs. In Kubernetes RBAC, running commands in a pod uses a subresource. Once you grant create rights on that subresource, RBAC steps aside.
Kubernetes RBAC + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
A Dify agent can then open a shell inside a running pod. From that shell, the agent can erase files or drop tables inside a database. RBAC sees a valid subresource call, not the destructive shell command inside it. Also, one Dify service account usually serves many different users and workflows. Kubernetes only sees the shared Dify account, not the human who triggered the run. Native roles cannot pause a risky command to ask a human for approval. They also cannot rewrite sensitive fields like emails, phone numbers, card numbers, or national IDs in pod logs.
Why shared service accounts create blind spots
When Dify connects to a cluster, every builder shares the same underlying credentials. You must give that one account enough rights to handle every valid workflow. If one workflow needs to edit deployments, every workflow gets that same power. A bad prompt can shrink a deployment down to zero replicas. Technically, this is an update action, not a delete action. Native RBAC allows the update, even though it takes your app offline.
To stay safe, teams need a way to check individual commands in real time. You need to see which user triggered the Dify workflow before a command runs. You also need to block destructive shell scripts even when pod access is allowed.
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 an explicit deny rule for deletes in Kubernetes RBAC?
No, Kubernetes RBAC rules are purely additive and have no deny rules. To block deletes, you must omit the delete verb from every Role bound to Dify.
Should I use a Role or a ClusterRole for Dify?
Use a Role and a RoleBinding when Dify only works inside one namespace. Use a ClusterRole only if Dify must read or change cluster-wide resources like nodes.
Does blocking the delete verb stop Dify from erasing data inside a pod?
No, blocking the delete verb only stops API calls that remove the pod object. If Dify has pod exec rights, it can still run shell commands that delete files.
Related guides
In this post