turbot/azure_compliance

Query: sql_server_auditing_storage_account_destination_retention_90_days

Usage

powerpipe query azure_compliance.query.sql_server_auditing_storage_account_destination_retention_90_days

SQL

with sql_server as(
select
id,
name,
subscription_id,
resource_group,
p -> 'properties' ->> 'retentionDays' as retentionDays
from
azure_sql_server,
jsonb_array_elements(server_audit_policy) as p
where
p -> 'properties' ->> 'state' = 'Enabled'
and p -> 'properties' ->> 'storageEndpoint' is not null
)
select
a.id as resource,
case
when s.id is null then 'skip' -- The value in days of the retention period (0 is an indication for unlimited retention).
when s.retentionDays :: Integer = 0 then 'ok'
when s.retentionDays :: Integer >= 90 then 'ok'
else 'alarm'
end as status,
case
when s.id is null then a.name || ' auditing to storage account destination not enabled.'
when s.retentionDays :: Integer = 0 then a.name || ' auditing to storage account destination configured with unlimited retention days.'
when s.retentionDays :: Integer >= 90 then a.name || ' auditing to storage account destination configured with 90 days retention or higher.'
else a.name || ' auditing to storage account destination not configured with 90 days retention or higher.'
end as reason,
a.resource_group as resource_group,
sub.display_name as subscription
from
azure_sql_server as a
left join sql_server as s on s.id = a.id,
azure_subscription as sub
where
sub.subscription_id = a.subscription_id;

Controls

The query is being used by the following controls: