Review Azure Key Vault audit-log collection

Send Key Vault AuditEvent logs to the required destination and verify actual access records.

Description

Export the Key Vault AuditEvent category to trace who accessed keys, secrets or certificates.

Potential impact

Missing audit records can leave you unable to identify which account retrieved a secret or used a key.

Remediation

Check existing collection paths. If needed, add an azurerm_monitor_diagnostic_setting for the vault and send the logs to a storage account, Log Analytics or Event Hubs. Perform an authorized operation and find its name and caller at the destination. Set log retention, restrict read access and configure alerts for unusual activity.

Examples

The excerpts omit the referenced resource definitions. Review key permissions, network access and deletion protection separately.

Before

hcl
resource "azurerm_key_vault" "example" {
  name                        = "testvault"
  location                    = azurerm_resource_group.example.location
  resource_group_name         = azurerm_resource_group.example.name
  enabled_for_disk_encryption = true
  tenant_id                   = data.azurerm_client_config.current.tenant_id
  soft_delete_retention_days  = 7
  purge_protection_enabled    = false

  sku_name = "standard"
}

After

hcl
resource "azurerm_key_vault" "example" {
  name                        = "testvault"
  location                    = azurerm_resource_group.example.location
  resource_group_name         = azurerm_resource_group.example.name
  enabled_for_disk_encryption = true
  tenant_id                   = data.azurerm_client_config.current.tenant_id
  soft_delete_retention_days  = 7
  purge_protection_enabled    = false

  sku_name = "standard"
}

resource "azurerm_monitor_diagnostic_setting" "example" {
  name               = "keyvault-diagnostics"
  target_resource_id = azurerm_key_vault.example.id
  storage_account_id = data.azurerm_storage_account.example.id

  enabled_log {
    category = "AuditEvent"
  }
}

The second excerpt sends AuditEvent to an existing storage account. Look for records in its insights-logs-auditevent container.

References