説明
Azure Container Instances のコンテナーは、コンテナーグループのマネージド ID を使って他の Azure サービスに接続できます。
想定される影響
コンテナーの環境変数やデプロイの状態ファイルからアクセスキーが流出すると、そのキーで他のリソースにアクセスされるおそれがあります。
対処方法
グループの identity に SystemAssigned を指定するか、UserAssigned と identity_ids を設定します。対象リソースで必要なロールを ID に付与し、コンテナーがその ID で認証するようにします。
例
どちらの例もプライベート サブネットを使います。古い資格情報を失効させる前に、コンテナー内から対象に接続し、必要な操作を実行できることを確認します。
変更前
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"
}
}
変更後
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"
}
}