How to Configure AKS Service Account
You set up an aks service account by creating the account in a namespace. Next, you bind that account to a Kubernetes role with specific rules. Platform teams often start with broad cluster roles to get apps running fast. When roles are too broad, one bad pod can read secrets across the cluster. Teams must scope every account down to the exact API calls it needs. How an aks service account works with RBAC Every pod in Azure Kubernetes Service needs an identity to talk to the API server. The s
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 an aks service account by creating the account in a namespace. Next, you bind that account to a Kubernetes role with specific rules. Platform teams often start with broad cluster roles to get apps running fast. When roles are too broad, one bad pod can read secrets across the cluster. Teams must scope every account down to the exact API calls it needs.
How an aks service account works with RBAC
Every pod in Azure Kubernetes Service needs an identity to talk to the API server. The service account provides this identity for apps running inside your cluster. By default, a new account has no extra rules attached to it. You must grant permissions using Role-Based Access Control on the API server. Kubernetes RBAC rules are additive, which means there are no deny rules. You start with zero rights and add only the actions the app requires.
First, you pick between a namespace Role and a cluster-wide ClusterRole. A Role sets permissions inside one single namespace for local workloads. A ClusterRole covers cluster-scoped objects like nodes or resources across all namespaces. Most app teams should use a standard Role to keep boundaries tight. You list the target API objects and the allowed verbs like read or write. Some API calls use a subresource, such as reading pod logs or running exec commands. You must list those subresources in your role rules if the pod needs them.
After you write the role, you link it to the aks service account. A RoleBinding grants those permissions inside one specific namespace. A RoleBinding can point to a local Role or a shared ClusterRole. If a pod truly needs cluster-wide reach, you use a ClusterRoleBinding instead. Once bound, the pod uses its mounted token to call the Kubernetes API.
How to scope permissions across namespaces
Good cluster hygiene starts with giving each app its own dedicated identity. Never let different apps share the default account in a namespace. When apps share an identity, every pod gets the sum of all bound rules. Splitting accounts lets you audit which app made a specific API request. It also stops a small background worker from using rights meant for a deploy tool.
You can reuse a single ClusterRole across many namespaces with separate RoleBindings. For example, a logging tool might need to read pod subresources in three namespaces. You define the read rule once in a ClusterRole. Then you place a RoleBinding in each of the three target namespaces. The service account gains read rights in those three places and nowhere else. This pattern avoids full cluster bindings while keeping role files easy to manage.
Service-to-Service Authentication + Service Account Governance: 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 RBAC is great at checking who can call a Kubernetes API endpoint. It stops unauthorized pods from listing secrets or starting new workloads in other namespaces. It also controls which users or accounts can open an exec session into a pod. For pure workload-to-API traffic, scoped roles and bindings do the heavy lifting.
Still, Kubernetes RBAC only checks permission at the start of an API request. Once RBAC allows an exec subresource call, it cannot see the shell commands inside. If a human or tool runs a shell through that account, RBAC steps aside. It cannot block a dangerous command inside the container or mask sensitive output. It cannot rewrite emails, phone numbers, card numbers, or national IDs in query results. Native roles decide who gets in the door, not what happens inside the session.
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 proxy, a sidecar for your Kubernetes API, inline on the API connection. On every kubectl or API call an AI agent or engineer runs against production, hoop.dev decides to pass, mask, block, or hold it for human review.
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, or hold risky calls for approval. On the way back, hoop.dev data masking walks JSON responses by key and masks matched values in Secrets, ConfigMaps, and pod logs in memory. View the project on GitHub.
Frequently asked questions
Can I add a deny rule to an aks service account?
No, Kubernetes RBAC permissions are additive and do not support deny rules. To block an action, you must remove the rule or binding that grants it.
Should I use a RoleBinding or a ClusterRoleBinding for app pods?
Use a RoleBinding whenever the pod only needs resources inside one namespace. Save ClusterRoleBindings for cluster tools that must read nodes or watch all namespaces.
How do I let a service account read pod logs?
Pod logs are a subresource in the Kubernetes API. You must add a rule for the pods and log subresource with read verbs.
Related guides
In this post