turbot/steampipe-mod-azure-compliance

Control: 7.1.1.4 Ensure that logging for Azure Key Vault 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 Key Vault. Enabling logging for Key Vault saves information in a user provided destination of either an Azure storage account or Log Analytics workspace. The same destination can be used for collecting logs for multiple Key Vaults.

Remediation

From Azure Portal

  1. Go to Key vaults.
  2. Select a Key vault.
  3. Under Monitoring, select Diagnostic settings.
  4. Click Edit setting to update an existing diagnostic setting, or Add diagnostic setting to create a new one.
  5. If creating a new diagnostic setting, provide a name.
  6. Configure an appropriate destination.
  7. Under Category groups, check audit and allLogs.
  8. Click Save.

From Azure CLI

To update an existing Diagnostic Settings

az monitor diagnostic-settings update --name "<diagnostic_setting_name>" --resource <key_vault_id>

To create a new Diagnostic Settings

az monitor diagnostic-settings create --name "<diagnostic_setting_name>" --resource <key_vault_id> --logs "[{category:audit,enabled:true},{category:allLogs,enabled:true}]" --metrics "[{category:AllMetrics,enabled:true}]" <[--event-hub <event_hub_ID> --event-hub-rule <event_hub_auth_rule_ID> | --storage-account <storage_account_ID> |--workspace <log_analytics_workspace_ID> | --marketplace-partner-id <solution_resource_ID>]>

From PowerShell

Create the Log settings object

$logSettings = @()
$logSettings += New-AzDiagnosticSettingLogSettingsObject -Enabled $true -Category audit
$logSettings += New-AzDiagnosticSettingLogSettingsObject -Enabled $true -Category allLogs

Create the Metric settings object

$metricSettings = @()
$metricSettings += New-AzDiagnosticSettingMetricSettingsObject -Enabled $true -Category AllMetrics

Create the Diagnostic Settings for each Key Vault

New-AzDiagnosticSetting -Name "<diagnostic_setting_name>" -ResourceId <key_vault_id> -Log $logSettings -Metric $metricSettings [-StorageAccountId <storage_account_ID> | -EventHubName <event_hub_name> -EventHubAuthorizationRuleId <event_hub_auth_rule_ID> | -WorkSpaceId <log analytics workspace ID> | -MarketPlacePartnerId <full resource ID for third-party solution>]

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_v400_7_1_1_4

Snapshot and share results via Turbot Pipes:

powerpipe login
powerpipe control run azure_compliance.control.cis_v400_7_1_1_4 --share

SQL

This control uses a named query:

with audit_logging_details as (
select
id
from
azure_key_vault,
jsonb_array_elements(diagnostic_settings) setting,
jsonb_array_elements(setting -> 'properties' -> 'logs') log
where
diagnostic_settings is not null
and log -> 'categoryGroup' = '"audit"'
and (log -> 'enabled')::bool = true
),
alllogs_logging_details as (
select
id
from
azure_key_vault,
jsonb_array_elements(diagnostic_settings) setting,
jsonb_array_elements(setting -> 'properties' -> 'logs') log
where
diagnostic_settings is not null
and log -> 'categoryGroup' = '"allLogs"'
and (log -> 'enabled')::bool = true
)
select
v.id as resource,
case
when v.diagnostic_settings is null then 'alarm'
when audit.id is not null and alllogs.id is not null then 'ok'
else 'alarm'
end as status,
case
when v.diagnostic_settings is null then v.name || ' logging not enabled.'
when audit.id is not null and alllogs.id is not null then v.name || ' logging enabled.'
when audit.id is null then v.name || ' logging not enabled for audit category group.'
when alllogs.id is null then v.name || ' logging not enabled for allLogs category group.'
else v.name || ' logging not enabled.'
end as reason
, v.resource_group as resource_group
, sub.display_name as subscription
from
azure_key_vault v
left join audit_logging_details as audit on audit.id = v.id
left join alllogs_logging_details as alllogs on alllogs.id = v.id,
azure_subscription sub

Tags