How to Configure AKS Secrets

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up aks secrets by creating secret objects in a namespace. Next, you bind a Kubernetes role to control who can read them. Many teams start by giving developers broad cluster roles to speed up work. When roles are too broad, anyone can read sensitive keys across all apps. A safe setup scopes permissions down to one namespace and specific users. How aks secrets work with Kubernetes RBAC Kubernetes uses Role-Based Access Control to manage who can read or write cluster items. In this syste

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 secrets by creating secret objects in a namespace. Next, you bind a Kubernetes role to control who can read them. Many teams start by giving developers broad cluster roles to speed up work. When roles are too broad, anyone can read sensitive keys across all apps. A safe setup scopes permissions down to one namespace and specific users.

How aks secrets work with Kubernetes RBAC

Kubernetes uses Role-Based Access Control to manage who can read or write cluster items. In this system, permissions are additive, which means there are no deny rules. You start with zero access and add rules for each action you need. A Role sets permissions inside one specific namespace. A ClusterRole sets permissions across the whole cluster and covers all namespaces.

To protect aks secrets, you define a Role in the target namespace. That Role lists secrets as the resource and sets the allowed verbs. Verbs include actions like get, list, watch, create, update, or delete. Once the Role exists, you create a RoleBinding in that same namespace. The RoleBinding links the Role to a specific user, group, or service account.

You can also use a RoleBinding to reference a broader ClusterRole. When you do this, the user only gets permissions inside that single namespace. By contrast, a ClusterRoleBinding grants permissions across every namespace in the cluster. Teams should avoid ClusterRoleBindings for secret rules unless a tool needs cluster-wide reach. Scoping every secret rule to one namespace keeps app credentials isolated from other teams.

How pods and subresources interact with secret permissions

Granting secret permissions is only one part of cluster security. Users who cannot read aks secrets directly might still reach them through running pods. When a pod starts, it often mounts secret values as files or environment variables. Kubernetes RBAC treats pod actions like viewing logs or running commands as subresources. In RBAC rules, a subresource appears with a slash after the main resource name.

For example, reading pod logs or running an exec command uses specific pod subresources. If a developer has permission to run exec on a pod, they can open a shell. From that shell, they can read any secret mounted inside that container. So, locking down secrets also requires tight rules on pod exec subresources. You must audit both direct secret roles and pod subresource roles in each namespace.

K8s Secrets Management + AKS Managed Identity: 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 Kubernetes RBAC is great at deciding who can call the cluster API. It stops unauthorized users from listing secrets or starting shells in other namespaces. Still, RBAC only checks permissions at the moment a request hits the API server. Once a user passes that check, RBAC does not inspect what happens next.

If an engineer gets exec access to fix a live bug, they have full container reach. Native RBAC cannot approve individual commands or redact sensitive values inside that shell output. It cannot rewrite emails, phone numbers, card numbers, or national IDs in command results. Also, static role bindings stay active until someone removes them by hand. Teams need a way to govern live commands and remove standing permissions after a fix.

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 sits inline as an open-source proxy, a sidecar for your Kubernetes API, without replacing RBAC. On every production call from an engineer or AI agent, hoop.dev decides to pass, mask, block, or hold it for human approval.

First, hoop.dev guardrails refuse banned methods, paths, or headers before they run or hold risky deletes for review. 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

Should I use a RoleBinding or a ClusterRoleBinding for aks secrets?

Use a RoleBinding for almost all app and team secret permissions. A RoleBinding keeps secret access inside one namespace, while a ClusterRoleBinding exposes secrets across the entire cluster.

Can I write a deny rule in Kubernetes RBAC to block secret access?

No, Kubernetes RBAC rules are strictly additive and do not support deny rules. To block access, you must remove the RoleBinding or ClusterRoleBinding that grants the permission.

Why can users without secret permissions still see keys inside a pod?

Users with permission for the pod exec subresource can open a shell inside the container. Once inside the container, they can read secret values mounted as files or variables.

The query runs. The emails stay hidden.