How to Configure Gemini CLI Kubernetes Permissions

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up gemini cli kubernetes permissions by assigning RBAC roles to the agent identity. These roles define which cluster objects and verbs the command line tool can use. Engineering teams often run AI agents with their own local kubeconfig files. This setup gives the agent the same broad rights as a human operator. When a role is too wide, a bad prompt can delete workloads or read secrets. Scoping down these rights is the first step toward safe cluster operations. How gemini cli kubernetes

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 gemini cli kubernetes permissions by assigning RBAC roles to the agent identity. These roles define which cluster objects and verbs the command line tool can use. Engineering teams often run AI agents with their own local kubeconfig files. This setup gives the agent the same broad rights as a human operator. When a role is too wide, a bad prompt can delete workloads or read secrets. Scoping down these rights is the first step toward safe cluster operations.

How gemini cli kubernetes permissions work in RBAC

The AI tool runs shell commands or calls external tools on your machine. When it interacts with a cluster, it uses the credentials active in your terminal session. Kubernetes checks these credentials against its native role-based access control system. In this system, all rules are additive, and there are no deny rules. You start with zero rights and add allowed actions one by one.

Kubernetes splits permissions into namespace roles and cluster-wide roles. A standard Role grants rights inside a single namespace. A ClusterRole grants rights across all namespaces or for cluster-wide objects like nodes. To attach these rules to the identity that the AI agent uses, you create a binding. A RoleBinding applies rules to one namespace, while a ClusterRoleBinding applies them everywhere. For a local AI helper, binding a role to a single test namespace limits mistakes.

You also need to control subresources. Kubernetes treats actions like reading pod logs or running commands inside a pod as subresources. In RBAC rules, these appear with a slash, such as the pod log or exec subresource. If you only grant read access to pods, the agent can see pod status. It cannot read app logs unless you also add the log subresource to the role.

Why you should restrict subresources and secrets

Giving an AI tool access to the exec subresource carries high risk. If the role allows pod execution, the agent can open a shell inside a running container. From there, it can run arbitrary commands, inspect mounted files, or reach internal networks. Most debugging tasks only need read access to pod status, events, and logs. Leaving the exec subresource out of the role stops the agent from altering live containers.

Secrets require similar care in your role definitions. If a role allows reading secrets in a namespace, the agent can fetch raw API keys. Those keys then enter the model prompt context and travel to the external model provider. You should keep secret objects out of the agent role whenever possible.

Kubernetes RBAC + AI Agent Permissions: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native RBAC solves and what it leaves open

Native Kubernetes RBAC solves the problem of who can reach which API endpoints. It stops an agent in a development namespace from deleting production deployments. It also blocks access to cluster nodes or sensitive object types like secrets.

Still, static RBAC rules only check the resource type and the action verb at login. They do not inspect what happens inside an allowed request in flight. For example, an agent often needs the log subresource to help fix an app bug. App logs frequently print customer emails, phone numbers, or card numbers during an error. Because RBAC allows the log read, all that sensitive text flows back to the AI agent.

The same gap appears when an engineer needs the agent to run a diagnostic command inside a pod. Once RBAC grants the exec subresource, it cannot check which shell command the agent runs inside. It also cannot ask a human to approve a risky command before it executes. Native roles are static gates, not live command filters or data scrubbers.

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 use a deny rule to block Gemini CLI from reading secrets?

No, Kubernetes RBAC is purely additive and does not support deny rules. To block secret access, you must leave secrets out of every role bound to the agent identity.

Should I use a RoleBinding or a ClusterRoleBinding for an AI agent?

Use a RoleBinding whenever possible so the agent can only act inside one specific namespace. You can bind a reusable ClusterRole to a single namespace by referencing it in a RoleBinding.

How do I let Gemini CLI read pod logs without giving it shell access?

Grant the get and list verbs on the pods resource and the pods log subresource. Do not include the pods exec subresource in the role definition.

The query runs. The emails stay hidden.