説明
アプリがマネージド ID に対応する Azure サービスに接続する場合、コードや設定に認証情報を保存せずに認証できます。アプリにログインするユーザーの認証は別途設定してください。
想定される影響
長期利用するキーをアプリ設定に保存すると、漏えいするおそれがあります。キーを交換するたびに、そのキーを使う設定の更新も必要です。
対処方法
identity ブロックで SystemAssigned または UserAssigned を選びます。 UserAssigned の場合は、割り当てるマネージド ID の Azure リソース ID を identity_ids に指定します。接続先で必要な権限だけを付与し、アプリの接続をマネージド ID 認証に切り替えてください。その ID で必要な操作が成功したら古いシークレットを取り除き、ほかでも不要になった認証情報を失効させます。
例
AzureRM 3.x の azurerm_app_service の例ではシステム割り当て ID だけを追加します。現在の Linux・Windows Web App でも identity ブロックを使えます。他のリソースにアクセスしないアプリでは、この目的で ID を設定する必要はありません。
変更前
hcl
resource "azurerm_app_service" "example" {
name = "example-app-service"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
app_service_plan_id = azurerm_app_service_plan.example.id
}
変更後
hcl
resource "azurerm_app_service" "example" {
name = "example-app-service"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
app_service_plan_id = azurerm_app_service_plan.example.id
identity {
type = "SystemAssigned"
}
}