How to Configure Dify Kubernetes Credentials

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up dify kubernetes credentials by creating a scoped service account in your cluster. Then you bind that account to a Kubernetes role and add the token to Dify. Many teams skip scoped roles during early tests. They attach broad cluster admin rights to get an AI workflow running fast. Overly broad rights let a single prompt mistake change or delete live workloads across namespaces. How dify kubernetes credentials work in native RBAC Dify uses tools and custom plugins to talk to the Kube

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 dify kubernetes credentials by creating a scoped service account in your cluster. Then you bind that account to a Kubernetes role and add the token to Dify. Many teams skip scoped roles during early tests. They attach broad cluster admin rights to get an AI workflow running fast. Overly broad rights let a single prompt mistake change or delete live workloads across namespaces.

How dify kubernetes credentials work in native RBAC

Dify uses tools and custom plugins to talk to the Kubernetes API server. Each call from a Dify workflow needs a valid identity and a set of rules. Kubernetes uses Role-Based Access Control to check these calls. In Kubernetes RBAC, a Role or ClusterRole holds rules that represent a set of permissions. These permissions are purely additive, which means there are no deny rules.

A standard Role always sets permissions within a single namespace. A ClusterRole is not namespaced and can cover cluster-scoped resources like nodes. It can also cover namespaced resources across all namespaces. To link Dify to these rules, you create a RoleBinding or a ClusterRoleBinding. A RoleBinding grants permissions inside one namespace and can reference a Role or a ClusterRole. A ClusterRoleBinding grants access across the whole cluster.

When Dify reads pod logs or runs commands inside containers, RBAC checks subresources. Kubernetes RBAC refers to resources by the exact name in the API URL. Subresources use a slash format, such as the subresource for pod logs or pod exec. You must list these subresources in your Role rules if Dify needs them.

How to scope roles for AI workflows

Start by putting your Dify workloads or target apps in a dedicated namespace. Create a dedicated identity for the Dify tool rather than sharing a human admin account. Next, write a Role in that namespace that lists only the needed API verbs. Most AI triage agents only need read verbs on pods, events, and pod logs.

Bind this Role to your Dify identity with a RoleBinding in the same namespace. Avoid using a ClusterRoleBinding unless the workflow must inspect nodes or cluster-wide state. If you store the credential in Dify, rotate the token on a regular schedule. Check your RBAC bindings often to make sure extra roles were not added over time.

Ephemeral Credentials + Kubernetes RBAC: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native RBAC solves and what it leaves open

Native Kubernetes RBAC solves the problem of who can call a specific API endpoint. It stops a Dify workflow from touching namespaces or resource types outside its Role. This boundary is essential for basic cluster safety.

Still, native setup only checks the identity and the API resource at the door. Once a role grants pod exec or secret read rights, RBAC does not inspect payloads. It cannot pause a dangerous command inside an exec call for human approval. It also cannot mask sensitive fields like emails, phone numbers, card numbers, or national IDs. If pod logs contain customer card numbers, raw log output flows straight into the model. Teams need runtime controls to inspect commands and rewrite matched fields in results.

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

Should Dify use a Role or a ClusterRole for Kubernetes tasks?

Use a namespaced Role and RoleBinding whenever your Dify workflow works inside one namespace. Only use a ClusterRole and ClusterRoleBinding if Dify must read nodes or every namespace.

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

No, Kubernetes RBAC only controls who can call the pod exec subresource. It does not inspect or block the shell commands that run inside the container.

How do I stop Dify from reading all secrets in a cluster?

Do not include secret resources in a ClusterRole bound to Dify. Keep secret read rules out of your Role, since RBAC rules are purely additive.

The query runs. The emails stay hidden.