How to Configure CrewAI Kubernetes Audit Log

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up a crewai kubernetes audit log by defining API server audit rules. You also bind a distinct service account to the tools your agents run. Platform teams often start by giving AI agents a shared admin role. That broad role lets agents read or change workloads across every namespace. When an agent runs a bad command, the logs show one generic identity. You cannot tell which agent task or human user triggered the cluster change. How the crewai kubernetes audit log works with cluster rol

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 crewai kubernetes audit log by defining API server audit rules. You also bind a distinct service account to the tools your agents run. Platform teams often start by giving AI agents a shared admin role. That broad role lets agents read or change workloads across every namespace. When an agent runs a bad command, the logs show one generic identity. You cannot tell which agent task or human user triggered the cluster change.

How the crewai kubernetes audit log works with cluster roles

In CrewAI, you group AI agents together to complete multi-step tasks. You give those agents tools that call the Kubernetes API to check pods. Each tool uses a Kubernetes identity, which is usually a service account. When the tool makes a call, the API server checks its permissions. Kubernetes RBAC uses Roles and ClusterRoles to hold sets of permission rules. These rules are purely additive, which means there are no deny rules. A Role sets permissions inside one single namespace for your agent workloads. A ClusterRole covers the whole cluster, including nodes and all namespaces. You link the agent identity to a Role using a RoleBinding. You can also use a ClusterRoleBinding to grant permissions across the whole cluster.

Every time a CrewAI tool calls the API, the server records an event. The API server writes these entries to the native audit log. This log shows the service account name, the target resource, and the action. Some API calls use subresources, such as reading pod logs or running commands. In RBAC rules, you write these subresources with a slash. If an agent reads pod output, the audit log records the subresource call. If you give each agent crew its own service account, the log separates them. You can then filter the audit records by that specific service account name.

What native cluster logging solves and what it misses

Native roles and audit logs solve the basic problem of cluster entry. They verify which service account logged in and whether it had permission. If a CrewAI agent tries to delete a deployment without permission, RBAC blocks it. The audit log then records that rejected API call for your security team. Setting up namespace Roles also stops an agent from touching other teams' pods. This native setup gives you a clear record of API requests over time.

Still, native RBAC and audit logs leave a big operational gap open. RBAC only checks if the service account can use a resource or subresource. It does not check what individual commands or queries do in flight. For example, an agent might have permission to run commands inside a pod. The native audit log records that an exec session started on that pod. It does not inspect every shell command the agent sends inside that session. It also cannot pause a single risky command for a human to approve. In the same way, pod logs might return customer emails or phone numbers. Native Kubernetes logs do not rewrite matched fields in results before agents read them. Static service account keys can also sit on developer machines for months. If a key leaks, anyone can make API calls under the agent's name.

Audit Log Integrity + Kubernetes Audit Logs: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

How to scope agent permissions before running tasks

Start by creating a separate Kubernetes namespace for each CrewAI project you run. Create a dedicated service account for each specific agent tool in that namespace. Write a Role that grants only read verbs on the pods resource. Avoid using ClusterRoles or ClusterRoleBindings unless the agent must check cluster nodes. Do not grant exec subresource permissions to agents that only check pod health. Next, set up your API server audit rules to log events for those accounts. Send those audit events to a central log store for your security team. Review the logs each week to remove any permissions the agents never use. This keeps your native cluster rules tight while you add deeper runtime controls.

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

Why do all my CrewAI agents look the same in the Kubernetes log?

Your agents likely share one default service account or one static kubeconfig file. Give each agent tool its own service account so the log shows distinct names.

Can Kubernetes RBAC block a specific shell command inside a pod exec call?

No, Kubernetes RBAC only controls whether the identity can call the exec subresource. Once the session starts, native RBAC does not filter the commands run inside it.

Should I use a Role or a ClusterRole for CrewAI troubleshooting agents?

Use a Role and a RoleBinding whenever the agent works in one namespace. Only use a ClusterRole if the agent must inspect nodes or many namespaces.

The query runs. The emails stay hidden.