How to Configure AKS Network Policy

Published
Length
3 min read

Luis Felipe Dias

All posts

You set up an aks network policy by turning on a policy engine for your cluster. Next, you apply rules that match pod labels to allow or block traffic. Without these rules, every pod in your cluster can talk to every other pod. Teams also pair network rules with role rules to lock down cluster use. When role rules are too broad, users can run risky commands inside pods. How an aks network policy works with cluster roles In a standard Kubernetes cluster, all pods can send traffic to each other

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 network policy by turning on a policy engine for your cluster. Next, you apply rules that match pod labels to allow or block traffic. Without these rules, every pod in your cluster can talk to every other pod. Teams also pair network rules with role rules to lock down cluster use. When role rules are too broad, users can run risky commands inside pods.

How an aks network policy works with cluster roles

In a standard Kubernetes cluster, all pods can send traffic to each other by default. An aks network policy changes this open setup at the network level. The policy uses labels to pick a group of pods in a namespace. Then it defines which other pods or IP blocks can send data to them. It can also limit where those chosen pods can send data out. If a pod is not selected by any policy, its traffic keeps the session active. Once a policy selects a pod, it blocks all traffic not on the allow list.

Network rules control how apps talk to each other over the network. They do not control who can change those rules or log in to pods. For user permissions, teams rely on Kubernetes role-based access control, known as RBAC. In RBAC, a Role sets permissions inside one single namespace. A ClusterRole sets permissions across the whole cluster and covers nodes or all namespaces. You link these roles to users with a RoleBinding or a ClusterRoleBinding.

RBAC rules are purely additive, which means there are no deny rules. You start with zero access and add permissions for each API resource. Teams must restrict who can edit network policy objects in each namespace. If a user can change network rules, they can open traffic to private pods.

What native network and role rules solve and miss

Combining an aks network policy with RBAC solves two big security needs. First, the network policy stops a compromised pod from scanning the whole cluster. A frontend app can only talk to the backend app it needs. Second, RBAC stops unauthorized users from deleting pods or changing network rules.

Still, this native setup leaves an important operational gap open during daily work. Engineers often need to debug live pods or check app logs. In Kubernetes RBAC, permissions for pod logs and pod exec use subresources. An admin grants a user permission to the pod exec subresource for debugging. Once RBAC checks that role and lets the user in, its job ends.

AKS Managed Identity + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Neither the network policy nor RBAC inspects what the engineer runs inside that pod. Also, an aks network policy only filters pod-to-pod traffic on the cluster network. It does not filter commands sent through the Kubernetes API server via exec. A user with exec rights in a pod can run any shell command inside it. They can read local files or query a database that the pod can reach. Native roles decide who logs in, not what commands do in flight.

How to tighten pod traffic and user access

Start by setting up a default deny rule for each namespace in your cluster. This rule selects all pods in the namespace and blocks all incoming traffic. Next, write specific allow rules for each app based on its pod labels. Only open the exact ports that the receiving pod needs to run.

After you lock down the network, audit your RBAC bindings across all namespaces. Avoid using a ClusterRoleBinding when a user only works in one namespace. Check which roles grant access to the pod exec and secret resources. Keep the group of users who can edit network policies very small. For live debugging, teams need controls that check individual commands and mask sensitive output.

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

Does an aks network policy block kubectl exec sessions?

No, it only controls network traffic between pods and IP addresses. Kubectl exec traffic goes through the Kubernetes API server and kubelet. You must use Kubernetes RBAC rules to control who can start exec sessions.

Can I write a deny rule in Kubernetes RBAC?

No, Kubernetes RBAC rules are purely additive and have no deny rules. To block an action, you must remove the role binding that grants that permission. Network policies work in a similar way by allowing only listed traffic once applied.

What happens when no aks network policy selects a pod?

If no policy selects a pod, all traffic to and from it stays allowed. Once at least one policy selects that pod, unmatched traffic gets blocked. That is why teams start with a policy that selects all pods in a namespace.

The query runs. The emails stay hidden.