# Customer-managed key for the evidence account. # # A vault with purge protection, a key, and an identity the storage account # uses to reach that key. Disabling the key cuts off every read of the # evidence at once, without touching the data. resource "azurerm_key_vault" "evidence" { name = "kv${var.name}${random_string.suffix.result}" location = azurerm_resource_group.responder.location resource_group_name = azurerm_resource_group.responder.name tenant_id = data.azurerm_client_config.current.tenant_id sku_name = "standard" purge_protection_enabled = true soft_delete_retention_days = 90 rbac_authorization_enabled = true tags = local.tags # Storage reaches the key as a trusted Azure service, which the bypass allows. network_acls { default_action = "Allow" bypass = "AzureServices" } } # Whoever runs Terraform needs to create the key. On a first apply this role # can take a minute to take effect, and the key creation can fail with 403. # Running apply again is the fix. resource "azurerm_role_assignment" "runner_crypto_officer" { scope = azurerm_key_vault.evidence.id role_definition_name = "Key Vault Crypto Officer" principal_id = data.azurerm_client_config.current.object_id } resource "azurerm_key_vault_key" "evidence" { name = "evidence" key_vault_id = azurerm_key_vault.evidence.id key_type = "RSA" key_size = 3072 key_opts = ["wrapKey", "unwrapKey"] tags = local.tags rotation_policy { automatic { time_before_expiry = "P30D" } expire_after = "P1Y" notify_before_expiry = "P29D" } depends_on = [azurerm_role_assignment.runner_crypto_officer] } resource "azurerm_user_assigned_identity" "storage" { name = "id-${var.name}-storage" location = azurerm_resource_group.responder.location resource_group_name = azurerm_resource_group.responder.name tags = local.tags } resource "azurerm_role_assignment" "storage_key_user" { scope = azurerm_key_vault.evidence.id role_definition_name = "Key Vault Crypto Service Encryption User" principal_id = azurerm_user_assigned_identity.storage.principal_id }