Control: 5.1.5 Ensure that logging for Azure KeyVault is 'Enabled'
Description
Enable AuditEvent logging for key vault instances to ensure interactions with key vaults are logged and available.
Monitoring how and when key vaults are accessed, and by whom enables an audit trail of interactions with confidential information, keys and certificates managed by Azure Keyvault. Enabling logging for Key Vault saves information in an Azure storage account that the user provides. This creates a new container named insights-logs-auditevent
automatically for the specified storage account, and this same storage account can be used for collecting logs for multiple key vaults.
Remediation
From Azure Portal
- Go to
Keyvaults
- For each Key vault
- Go to
Diagnostic settings
- Click on
Edit Settings
- Enable
Archive to a storage account
- Check
AuditEvent
- Change the retention days to be 180, 0 (for indefinite) or as appropriate
From Azure CLI
az monitor diagnostic-settings update --name "Key vault retention policy" --resource "" --set retentionPolicy.days=90
Default Value
By default, Diagnostic AuditEvent logging is not enabled for Key Vault instances.
Usage
Run the control in your terminal:
powerpipe control run azure_compliance.control.cis_v150_5_1_5
Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run azure_compliance.control.cis_v150_5_1_5 --share
SQL
This control uses a named query:
with logging_details as ( select name as key_vault_name from azure_key_vault, jsonb_array_elements(diagnostic_settings) setting, jsonb_array_elements(setting -> 'properties' -> 'logs') log where diagnostic_settings is not null and setting -> 'properties' ->> 'storageAccountId' <> '' and (log ->> 'enabled') :: boolean and log ->> 'category' = 'AuditEvent' and (log -> 'retentionPolicy') :: JSONB ? 'days')select v.id as resource, case when v.diagnostic_settings is null then 'alarm' when l.key_vault_name not like concat('%', v.name, '%') then 'alarm' else 'ok' end as status, case when v.diagnostic_settings is null then v.name || ' logging not enabled.' when l.key_vault_name not like concat('%', v.name, '%') then v.name || ' logging not enabled.' else v.name || ' logging enabled.' end as reason , v.resource_group as resource_group , sub.display_name as subscriptionfrom azure_key_vault v, logging_details l, azure_subscription subwhere sub.subscription_id = v.subscription_id;