説明
Azure Storage は既定で Microsoft 管理キーを使ってデータを暗号化します。診断ログを保存する組織がキーの権限や更新時期を管理する必要があれば、カスタマー管理キーを関連付けてください。
想定される影響
アカウントのマネージド ID がキーを利用できなくなると、ログデータにアクセスできなくなる場合があります。
対処方法
論理的な削除と消去保護を有効にした Key Vault に、サポート対象の RSA キーまたは RSA-HSM キーを用意します。キーの復旧・ローテーション手順を決め、マネージド ID にそのキーの get、wrapKey、unwrapKey 権限を付与します。Terraform では customer_managed_key ブロックか、独立した azurerm_storage_account_customer_managed_key リソースで関連付けを管理してください。適用後、アカウントが目的のキーを参照していることを確認します。
例
例はユーザー割り当て ID と独立した関連付けリソースを使います。設定の競合を防ぐため、アカウントの lifecycle.ignore_changes に customer_managed_key を指定してください。収集する診断ログのカテゴリも指定します。
変更前
hcl
resource "azurerm_storage_account" "logs" {
name = "examplediagnosticlogs"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "GRS"
}
resource "azurerm_monitor_diagnostic_setting" "example" {
name = "subscription-diagnostics"
target_resource_id = data.azurerm_subscription.current.id
storage_account_id = azurerm_storage_account.logs.id
}
変更後
hcl
resource "azurerm_storage_account" "logs" {
name = "examplediagnosticlogs"
resource_group_name = azurerm_resource_group.example.name
location = azurerm_resource_group.example.location
account_tier = "Standard"
account_replication_type = "GRS"
identity {
type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.storage.id]
}
}
resource "azurerm_storage_account_customer_managed_key" "logs" {
storage_account_id = azurerm_storage_account.logs.id
key_vault_key_id = azurerm_key_vault_key.storage.id
user_assigned_identity_id = azurerm_user_assigned_identity.storage.id
}
resource "azurerm_monitor_diagnostic_setting" "example" {
name = "subscription-diagnostics"
target_resource_id = data.azurerm_subscription.current.id
storage_account_id = azurerm_storage_account.logs.id
}