How to Configure Gemini CLI Kubernetes Prevent Delete
To set up a gemini cli kubernetes prevent delete rule, you restrict the agent role. You give the terminal identity read or write verbs while leaving out delete actions. Engineering teams often connect command-line AI agents straight to their local cluster contexts. When that local profile holds broad admin rights, one bad prompt can wipe out workloads. The agent inherits every permission that the local user holds in the terminal session. If the user can remove namespaces or pods, the AI tool can
Kubernetes RBAC + End-to-End Encryption: the complete guide
Architecture patterns, implementation strategies, and security best practices. Delivered to your inbox.
To set up a gemini cli kubernetes prevent delete rule, you restrict the agent role. You give the terminal identity read or write verbs while leaving out delete actions. Engineering teams often connect command-line AI agents straight to their local cluster contexts. When that local profile holds broad admin rights, one bad prompt can wipe out workloads. The agent inherits every permission that the local user holds in the terminal session. If the user can remove namespaces or pods, the AI tool can do it too.
How a gemini cli kubernetes prevent delete setup works
Kubernetes uses role-based rules to control what users and tools can do. In this system, permissions are additive, and there are no explicit deny rules. You cannot attach a block rule on top of an existing admin profile. Instead, you must build a new role from scratch that only lists safe verbs. You grant view or update rights and leave out the verb that removes objects.
A standard role sets permissions inside one single namespace at a time. A cluster role covers the whole cluster, including nodes and items across all namespaces. Once you define the allowed verbs, you bind that role to a specific identity. A role binding applies those rules inside one namespace for the chosen user. A cluster role binding gives that identity access across the entire cluster at once.
To keep the AI tool from dropping items, give it a dedicated user identity. You bind that identity to a role that only allows viewing logs and pods. Kubernetes tracks subresources like pod logs using a slash format in the API path. You can allow log reads without giving the agent permission to remove the pod. When the agent tries to drop a resource, the API server rejects the call.
What native roles solve and what they leave open
Static cluster roles do a great job of blocking destructive API calls up front. If an identity lacks the verb to remove a deployment, the server stops it. This protects your cluster from direct mistakes when the agent guesses the wrong command. It also separates the AI tool from the human engineer's full admin profile. Teams can let the tool read pod status without risking a dropped namespace.
Still, static roles only check who logs in and which broad verb they use. They do not inspect the payload of an allowed command while it runs. For example, an engineer might need the agent to fix live apps or pods. If you grant permission to update a deployment, the agent can still break things. It could change the image tag to a broken build or scale replicas down.
Kubernetes RBAC + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Subresources like pod exec create another big blind spot for static role rules. If a role allows exec calls, the agent can run shell commands inside containers. The cluster API server only checks if the user can open that exec channel. It cannot see or block destructive shell commands running inside the container itself. Static roles also require teams to manage extra credentials on every developer laptop. Most engineers skip switching profiles and run the AI tool with their normal keys. That brings back the exact risk you tried to remove in the first place.
Why local agent credentials create risk
Command-line AI agents run in the local shell and read local config files. Any static token saved on disk is open to the agent during a task. If the tool misreads a prompt, it fires the command before anyone can react. Even with local confirmation prompts, engineers get tired and approve commands too fast. Relying on human review in a terminal window is not a safe control.
Teams also lack a clear log linking a specific AI prompt to cluster changes. The cluster log only shows the static identity that sent the API request. It cannot tell if a human typed the command or if an agent did. When an incident happens, responders waste time figuring out what changed the cluster state. You need controls that inspect each command in flight rather than trusting static profiles.
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 proxy, a sidecar for your Kubernetes API, inline on the API connection. On every kubectl or API call an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
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, or hold risky calls for approval. On the way back, hoop.dev data masking walks JSON responses by key and masks matched values in Secrets, ConfigMaps, and pod logs in memory. View the project on GitHub.
Frequently asked questions
Can I add a deny rule to an existing Kubernetes admin role?
No, Kubernetes role permissions are only additive and do not support deny rules. To block delete actions, you must create a new role that leaves out delete verbs.
How does Gemini CLI authenticate to a Kubernetes cluster?
The tool runs commands in your local shell and uses your active cluster config. It inherits the exact permissions and tokens assigned to your current local user profile.
Does blocking pod deletion stop an agent from breaking an app?
No, an agent with update or exec rights can still break a running app. It can scale replicas to zero or run destructive shell commands inside a container.
Related guides
In this post