How to Configure CrewAI Kubernetes Credentials
You set up crewai kubernetes credentials by linking a scoped service account to your agent tools. Your agent then uses that token to talk to the cluster API server. Many teams start by giving agents a single admin key during testing. That broad key often stays in place when the app moves to production. If an agent makes a mistake, a wide role lets it change or delete live workloads. How crewai kubernetes credentials work with cluster roles In CrewAI, you assign tasks to agents and give each a
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 crewai kubernetes credentials by linking a scoped service account to your agent tools. Your agent then uses that token to talk to the cluster API server. Many teams start by giving agents a single admin key during testing. That broad key often stays in place when the app moves to production. If an agent makes a mistake, a wide role lets it change or delete live workloads.
How crewai kubernetes credentials work with cluster roles
In CrewAI, you assign tasks to agents and give each agent a set of tools. When a task needs cluster state, the tool sends requests to the Kubernetes API server. The tool reads a token or local config file to log in. Kubernetes checks that identity against Role-Based Access Control rules before running the request.
In Kubernetes RBAC, a Role or ClusterRole holds a list of permission rules. These rules are additive, which means there are no deny rules in the system. A Role sets permissions inside one namespace for your agent workloads. A ClusterRole works across the whole cluster and covers nodes or all namespaces.
To grant those permissions, you create a RoleBinding or a ClusterRoleBinding for the agent identity. A RoleBinding applies rules inside one namespace and can point to a Role or ClusterRole. A ClusterRoleBinding grants permissions across every namespace in the cluster at once. When you set up crewai kubernetes credentials, a single namespace RoleBinding is the safer choice.
Scoping subresources for agent tools
Agent tools often need to read pod logs or run checks inside a container. Kubernetes treats these actions as subresources under the main pod resource in the API URL. In RBAC rules, you write a subresource with a slash, such as pods/log or pods/exec. If you grant broad pod rules, an agent might gain access to subresources by accident.
You should list only the exact resources and verbs that each CrewAI tool needs. An agent that checks app health only needs to read pod status and logs. An agent that fixes issues might need permission to restart a specific deployment. Splitting roles by agent task keeps one confused prompt from breaking the whole cluster.
Kubernetes also lets you limit rules to specific resource names in some cases. Still, the resource name limit on create actions applies only to top-level resources, not subresources. That means RBAC alone cannot restrict which pod names receive new subresource calls on create. Teams must account for this detail when they give container command tools to agents.
Ephemeral Credentials + Kubernetes RBAC: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
What native RBAC solves and what it misses
Native Kubernetes RBAC controls who can log in and which API paths they can call. It stops an unauthorized agent from touching namespaces or resources outside its assigned role. This setup is a strong first step for any team running automated agent crews.
Still, RBAC evaluates the API endpoint and verb, not the content inside the request. Once an agent has pods/exec permissions, RBAC does not inspect the shell command inside it. An agent could run a safe check or a destructive script under the same role. Native RBAC also does not rewrite sensitive data like emails or phone numbers in logs.
Static tokens on agent hosts create another risk for operations teams to manage. Any tool or process on that host can read the file and reuse the key. Teams also lack a clear audit trail that ties each cluster command to one agent task. Reviewing raw API logs takes hours when multiple agents share one service account.
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 all agents in a crew share one Kubernetes service account?
No, sharing one account gives every agent the widest permissions needed by any single task. Give read-only agents a separate role from agents that change state or run container commands.
Can Kubernetes RBAC block specific shell commands inside pods/exec?
No, Kubernetes RBAC only checks if the user can call the pods/exec subresource API. It does not read or filter the shell commands that run inside the container session.
Why is a RoleBinding safer than a ClusterRoleBinding for AI agents?
A RoleBinding keeps the agent inside one namespace so it cannot touch other apps. A ClusterRoleBinding applies across all namespaces and raises the blast radius of bad prompts.
Related guides
In this post