Container Group has no managed identity configured

Reduce static credentials by using managed identity for supported Azure connections from a Container Group.

Description

Containers in Azure Container Instances can use the container group’s managed identity to access other Azure services.

Potential impact

An access key exposed in container environment variables or deployment state can give someone access to the resources that key permits.

Remediation

Set the group’s identity to SystemAssigned, or use UserAssigned and specify identity_ids. Grant the identity the required role on the target resource and configure the container to authenticate with it.

Examples

Both examples use a private subnet. From inside the container, check that you can reach the target and perform the required operation before revoking the old credentials.

Before

hcl
resource "azurerm_container_group" "example" {
  name                = "example-continst"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  ip_address_type     = "Private"
  subnet_ids          = [azurerm_subnet.aci.id]
  os_type             = "Linux"

  container {
    name   = "app"
    image  = "nginx:stable"
    cpu    = "0.5"
    memory = "1.5"
  }
}

After

hcl
resource "azurerm_container_group" "example" {
  name                = "example-continst"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  ip_address_type     = "Private"
  subnet_ids          = [azurerm_subnet.aci.id]
  os_type             = "Linux"

  identity {
    type = "SystemAssigned"
  }

  container {
    name   = "app"
    image  = "nginx:stable"
    cpu    = "0.5"
    memory = "1.5"
  }
}

References