How to Configure AKS Least Privilege

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up aks least privilege by creating narrow Kubernetes roles and binding them to specific namespaces. This limits each user or service account to the exact API calls required for their job. Many teams start with broad cluster admin rights to get apps running fast. Broad rights create huge risk because one bad command can break the whole cluster. If a key leaks, an attacker gains full control over every namespace and node. Moving to tight rules stops users from touching resources outside th

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 aks least privilege by creating narrow Kubernetes roles and binding them to specific namespaces. This limits each user or service account to the exact API calls required for their job. Many teams start with broad cluster admin rights to get apps running fast. Broad rights create huge risk because one bad command can break the whole cluster. If a key leaks, an attacker gains full control over every namespace and node. Moving to tight rules stops users from touching resources outside their own team space.

How to set up aks least privilege with native roles

Kubernetes role-based access control uses four main objects to manage permissions across your cluster. A Role sets permissions inside a single namespace for one specific team or app. A ClusterRole sets permissions across the whole cluster for nodes or shared items. Every rule in this system is additive, which means there are no deny rules. You start with zero rights and add only the verbs and resources a person needs.

Once you define a Role, you link it to a user with a RoleBinding. That binding grants those exact permissions inside one namespace and nowhere else. You can also point a RoleBinding at a ClusterRole to reuse common rule sets. When you do that, the user still gets rights only inside the bound namespace. By contrast, a ClusterRoleBinding grants rights across every namespace in the entire cluster. To keep permissions tight, teams avoid cluster-wide bindings for daily developer work.

You also need to control subresources when you build your permission rules. Kubernetes treats actions like reading pod logs or running commands in pods as subresources. In your rules, you name both the top resource and the subresource separately. A developer might need to read pod logs without getting shell entry to pods. Splitting these rules lets you grant log reading while blocking interactive shell commands.

Why native roles are not enough for live sessions

Native roles do a great job of deciding who can reach a Kubernetes resource. They block unauthorized users at the API server before a request even starts. Still, static role bindings stay active all day long once you create them. Engineers keep standing rights even when they are not fixing a live issue. Over time, people collect extra bindings across namespaces as they switch tasks or teams.

Another big gap appears once a user gets permission to run commands in a pod. Kubernetes checks the role when the user starts the interactive shell session. Once that shell opens, native RBAC cannot see or filter what happens inside. The engineer can run any binary, read local files, or query attached data stores. Native rules control who opens the door, not what commands run inside the room.

Least Privilege Principle + AKS Managed Identity: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Managing subresources and service accounts

Human users are only half of the permission puzzle in a cloud cluster. Apps and build tools also use service accounts to talk to the cluster API. If a pod runs with a broad service account, a compromised app can alter cluster state. You should create one dedicated service account for each app that needs API rights. Bind that account to a narrow Role inside its own namespace only.

Review your bindings often to spot old rules that teams no longer use. Remove cluster-wide bindings and replace them with namespace-scoped bindings wherever you can. Keep shell subresource rights out of standard developer roles to reduce daily risk. When someone needs shell entry to fix a bug, handle that request with strict controls.

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

Can I write a deny rule in Kubernetes RBAC to block one specific action?

No, Kubernetes permissions are purely additive and do not support deny rules. To block an action, you must remove the binding or leave that verb out of the Role.

What is the difference between a RoleBinding and a ClusterRoleBinding?

A RoleBinding grants permissions inside one specific namespace only. A ClusterRoleBinding grants permissions across all namespaces and cluster-wide resources at once.

How do I let developers read pod logs without giving them shell access?

Grant get and list rights on the pods log subresource in their Role. Leave the pods exec subresource out of the Role so shell commands fail.

The query runs. The emails stay hidden.