Container Apps Run Your Microservices — Lock Them Down
Azure Container Apps provides a serverless container platform built on Kubernetes. While it abstracts away infrastructure management, security responsibility still falls on you — network isolation, identity management, secret handling, and ingress configuration all need deliberate hardening. This guide covers every step to secure your Container Apps environment.
Threat Landscape and Attack Surface
Hardening Azure Container Apps requires understanding the threat landscape specific to this service. Azure services are attractive targets because they often store, process, or transmit sensitive data and provide control-plane access to cloud infrastructure. Attackers probe for misconfigured services using automated scanners that continuously sweep Azure IP ranges for exposed endpoints, weak authentication, and default configurations.
The attack surface for Azure Container Apps includes several dimensions. The network perimeter determines who can reach the service endpoints. The identity and access layer controls what authenticated principals can do. The data plane governs how data is protected at rest and in transit. The management plane controls who can modify the service configuration itself. A comprehensive hardening strategy addresses all four dimensions because a weakness in any single layer can be exploited to bypass the controls in other layers.
Microsoft’s shared responsibility model means that while Azure secures the physical infrastructure, network fabric, and hypervisor, you are responsible for configuring the service securely. Default configurations prioritize ease of setup over security. Every Azure service ships with settings that must be tightened for production use, and this guide walks through the critical configurations that should be changed from their defaults.
The MITRE ATT&CK framework for cloud environments provides a structured taxonomy of attack techniques that adversaries use against Azure services. Common techniques relevant to Azure Container Apps include initial access through exposed credentials or misconfigured endpoints, lateral movement through overly permissive RBAC assignments, and data exfiltration through unmonitored data plane operations. Each hardening control in this guide maps to one or more of these attack techniques.
Compliance and Regulatory Context
Security hardening is not just a technical exercise. It is a compliance requirement for virtually every regulatory framework that applies to cloud workloads. SOC 2 Type II requires evidence of security controls for cloud services. PCI DSS mandates network segmentation and encryption for payment data. HIPAA requires access controls and audit logging for health information. ISO 27001 demands a systematic approach to information security management. FedRAMP requires specific configurations for government workloads.
Azure Policy and Microsoft Defender for Cloud provide built-in compliance assessments against these frameworks. After applying the hardening configurations in this guide, run a compliance scan to verify your security posture against your applicable regulatory standards. Address any remaining findings to achieve and maintain compliance. Export compliance reports on a scheduled basis to satisfy audit requirements and demonstrate continuous adherence.
The Microsoft cloud security benchmark provides a comprehensive set of security controls mapped to common regulatory frameworks. Use this benchmark as a checklist to verify that your hardening effort covers all required areas. Each control includes Azure-specific implementation guidance and links to the relevant Azure service documentation.
Step 1: Deploy in a Custom VNet with Internal-Only Ingress
# Create Container Apps environment in a custom VNet
az containerapp env create \
--name env-prod --resource-group rg-apps --location eastus \
--infrastructure-subnet-resource-id "/subscriptions/{sub}/resourceGroups/rg-network/providers/Microsoft.Network/virtualNetworks/vnet-prod/subnets/snet-containerapps" \
--internal-only true
Internal-only mode removes the public IP from the environment. Applications are only accessible through the VNet, via Private DNS zones, Application Gateway, or peered networks.
Step 2: Enable Managed Identity for All Services
# Enable system-assigned managed identity
az containerapp identity assign \
--name myapp --resource-group rg-apps --system-assigned
# Use managed identity for ACR pull (no admin credentials)
az containerapp registry set \
--name myapp --resource-group rg-apps \
--server myacr.azurecr.io --identity system
Never enable the ACR admin user. Managed identity provides auditable, credential-free authentication between Container Apps and Azure Container Registry.
Step 3: Configure Ingress Security
# Restrict ingress to VNet only
az containerapp ingress update --name myapp --resource-group rg-apps \
--type internal
# Add IP restrictions
az containerapp ingress access-restriction set \
--name myapp --resource-group rg-apps \
--rule-name AllowFrontDoor --action Allow \
--ip-address 147.243.0.0/16 --description "Azure Front Door"
# Enforce HTTPS
az containerapp ingress update --name myapp --resource-group rg-apps \
--allow-insecure false
Step 4: Use Key Vault References for Secrets
# Create user-assigned managed identity for Key Vault access
az identity create --name id-containerapp --resource-group rg-apps
# Grant Key Vault access
az keyvault set-policy --name kv-prod \
--object-id $(az identity show --name id-containerapp --resource-group rg-apps --query principalId -o tsv) \
--secret-permissions get
# Set secrets from Key Vault
az containerapp secret set --name myapp --resource-group rg-apps \
--secrets "db-password=keyvaultref:https://kv-prod.vault.azure.net/secrets/db-password,identityref:/subscriptions/{sub}/resourceGroups/rg-apps/providers/Microsoft.ManagedIdentity/userAssignedIdentities/id-containerapp"
Step 5: Configure Minimum Replicas and Health Probes
# Set minimum replicas to prevent cold starts in sensitive apps
az containerapp update --name myapp --resource-group rg-apps \
--min-replicas 2 --max-replicas 10
# Configure liveness and readiness probes
az containerapp update --name myapp --resource-group rg-apps \
--set-env-vars "ASPNETCORE_URLS=http://+:8080" \
--container-name mycontainer
# In the container app YAML configuration
properties:
template:
containers:
- name: myapp
probes:
- type: Liveness
httpGet:
path: /healthz
port: 8080
initialDelaySeconds: 10
periodSeconds: 30
- type: Readiness
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
Identity and Access Management Deep Dive
Identity is the primary security perimeter in cloud environments. For Azure Container Apps, implement a robust identity and access management strategy that follows the principle of least privilege.
Managed Identities: Use system-assigned or user-assigned managed identities for service-to-service authentication. Managed identities eliminate the need for stored credentials (connection strings, API keys, or service principal secrets) that can be leaked, stolen, or forgotten in configuration files. Azure automatically rotates the underlying certificates, removing the operational burden of credential rotation.
Custom RBAC Roles: When built-in roles grant more permissions than required, create custom roles that include only the specific actions needed. For example, if a monitoring service only needs to read metrics and logs from Azure Container Apps, create a custom role with only the Microsoft.Insights/metrics/read and Microsoft.Insights/logs/read actions rather than assigning the broader Reader or Contributor roles.
Conditional Access: For human administrators accessing Azure Container Apps through the portal or CLI, enforce Conditional Access policies that require multi-factor authentication, compliant devices, and approved locations. Set session lifetime limits so that administrative sessions expire after a reasonable period, forcing re-authentication.
Just-In-Time Access: Use Azure AD Privileged Identity Management (PIM) to provide time-limited, approval-required elevation for administrative actions. Instead of permanently assigning Contributor or Owner roles, require administrators to activate their role assignment for a specific duration with a business justification. This reduces the window of exposure if an administrator’s account is compromised.
Service Principal Hygiene: If managed identities cannot be used (for example, for external services or CI/CD pipelines), use certificate-based authentication for service principals rather than client secrets. Certificates are harder to accidentally expose than text secrets, and Azure Key Vault can automate their rotation. Set short expiration periods for any client secrets and monitor for secrets that are approaching expiration.
Step 6: Restrict Container Capabilities
# Run as non-root user (in Dockerfile)
# FROM mcr.microsoft.com/dotnet/aspnet:8.0
# RUN adduser --disabled-password appuser
# USER appuser
Container Apps does not allow privileged containers by default. Ensure your Dockerfiles:
- Run as non-root user
- Use minimal base images (distroless or Alpine)
- Do not install unnecessary tools (curl, wget, shell) in production images
- Scan images for vulnerabilities before deployment
Step 7: Enable Dapr with mTLS
# Enable Dapr on the Container Apps environment
az containerapp env dapr-component set \
--name env-prod --resource-group rg-apps \
--dapr-component-name statestore \
--yaml dapr-statestore.yaml
Dapr provides automatic mTLS between services, built-in secret management, and API-level access control. When using Dapr, inter-service communication is encrypted without application code changes.
Step 8: Configure Revision Management
# Use single revision mode to prevent old versions from running
az containerapp update --name myapp --resource-group rg-apps \
--revision-suffix v2-secured \
--set-env-vars "APP_VERSION=2.0"
# Deactivate old revisions
az containerapp revision deactivate \
--name myapp --resource-group rg-apps \
--revision myapp--v1-old
Old revisions may run vulnerable code. Deactivate them promptly after deploying security updates.
Step 9: Enable Diagnostic Logging
# Configure diagnostics on the environment
az monitor diagnostic-settings create \
--name ca-diag \
--resource "/subscriptions/{sub}/resourceGroups/rg-apps/providers/Microsoft.App/managedEnvironments/env-prod" \
--workspace law-prod-id \
--logs '[
{"category":"ContainerAppConsoleLogs","enabled":true},
{"category":"ContainerAppSystemLogs","enabled":true}
]'
Step 10: Apply Azure Policy
# Enforce managed identity
az policy assignment create \
--name ca-require-identity \
--display-name "Container Apps must use managed identity" \
--policy "built-in-policy-id" \
--scope "/subscriptions/{sub}/resourceGroups/rg-apps"
Key policies to enforce:
- Container Apps should only be accessible over HTTPS
- Container App environments should use network injection
- Container Apps should use managed identity
- Container Apps environment should disable public network access
Defense in Depth Strategy
No single security control is sufficient. Apply a defense-in-depth strategy that layers multiple controls so that the failure of any single layer does not expose the service to attack. For Azure Container Apps, this means combining network isolation, identity verification, encryption, monitoring, and incident response capabilities.
At the network layer, restrict access to only the networks that legitimately need to reach the service. Use Private Endpoints to eliminate public internet exposure entirely. Where public access is required, use IP allowlists, service tags, and Web Application Firewall (WAF) rules to limit the attack surface. Configure network security groups (NSGs) with deny-by-default rules and explicit allow rules only for required traffic flows.
At the identity layer, enforce least-privilege access using Azure RBAC with custom roles when built-in roles are too broad. Use Managed Identities for service-to-service authentication to eliminate stored credentials. Enable Conditional Access policies to require multi-factor authentication and compliant devices for administrative access.
At the data layer, enable encryption at rest using customer-managed keys (CMK) in Azure Key Vault when the default Microsoft-managed keys do not meet your compliance requirements. Enforce TLS 1.2 or higher for data in transit. Enable purge protection on any service that supports soft delete to prevent malicious or accidental data destruction.
At the monitoring layer, enable diagnostic logging and route logs to a centralized Log Analytics workspace. Configure Microsoft Sentinel analytics rules to detect suspicious access patterns, privilege escalation attempts, and data exfiltration indicators. Set up automated response playbooks that can isolate compromised resources without human intervention during off-hours.
Continuous Security Assessment
Security hardening is not a one-time activity. Azure services evolve continuously, introducing new features, deprecating old configurations, and changing default behaviors. Schedule quarterly security reviews to reassess your hardening posture against the latest Microsoft security baselines.
Use Microsoft Defender for Cloud’s Secure Score as a quantitative measure of your security posture. Track your score over time and investigate any score decreases, which may indicate configuration drift or new recommendations from updated security baselines. Set a target Secure Score and hold teams accountable for maintaining it.
Subscribe to Azure update announcements and security advisories to stay informed about changes that affect your security controls. When Microsoft introduces a new security feature or changes a default behavior, assess the impact on your environment and update your hardening configuration accordingly. Automate this assessment where possible using Azure Policy to continuously evaluate your resources against your security standards.
Conduct periodic penetration testing against your Azure environment. Azure’s penetration testing rules of engagement allow testing without prior notification to Microsoft for most services. Engage a qualified security testing firm to assess your Azure Container Apps deployment using the same techniques that real attackers would employ. The findings from these tests often reveal gaps that automated compliance scans miss.
Hardening Checklist
- Custom VNet with internal-only ingress
- Managed identity for all service-to-service authentication
- IP restrictions and HTTPS enforcement on ingress
- Key Vault references for all secrets
- Minimum replicas and health probes configured
- Non-root containers with minimal base images
- Dapr with mTLS for inter-service communication
- Old revisions deactivated promptly
- Diagnostic logging to Log Analytics
- Azure Policy enforcement
For more details, refer to the official documentation: Azure Container Apps overview, Ingress in Azure Container Apps, Update and deploy changes in Azure Container Apps.