How to Configure Dify Kubernetes Connect
To set up a dify kubernetes connect workflow, you give your Dify app a Kubernetes role and key. This setup lets AI workflows call the cluster API to read pod state or run tasks. Teams often start by binding a broad cluster role to get the workflow running fast. That wide permission creates a big risk if an AI prompt triggers a bad command. Scoping the role down from day one keeps your cluster safe from accidental deletions. How to set up dify kubernetes connect with RBAC Kubernetes uses Role-
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 dify kubernetes connect workflow, you give your Dify app a Kubernetes role and key. This setup lets AI workflows call the cluster API to read pod state or run tasks. Teams often start by binding a broad cluster role to get the workflow running fast. That wide permission creates a big risk if an AI prompt triggers a bad command. Scoping the role down from day one keeps your cluster safe from accidental deletions.
How to set up dify kubernetes connect with RBAC
Kubernetes uses Role-Based Access Control to check every API request from an external tool. In this system, a Role or ClusterRole holds a list of rules. Each rule represents a set of allowed actions. These permissions are purely additive, which means there are no deny rules at all. You only state what the caller can do.
A standard Role sets rules inside one single namespace. This is the safest choice when your Dify agent only manages one team's workloads. A ClusterRole is not tied to one namespace. It can cover cluster-wide objects like nodes or apply to resources across all namespaces.
Once you define the rules, you attach them to the identity your Dify workflow uses. A RoleBinding grants those permissions inside one specific namespace. A RoleBinding can point to a local Role or a broader ClusterRole. If your Dify agent needs to inspect the whole cluster, you use a ClusterRoleBinding instead. That binding grants access across the entire cluster.
Kubernetes RBAC also controls subresources through the same API path names. For example, reading pod logs or running commands inside a container uses subresources. You write these in your rules with a slash, such as the pod log subresource. If you leave out the subresource rule, the Dify tool can see the pod object. Still, it cannot read the logs or run shell commands inside it.
What native RBAC solves and what keeps the session active
Native Kubernetes RBAC does a great job deciding which identity can reach an API endpoint. You can limit a Dify tool so it only reads pods in a test namespace. You can also block it from touching nodes or secrets in other namespaces. This stops an AI workflow from wandering into parts of the cluster it does not own.
Still, RBAC only checks the resource type and the action verb when the request arrives. It does not inspect what happens inside an allowed session or what data returns. If you grant access to the pod exec subresource, the AI agent can open a shell. RBAC cannot tell a safe diagnostic command apart from a destructive shell command inside that pod.
Kubernetes RBAC + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
The same gap appears when a workflow reads pod logs or config data. Pod logs often print sensitive customer data by mistake. You might find emails, phone numbers, card numbers, or national IDs in those text streams. Native RBAC hands the full log output straight back to the Dify workflow. A complete setup needs a way to check commands in flight and mask sensitive fields in results.
Scoping subresources for safer AI workflows
When you build AI agents that fix alerts, keep read rules separate from write rules. Give your first Dify tool a Role that only allows get and list on pods. Add the pod log subresource so the agent can read error output and suggest a fix.
Do not include the pod exec subresource in that same everyday role. If a workflow must run commands inside a container, put that rule in a separate Role. Bind that role only to the specific namespace where the fix must run. Also remember that Kubernetes restricts how you filter subresources by name on creation calls. The resource names filter on create rules applies only to top-level resources, not to subresources. Because of this rule, namespace boundaries remain your best tool for limiting where an agent can act.
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
Can I add a deny rule to block a Dify agent from one namespace?
No, Kubernetes RBAC rules are purely additive and do not support deny rules. To block access to a namespace, use RoleBindings in only the allowed namespaces instead of a ClusterRoleBinding.
How do I let a Dify workflow read pod logs without full pod access?
In Kubernetes RBAC, pod logs are a subresource written with a slash after the pod resource. You create a Role that grants get permission on that specific log subresource inside the target namespace.
Should I use a Role or a ClusterRole for a Dify integration?
Start with a Role and a RoleBinding so the Dify workflow stays inside one single namespace. Only use a ClusterRole and ClusterRoleBinding if the AI agent must read nodes or check all namespaces.
Related guides
In this post