Other Articles

Container Instance – Enforce Managed Identity Usage

Secure Configuration Checks > Azure

This check ensures that Azure container groups use a managed identity to authenticate to other Azure services. A managed identity is created and managed by Azure, so the containers do not need to store passwords, keys or connection strings.

Check Details

  • Resource: Container Instance (Container Group)
  • Check: Enforce Managed Identity Usage
  • Risk: Without a managed identity, applications in the container must use stored credentials such as keys, passwords or connection strings. These can be leaked from the image or environment variables, and they have to be rotated manually.

Before you start

  • A container group can use a system-assigned identity, a user-assigned identity, or both.
  • After enabling the identity, grant it only the roles it needs on the Azure resources it accesses (for example, Key Vault Secrets User or Storage Blob Data Reader).

Remediation via Azure Portal

  1. Log in to the Azure Portal. Azure Portal dashboard
  2. Navigate to Container instances and select the affected container group. Azure Container instances list
  3. In the left menu, click on Identity under Settings. Identity in the container group menu
  4. On the System assigned tab, set Status to On and click Save. To use a user-assigned identity instead, open the User assigned tab and click Add. System-assigned managed identity turned on
  5. Click Yes to confirm.
  6. Open Access control (IAM) on the Azure resource the container needs to access and assign the required role to the managed identity.

Remediation via Azure CLI

  1. Open Azure Cloud Shell from the Azure Portal or use a local terminal with Azure CLI installed. Azure Cloud Shell
  2. Run the following command to create the container group with a system-assigned managed identity:
    az container create \
    --resource-group <resource-group-name> \
    --name <container-group-name> \
    --image <image> \
    --assign-identity
    
  3. Run the following command to get the principal ID of the identity:
    az container show \
    --resource-group <resource-group-name> \
    --name <container-group-name> \
    --query identity.principalId \
    --output tsv
    
  4. Run the following command to grant the identity access to an Azure resource:
    az role assignment create \
    --assignee <principal-id> \
    --role "<role-name>" \
    --scope <resource-id>
    

    Replace <resource-group-name>, <container-group-name>, <image>, <principal-id>, <role-name> and <resource-id> with your actual values. To use a user-assigned identity, pass its resource ID to --assign-identity instead. Managed identity is set when a container group is created, so to add it to an existing container group from the CLI, create the group again with --assign-identity and delete the old one.

Updated on 06 November, 2026