Kubernetes RBAC for AI agents

For platform teams: Claude Code in Krust gets least-privilege Kubernetes RBAC through one user, krust-agent. Krust doesn't need its own RBAC file. It needs a few names on the cluster, and it checks two rules. Everything else about what krust-agent may do is yours to decide, in the tools you already use.

New to cluster enforcement? Start with how it works.

Early access: cluster enforcement is free during early access.

What Krust relies on

NameWhat it isNeeded
krust-agentThe user Claude's requests are sent asEach person who uses Krust may impersonate it
krust:agent-readGroup on every requestWhat Claude may read
krust:agent-writeGroup added to changes the tab's mode let throughWhat an approved change may do. Optional.
userextras/krust-mode, userextras/krust-sessionExtra fields Krust sendsEach person may impersonate them
/krust-agent-identityNon-resource URL; nothing serves itget for krust:agent-read. It tells Krust the cluster is set up.

The two rules Krust checks

  1. krust:agent-read alone can't create pods. Otherwise a Read-only tab would be limited only by Krust, not by the cluster.
  2. krust:agent-read and krust:agent-write together can't create ClusterRoleBindings. Otherwise an approved change could give krust-agent, or anyone, more access.

Krust asks rule 1 across every namespace at once, so it can't see a grant in a single namespace. A RoleBinding that lets krust:agent-read create pods in one namespace breaks rule 1 there without Krust noticing. Keep the read group out of RoleBindings that allow writes, and check the namespaces that matter.

If either rule fails, Krust shows Cluster setup too broad and doesn't use krust-agent on that cluster. Claude's requests then go as the person, limited by Krust's checks, until the setup is narrowed.

How the default RBAC fits together

Subjects, bindings and roles in Krust's default setupEach person is bound to the krust-agent-impersonator role. The group krust:agent-read is bound to krust-agent-read and krust-agent-identity. The group krust:agent-write is bound to the built-in edit role.SubjectClusterRoleBindingClusterRoleYou, or your teamUser or Groupkrust:agent-readevery requestkrust:agent-writeapproved changeskrust-agent-impersonator-<hash>krust-agent-readkrust-agent-identitykrust-agent-writekrust-agent-impersonatorimpersonate, by namekrust-agent-readget, list, watchkrust-agent-identitythe markereditbuilt-in
Six objects are shared by everyone on the cluster. Only the impersonator binding is per person or per team.

Krust's default file

Seven objects, all labelled app.kubernetes.io/managed-by: krust. In the app, Krust fills in the person's name and adds a comment to each object. This is the file for [email protected]:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: krust-agent-impersonator
  labels:
    app.kubernetes.io/managed-by: krust
rules:
- apiGroups: [""]
  resources: ["users"]
  verbs: ["impersonate"]
  resourceNames: ["krust-agent"]
- apiGroups: [""]
  resources: ["groups"]
  verbs: ["impersonate"]
  resourceNames: ["krust:agent-read", "krust:agent-write"]
- apiGroups: ["authentication.k8s.io"]
  resources: ["userextras/krust-mode", "userextras/krust-session"]
  verbs: ["impersonate"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: krust-agent-read
  labels:
    app.kubernetes.io/managed-by: krust
rules:
- apiGroups: ["*"]
  resources: ["*"]
  verbs: ["get", "list", "watch"]
- nonResourceURLs: ["*"]
  verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: krust-agent-read
  labels:
    app.kubernetes.io/managed-by: krust
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: krust-agent-read
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: Group
  name: krust:agent-read
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: krust-agent-write
  labels:
    app.kubernetes.io/managed-by: krust
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: edit
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: Group
  name: krust:agent-write
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
  name: krust-agent-identity
  labels:
    app.kubernetes.io/managed-by: krust
rules:
- nonResourceURLs: ["/krust-agent-identity"]
  verbs: ["get"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: krust-agent-identity
  labels:
    app.kubernetes.io/managed-by: krust
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: krust-agent-identity
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: Group
  name: krust:agent-read
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: krust-agent-impersonator-b9738f1fd857
  labels:
    app.kubernetes.io/managed-by: krust
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: krust-agent-impersonator
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: User
  name: [email protected]

The last binding's name ends with the first 12 hex characters of the SHA-256 of user:<name> or group:<name>, so one person's binding never replaces another's.

Apply it as someone who may change RBAC. kubectl create adds only what's missing; objects a teammate already added show as AlreadyExists:

kubectl --context my-cluster create --dry-run=server -f krust-agent.yaml
kubectl --context my-cluster create -f krust-agent.yaml

What the built-in edit role allows

edit leaves RBAC, nodes and other cluster-wide objects alone. In each namespace it covers, though, it reads Secrets and starts pods that can run as any service account there, with that account's rights. Bound cluster-wide, that includes kube-system. If that's more than you want, narrow it with one of the changes below.

Least privilege: grant it your own way

Use Helm, Argo CD, Flux or your own roles. Keep the names above and the two rules hold. These are the changes teams make most.

Writes in some namespaces only

Leave out the krust-agent-write ClusterRoleBinding. Bind edit, or your own role, in each namespace Claude may change:

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: krust-agent-write
  namespace: shop
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: edit
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: Group
  name: krust:agent-write

Keep Secrets from the agent

Bind krust:agent-read to the built-in view role instead of krust-agent-read. Krust hides Secret values in Read-only and Ask tabs, but not in Write, and not in Helm release Secrets, which hold the chart's values. This makes the cluster refuse Secrets in every mode. Helm in the tab then can't list releases, because Helm stores them in Secrets.

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: krust-agent-read
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: view
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: Group
  name: krust:agent-read

Keep the krust-agent-identity role and binding when you do. view doesn't include the marker.

Read-only everywhere

Leave out every binding for krust:agent-write. A change approved in the app then fails at the cluster with Forbidden.

One binding for a whole team

Instead of a binding per person, bind the impersonator role to a group your identity provider already sends, such as a Google group on GKE or a group mapped by an EKS access entry:

apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
  name: krust-agent-impersonator-platform
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: krust-agent-impersonator
subjects:
- apiGroup: rbac.authorization.k8s.io
  kind: Group
  name: [email protected]

In the app, a person can type the group instead of their user when Krust asks who to name.

Keep impersonation narrow

Don't grant impersonate without resourceNames. Someone who may impersonate any user or group can act as a cluster admin. Krust's role lists exactly krust-agent and its two groups by name. The extras rule names the two extras but not their values, because the session value changes with every tab.

Check the setup

Run these as a person who uses Krust. The answers should be yes, no, no:

kubectl auth can-i get /krust-agent-identity \
  --as=krust-agent --as-group=krust:agent-read
kubectl auth can-i create pods -A \
  --as=krust-agent --as-group=krust:agent-read
kubectl auth can-i create clusterrolebindings.rbac.authorization.k8s.io -A \
  --as=krust-agent --as-group=krust:agent-read --as-group=krust:agent-write

If the first one fails with Forbidden on impersonation, that person has no impersonator binding yet. -A asks whether it's allowed in every namespace at once, the same question Krust asks. A RoleBinding that lets the read group create pods in one namespace still answers no. To check a namespace, ask there:

kubectl auth can-i create pods -n shop \
  --as=krust-agent --as-group=krust:agent-read

Krust asks the same three questions, with SelfSubjectAccessReview, whenever a Claude tab opens on a protected cluster. If you change the RBAC later, Krust notices on the next tab.

Remove it