Back to Terraform

Policy and Isolation: Quotas, Admission and Network Enforcement

November 6, 2026 Wasil Zafar 22 min read

Prove that declared security controls are supported and enforced by the cluster data plane

Table of Contents

  1. Choose the Control That Matches the Requirement
  2. Verify NetworkPolicy Enforcement in the Selected Cluster
  3. Configure Namespace Resource and Pod Security Boundaries
  4. Review Admission Controller Ownership and Failure Behavior
  5. Prove Isolation Without Breaking Legitimate Health Checks

Choose the Control That Matches the Requirement

Four controls sit at four different moments. Authorization decides whether an identity may send a request, quota decides whether the namespace has room for the result, admission decides whether the object itself is acceptable, and network policy decides whether a packet may move. One requirement can be satisfied by one of them and left untouched by the other three.

RBAC runs before the object exists. The authorizer unions every binding that matches the subject and compares the request's verb and resource against the result. It has no deny rules and no knowledge of capacity, labels or packets, so a granted verb is permission to try rather than permission to succeed.

Quota is arithmetic at admission. The quota plugin adds the incoming object's requests to the namespace's recorded usage and rejects the create when the sum would cross a hard limit. It never looks at the identity, which is why two teams with identical rights get different outcomes when one namespace is fuller than the other.

LimitRange fills the gap a quota exposes. A compute quota cannot be charged for a pod that declares nothing, so the limit range supplies default requests and limits and can enforce per-container minimums, maximums and a limit-to-request ratio. It acts only on objects admitted after it exists, and it rewrites nothing that is already running.

Admission policy is the extensible layer. Built-in plugins such as Pod Security, LimitRanger and ResourceQuota run inside the API server, while validating webhooks call a service you operate. Both can reject a request, but only the webhook can fail because of the network.

Network policy is evaluated last, and outside the API server. The object is validated and stored like any other, then enforced at the pod's interface by the CNI plugin. Its rejection is a dropped packet rather than a status code, so Terraform reports a clean apply while the workload sees a timeout.

The decision below routes a requirement to the control that can actually answer it, and names the failure each one produces.

