Container Security
Defender for Containers · AKS access, identity and hardening · Azure Container Registry · Azure Container Instances · Azure Container Apps
By the tools4free.dev team · Last reviewed November 13, 2026
Practice questions for this topic →
Defender for Containers
Defender for Containers is a cloud-native solution that monitors and protects containerized assets: Kubernetes clusters, nodes, workloads, registries and images, across multicloud and on-premises environments. It covers five domains: security posture management, vulnerability assessment, run-time threat protection, software supply chain protection, and deployment and monitoring.
| Capability | Agentless | Needs in-cluster components |
|---|---|---|
| Image vulnerability assessment | Yes | No |
| Kubernetes posture assessment | Yes | No |
| Runtime threat detection | No | Yes |
| Control plane threat detection | Yes | No |
Components on AKS
- Defender sensor: a lightweight DaemonSet on AKS nodes that collects runtime telemetry (Kubernetes events, process and network data) by using eBPF. On AKS it is deployed as an AKS Security profile, natively integrated into the AKS resource provider.
- Azure Policy for Kubernetes: a pod that extends Gatekeeper v3 and registers as an admission control webhook. On AKS it is an add-on and you need to install it on only one node.
- ACR integration: push-triggered and periodic image scanning with no extra components. Agentless discovery and agentless scanning for machines (node disk snapshots) need no agents.
- AKS control plane audit logs are collected natively through Azure; you don't enable audit logging in the cluster. All components use outbound-only connectivity, with no inbound access to the cluster.
- Clusters outside Azure (EKS, GKE, on-premises) need Azure Arc-enabled Kubernetes to deploy the Defender components.
Runtime protection
- Threat protection uses the Defender sensor (sensor-based) and analysis of Kubernetes audit logs (agentless). Alerts are triggered only for actions and deployments after you enable Defender for Containers on the subscription.
- Examples: exposed Kubernetes dashboards, an exposed Kubernetes service (a
LoadBalancerService that publicly exposes workloads), creation of high privileged roles, sensitive mounts. Alerts map to the MITRE ATT&CK matrix for Containers. - Sensor-based capabilities include antimalware, DNS detection, binary drift detection (alert on unauthorized external processes in containers) and binary drift blocking.
Data plane hardening (misconfiguration prevention)
- Enable Defender for Containers on the subscription. It deploys Azure Policy for Kubernetes automatically when automatic provisioning is on.
- If it was turned off, remediate the recommendation Azure Kubernetes Service clusters should have the Azure Policy add-on for Kubernetes installed with Fix.
- Wait for recommendations (this can take up to 30 minutes). Microsoft components such as the Defender sensor sit in
kube-systemand aren't flagged as noncompliant. - Configure parameters where required: for example Container images should be deployed from trusted registries only needs a list of trusted registries, and unconfigured resources show as unhealthy. Use fully qualified image names in exclusions.
- Policies evaluate in audit mode by default. To enforce, set the effect to Deny on the recommendation's Take action tab (or Manage effect and parameters on the standard). Example: block privileged containers.
Vulnerability assessment
- Uses Microsoft Defender Vulnerability Management. Registry vulnerability assessment needs Registry access enabled. It covers ACR, ECR, GAR, GCR and configured external registries.
- Images are scanned on push or import (typically within a few hours). A daily rescan covers images pushed or pulled in the last 30 days and images running in monitored clusters. Older, idle images get no updated findings; pulling the image reactivates scanning.
- Findings for an image deleted from ACR are usually removed within one hour.
- Runtime scanning of running containers: with registry context it needs Registry access plus Kubernetes API access or the Defender sensor; the registry-agnostic option needs agentless scanning for machines plus Kubernetes API access or the Defender sensor (public preview in multicloud environments per Microsoft Learn at the time of writing).
- Running containers are inventoried about every 24 hours with agentless discovery and in near real time with the Defender sensor. Runtime assessment isn't supported for Windows nodes or AKS ephemeral OS disks.
- Gated deployment rules can audit or block deployments of images that don't meet your vulnerability policy.
AKS: control plane access and identity
By default the Kubernetes API server uses a public IP address and an FQDN. Limit it with authorized IP ranges, or make the cluster private. Network access and authorization are separate controls: network access doesn't grant permissions to the pipeline identity.
| Control | What it does | Limits |
|---|---|---|
| API server authorized IP ranges | Only the listed ranges can reach the public API server; other requests are blocked. | Up to 200 ranges (API Server VNet Integration supports up to 2,000). Standard SKU load balancer only. Not usable with private clusters. Rules can take up to two minutes to propagate. |
| Private cluster | API server gets internal (RFC1918) IPs; traffic between the API server and node pools stays on the private network (Private Link and a private endpoint). | Authorized ranges don't apply to the private endpoint. Needs Standard Load Balancer. No Azure DevOps Microsoft-hosted agents. Deleting or modifying the private endpoint breaks the cluster. |
- Creating with authorized ranges adds the API server public IP and the Standard load balancer's outbound IP automatically. The placeholder
0.0.0.0/32allows only the cluster's own outbound IP. - Include the cluster egress IP (firewall, NAT gateway or other, depending on the outbound type) and the administrators' networks.
- Disable the feature by passing an empty range
"". - Private cluster: create with
--enable-private-cluster. AKS creates private and public FQDNs with DNS zones by default. A custom DNS server must resolve the private zone (conditional forwarder to 168.63.129.16) and nodes must reach it over UDP and TCP port 53. - A private cluster that pulls from ACR needs a private link for the registry in the cluster VNet, or peering between the registry's VNet and the cluster's VNet.
- For pipelines: use a self-hosted agent or Managed DevOps Pool with network reach to a private endpoint, and use workload identity federation instead of long-lived credentials.
Authentication and authorization
- Managed Microsoft Entra integration: the AKS resource provider manages the client and server apps. You need a Microsoft Entra group registered as the cluster admin group. It can't be disabled once enabled. Enable on an existing Kubernetes-RBAC cluster with
az aks update --enable-aad. - Azure RBAC for Kubernetes authorization uses Azure role assignments to grant access to Kubernetes resources. It needs managed Entra integration first, a tenant that matches the subscription's tenant, and new assignments can take up to five minutes to propagate. On AKS Standard enable it with
--enable-azure-rbac; on AKS Automatic it is preconfigured. - To retrieve credentials for an Entra-integrated cluster, the pipeline identity needs the Azure Kubernetes Service Cluster User Role, which allows credential retrieval but doesn't authorize Kubernetes API operations.
| AKS RBAC role | Access |
|---|---|
| Azure Kubernetes Service RBAC Reader | Read-only on most objects in a namespace. Can't view Secrets (reading them would allow privilege escalation). |
| Azure Kubernetes Service RBAC Writer | Read/write on most objects in a namespace. Can access Secrets and run Pods as any ServiceAccount in the namespace. |
| Azure Kubernetes Service RBAC Admin | Admin within a namespace, including creating roles and role bindings. No write on resource quota or the namespace itself. |
| Azure Kubernetes Service RBAC Cluster Admin | Super-user access to any resource in all namespaces. |
Workload identity
- Microsoft Entra Workload ID uses Service Account Token Volume Projection and OIDC federation so pods authenticate without stored credentials, for example to Key Vault.
- On AKS Standard, enable workload identity and the OIDC issuer on the cluster first (AKS 1.22 or higher). On AKS Automatic both are preconfigured.
- Limits: at most 20 federated identity credentials per managed identity; the virtual nodes add-on isn't supported.
AKS: node, network, workload and secret security
| Area | Facts |
|---|---|
| Nodes | Node authorization is enabled by default on AKS 1.24+ clusters. Nodes sit on a private subnet with no public IPs; SSH is enabled by default and reachable only on the internal IP (disabling SSH is in preview). Gen2 node VMs support Trusted Launch. |
| Network | AKS manages the NIC-level NSG. With your own subnet, don't modify it; add subnet-level NSGs instead and don't block load balancer access, control plane communication or egress. Use Kubernetes network policies to limit pod-to-pod traffic. |
| Policy | Install the Azure Policy add-on for AKS to apply built-in policies and initiatives. |
| Images | Image Cleaner removes unused vulnerable images. Optional on AKS Standard (--enable-image-cleaner, default interval one week, minimum 24 hours, maximum three months); no Windows node pools or virtual nodes. |
| Secrets | Kubernetes Secrets are namespaced and kept in etcd; AKS supports customer-managed keys for etcd encryption at rest. The Key Vault provider for the Secrets Store CSI Driver mounts secrets, keys and certificates and supports autorotation. |
- AKS Automatic starts from a hardened baseline: Azure RBAC for Kubernetes authorization, API server VNet integration, workload identity with OIDC issuer, deployment safeguards with baseline Pod Security Standards in enforce mode, Image Cleaner and restricted managed system node pools. AKS Standard gives more flexibility but needs explicit enablement.
- Kubernetes environments aren't safe for hostile multitenant usage. Use physically isolated clusters for such workloads. Confidential Containers and Pod Sandboxing are in preview per Microsoft Learn at the time of writing.
- A
ConfigMaporSecretused as asubPathmount doesn't receive automatic updates when the secret rotates: reload the file or restart the pod. - The CSI add-on creates a managed identity (
azurekeyvaultsecretsprovider-xxxxx) in the node resource group. You can use it or your own; preventing its creation isn't supported.
Azure Container Registry
| Authentication method | Use | Notes |
|---|---|---|
| Individual Microsoft Entra identity | Interactive push/pull by developers (az acr login) | Token valid for 3 hours; Azure RBAC applies. |
| Service principal | Unattended CI/CD and external pulls | Azure RBAC applies; password default expiry 1 year. |
| Managed identity | Unattended push/pull from Azure services | Azure RBAC applies; only from services that support managed identities. |
| Admin user | Single user testing; portal deploy to ACI or Container Apps | Disabled by default; full push and pull; one account with two regenerable passwords; no RBAC. |
| Token-based repository permissions | Repository-scoped tokens | Non-Entra: doesn't support Entra RBAC role assignments. |
- Enable the admin user with
az acr update -n <acrName> --admin-enabled true. Don't share it: all users appear as one user. az acr login --expose-tokenreturns an access token when the Docker daemon isn't running.
Roles and permissions
- To perform role assignments you need Owner or Role Based Access Control Administrator on the registry.
- Microsoft Entra ABAC scopes role assignments to specific repositories. Registry role assignment permissions mode: RBAC Registry + ABAC Repository Permissions or RBAC Registry Permissions (no ABAC conditions).
- Container Registry Repository Reader: data plane read-only pull. Repository Writer: push, pull and update, but not delete. Repository Contributor: also delete.
- Repository Catalog Lister lists all repositories; it doesn't support ABAC conditions.
- Container Registry Contributor and Data Access Configuration Administrator: control plane (including deleting the registry); not data plane operations or role assignments.
- Connected registries don't support Azure role assignments or Entra-based permissions.
Network access
| Setting | Facts |
|---|---|
| Default | A registry accepts connections over the internet from hosts on any network. |
| IP network rules (firewall) | Premium tier; up to 200 IP access rules; configured on the public endpoint and don't apply to private endpoints. Set the default action to Deny, then add rules; rules take a few minutes. |
| Private endpoint (Private Link) | Premium tier. DNS zone privatelink.azurecr.io to resolve the registry FQDN to the private IP. Azure DevOps managed agents aren't supported: use a self-hosted agent. |
| Disable public network access | Overrides all firewall configurations. Trusted services such as Defender for Cloud can reach the registry only if a bypass setting is enabled. With an approved private endpoint, you can't list repositories and tags from outside the VNet. |
Encryption, anonymous pull and signing
- Registry content is encrypted at rest with service-managed keys by default. A customer-managed key needs Premium, can be enabled only when creating the registry, can't be disabled afterward, needs a user-assigned managed identity, and supports only RSA or RSA-HSM keys. Content trust isn't supported in such a registry, and ACR task logs are kept 24 hours.
- Key versions: a non-versioned key is picked up within one hour; a specific version stays until you rotate manually. A Managed HSM uses local RBAC: give the registry identity Managed HSM Crypto Service Encryption User.
- Anonymous pull: Standard and Premium, disabled by default, applies to all repositories (repository permissions don't stop pulls), data-plane only. Enable with
az acr update --anonymous-pull-enabled. - Docker Content Trust: from May 31, 2026 it can't be enabled on new registries and it is removed March 31, 2028. It requires Premium. Use Notary Project style signing with OCI referrers and the Repository Writer role instead (see the transition guidance).
Azure Container Instances and Container Apps
Azure Container Instances (ACI)
- Virtual network: the subnet must be delegated to container groups and can contain only container groups, in the same subscription; use at least a /24. A NAT gateway is required for outbound connectivity.
- In a virtual network there is no public IP or DNS label for the container group, no global peering, and DNS settings aren't inherited. Use NSG rules for access control and a service endpoint to connect to Azure Storage.
- Private image pulls: ACI supports pulling only from ACR for private registries; use ACR with a private endpoint and a managed identity.
- Secrets: use
secureValuefor environment variables (not visible in container properties; readable only from inside the container) or secret volumes. - Managed identity: system-assigned, user-assigned or both. Enabling or updating identities on a running group restarts it. Grant the identity access to the target resources.
- Deployment data is encrypted with 256-bit AES by default; customer-managed keys in Key Vault are optional and then you handle rotation.
- Network profiles are retired as of API version 2021-07-01.
Azure Container Apps
| Area | Facts |
|---|---|
| Network type | Default Azure network is public; to use NSGs, Application Gateway, Azure Firewall or private endpoint access you provide your own VNet, with a subnet used only by the environment. The network type can't be changed after creation. |
| Environment type | Workload profiles (default): UDRs, NAT Gateway egress, private endpoints, subnet at least /27. Consumption only (legacy): none of those, subnet at least /23. |
| Accessibility | External: public virtual IP. Internal: no public endpoints, internal load balancer; public network access can't be changed to accept internet traffic. To create private endpoints, set public network access to Disabled. |
| IP restrictions | Allow or Deny rules in CIDR (IPv4). No rules means all inbound traffic is allowed. All rules must be the same type; delete existing deny rules before adding allow rules. |
| Client certificates (mTLS) | clientCertificateMode: require, accept or ignore. PKCS12 certificates from a trusted CA or self-signed. |
| Managed identity | One system-assigned identity plus multiple user-assigned. Adding or changing an identity doesn't restart the app or create a revision. Can authenticate to a private ACR without a username and password. Init containers can't use managed identities in consumption-only and dedicated workload profile environments. |
| Secrets | Scoped to the app, not a revision. Changing a secret creates no revision and doesn't affect existing revisions: deploy a new revision or restart. Prefer Key Vault references over direct values in production. Roles with wildcard actions (Container Apps Contributor, Operator, Jobs Contributor and Operator) can read secret values via listSecrets; use a custom role to omit it. |
| Built-in auth (Easy Auth) | Secures an external-ingress app with no code; same system as App Service. Providers: Microsoft identity platform, Facebook, GitHub, Google, X and OpenID Connect. |
The Container Apps edge proxy terminates TLS. Outbound through NAT Gateway or another proxy is supported only in a workload profile environment.
CLI and PowerShell
| Task | Azure CLI | PowerShell |
|---|---|---|
| Create an AKS cluster with API server authorized IP ranges | az aks create --resource-group myResourceGroup --name myAKSCluster --vm-set-type VirtualMachineScaleSets --load-balancer-sku standard --api-server-authorized-ip-ranges 73.140.245.0/24 --generate-ssh-keys | New-AzAksCluster -ResourceGroupName myResourceGroup -Name myAKSCluster -NodeVmSetType VirtualMachineScaleSets -LoadBalancerSku Standard -ApiServerAccessAuthorizedIpRange '73.140.245.0/24' -GenerateSshKey |
| Update authorized IP ranges | az aks update --resource-group myResourceGroup --name myAKSCluster --api-server-authorized-ip-ranges 73.140.245.0/24 | Set-AzAksCluster -ResourceGroupName myResourceGroup -Name myAKSCluster -ApiServerAccessAuthorizedIpRange '73.140.245.0/24' |
| Disable authorized IP ranges | az aks update --resource-group myResourceGroup --name myAKSCluster --api-server-authorized-ip-ranges "" | Set-AzAksCluster -ResourceGroupName myResourceGroup -Name myAKSCluster -ApiServerAccessAuthorizedIpRange '' |
| Create a private AKS cluster | az aks create --name <private-cluster-name> --resource-group <private-cluster-resource-group> --load-balancer-sku standard --enable-private-cluster --generate-ssh-keys | - |
| Enable Azure RBAC for Kubernetes on an AKS Standard cluster | az aks update --resource-group $RESOURCE_GROUP --name $CLUSTER_NAME --enable-azure-rbac | - |
| Sign in to a registry as your Entra identity | az acr login --name <acrName> | Connect-AzContainerRegistry |
| Get a registry access token without Docker | az acr login --name <acrName> --expose-token | - |
| Enable the registry admin user | az acr update -n <acrName> --admin-enabled true | Update-AzContainerRegistry -Name <acrName> -ResourceGroupName myResourceGroup -EnableAdminUser |
| Enable anonymous pull | az acr update --name myregistry --anonymous-pull-enabled | - |
| Deny registry access from all networks by default | az acr update --name myContainerRegistry --default-action Deny | - |
| Disable public network access to a registry | az acr update --name myContainerRegistry --public-network-enabled false | - |
| Assign a system-assigned identity to a container app | az containerapp identity assign --name myApp --resource-group myResourceGroup --system-assigned | - |
Exam Tips
Tick each tip once you can answer it without looking.
“Defender for Containers: which capabilities need no in-cluster components” → Image vulnerability assessment, Kubernetes posture assessment and control plane threat detection; only runtime threat detection needs components.. Trap: Runtime threat detection needs the Defender sensor (DaemonSet).
“Block privileged containers from being created on AKS” → Azure Policy for Kubernetes (add-on) with the policy effect set to Deny.. Trap: Policies evaluate in audit mode by default, so they only report until the effect is set to Deny.
“Non-Azure Kubernetes cluster needs Defender for Containers components” → Connect it with Azure Arc-enabled Kubernetes.. Trap: Inbound connectivity to the cluster isn't required; connections are outbound-only.
“Registry image shows no vulnerability findings and hasn't been used for months” → Pull it (or run it): images not pushed or pulled in 30 days aren't in the daily rescan.. Trap: Registry vulnerability assessment also needs Registry access enabled.
“Limit the public AKS API server to office IPs” → API server authorized IP ranges (up to 200, Standard load balancer, not with private clusters).. Trap: A private cluster is the other option; it isn't combined with authorized ranges.
“AKS API server must have no public endpoint” → Private cluster (--enable-private-cluster); resolve the private zone via 168.63.129.16.. Trap: Authorized IP ranges apply only to the public API server.
“Pipeline reaches a private cluster; hosted agents fail” → Self-hosted agent or Managed DevOps Pool with network reach to the private endpoint.. Trap: Azure DevOps Microsoft-hosted agents aren't supported with private clusters.
“Entra users get Kubernetes permissions from Azure role assignments” → Azure RBAC for Kubernetes authorization (--enable-azure-rbac), on top of managed Entra integration.. Trap: Entra integration alone gives Kubernetes RBAC bindings, and it can't be disabled afterward.
“Pods must call Key Vault without stored credentials” → Microsoft Entra Workload ID with the OIDC issuer enabled and a federated credential (max 20 per managed identity).. Trap: The virtual nodes add-on isn't supported.
“Private-network-only registry, firewall rules ignored for private clients” → Premium tier private endpoint; IP rules apply to the public endpoint only.. Trap: Disabling public access overrides the firewall; trusted services need the bypass setting.
“Customer-managed key for ACR” → Premium, only at registry creation, user-assigned identity, RSA key; can't be disabled later.. Trap: Elliptic-curve keys aren't supported, and content trust doesn't work in such a registry.
“Anonymous pull enabled but one repository must stay private” → Not possible: it applies to all repositories; keep that registry authenticated-only.. Trap: Repository-scoped permissions don't stop anonymous pulls.
“Registry admin user” → Disabled by default, single shared account with full push and pull, no RBAC.. Trap: It is needed for portal deployment to ACI or Container Apps, but use it only when necessary.
“Identity must pull images but not list the catalog” → Container Registry Repository Reader (optionally with ABAC conditions).. Trap: The Catalog Lister role lists all repositories and doesn't support ABAC.
“ACI in a virtual network has no outbound internet” → NAT gateway for outbound connectivity (the only supported configuration).. Trap: Public IPs and DNS labels aren't supported for groups in a virtual network.
“Container Apps secret changed but the app still uses the old value” → Deploy a new revision or restart the existing one.. Trap: Changing a secret doesn't create a revision or change existing ones.
“Container Apps: allow only office IPs and later add a deny rule” → Not allowed: all IP restriction rules must be the same type.. Trap: No rules at all means all inbound traffic is allowed.
Sources
- Introduction to Microsoft Defender for Containers
- Defender for Containers deployment overview
- Container security architecture
- Vulnerability management for containers
- Kubernetes data plane hardening
- Security concepts for AKS
- API server authorized IP ranges in AKS
- Create a private AKS cluster
- Enable Microsoft Entra ID authentication for the AKS control plane
- Use Microsoft Entra ID authorization for the Kubernetes API in AKS
- Use a Microsoft Entra Workload ID on AKS
- Use Image Cleaner on AKS
- Use Azure Policy to secure your AKS clusters
- Azure Key Vault provider for Secrets Store CSI Driver on AKS
- Azure Container Registry authentication options
- Azure Container Registry Entra permissions and role assignments
- Configure public registry access
- Set up a private endpoint with Private Link for ACR
- Customer-managed keys for Azure Container Registry
- Enable anonymous pull access in Azure Container Registry
- Manage signed images with Docker Content Trust
- Azure Container Registry service tiers
- Scenarios to use a virtual network with Azure Container Instances
- Set environment variables in container instances
- Enable managed identity in a container group
- Encrypt deployment data in Azure Container Instances
- Networking in an Azure Container Apps environment
- Managed identities in Azure Container Apps
- Manage secrets in Azure Container Apps
- Set up IP ingress restrictions in Azure Container Apps
- Configure client certificate authentication in Azure Container Apps
- Authentication and authorization in Azure Container Apps
Checked against Microsoft Learn on November 13, 2026.