How to Configure Mastra Kubernetes Audit Log
You set up a mastra kubernetes audit log by turning on API server audit rules. Then you bind your agent service account to a tight role. Engineering teams often deploy AI agents inside a cluster to automate daily work. Many teams start by giving the agent broad cluster permissions to avoid errors. When roles are too wide, the agent can read or change unintended cluster resources. A clear audit trail helps your team see what the agent does at all times. How a mastra kubernetes audit log works i
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 a mastra kubernetes audit log by turning on API server audit rules. Then you bind your agent service account to a tight role. Engineering teams often deploy AI agents inside a cluster to automate daily work. Many teams start by giving the agent broad cluster permissions to avoid errors. When roles are too wide, the agent can read or change unintended cluster resources. A clear audit trail helps your team see what the agent does at all times.
How a mastra kubernetes audit log works in your cluster
Mastra runs automated workflows and agent tasks that often talk to the cluster API. Every request from the agent hits the Kubernetes API server first. The API server checks who the user is and what role they hold. It also records the request details in the cluster audit log.
In Kubernetes, a Role or ClusterRole holds a set of permissions. These rules are additive, which means there are no deny rules in the system. A Role sets permissions inside one single namespace. A ClusterRole works across the whole cluster and covers nodes or all namespaces. You link an agent identity to these rules with a RoleBinding or ClusterRoleBinding. A RoleBinding grants permissions inside one namespace, even if it points to a ClusterRole. A ClusterRoleBinding gives the agent access across the entire cluster.
When your agent reads pod logs or runs commands, it uses API subresources. Kubernetes RBAC names these subresources with a slash, like the pod log endpoint. The audit log records when the agent calls these top-level resources or subresources. Your team can read these log entries to check which endpoint the agent hit. You can also see the response code and the time of the call.
What native cluster roles and logs miss in flight
Native cluster roles and audit logs solve the first step of access control. Role bindings decide which service account or user can log in and call APIs. The cluster audit log shows that a pod execution call happened at a specific time. This setup keeps unauthorized apps out of your namespaces.
Still, native setup leaves an operational gap during live execution. RBAC decides who can start a session, not what commands run inside that session. Once an agent gets pod execution rights, it can run any shell command inside. The standard API server audit log shows the request to open the exec stream. It does not inspect or block individual shell commands sent over that open stream. Also, native RBAC restrictions on resource names do not apply when creating subresources.
Audit Log Integrity + Kubernetes Audit Logs: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Why runtime command and data controls matter for agents
AI agents act fast and can run many tasks in seconds. If an agent hallucinates a bad command, broad roles will not stop it. Relying only on static roles means you find out about mistakes after they happen. You read the audit log after the bad command already changed your pod state.
Teams also need to worry about sensitive data inside pod logs or database outputs. When an agent pulls data to finish a task, it might fetch personal details. Without field masking, raw emails, phone numbers, card numbers, or national IDs flow back. Masking tools rewrite matched fields in results before the agent or user processes them. Pairing cluster audit logs with command-level checks gives your team real control over agents.
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
How do I limit Mastra to a single Kubernetes namespace?
Create a standard Role and a RoleBinding inside that specific namespace. Do not use a ClusterRoleBinding, because that grants permissions across the whole cluster.
Does Kubernetes RBAC let me write deny rules for risky agent actions?
No, Kubernetes RBAC permissions are purely additive and never include deny rules. You must start with zero permissions and only add the exact verbs needed.
Can native audit logs show every shell command run inside a pod?
Native API audit logs record the initial subresource call to open a pod session. They do not inspect or filter the interactive commands typed inside that stream.
Related guides
In this post