Choose the Control That Matches the Requirement
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    R["One requirement,
stated in a sentence"] --> Q1{"Does it constrain who
may call the API?"} Q1 -->|"yes"| A1["RBAC Role and RoleBinding
403 when no rule matches"] Q1 -->|"no"| Q2{"Does it constrain the
namespace's capacity?"} Q2 -->|"yes"| A2["ResourceQuota with a LimitRange
403 when the sum would exceed"] Q2 -->|"no"| Q3{"Does it constrain the
pod spec at creation?"} Q3 -->|"yes"| A3{"Does a built-in
plugin cover it?"} A3 -->|"yes"| A4["Pod Security labels
403 naming the control"] A3 -->|"no"| A5["Validating webhook
availability is a dependency"] Q3 -->|"no"| Q4{"Does it constrain traffic
between pods?"} Q4 -->|"yes"| A6["NetworkPolicy plus a CNI
that implements it"] Q4 -->|"no"| A7["No control required
record the decision"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class R,Q1,Q2,Q3,Q4,A3 primary; class A1,A2,A6 secondary; class A4,A7 ok; class A5 warn;

The branches are not exclusive in practice. A quota needs a limit range before it can charge a pod that declares nothing, and a network requirement needs both the policy object and a plugin that implements it. The diagram names the primary control; the review still has to name its dependency.

Two enforcement paths: an API request through admission, and a packet through the CNI The upper path shows an API request passing authentication, authorization, admission and storage, where RBAC, quota, LimitRange and webhooks can each reject it. The lower path shows a packet leaving one pod and reaching another through the CNI, which applies NetworkPolicy at the destination pod interface. A footer notes that the API server is absent from the packet path, so a stored policy only takes effect when the CNI implements it. One request, two paths, one missing participant The upper path can return an error. The lower path can only drop. API request path, evaluated at admission authenticate who is this identity and its groups authorize RBAC unions rules and has no deny admit quota and LimitRange PSA and webhooks persist object written to the API store Each stage can return a status code that Terraform, kubectl and the pipeline can read. A rejection here means the object was never created. Packet path, evaluated at the pod interface pod A client, same namespace CNI policy engine allow, drop, and log pod B selected by the policy explicit allow no matching rule in a selected direction the packet is dropped at this interface Admission rejects the object. The CNI drops the packet. Terraform reports success for both.

The split explains the silent failure. A rejected API request produces an error the pipeline can read and a message a human can search. A dropped packet produces a deadline exceeded in one workload, which looks like an application bug until someone checks which policies select the destination.

The table is the comparison worth keeping; the last column is where a diagnosis starts.

ControlQuestion it answersWhere it is enforcedHow it fails
Authorization (RBAC)may this identity send this requestAPI server authorizer, before any object is written403 Forbidden, and nothing is created
ResourceQuotadoes the namespace have room for the resultquota admission plugin, on create and update403 with exceeded quota in the message
LimitRangedoes this object carry bounded resourcesLimitRanger plugin, on create403 on min or max, or silent defaulting
Pod Security Admissiondoes the pod spec meet a named levelPSA plugin, on pod create403 naming the violated control
NetworkPolicymay this packet reach that podCNI plugin, at the destination interfacetimeout or reset, with no API error

Two combinations are worth naming. A quota without a limit range rejects every pod that declares nothing, and a network policy without an enforcing CNI changes nothing at all. Both look like policy in review and like a gap in production.

Verify NetworkPolicy Enforcement in the Selected Cluster

A NetworkPolicy is a request to the data plane. The API server validates the schema and stores the object, and the CNI plugin on each node turns it into filter rules. Identical YAML therefore produces different behaviour on two clusters, and only one of those behaviours is isolation.

Support is a three-valued answer. A plugin may enforce both directions, enforce ingress only, or ignore the object entirely. Managed offerings change the answer through a dataplane choice or an optional policy agent, so read the documentation for the cluster in front of you rather than for Kubernetes in general.

Default deny is a policy with an empty selector. Selecting every pod in a namespace and listing no rules denies every flow in the listed direction. Ingress and egress are separate, and a pod becomes isolated per pod and per direction the moment one policy selects it that way.

Allow rules are additive, and there is no deny. Every policy that selects a pod is unioned, and a flow is permitted if any rule in any of them matches. An exception is created by narrowing a selector, never by subtracting a rule.

The empty rule is the trap. A rule list containing one empty element allows every peer, while an empty list allows none. The two differ by a pair of braces in a file that reviewers read quickly.

The flow follows one policy from authoring to a dropped packet, and marks the branches where the intent is lost.

Verify NetworkPolicy Enforcement in the Selected Cluster
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','signalColor':'#5a6e82','noteBkgColor':'#c4873b','noteTextColor':'#132440','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
    W["Policy written in Terraform"] --> A["API server validates
and stores the object"] A --> S{"Does any policy select
the destination pod
for this direction?"} S -->|"no"| OPEN["Direction stays open
traffic allowed by default"] S -->|"yes"| C{"Does the CNI
implement policy?"} C -->|"no"| IGN["Object stored, nothing enforced
apply still exits zero"] C -->|"ingress only"| PART["Ingress filtered
egress unrestricted"] C -->|"yes"| Eval["Build the union of
allow rules for the pod"] Eval --> P{"Does a peer and
port rule match?"} P -->|"no"| DROP["Packet dropped
client sees a timeout"] P -->|"yes"| DNS{"Is egress DNS
allowed too?"} DNS -->|"no"| NX["Name resolution fails
numeric address still works"] DNS -->|"yes"| OK["Allowed path
request reaches the pod"] classDef primary fill:#132440,color:#ffffff,stroke:#0b172b; classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a; classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f; classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420; classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f; class W,A,Eval primary; class S,C,P,DNS warn; class OK secondary; class OPEN,IGN,DROP,NX danger; class PART warn;

Peers combine with and inside one element, and with or across elements. A namespace selector and a pod selector in the same entry must both match, while two entries are alternatives. Most copied policies that fail in production have merged two alternatives into one entry, which narrows the rule to nothing.

Egress is where a working policy breaks name resolution. A default-deny egress policy blocks DNS along with everything else, so the rule set must allow port 53 to the cluster DNS pods. A node-local DNS cache changes the pod label that rule has to select, and a policy written only for the cluster DNS silently misses it.

A Service does not bypass the filter. The virtual address is rewritten to a pod address before the packet arrives, and the policy is evaluated at the destination interface. Allowing an ingress controller means allowing its namespace and its pods, not the Service address it fronts.

Node-sourced traffic is a plugin detail. Kubelet probes connect from the node rather than from a pod, and whether a policy applies to that path depends on the CNI. Prove it with a probe instead of assuming either answer, because the failure removes a pod from service while every test from inside the cluster still passes.

Cluster services need their own egress rule. A pod that calls the API server or reads a metrics endpoint is subject to the same egress policy as any other destination, and the in-cluster service address is environment-specific. Reference a stable service address rather than a CIDR copied from another cluster.

Configure Namespace Resource and Pod Security Boundaries

Quota counts objects and sums requests. The hard map can limit pod, Service, Secret, ConfigMap and PVC counts, aggregate CPU and memory, storage requests, and the number of load balancers. Counts and capacity use the same mechanism with different keys, which is why one object can cover a namespace's whole shape.

A compute quota forces every pod to declare. Once CPU or memory appears in the hard map, a pod that omits that resource is rejected rather than charged as zero. That is the reason quotas and limit ranges are deployed as a pair, and why a quota added alone breaks the next Deployment rather than the quota apply.

Usage is reconciled, so status lags. Admission charges the quota during the create, while the reported usage is refreshed by the quota controller. Read the used column as a trend; the authoritative answer to whether there is room is the API's response to the next create.

Quota is neither retroactive nor evicting. Applying a quota to a namespace already above it leaves the running pods alone, records usage above the hard limit, and rejects the next create. Nothing is deleted to make the numbers agree, so the review has to look at what is already running.

The provider declares all three as ordinary objects. Quota, limit range and network policy each take a spec block, with the namespace in metadata rather than in a separate argument. No field reads usage back, so state holds the desired ceiling and never the current total.

A LimitRange has three object types and two jobs. The container and pod entries default and validate compute, and the PVC entry bounds storage requests. Defaults apply only to omitted fields, and changing the object does not rewrite pods that already exist.

The ratio limit catches the loud neighbour. A container requesting 100 millicores with a 4-CPU limit has a ratio of forty, and a maximum ratio of four rejects it at admission. The ratio is the cheapest way to stop a pod from claiming a whole node while looking modest in its request.

Pod Security Admission is labels, not an object. The namespace carries enforce, audit and warn labels plus a version, each naming privileged, baseline or restricted. Only enforce blocks a pod, while audit and warn record the same decision in the audit log and in the API response.

Restricted is a specific set of fields. Non-root execution, a runtime-default seccomp profile, no privilege escalation, all capabilities dropped, and a restricted volume set. A workload that cannot meet it belongs in a namespace one level lower with its own quota, not in a per-pod exception that reopens the level for everything else.

Tightening a label is not retroactive. Running pods keep their privileges, and only the next admitted pod must comply. Roll the change out through audit and warn, fix the workloads, then enforce, so the failure lands in a controlled rollout rather than in an incident.

Exemptions live in the API server, not the namespace. The admission configuration can exempt users, runtime classes and whole namespaces, and the control plane's own namespaces are commonly excluded. That list is cluster-scoped configuration owned by the platform team, so a team cannot grant itself an exemption with a label.

Review Admission Controller Ownership and Failure Behavior

Built-in admission cannot fail for network reasons; a webhook can. The API server evaluates Pod Security, LimitRanger and ResourceQuota in process. A mutating or validating webhook is an HTTPS call to a Service, and that call is now part of every matching request.

Mutating runs before validating. A mutating webhook may change the object, and a validating webhook may only accept or reject what it receives. Do not assume a deterministic order between two webhooks of the same kind, and do not let one depend on another's edit.

The failure policy decides what an outage looks like. Fail rejects the request when the call fails, and Ignore admits it without evaluation. Fail is the default, so an expired certificate behind a single-replica webhook stops every matching create in the cluster.

The timeout is part of the blast radius. A long timeout turns a slow webhook into a slow API for every matching request, and the API server default is already ten seconds. Keep it short and make the webhook's own dependencies faster than the timeout it declares.

A webhook must not depend on the workloads it admits. If the policy engine runs in the cluster and its namespace is not excluded, a rule that rejects its pods also blocks its own recovery. Exclude that namespace and keep the rule set narrow enough to reason about during an incident.

Certificates expire on a schedule you can read. The CA bundle in the webhook configuration must match the serving certificate, and a rotation has to update both. Monitor rejection counts and call latency, and know the cluster-scoped delete that restores service before you need it.

Prefer the built-in control when it already answers the question. Pod Security covers the common pod-field rules without a webhook, and ResourceQuota covers capacity without one. A webhook is for the rule Kubernetes does not ship, and every added webhook is another dependency in the request path.

The two panels show the same policy with different ownership choices, and what each one costs when it fails.

A single-replica webhook with Fail compared with a scoped, replicated webhook The left panel shows an API request calling one webhook pod. When its certificate expires or the pod is evicted, the Fail policy rejects every matching create, including namespace creation when it is matched. The right panel lists four ownership choices: three replicas with a disruption budget, a short timeout, a namespace selector that excludes the policy engine, and certificate rotation that updates the CA bundle in the same change. A footer explains that the failure policy decides whether an unavailable webhook blocks admission or silently skips evaluation. The same policy, two ownership choices failurePolicy decides whether an outage blocks admission or skips it. Fail, one replica API server matching create webhook pod one endpoint cert expired or pod evicted the call has no healthy endpoint Every matching create is rejected including namespace creation when matched The API stays up and admits nothing new. Scoped and replicated 3 replicas with a disruption budget timeoutSeconds kept short namespaceSelector excludes the engine caBundle rotation in the same change Fail for guardrails, Ignore for advisory rules excluded namespaces stay reachable A webhook is a network dependency inside the admission path. Its availability, scope and timeout belong in the same review as the policy it enforces. Deleting a webhook configuration is cluster-scoped, so break-glass access must exist before the incident.

The difference between the panels is not replica count. It is scope, timeout, exclusion and a documented failure mode, and each of those is a field someone owns. A webhook with three replicas and a cluster-wide rule still stops every create when its certificate expires.

Prove Isolation Without Breaking Legitimate Health Checks

The lab proves what a plan cannot. A no-change baseline shows the configuration matches the cluster, one allowed request proves the path that health checks also need, and one denied request proves the boundary exists. Run it in a disposable namespace with Terraform 1.17.1 and hashicorp/kubernetes 3.5.0.

Lab

Prove Isolation Without Breaking Legitimate Health Checks

Execution status: design-only. These steps were not run against a live cluster for this article. The sequence is written to be executed and recorded, not quoted as a transcript.

Prerequisites. A disposable namespace on a cluster whose CNI documents NetworkPolicy support, Terraform 1.17.1 with hashicorp/kubernetes 3.5.0, kubectl, and two small images: one HTTP server that answers on port 8080, and one client with a shell. A second namespace is needed for the denied path. Nothing here creates a load balancer or a volume.

  1. Record the baseline. Apply the namespace with the restricted enforce label, a quota, a limit range, a default-deny policy for both directions, a DNS allow rule, and one allow rule for the client pods. Run a second plan and expect no changes.
  2. Confirm the data plane implements policy. List the policy objects, then confirm a policy agent runs on the nodes. Expect an agent DaemonSet in the CNI's namespace; its absence is the finding, not a later timeout.
  3. Prove the allowed neighbour path. Run kubectl exec -n policy-lab client -- curl -s -m 3 http://server:8080/ and expect the server's marker. This is the same path a readiness check and an ingress controller take.
  4. Prove the denial. Repeat the request against the second namespace, where no allow rule names the client. Expect a timeout after the deadline rather than an HTTP error, because a packet filter has no status code to return.
  5. Prove DNS is egress. Resolve the server name from the client, then remove the DNS allow rule and repeat. Expect resolution to fail while the numeric address still answers, which separates name resolution from reachability.
  6. Prove a quota rejection. Create a pod that requests more CPU than the quota has left and read the error. Expect 403 with the words exceeded quota, plus the requested and used amounts, and confirm no pod object exists.
  7. Prove defaulting. Create a pod with no resource fields and read the stored object. Expect the limit range defaults in the spec, which shows admission rewrote the request rather than the manifest being correct.
  8. Prove the pod security boundary. Apply a privileged container into the restricted namespace and expect a rejection that names the restricted policy. Confirm the same pod is accepted in a privileged namespace you own.
  9. Prove the probe survived the denial. Read the pod's Ready condition and its events after the denied request. Expect Ready true with no probe failures, which shows the kubelet path was not cut by the policy.
  10. Destroy and inventory. Delete the namespace, then confirm no policy, quota or limit range remains. Check the cluster for webhook configurations, because those are cluster-scoped and would outlive the lab.
EvidenceWhere it comes fromPass looks likeFailure it rules out
Baseline planTerraform after the first applyno changes, no replacementdrift you did not create
Policy agentthe CNI namespacea running agent on every nodea stored object with no enforcement
Allowed requestexec from the client podthe server's markeran allow rule that missed the peer
Denied requestexec from the second namespacedeadline exceededa policy that selects nothing
DNS resolutionthe same client podthe service name resolvesegress cut before DNS was allowed
Quota rejectionthe API error on create403 naming exceeded quotaa quota that was never charged
Defaulted podthe stored pod specrequests equal to the defaultsan admission plugin that did not run
PSA rejectionthe API error on create403 naming restricteda label pinned to a weaker level
Probe statepod conditions and eventsReady true throughouta CNI that also blocked node traffic

Expected observation. The client reaches the server in its own namespace and times out in the other, the service name resolves only while DNS egress is allowed, and the oversized pod is rejected with a quota message rather than a scheduling message. The probe stays green through all of it, which is the difference between isolation and an outage.

Failure checks. If the allowed request times out, the allow rule and the client label disagree, or the policy selects the wrong port. If the denied request returns a marker, no policy selects the destination for that direction. If the name fails while the address works, the DNS rule is missing or selects a cache that is not running. If a pod is created despite the quota, the request fits or the quota does not constrain that resource.

Cost dimensions. The lab is close to free: two namespaces, a handful of pods, and objects the API server stores. The realistic charges are a node pool that stays scaled and a load balancer added for the allowed path, and this lab adds neither.

Cleanup. Delete both namespaces and confirm the policies, quotas and limit ranges are gone with them. Run a final plan, then check the cluster for webhook configurations and for any policy object created outside the lab namespace.

Next in the Series

In Operate Kubernetes Resources: Multi-Cluster Aliases, Drift and Teardown, we'll explore Maintain stateful API ownership through imports, controller changes and partially completed operations.