Skip to main content

More Info:

Restrict container image pulls to an approved set of registries using firewall rules, admission controllers, or Azure Policy, and limit egress traffic to those registries.

Risk Level

Medium

Address

Security

Compliance Standards

  • CIS AKS

Triage and Remediation

Remediation

Manual Steps

  1. Inventory current image registries in use
    • Run on any machine with kubectl access:
    • Extract the registry hostnames (first path segment before /) and compile a list of all registries currently used by workloads (including system namespaces like kube-system and azure-*).
  2. Define and document the approved registry list
    • Using your organization’s security policy, decide which registries are approved (for example, specific Azure Container Registries and any required Microsoft/AKS system registries).
    • Document them as explicit FQDNs, e.g.:
      • mycorpprod.azurecr.io
      • mycorptest.azurecr.io
      • Required Microsoft endpoints as per AKS / egress docs.
  3. Restrict access at the registry and network level (Azure side)
  4. Enforce registry usage with Azure Policy / admission control
    • In Azure Portal: PolicyDefinitions and locate policies such as:
      • Kubernetes cluster containers should only use allowed images
    • Assign to the AKS cluster’s scope and configure the list of allowed registries (FQDNs from step 2).
    • If using Gatekeeper/another admission controller (via IaC), create/update a policy that rejects images whose registry host is not in the approved list. Example (conceptual) for Gatekeeper ConstraintTemplate/Constraint; apply via your existing GitOps/IaC pipeline.
  5. Verify enforcement and impact
    • Attempt to deploy a pod pulling from an unapproved registry, on any machine with kubectl access:
    • Confirm that:
      • The admission policy rejects the pod (check events):
      • Or, if admitted, that image pull fails due to network/egress restrictions (image pull errors in events).
  6. Re-audit running workloads and system behavior
    • Re-run the inventory command (step 1) to confirm that all new pods only use approved registries.
    • Review AKS egress logs/firewall logs (Azure Firewall, NSG flow logs, etc.) to ensure no successful outbound connections from AKS subnets to non-approved registries.
kubectl cannot be used to restrict container image pulls to approved registries because this control is enforced at the cloud/provider configuration level (Azure Container Registry firewall rules, Azure Policy, and egress controls), not via Kubernetes API objects. Apply the remediation in the cloud console or IaC as described in the Manual Steps section.
How to run (any machine with kubectl access)
Interpreting the output (what indicates a problem)
  • /tmp/aks-registries-all.txt lists every registry/domain in use.
    • Any entry that is not on your formally approved list (for example, your ACR FQDNs) is a potential problem.
    • dockerhub_implicit indicates images like nginx:latest with no explicit registry, typically Docker Hub. Treat this as unapproved unless your policy explicitly allows it.
  • The “Non-approved registries in use:” section (when approved-registries.txt is present) shows registries that:
    • Must be blocked via ACR firewall rules, Azure Policy/admission controls, or
    • Must be reviewed and either added to the approved list or removed/migrated.
  • /tmp/aks-image-usage-by-pod.txt lets you trace unapproved registries back to the exact namespaces/workloads to drive remediation decisions.