How to Configure Mastra Kubernetes Prevent Delete
You set up a mastra kubernetes prevent delete workflow by using custom RBAC roles. You must leave out delete verbs from the agent role rules. Teams often give AI agents broad cluster roles during early tests. Those broad roles let an agent wipe pods, services, or whole namespaces by mistake. A safer setup grants only read or update rules to the agent identity. How a mastra kubernetes prevent delete setup works Kubernetes uses Role and ClusterRole objects to hold sets of permission rules. Thes
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 mastra kubernetes prevent delete workflow by using custom RBAC roles. You must leave out delete verbs from the agent role rules. Teams often give AI agents broad cluster roles during early tests. Those broad roles let an agent wipe pods, services, or whole namespaces by mistake. A safer setup grants only read or update rules to the agent identity.
How a mastra kubernetes prevent delete setup works
Kubernetes uses Role and ClusterRole objects to hold sets of permission rules. These rules are additive, which means there are no deny rules in RBAC. To stop an agent from deleting items, you never grant the delete verb. You start with a clean Role inside a single namespace. A Role sets permissions within that one namespace only.
If your Mastra agent needs cluster-wide reach, you use a ClusterRole instead. A ClusterRole covers cluster-scoped items like nodes, or namespaced items across all namespaces. Once you define the allowed verbs, you link the role to the agent. A RoleBinding grants permissions inside one specific namespace. A ClusterRoleBinding grants those permissions across the whole cluster.
You also need to watch subresources in the API URL. RBAC names resources the exact same way they appear in the API path. For example, reading pod logs uses a subresource written with a slash. If you allow pod execution subresources, an agent can run shell commands inside containers. Keep subresource rules tight so the agent only reads status and logs.
Why native roles are not enough for agent actions
Native RBAC roles decide which identity can call a specific API endpoint. They work well when an agent only needs to read pod status. Still, real operations often require the agent to fix broken workloads. Fixing a workload might require permission to restart a pod or update a deployment. In Kubernetes, restarting a pod often means deleting it so the controller makes a new one.
Because RBAC has no deny rules, you face a hard choice. If you leave out the delete verb, the agent cannot restart a stuck pod. If you add the delete verb, the agent can delete every pod in that namespace. Native RBAC cannot check why an agent wants to delete a pod. It also cannot ask a human to approve a single delete call in flight.
Kubernetes RBAC + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
How to scope agent permissions across namespaces
Start by listing every task your Mastra workflow will run in the cluster. Group these tasks into read actions and write actions. Create a dedicated service account for the Mastra agent in its target namespace. Bind that account to a Role that only contains read verbs like get and list. Never reuse default admin roles or shared human accounts for an automated agent.
When an agent needs to run commands or remove a single stuck pod, pause. Check if you can limit the rule to specific resource names. Keep in mind that resource name limits have gaps on create calls for subresources. For high-risk verbs like delete or exec, static roles leave your cluster exposed. You need a way to check and approve each risky command before it runs.
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 write a deny rule in Kubernetes RBAC to block deletes?
No, Kubernetes RBAC permissions are purely additive and do not support deny rules. To block deletes, you must build a role that omits the delete verb.
What is the difference between a RoleBinding and a ClusterRoleBinding for Mastra?
A RoleBinding grants permissions inside one namespace, even if it references a ClusterRole. A ClusterRoleBinding grants permissions across all namespaces and cluster-scoped resources.
Why are pod subresources risky when configuring Mastra agents?
Subresources like pod exec let an agent run commands inside a running container. Even without delete permissions on pods, an agent could delete files inside the container.
Related guides
In this post