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
| Name | What it is | Needed |
|---|---|---|
krust-agent | The user Claude's requests are sent as | Each person who uses Krust may impersonate it |
krust:agent-read | Group on every request | What Claude may read |
krust:agent-write | Group added to changes the tab's mode let through | What an approved change may do. Optional. |
userextras/krust-mode, userextras/krust-session | Extra fields Krust sends | Each person may impersonate them |
/krust-agent-identity | Non-resource URL; nothing serves it | get for krust:agent-read. It tells Krust the cluster is set up. |
The two rules Krust checks
krust:agent-readalone can't create pods. Otherwise a Read-only tab would be limited only by Krust, not by the cluster.krust:agent-readandkrust:agent-writetogether can't create ClusterRoleBindings. Otherwise an approved change could givekrust-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
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.yamlWhat 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-writeKeep 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-readKeep 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-writeIf 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-readKrust 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
- For one person: delete their
krust-agent-impersonator-<hash>binding. In the app, on a cluster-enforced cluster, Stop and Copy Remove Command copies that command for the person's own user binding; Krust doesn't run it. A team binding is removed by whoever manages it. Their open Claude tabs switch back to sending as them, and the Claude bar shows it. - For everyone: delete every object Krust's file added.
Objects you created your own way don't have this label. Delete those with the tool that created them.kubectl --context my-cluster delete clusterrolebinding,clusterrole \ -l app.kubernetes.io/managed-by=krust