How to Configure LangChain Kubernetes Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up langchain kubernetes read only access by binding a read role to an agent account. This setup lets your AI agent inspect cluster state and read logs without changing workloads. Many teams start by giving their agent a broad admin role to test prompts fast. That shortcut creates a major risk when a model runs a bad tool call. If an agent holds write rights, one bad prompt can delete pods or read secrets. Scoping down the role early stops the model from breaking live apps. How to set u

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 langchain kubernetes read only access by binding a read role to an agent account. This setup lets your AI agent inspect cluster state and read logs without changing workloads. Many teams start by giving their agent a broad admin role to test prompts fast. That shortcut creates a major risk when a model runs a bad tool call. If an agent holds write rights, one bad prompt can delete pods or read secrets. Scoping down the role early stops the model from breaking live apps.

How to set up langchain kubernetes read only access with RBAC

Kubernetes uses role-based rules to control what users and apps can do on the server. All rules in this system are additive, which means there are no deny rules. You start with zero rights and add only the exact actions your agent needs. A Role sets permissions inside one single namespace for a specific team or app. A ClusterRole sets permissions across all namespaces or for cluster-wide items like nodes.

To keep your AI agent safe, create a dedicated service account for the tool. Next, define a Role that only allows read verbs like get, list, and watch. You should limit the target resources to safe items like pods, deployments, and services. Do not include secrets in the resource list for your read role. If a role allows reading secrets, the agent can pull database keys into its prompt.

Once the role is ready, you link it to the agent account with a RoleBinding. A RoleBinding grants those read rules inside one chosen namespace. If your agent must check workloads in every namespace, you use a ClusterRoleBinding instead. Most teams should stick to a single namespace RoleBinding to limit the blast radius. Your LangChain tool then uses that account token to talk to the cluster API. The API server checks every request from the tool against those additive rules.

Handling subresources like pod logs and exec

Reading pod state is often not enough when an agent needs to debug a crash. The agent also needs to read app output from the pod log subresource. In Kubernetes, the API groups subresources under the main resource using a slash path. You must add the pod log subresource to your Role so the agent can read logs.

At the same time, you must leave the pod exec subresource out of the role. The exec subresource lets a caller run shell commands inside a running container. Even if a user only has read rights on pods, exec rights allow live changes. A model with exec access can alter files or call internal services from the pod. Keeping exec out of the role ensures the agent stays read only.

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

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Why native RBAC leaves gaps for AI agents

Native cluster roles decide who can call an API endpoint, not what data comes back. Once the API server allows a log read, it sends the full text to LangChain. App logs often hold sensitive user data from recent requests or errors. Those log lines can include emails, phone numbers, card numbers, or national IDs. When the tool reads those logs, that raw data flows straight into the model prompt.

Static roles also require teams to manage long-lived tokens for each agent app. If an engineer shares a kubeconfig file with the agent, the tool inherits their personal rights. Native RBAC also logs requests at the API level without linking them to the user prompt. Security teams can see that a service account read a pod log. Still, they cannot see which user or agent run triggered that check. Teams also lack a way to rewrite sensitive fields in log output before the model reads them.

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 Kubernetes RBAC block an AI agent from reading secrets?

Yes, Kubernetes RBAC is additive and starts with no access by default. If you leave secrets out of the Role rules, the API server blocks secret reads.

Should I use a Role or a ClusterRole for a LangChain agent?

Use a Role and a RoleBinding when the agent only checks one namespace. Use a ClusterRole and ClusterRoleBinding only when the agent must inspect nodes or all namespaces.

Why do pod logs still create a risk with read only access?

Read rights on pod logs return every line printed by the container. If the app logs emails, phone numbers, or card numbers, the agent sends them to the model.

The query runs. The emails stay hidden.