How to Configure LangChain Kubernetes Permissions
You set up langchain kubernetes permissions by creating a narrow Role and binding it to your agent. Then your agent uses that account to call the cluster API. Many teams start by giving an AI agent a broad cluster role so tests pass right away. That shortcut lets a bad prompt delete workloads, read secrets, or run commands across every namespace. How to set up langchain kubernetes permissions with RBAC Kubernetes controls API calls through Role-Based Access Control, or RBAC. In RBAC, rules ar
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 permissions by creating a narrow Role and binding it to your agent. Then your agent uses that account to call the cluster API. Many teams start by giving an AI agent a broad cluster role so tests pass right away. That shortcut lets a bad prompt delete workloads, read secrets, or run commands across every namespace.
How to set up langchain kubernetes permissions with RBAC
Kubernetes controls API calls through Role-Based Access Control, or RBAC. In RBAC, rules are always additive, and there are no deny rules. You start with zero access and add only the actions your agent needs. A Role sets permissions inside a single namespace. A ClusterRole sets permissions across the whole cluster, including nodes and all namespaces.
To keep your LangChain agent contained, place its target workloads in one dedicated namespace. Create a Role in that namespace instead of a ClusterRole. List the exact resources the agent can touch, such as pods or deployments. Next, pick the verbs the agent needs, like get, list, or watch for read-only tasks. Avoid giving write verbs like create, delete, or patch unless the agent must change state.
Once the Role exists, you attach it to the agent identity with a RoleBinding. A RoleBinding grants the permissions inside that single namespace. You can also reference a shared ClusterRole inside a RoleBinding to scope it to one namespace. By contrast, a ClusterRoleBinding gives access across the entire cluster, which most AI agents do not need. When your LangChain tool runs, it presents its token to the API server, which checks these bindings.
Handling subresources like pod logs and exec
Many LangChain agents help teams debug failing apps by reading logs or checking running containers. In Kubernetes RBAC, features like pod logs and container command execution are subresources. The API refers to them using a slash between the main resource and the subresource. If an agent only has permission to read pods, it still cannot read pod logs.
You must add the log subresource to your Role so the agent can fetch container output. The same rule applies when an agent runs a shell command inside a container. That action uses the exec subresource, which is risky to give to an automated model. If you allow exec access, the agent can run any binary inside that container. For most triage tasks, grant access to pod status and pod logs while leaving exec off.
Kubernetes RBAC + AI Agent Permissions: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Where native RBAC stops and runtime risks begin
Native RBAC does a good job of deciding which API endpoints an identity can call. It checks the user or account, the verb, and the target resource on each request. Still, RBAC cannot inspect the contents of a command or the payload returned to the model. Once a role grants access to a resource or subresource, every allowed call goes through.
This gap matters when a LangChain agent has permission to run exec commands or read pod logs. If the agent can use the exec subresource, RBAC cannot block dangerous shell commands inside the container. Similarly, pod logs often contain sensitive customer details like emails, phone numbers, card numbers, or national IDs. Native Kubernetes roles return the full log stream without rewriting sensitive strings in the output. Teams also lack a clear link between the user prompt and the resulting cluster action.
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 HTTP proxy, a sidecar for your Kubernetes API. The kubectl client changes only the server address it talks to while RBAC stays in place.
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. On the way back, hoop.dev data masking walks JSON responses by key and masks matched values in Secrets, ConfigMaps, and pod logs. Every request and verdict is logged without storing bearer tokens. View the project on GitHub.
Frequently asked questions
Should a LangChain agent use a Role or a ClusterRole?
Use a Role whenever your agent works inside one namespace. A Role limits blast radius to that namespace, while a ClusterRole can reach across the whole cluster. You can also bind a ClusterRole with a RoleBinding to keep permissions inside a single namespace.
Can I add a deny rule to block my agent from reading secrets?
No, Kubernetes RBAC rules are purely additive and do not support deny rules. To block an agent from reading secrets, omit the secrets resource from every Role bound to it. Always check all bindings for the agent identity to make sure no broad role is attached.
How do I let a LangChain agent read pod logs without giving 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 rules. This setup lets the agent read status and log output without running commands inside containers.
Related guides
In this post