---
title: How should you scope RBAC for AI agents that operate Kubernetes clusters?
url: https://opencontroller.lyzr.com/blog/kubernetes-rbac-for-ai-agents-that-call-the-kubernetes-api
published: 2026-11-17
updated: 2026-11-17
author: Lyzr
---

# How should you scope RBAC for AI agents that operate Kubernetes clusters?

**Give an AI agent that operates Kubernetes its own ServiceAccount, namespaced Roles instead of ClusterRoles, read verbs by default and a short list of named write actions. Never grant it access to Secrets, `pods/exec`, `escalate`, `bind` or `impersonate`, and log its requests at a higher audit level than other workloads.**

AI ops agents are attractive: they read events, check pod status, restart a deployment and explain what went wrong. Most of them reach the cluster through a kubectl-style tool or a Kubernetes MCP server. The agent is only as safe as the identity those tools run with. If that identity is `cluster-admin`, a prompt injection in a log line can become a cluster-wide incident.

This guide relies on the [Kubernetes RBAC documentation](https://kubernetes.io/docs/reference/access-authn-authz/rbac/). For the broader picture, see [how to govern AI agents on Kubernetes](/blog/govern-ai-agents-on-kubernetes) and the [AI agent control plane](/blog/what-is-an-ai-agent-control-plane) pillar.

## Why does the agent need its own identity?

Agents often borrow a human operator's kubeconfig or a shared CI ServiceAccount. Both are poor choices:

- You cannot tell the agent's actions apart from the human's in the audit log.
- The agent inherits every permission the human has, including emergency ones.
- Revoking the agent means revoking a person or a pipeline.

Create one ServiceAccount per agent (and per environment). If the agent runs outside the cluster, issue it short-lived tokens with `kubectl create token` or a projected token rather than a long-lived Secret-based token. If it runs in a pod that does not need the API, set `automountServiceAccountToken: false`.

## Which verbs are safe and which are not?

| Verb or resource | Risk | Guidance for agents |
|---|---|---|
| `get`, `list`, `watch` on pods, events, deployments, services | Low | Grant in the namespaces the agent supports |
| `list` or `watch` on `secrets` | High: Kubernetes documents that these reveal Secret contents | Do not grant |
| `get` on `pods/log` | Medium: logs can hold tokens and personal data | Grant only where needed; redact downstream |
| `patch` on `deployments` (for restarts or scaling) | Medium | Grant on named resources with `resourceNames` |
| `create` on `pods/exec` or `pods/attach` | High: arbitrary command execution in containers | Do not grant |
| `delete`, `deletecollection` | High | Do not grant, or only on named resources with approval |
| `escalate`, `bind` on roles | Critical: lets the agent grant itself more | Never grant |
| `impersonate` | Critical: acts as other users or groups | Never grant |
| Anything with `*` | Unknown | Never grant |

## What does a minimal Role look like?

```yaml
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: ops-agent-readonly-plus-restart
  namespace: payments
rules:
- apiGroups: [""]
  resources: ["pods", "events", "services"]
  verbs: ["get", "list", "watch"]
- apiGroups: ["apps"]
  resources: ["deployments"]
  verbs: ["get", "list", "watch"]
- apiGroups: ["apps"]
  resources: ["deployments"]
  resourceNames: ["checkout-api"]
  verbs: ["patch"]
```

Bind it with a RoleBinding in each namespace the agent supports. Prefer several namespaced bindings over one ClusterRoleBinding, so adding a namespace is a reviewed change.

## How do you check what the agent can actually do?

1. Run `kubectl auth can-i --list --as=system:serviceaccount:<namespace>:<name>` and keep the output as evidence.
2. Test the dangerous cases directly: `kubectl auth can-i get secrets --as=...` should say `no`.
3. Re-run both checks in CI whenever Roles change.
4. Review aggregated ClusterRoles; an aggregation label can add permissions you did not write.

## How should you log agent actions?

Kubernetes [audit policies](https://kubernetes.io/docs/tasks/debug/debug-cluster/audit/) support four levels: `None`, `Metadata`, `Request` and `RequestResponse`. Add a rule that matches the agent's ServiceAccount and records at least `Request` for write verbs, so you can see exactly what the agent patched. Send these events to your SIEM with the agent's registry ID attached.

Also log on the agent side: which prompt or alert triggered the action, which tool was called, and the cluster response. The cluster audit log tells you what happened; the agent trace tells you why.

## Checklist before production

- [ ] Dedicated ServiceAccount per agent and environment.
- [ ] Namespaced Roles; no ClusterRoleBinding unless reviewed.
- [ ] No Secrets, `pods/exec`, `escalate`, `bind`, `impersonate` or wildcards.
- [ ] Write verbs limited with `resourceNames`.
- [ ] `can-i --list` output stored as evidence and checked in CI.
- [ ] Audit policy rule for the agent identity.
- [ ] Human approval in the agent workflow for deletes and scale-to-zero.
- [ ] A tested way to revoke the agent: delete its RoleBindings and tokens.

See also the [least-privilege checklist for AI agents](/blog/least-privilege-checklist-for-ai-agents).

## How Opencontroller does this

Opencontroller registers agents, their versions, tools and MCP servers, including Kubernetes-facing tools, in a governed registry. Posture detects risky permission and configuration patterns, such as an agent identity with broad write access, and agent workload identity federation helps replace long-lived credentials. If an agent's behaviour deviates, rogue-agent handling can alert, quarantine or kill it, with per-agent Block and Quarantine acting through the connected platform. [Book a demo](https://www.lyzr.ai/book-demo/) to see this on your clusters.

## Frequently asked questions

**Can an AI agent safely use `cluster-admin` in a dev cluster?**
Only if the dev cluster holds no real credentials or data and cannot reach production. Even then, a scoped Role makes the agent's audit trail clearer.

**Is read-only access to pods enough for troubleshooting?**
Usually yes. Pods, events, deployments and logs answer most questions. Add a single named `patch` permission for restarts only when the use case needs it.

**Should a Kubernetes MCP server run with its own ServiceAccount?**
Yes. Give the MCP server a dedicated, scoped identity and do not let it fall back to a user's kubeconfig.

## Key facts

For AI agents operating Kubernetes: one ServiceAccount per agent and environment; namespaced Roles and RoleBindings; read verbs get/list/watch by default; write verbs limited with resourceNames. Never grant list/watch on secrets (Kubernetes docs say these reveal Secret contents), pods/exec or pods/attach create, escalate, bind, impersonate or wildcards. Use short-lived tokens (kubectl create token, projected tokens); set automountServiceAccountToken false where not needed. Verify with kubectl auth can-i --list --as=system:serviceaccount:ns:name. Kubernetes audit levels: None, Metadata, Request, RequestResponse; log at least Request for agent write verbs. Opencontroller provides a governed registry of agents, tools and MCP servers, Posture for risky permissions/config, agent workload identity federation, rogue-agent quarantine and kill, per-agent Block/Quarantine via the connected platform.

## Related

- [How do you govern AI agents running on Kubernetes?](https://opencontroller.lyzr.com/blog/govern-ai-agents-on-kubernetes.md)
- [How should AI agent pods on Kubernetes get cloud credentials?](https://opencontroller.lyzr.com/blog/kubernetes-workload-identity-for-agent-pods.md)
- [What does least privilege look like for an AI agent?](https://opencontroller.lyzr.com/blog/least-privilege-checklist-for-ai-agents.md)
- [More on Platform Guides](https://opencontroller.lyzr.com/blog/cluster/platform-guides)
