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

A Claude Code request through Krust to the API serverThe Claude Code tab sends kubectl to Krust's local proxy. The proxy checks the tab's mode, adds your credential and impersonation headers, and forwards the request. The API server authenticates you, checks that you may act as krust-agent, then authorizes the request as krust-agent.Claude Code tabkubectl, helmholds a proxy token,not your credentialKrust proxy127.0.0.1, inside Krust1 Check the tab's mode2 Add your credential3 Add Impersonate headersAPI serveryour cluster1 Authenticate: you2 May you be krust-agent?3 Authorize krust-agentby its groups' RBACA request the moderefuses never leavesKrust.Impersonate-User: krust-agentImpersonate-Group: krust:agent-readevery requestImpersonate-Group: krust:agent-writeapproved changesImpersonate-Extra-krust-mode, -krust-session
Krust checks first. The cluster checks again, as krust-agent, whatever Krust decided.
  1. The tab sends a request. Claude Code's kubectl and helm talk to Krust's proxy on 127.0.0.1. Their kubeconfig holds a proxy token that the cluster doesn't accept.
  2. 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 --as and --as-group fail in every mode and Claude can't choose its own identity.
  3. Krust forwards the request through its own connection, with your credential and the impersonation headers below.
  4. The API server authenticates you, then checks that you may impersonate krust-agent, those groups and those extras.
  5. 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.

HeaderValueWhen
Impersonate-Userkrust-agentEvery request
Impersonate-Groupkrust:agent-readEvery request
Impersonate-Groupkrust:agent-writeA change, exec, attach or port-forward that the tab's mode let through
Impersonate-Extra-krust-moderead-only, ask or writeEvery request
Impersonate-Extra-krust-sessionThe tab's IDEvery request

What each mode sends

ModeReadsChanges
Read-onlyRead groupRefused by Krust. They never carry the write group, so the cluster would refuse them too.
AskRead groupRead and write groups, once you approve
WriteRead groupRead 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.

Which access control applies at each stepStep 2 checks whether you may act as krust-agent; cloud access or Kubernetes RBAC can allow it. Step 3 checks what krust-agent may do; only Kubernetes RBAC applies, because krust-agent is not a cloud identity.Step 2, as youMay you act askrust-agent?Cloud accessGKE IAM roles, EKSaccess policiesorKubernetes RBACyour impersonatorbindingStep 3, as krust-agentMay it do this?Cloud accesskrust-agent isn't acloud identity: skippedKubernetes RBACkrust:agent-readkrust:agent-write
Cloud roles can let you act as krust-agent. Only RBAC decides what krust-agent may do.

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:

QuestionGroupsNeeded answer
May it get /krust-agent-identity?Readyes: the setup is there
May it create pods, in every namespace?Readno: Read-only holds at the cluster
May it create ClusterRoleBindings?Read and writeno: 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.

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

ApproachWhat it needsTrade-off
Impersonation (Krust)An RBAC binding per person or teamNo new secret. Each person grants it with their own binding, and the audit log names them.
A service account for the agentA long-lived token on each MacA shared secret to store and rotate. The audit log names the service account, not the person.
A second cloud identityAn extra IAM user or role per personMore 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