How to Configure Mastra Kubernetes Permissions

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up mastra kubernetes permissions by linking a service identity to a cluster role. This role holds additive rules that say which cluster objects the agent can read or change. Many teams start by giving their AI agents broad cluster rights to move fast. Broad rights create big risks when an agent runs a bad command or reads secret data. If a role covers every namespace, one mistake can break the whole cluster. How mastra kubernetes permissions work in native RBAC Kubernetes controls who

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

You set up mastra kubernetes permissions by linking a service identity to a cluster role. This role holds additive rules that say which cluster objects the agent can read or change. Many teams start by giving their AI agents broad cluster rights to move fast. Broad rights create big risks when an agent runs a bad command or reads secret data. If a role covers every namespace, one mistake can break the whole cluster.

How mastra kubernetes permissions work in native RBAC

Kubernetes controls who can do what through role-based rules on the API server. Every rule in this system is additive, which means there are no deny rules. You start with zero rights and add rules for each needed action. A basic role sets permissions inside one single namespace. A cluster role is not stuck to one namespace. It can cover nodes, non-resource endpoints, or objects across all namespaces at once.

Once you write a role, you must attach it to the identity that Mastra uses. A role binding grants those permissions inside one specific namespace. That binding can point to a local role or a wider cluster role. If the agent needs rights across the whole system, you use a cluster role binding instead. This setup lets you wall off your agent so it only touches its own namespace.

Handling subresources like pod logs and exec

Agents often need to read pod logs or run commands inside a container to fix issues. In the cluster API, these features are called subresources. You write them in your rule list by adding a slash after the main resource name. For example, reading logs uses the pods and log path. Running a shell command uses the pods and exec path.

Giving an agent rights to the pods resource does not grant rights to its subresources. You must list each subresource in the role rules on its own. Also, you cannot always limit create actions on subresources to specific object names. When you grant exec rights in a role, the agent can often run commands in any pod within that namespace. Teams must watch these subresource rules closely so agents do not gain shell rights everywhere.

Kubernetes RBAC + AI Agent Permissions: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native roles solve and what they miss

Native roles and bindings do a good job of sorting out who can call which API path. They stop an agent in a test namespace from deleting workloads in a production namespace. They also let you separate read-only log checks from write actions like deleting pods. For basic setup boundaries, native roles are the right first step.

Still, native cluster permissions only check the API call at the door. Once a role grants pod exec rights, the cluster does not check the shell commands inside. An agent with exec rights can read local files, dump variables, or stop processes. In the same way, log permissions return the full text of the pod output. If that log holds emails, phone numbers, card numbers, or national IDs, the agent gets them all. Native roles decide who logs in, not what each command or response does in flight.

Check Kubernetes API requests and responses on the wire

Kubernetes RBAC decides who may call the API server. RBAC does not check response payloads or split listing Secret names from reading Secret values when a role grants get access. With hoop.dev, you run an open-source HTTP proxy, a sidecar for your Kubernetes API. The kubectl client changes only the server address it talks to while RBAC stays in place.

On each call, hoop.dev guardrails read the method, normalized path, and headers to refuse bad deletes or full Secret reads with a 403 error. On the way back, hoop.dev data masking walks JSON responses by key and masks matched values in Secrets, ConfigMaps, and pod logs. Every request and verdict is logged without storing bearer tokens. View the project on GitHub.

Frequently asked questions

Can I write a deny rule to block Mastra from one specific pod?

No, cluster role rules are purely additive and never include deny rules. You must build roles from the ground up by only listing the exact objects the agent should use.

When should I use a role binding instead of a cluster role binding?

Use a role binding when the agent only needs to work inside one single namespace. Use a cluster role binding only when the agent must check nodes or objects across all namespaces.

Why can my agent still not read logs after I grant pod read rights?

Pod logs are a subresource in the cluster API, not part of the main pod object. You must add a separate rule for the log subresource before the agent can read log output.

The query runs. The emails stay hidden.