How to Configure Dify Kubernetes Audit Log
You set up a dify kubernetes audit log by turning on API server audit policies. Next, you bind scoped RBAC roles to your Dify namespace and service accounts. Platform teams often start with broad cluster roles to get Dify pods running fast. Broad roles let any user or pod read secrets and run commands across namespaces. Scoping roles and recording API events helps teams track who touches AI workloads. How a dify kubernetes audit log works with RBAC Kubernetes tracks cluster actions through it
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 dify kubernetes audit log by turning on API server audit policies. Next, you bind scoped RBAC roles to your Dify namespace and service accounts. Platform teams often start with broad cluster roles to get Dify pods running fast. Broad roles let any user or pod read secrets and run commands across namespaces. Scoping roles and recording API events helps teams track who touches AI workloads.
How a dify kubernetes audit log works with RBAC
Kubernetes tracks cluster actions through its API server. Every request from a user or a Dify pod goes through this central point. Before the API server runs a request, it checks role-based access control rules. In Kubernetes, permissions are additive, and there are no deny rules. You build access from zero by writing explicit allow rules.
A Role sets permissions inside one single namespace, such as your Dify workspace. A ClusterRole sets permissions across the whole cluster, including nodes and all namespaces. To give those permissions to a user or Dify service account, you create a binding. A RoleBinding grants access inside one namespace. It can point to a local Role or a shared ClusterRole. A ClusterRoleBinding grants access across every namespace in the cluster.
RBAC names resources the exact same way they appear in the API URL. Some actions use a subresource, such as reading a pod log or opening a shell. RBAC writes these subresources with a slash, covering pod logs or pod execution calls. When the API server checks these calls, the audit log records the event. The log captures who made the call, the target namespace, and the subresource used.
What native audit logs solve and what they miss
Native roles and audit logs solve the first layer of cluster control. They tell you which identity asked the API server to view a pod or secret. By using a RoleBinding in the Dify namespace, you block lateral moves to other apps. If an engineer or service account tries to list pods elsewhere, the API blocks it. The audit log records both allowed calls and denied attempts for your review team.
Still, native setup stops at the API server door. Once RBAC allows a pod execution subresource call, the user opens a live shell inside Dify. The Kubernetes audit log records that the shell started, along with the user identity. It does not inspect individual shell commands or database queries run inside that container. It also does not mask sensitive data returned during those live debugging sessions.
Audit Log Integrity + Kubernetes Audit Logs: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Dify workloads often hold database keys and user records like emails, phone numbers, or card numbers. If an engineer runs a query from a pod shell, native RBAC cannot rewrite the result. A static role decides who can start a session, not what happens in flight. Teams also struggle when restricting create calls on subresources by specific resource names. Kubernetes applies resource name limits on create calls only to top-level resources, not subresources.
Best practices for scoping Dify cluster roles
Start by putting all Dify pods, worker queues, and storage claims into one dedicated namespace. Write a local Role that only grants access to the resources Dify needs to run. Avoid using a ClusterRoleBinding for app service accounts or daily developer debugging tasks. Separate the roles that let engineers read pod logs from roles that allow shell execution.
Review your audit policy so the API server logs calls to secrets and pod subresources. Send those audit events to a separate log store outside the main workload cluster. That way, an admin inside the cluster cannot alter past log entries. Regular checks of your RoleBindings help you spot leftover permissions before they become a risk.
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
Does the Kubernetes audit log record commands run inside a Dify pod shell?
The API server audit log records the initial request to open the pod execution subresource. It does not inspect or block individual shell commands or database queries inside that session.
Should I use a Role or a ClusterRole for Dify workloads?
Use a Role and a RoleBinding scoped to the specific namespace where Dify runs. A ClusterRoleBinding gives cluster-wide access, which exposes other namespaces if a pod or key is compromised.
Can I write a deny rule in Kubernetes RBAC to block secret access?
No, Kubernetes RBAC permissions are purely additive and do not support deny rules. To block access to secrets, omit secret permissions from the Role and remove broad bindings.
Related guides
In this post