How to Configure Gemini CLI Kubernetes Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up gemini cli kubernetes read only access by binding a view role to the agent identity. You then point the local cluster config to that restricted account before starting the session. Many teams let their AI coding tools use an engineer's existing workstation credentials. That local context often holds admin rights across key namespaces. If the AI assistant runs a bad command, it can delete pods or change live settings. Scoping permissions down to read actions stops the agent from changi

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 read only access by binding a view role to the agent identity. You then point the local cluster config to that restricted account before starting the session. Many teams let their AI coding tools use an engineer's existing workstation credentials. That local context often holds admin rights across key namespaces. If the AI assistant runs a bad command, it can delete pods or change live settings. Scoping permissions down to read actions stops the agent from changing cluster state.

Setting up gemini cli kubernetes read only access with RBAC

Kubernetes uses role-based rules to control what users and apps can do on the API server. Rules in this system only add permissions, and there are no deny rules at all. You start with zero rights and add only the exact read verbs the agent needs. A Role sets permissions inside one single namespace. A ClusterRole sets permissions across the whole cluster or for resources that have no namespace. To let the terminal agent check workloads, you create a role that allows read verbs. These read verbs let the caller get, list, and watch resources like pods and deployments.

Next, you link that role to the identity that the AI tool uses on the machine. A RoleBinding grants those permissions inside one specific namespace. A ClusterRoleBinding grants the rules across every namespace in the cluster. A RoleBinding can also reference a ClusterRole to keep the permissions inside one namespace. When the terminal agent runs a cluster command, it uses the local config file. The API server checks the bound role and lets read requests pass while blocking changes.

Scoping subresources and secret objects in the cluster

Letting an AI agent read everything in a namespace still carries real risk. In Kubernetes, broad read rules can expose sensitive objects if you are not careful. If a role allows reading secret objects, the agent can pull raw keys into its prompt context. Those secret values then get sent to the external model provider during the chat session. You should build a custom role that leaves secret objects out of the allowed list.

You also need to plan how the role handles API subresources like pod logs. In Kubernetes RBAC, subresources appear in the API path with a slash after the main resource. You grant access to pod logs separately from the pod object itself. This lets the agent read app logs to find bugs without getting exec permissions. Keeping the exec subresource off the role stops the agent from opening a shell inside running containers.

Auditor Read-Only Access + Kubernetes API Server Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Where native cluster roles fall short in daily use

Native cluster roles decide which API objects an identity can read or change at login time. They do not inspect the actual data returning inside a permitted read request. An AI agent with access to pod logs can still pull sensitive customer data from stdout. When an app prints emails, phone numbers, or card numbers to logs, the agent reads them. That private data enters the model context along with the error trace.

Managing static local credentials for every developer machine also creates extra work for platform teams. Engineers often switch back to their admin profiles when they need to fix an issue fast. If they forget to switch back, the AI terminal agent inherits those full write rights again. Also, standard cluster logs only record the API call path and the service account name. They do not tie the specific AI prompt to the exact cluster command that ran.

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 Kubernetes RBAC block a single resource with a deny rule?

No, Kubernetes RBAC permissions are purely additive and do not support deny rules. To block access to secret objects, you must leave them out of the role definition.

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

Use a RoleBinding whenever possible to keep the agent inside a single target namespace. You can bind a shared read ClusterRole with a RoleBinding to limit access to one namespace.

Does pod read access let Gemini CLI view container logs automatically?

No, container logs live under a separate API subresource from the main pod object. Your role must include the pod log subresource explicitly so the agent can read app output.

The query runs. The emails stay hidden.