How to Configure Mastra Kubernetes Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up mastra kubernetes read only access by linking a service account to a view role. Next, you give those limited credentials to your agent workflow tools. Many teams start by giving their AI agents broad cluster admin roles during testing. That shortcut lets an automated agent change or delete live workloads by mistake. A strict read role stops the agent from making changes to your cluster. How mastra kubernetes read only access works in native RBAC Kubernetes uses Role-Based Access Co

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 read only access by linking a service account to a view role. Next, you give those limited credentials to your agent workflow tools. Many teams start by giving their AI agents broad cluster admin roles during testing. That shortcut lets an automated agent change or delete live workloads by mistake. A strict read role stops the agent from making changes to your cluster.

How mastra kubernetes read only access works in native RBAC

Kubernetes uses Role-Based Access Control to manage what users and apps can do. In this system, permissions are purely additive, and there are no deny rules. You start with zero access and add rules for each needed action. To let an agent read cluster state, you permit verbs like get, list, and watch.

You can scope these rules to one namespace or the whole cluster. A Role always sets permissions within a single namespace. A ClusterRole is not namespaced and can cover cluster-scoped resources like nodes. It can also cover namespaced resources across all namespaces in your setup.

After you define the rules, you bind them to the identity your Mastra agent uses. A RoleBinding grants permissions inside one specific namespace. That RoleBinding can point to a local Role or a shared ClusterRole. A ClusterRoleBinding grants access across the whole cluster at once.

For most Mastra workflows, a RoleBinding in one namespace is the safest choice. You create a dedicated service account for the Mastra app. Then you bind that account to a Role that allows only read actions on pods and deployments. Your Mastra tool uses that identity to query the API server and inspect workloads.

How subresources affect agent permissions

Reading basic pod status is often not enough for a support agent. Your Mastra workflow might also need to read container logs to find errors. In Kubernetes RBAC, some APIs involve a subresource, such as a pod's logs. RBAC refers to resources by the exact name that appears in the API URL. You write a subresource with a slash, such as the pod log path.

You must add that log subresource to your Role so Mastra can read app output. At the same time, you must leave out the exec subresource. The exec subresource lets a caller run commands inside a running container. Even if the main role seems read-only, allowing exec gives the agent shell access inside the pod.

Auditor Read-Only Access + Kubernetes API Server Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native RBAC solves and what it leaves open

Native Kubernetes RBAC solves the problem of who can call specific API endpoints. It stops a Mastra agent from deleting pods, editing deployments, or reading secret objects when configured well. This setup forms a solid base for safe cluster checks.

Still, static RBAC only checks the resource type and verb at the API level. It does not inspect what is inside the data returned to the agent. For example, a pod log might hold sensitive customer data like emails, phone numbers, or card numbers. Once RBAC allows access to the pod log subresource, the whole log stream goes to the agent.

Static service account credentials also create operational work for platform teams. If you store a long-lived key in the Mastra host, anyone with host access can use it. Native RBAC also logs calls by service account name rather than the human who triggered the agent. And because RBAC has no deny rules, a single broad binding can open access you meant to block.

Add request guardrails and response masking beside Kubernetes

Cluster roles and service accounts govern who reaches the Kubernetes API. Still, a broad role or agent can delete workloads or print sensitive values from ConfigMaps and logs. In practice, hoop.dev runs beside the API server as a sidecar for your Kubernetes API and checks every request and response alongside RBAC.

With hoop.dev Kubernetes controls, guardrails can allow listing Secret names while refusing reads of Secret data before execution. Data masking redacts matched keys in returned JSON responses and log streams in memory. Furthermore, hoop.dev holds SOC 2 Type II and is MIT licensed on GitHub.

Frequently asked questions

Should I use a Role or a ClusterRole for a Mastra agent?

Use a Role and a RoleBinding when your Mastra agent only checks one namespace. Use a ClusterRole and ClusterRoleBinding only when the agent must inspect nodes or resources across all namespaces.

Can a read-only role still expose sensitive data to Mastra?

Yes, a read-only role can still expose sensitive data if it allows reading Secrets or pod logs. Leave Secrets out of your RBAC rules, and remember that pod logs often contain emails or card numbers.

How do I let Mastra read pod logs without allowing container shell access?

Grant get and list verbs on pods and the pod log subresource in your Role. Do not include the pod exec subresource, because RBAC rules are additive and only grant what you list.

The query runs. The emails stay hidden.