How to Configure Mastra Kubernetes Connect

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up a mastra kubernetes connect workflow, bind an agent identity to a scoped role. The agent then uses that key to call the cluster API and run tasks. Many teams start by giving the agent a broad role across the whole cluster. This wide role lets an automated tool change or delete live workloads by mistake. Scoping permissions down to single namespaces keeps your cluster safe during automated runs. How a mastra kubernetes connect setup works A mastra kubernetes connect setup links your

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.

To set up a mastra kubernetes connect workflow, bind an agent identity to a scoped role. The agent then uses that key to call the cluster API and run tasks. Many teams start by giving the agent a broad role across the whole cluster. This wide role lets an automated tool change or delete live workloads by mistake. Scoping permissions down to single namespaces keeps your cluster safe during automated runs.

How a mastra kubernetes connect setup works

A mastra kubernetes connect setup links your agent framework to the cluster API server. Kubernetes uses role-based access control to check every API call from the agent. In this system, permissions are additive, and there are no deny rules. You start with zero access and add rules for each needed action. A Role sets permissions inside one single namespace for your agent workloads. A ClusterRole sets permissions across the whole cluster and covers cluster-scoped objects like nodes. It can also cover non-resource endpoints or namespaced objects across all namespaces.

After you define the rules, you bind them to the agent identity. A RoleBinding grants permissions inside one namespace and can point to a Role. A RoleBinding can also reference a ClusterRole to keep those rules inside one namespace. A ClusterRoleBinding grants access across the entire cluster at once. When the agent runs a task, the API server checks these bindings first. You also need separate rules for subresources like pod logs or pod exec calls. In role rules, you write the subresource with a slash after the main resource.

What native cluster roles solve and what they miss

Native cluster roles control which service accounts or users can reach the API server. They stop an agent in one namespace from reading pods in another namespace. They also let you separate read access for pod logs from pod exec rights. This setup gives your team a strong baseline for basic cluster security.

Still, native role bindings only check the start of an API request. Once a binding grants pod exec rights, the API server allows the session. Native RBAC does not inspect the shell commands that run inside that pod. It also cannot mask sensitive text that comes back in pod log streams. If a log line contains emails, phone numbers, card numbers, or national IDs, it flows straight to the agent. Native roles decide who can connect, not what commands or data pass in flight.

Kubernetes RBAC + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Scoping agent permissions for safer operations

Teams should start every agent setup with a namespace-scoped Role and RoleBinding. Avoid ClusterRoleBindings unless the agent must read nodes or cluster-wide state. Split your roles by task so read-only agents do not get write rules. Only add pod exec subresource rules when an agent must run commands inside containers. Even with tight roles, teams still need visibility into live shell commands and output data. Reviewing what agents run and masking sensitive output fields closes the runtime safety gap.

Govern kubectl and API calls in flight

Identity providers and Kubernetes RBAC decide who logs into a cluster. They cannot redact keys inside returned JSON objects or hold a risky delete call for review. By design, hoop.dev runs as an open-source proxy, a sidecar for your Kubernetes API, checking requests and responses without replacing RBAC.

First, hoop.dev guardrails refuse banned methods, paths, or headers before they run. Next, hoop.dev data masking rewrites sensitive keys in returned Secret, ConfigMap, and log responses in memory, and writes each decision to the audit trail. Explore the repo on GitHub.

Frequently asked questions

How do I limit a Mastra agent to one Kubernetes namespace?

Create a Role and a RoleBinding inside that specific namespace for the agent identity. Do not use a ClusterRoleBinding, because that grants access across all namespaces in the cluster.

Can Kubernetes RBAC block specific shell commands inside a pod exec session?

No, native RBAC only checks if the identity can call the pod exec subresource. Once the session starts, RBAC does not filter or block individual shell commands.

How does Kubernetes handle deny rules for AI agent roles?

Kubernetes RBAC does not have deny rules because all permissions are purely additive. To remove access, you must remove the rule or delete the binding for that role.

The query runs. The emails stay hidden.