How to Configure n8n Kubernetes Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up n8n kubernetes least privilege by binding your n8n pod to a scoped role. You also restrict which cluster APIs and external tools your workflows can call. Many teams first deploy n8n with wide cluster rights to make automation work fast. That broad setup lets a single workflow read secrets or change pods across every namespace. If an external webhook or an AI agent runs a bad step, the blast radius grows. How to set up n8n kubernetes least privilege To lock down n8n inside a cluster

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 n8n kubernetes least privilege by binding your n8n pod to a scoped role. You also restrict which cluster APIs and external tools your workflows can call. Many teams first deploy n8n with wide cluster rights to make automation work fast. That broad setup lets a single workflow read secrets or change pods across every namespace. If an external webhook or an AI agent runs a bad step, the blast radius grows.

How to set up n8n kubernetes least privilege

To lock down n8n inside a cluster, start with native role-based rules. In Kubernetes, a Role sets permissions inside one single namespace. A ClusterRole sets permissions across the whole cluster or for cluster-scoped objects like nodes. You should create a dedicated service account just for your n8n pods. Next, write a Role in the namespace where n8n runs or manages workloads.

Kubernetes rules are purely additive, which means there are no deny rules. You must start with zero permissions and add only the exact verbs and resources needed. A RoleBinding grants permissions inside one namespace and links your service account to that Role. A ClusterRoleBinding grants access across the entire cluster, so avoid it for n8n workloads. If n8n needs a ClusterRole rule set, bind it with a namespace RoleBinding instead.

Pay close attention to subresources when you write your role rules. Kubernetes APIs use subresources for actions like reading pod logs or running commands in pods. If a workflow only checks pod health, grant access to the main pod resource only. Do not grant access to the pod log or pod exec subresources by mistake. Keeping subresources out of the role stops workflows from running shell commands in other containers.

Scoping n8n workflows and AI agent tools

Cluster roles control what the n8n pod can do to the Kubernetes API. Still, n8n workflows also reach out to databases, HTTP endpoints, and internal services. The n8n AI Agent node builds an agent from a chat model and attached tools. Based on the prompt, the agent decides which tools to call to finish a task. Every AI Agent node requires at least one connected tool sub-node to run.

You can attach built-in database tool sub-nodes, custom code tools, or HTTP request tools. If your workflow uses an HTTP Request Tool to call the Kubernetes API, scope it down. Give that tool its own dedicated credentials rather than sharing the main pod identity. If the agent queries a database, attach a Postgres or MySQL tool sub-node with read-only rights. Never hand an AI agent a database account that can drop tables or alter schemas.

Least Privilege Principle + Kubernetes RBAC: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native roles solve and what keeps the session active

Native Kubernetes roles and scoped database accounts solve the initial login problem well. They decide which service account or user can open a session to a resource. If an n8n pod tries to list secrets in another namespace, the API server blocks it. This static boundary stops many basic lateral movement paths inside your cluster.

Still, native roles leave a major operational gap open during live workflow runs. Once a role allows an action, Kubernetes and databases do not inspect individual commands in flight. A role that allows pod exec cannot block one dangerous shell flag while allowing safe ones. A database role that reads a table returns all columns, including emails and card numbers by default. Also, when an AI agent picks tools on the fly, static roles cannot require human approval for one risky query. Teams need runtime controls that inspect each command, mask sensitive fields in results, and log every action.

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

Should n8n use a RoleBinding or a ClusterRoleBinding?

Use a RoleBinding whenever possible so permissions stay inside one single namespace. Even if you reference a ClusterRole, binding it with a RoleBinding limits its scope to that namespace.

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

No, Kubernetes RBAC only checks if the account can call the pod exec subresource. It does not read or filter the actual shell command sent inside that session.

How do I limit what an n8n AI Agent node can run?

Attach only the specific tool sub-nodes the agent needs for its task. Pair each tool sub-node with a restricted account that holds minimum read or write rights.

The query runs. The emails stay hidden.