AI agent security for Kubernetes: how it works
A secure AI agent shouldn't hold your credentials, and its limits shouldn't depend on the agent behaving. With cluster enforcement, every request from a Claude Code tab reaches the API server as krust-agent. This page follows one request from the tab to the cluster, and explains what each side checks.
One request, end to end
krust-agent, whatever Krust decided.- The tab sends a request. Claude Code's
kubectlandhelmtalk to Krust's proxy on127.0.0.1. Their kubeconfig holds a proxy token that the cluster doesn't accept. - Krust checks the tab's mode. In Read-only, a change is refused here. In Ask, it waits for your answer. The proxy also refuses any impersonation header from the tab, so
--asand--as-groupfail in every mode and Claude can't choose its own identity. - Krust forwards the request through its own connection, with your credential and the impersonation headers below.
- The API server authenticates you, then checks that you may impersonate
krust-agent, those groups and those extras. - The API server authorizes the request as
krust-agent, with only the groups Krust sent. Your own permissions no longer count.
The headers Krust adds
Krust uses Kubernetes user impersonation, the same mechanism as kubectl --as.
| Header | Value | When |
|---|---|---|
Impersonate-User | krust-agent | Every request |
Impersonate-Group | krust:agent-read | Every request |
Impersonate-Group | krust:agent-write | A change, exec, attach or port-forward that the tab's mode let through |
Impersonate-Extra-krust-mode | read-only, ask or write | Every request |
Impersonate-Extra-krust-session | The tab's ID | Every request |
What each mode sends
| Mode | Reads | Changes |
|---|---|---|
| Read-only | Read group | Refused by Krust. They never carry the write group, so the cluster would refuse them too. |
| Ask | Read group | Read and write groups, once you approve |
| Write | Read group | Read and write groups |
In Ask and Write, kubectl auth can-i and server-side dry runs also carry the write group, so they answer for what the tab can actually do.
GKE IAM and EKS access policies
On GKE and EKS, two systems can allow a request: the cloud's own access control and Kubernetes RBAC. Either one is enough. That still holds for you. It doesn't hold for krust-agent.
krust-agent. Only RBAC decides what krust-agent may do.- Step 2, as you: GKE checks your IAM roles and RBAC together. A broad IAM role such as
roles/container.admin, or an EKS cluster admin access policy, can already let you impersonate. Otherwise your impersonator binding does. - Step 3, as
krust-agent:krust-agentis not an IAM principal or an AWS identity, so no cloud role ever applies to it. What it may do comes only from the RBAC bound to its groups.
So a developer with roles/container.developer on a production project still gets only what krust:agent-read and krust:agent-write allow in a Claude tab.
How Krust knows the cluster is set up
Krust can't see RBAC objects that it may not read, and a platform team may name its roles differently. So Krust asks the API server what krust-agent may do, with SelfSubjectAccessReview requests sent as krust-agent. It asks when a Claude tab opens on a protected cluster:
| Question | Groups | Needed answer |
|---|---|---|
May it get /krust-agent-identity? | Read | yes: the setup is there |
| May it create pods, in every namespace? | Read | no: Read-only holds at the cluster |
| May it create ClusterRoleBindings? | Read and write | no: an approved change can't widen access |
Nothing serves /krust-agent-identity. Only the cluster's answer counts, so the marker works however narrowly the rest is granted.
The pods question covers every namespace at once. A RoleBinding that lets the read group create pods in a single namespace still gets "no", so Krust doesn't catch it. Check one namespace yourself.
- Cluster-enforced: all three answers as needed. The tab uses
krust-agent. - Not set up: no marker. The tab's requests go as you, limited by Krust's checks.
- Cluster setup too broad: the marker is there, but a rule fails. Krust won't use a
krust-agentthat can do what Krust promises Claude can't. The tab's requests go as you, limited by Krust's checks, until the setup is narrowed. - Not allowed: you may not impersonate
krust-agent. The tab's requests go as you.
If the cluster starts refusing impersonation while a tab is open, for example because someone removed your binding, Krust confirms it with the API server and switches that tab's requests back to you, so they don't all fail. The shield in the tab's Claude bar shows the new status.
In the audit log
An impersonated request keeps both identities. In a Kubernetes audit event, user is you, as your credential authenticated, and impersonatedUser is krust-agent with the groups and extras Krust sent:
"user": {
"username": "[email protected]",
"groups": ["system:authenticated"]
},
"impersonatedUser": {
"username": "krust-agent",
"groups": ["krust:agent-read", "krust:agent-write"],
"extra": {
"krust-mode": ["ask"],
"krust-session": ["…"]
}
},
"verb": "patch",
"objectRef": { "resource": "deployments", "namespace": "shop", "name": "api" }You can tell who the request was for, that it came through a Claude tab, which mode let it through and which tab it came from. On GKE, these fields appear in Cloud Audit Logs for the cluster. On EKS, in the control plane's audit log.
Krust sets krust-mode and krust-session. The impersonator role names which extras may be sent, not their values, because the session changes with every tab. So anyone who holds the role could send other values in their own Impersonate-Extra- headers: treat the extras as Krust's record, not as proof.
Securing an AI agent: why impersonation
| Approach | What it needs | Trade-off |
|---|---|---|
| Impersonation (Krust) | An RBAC binding per person or team | No new secret. Each person grants it with their own binding, and the audit log names them. |
| A service account for the agent | A long-lived token on each Mac | A shared secret to store and rotate. The audit log names the service account, not the person. |
| A second cloud identity | An extra IAM user or role per person | More accounts to manage, and cloud roles can still grant it more than RBAC. |
Claude never gets a credential for krust-agent. There is none: every request is yours, made smaller by the headers Krust adds.
What this does not cover
- Credentials on this Mac. Cluster enforcement limits requests that go through Krust. A kubeconfig file, or a
gcloudor AWS CLI sign-in on disk, still reaches the cluster as you. For a GKE or EKS cluster, the setup lists thegcloudand AWS CLI sign-ins it found. - Your own access. Outside a Claude tab, you have the access you always had.
- What
krust-agentis granted. Krust checks two rules. Everything elsekrust-agentmay do is up to the RBAC on the cluster. See Kubernetes RBAC for AI agents.