How to Configure K3s Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

To set up k3s least privilege, lock down the host kubeconfig file and create scoped roles. You must also stop sharing the default admin key with your team. Most teams install K3s on a small server and share the main root file. That file gives every user full control over the whole cluster. One bad command can delete live apps or expose private keys. How k3s least privilege works in practice K3s packs a full Kubernetes control plane into one small binary. When the server starts, it writes a lo

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 k3s least privilege, lock down the host kubeconfig file and create scoped roles. You must also stop sharing the default admin key with your team. Most teams install K3s on a small server and share the main root file. That file gives every user full control over the whole cluster. One bad command can delete live apps or expose private keys.

How k3s least privilege works in practice

K3s packs a full Kubernetes control plane into one small binary. When the server starts, it writes a local admin file on the host machine. Anyone who can read that host file owns the entire cluster. Your first step is to restrict file read rules on the host. Only the system root user should read that local admin file.

Next, you set up Role-Based Access Control inside the cluster. You group apps into separate spaces called namespaces. Then you create a specific role for each namespace. A role lists the exact objects a user or app can touch. You also pick the allowed actions, such as read, list, or delete. Finally, you bind that role to a user or a service account.

Apps running inside pods also need strict limits. By default, a pod gets a service account token by default. If the app does not talk to the cluster API, turn that off. You should also set a security context for every pod. Tell the pod to run as a non-root user ID. Drop extra Linux kernel powers that the app does not need.

Why you should separate cluster roles from node access

K3s often runs on edge devices or small virtual machines. Engineers often log into these Linux hosts using SSH to check logs. If a developer has sudo rights on the node, cluster roles do not matter. They can read the local state database or grab the root key. True least privilege means keeping engineers off the underlying Linux host.

You should also limit how nodes talk to the control plane. Worker nodes only need permissions to report status and run assigned pods. Keep your control plane API port closed to the public web. Use network rules so only trusted machines can send API requests. Rotate your cluster keys on a regular schedule to limit stolen credential risk.

Least Privilege Principle + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

What native K3s roles solve and what they miss

Native K3s roles decide who can call the API and which objects they see. This stops a developer in one namespace from deleting pods in another. It also keeps basic workloads from taking over the host machine. These controls form a strong base for cluster safety.

Still, static roles cannot inspect what happens inside an active session. Once an engineer gets permission to open a pod shell, RBAC steps aside. Native roles do not check individual shell commands in flight. They also cannot rewrite sensitive fields like emails or card numbers in output. If a user can read secrets, they get the raw values right away. Teams still need a way to govern live commands and protect data.

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 sits inline beside the API server as a sidecar for your Kubernetes API. For every production API call an agent or human sends, hoop.dev decides whether to pass, mask, block, or escalate it for review alongside RBAC.

With hoop.dev Kubernetes controls, guardrails allow listing Secret names while refusing reads of Secret data before execution, and 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

Why is the default K3s kubeconfig file risky?

The default file holds full cluster admin rights with no limits at all. If non-root users can read it, they can control every pod and secret.

How do I stop pods from using the K3s API?

Turn off automatic token mounting on the pod spec or the service account. This stops K3s from placing an API token inside the running container.

Can K3s RBAC block specific commands inside a pod shell?

No, native RBAC only checks if a user can start the shell session. Once the session opens, RBAC cannot filter or block the commands they run.

The query runs. The emails stay hidden.