How to Configure Dify Kubernetes Read Only Access

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up dify kubernetes read only access by binding a restricted Kubernetes role to the Dify account. This role grants view permissions for pods and logs while blocking write actions. Many teams start by giving their AI apps broad cluster admin rights for quick testing. Broad permissions let an AI workflow delete pods or read secret keys by mistake. Scoping permissions down before production prevents bad prompts from breaking your cluster. How dify kubernetes read only access works in nativ

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 read only access by binding a restricted Kubernetes role to the Dify account. This role grants view permissions for pods and logs while blocking write actions. Many teams start by giving their AI apps broad cluster admin rights for quick testing. Broad permissions let an AI workflow delete pods or read secret keys by mistake. Scoping permissions down before production prevents bad prompts from breaking your cluster.

How dify kubernetes read only access works in native RBAC

Kubernetes role-based access control uses rules that are purely additive. There are no deny rules in this system. You start with zero permissions and add exact verbs like get, list, and watch. A Role sets permissions inside one single namespace. A ClusterRole sets permissions across all namespaces or for cluster-wide items like nodes.

To connect Dify safely, you create a dedicated service account for your AI agent. Next, you define a Role or ClusterRole that lists only safe resources. You include pods, deployments, events, and services with read verbs only. You must leave out secrets so the AI workflow does not read private keys.

Kubernetes also uses subresources that match the names in the API URL. You write a subresource with a slash, such as the log subresource on pods. If your Dify agent checks why an app crashed, it needs permission on the pod log subresource. You must avoid granting permissions on the pod exec subresource. That exec rule lets a caller run live commands inside a running container.

Finally, you attach the role to the Dify service account with a binding. A RoleBinding grants permissions inside one namespace, even if it points to a ClusterRole. A ClusterRoleBinding grants access across the whole cluster. Using a RoleBinding keeps your Dify workflow locked inside one target namespace.

Where native Kubernetes roles fall short for AI agents

Native Kubernetes RBAC controls which account can call a given API path. This setup works well for static apps with fixed tasks. Still, AI workflows in Dify run dynamic queries based on user prompts. Once the service account passes the role check, Kubernetes returns the full output.

Read-only permissions do not filter the content inside pod logs or event messages. App logs often print user emails, phone numbers, card numbers, or national IDs. When Dify pulls those logs, that sensitive data flows straight into the language model prompt. A read-only role cannot rewrite matched fields in results before they reach the model.

Auditor Read-Only Access + Kubernetes API Server Access: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Static credentials also create a tracking problem for platform teams. Every Dify user shares the same service account token when querying the cluster. In the Kubernetes audit log, every action looks like it came from one bot account. You cannot see which person or Dify workflow triggered a specific cluster check.

Scoping subresources and namespace boundaries

Good cluster hygiene means separating human admin roles from machine roles. Give your Dify workflows a role that only covers non-sensitive namespaces. Never bind an AI tool to the system namespaces that run your cluster core.

You should also review your role definitions whenever you add new Dify tools. Keep the allowed resource list as short as possible. If the agent only checks pod status, do not include the pod log subresource. Tight boundaries reduce the blast radius when a prompt behaves in an unexpected way.

Govern kubectl and API calls in flight

Identity providers and Kubernetes RBAC decide who logs into a cluster. They cannot redact keys inside returned JSON objects or hold a risky delete call for review. By design, hoop.dev runs as an open-source proxy, a sidecar for your Kubernetes API, checking requests and responses without replacing RBAC.

First, hoop.dev guardrails refuse banned methods, paths, or headers before they run. Next, hoop.dev data masking rewrites sensitive keys in returned Secret, ConfigMap, and log responses in memory, and writes each decision to the audit trail. Explore the repo on GitHub.

Frequently asked questions

Can a read-only Kubernetes role block access to secrets?

Yes, Kubernetes permissions are purely additive and have no deny rules. If you omit the secrets resource from your role, the Dify account cannot read secret objects.

How do I let Dify read pod logs without giving container shell access?

Grant get and list verbs on the pods resource and the pod log subresource. Leave the pod exec subresource out of the role so the agent cannot run commands inside containers.

Should I use a RoleBinding or a ClusterRoleBinding for Dify?

Use a RoleBinding whenever possible to keep access inside a single namespace. You can bind a shared read-only ClusterRole to one namespace by using a RoleBinding.

The query runs. The emails stay hidden.