turbot/azure_compliance

Query: search_service_logging_enabled

Usage

powerpipe query azure_compliance.query.search_service_logging_enabled

SQL

with logging_details as (
select
distinct name as search_service_name
from
azure_search_service,
jsonb_array_elements(diagnostic_settings) setting,
jsonb_array_elements(setting -> 'properties' -> 'logs') log
where
diagnostic_settings is not null
and (
(
(log ->> 'enabled') :: boolean
and (log -> 'retentionPolicy' ->> 'enabled') :: boolean
and (log -> 'retentionPolicy') :: JSONB ? 'days'
)
or
(
(log ->> 'enabled') :: boolean
and (
log -> 'retentionPolicy' ->> 'enabled' <> 'true'
or setting -> 'properties' ->> 'storageAccountId' = ''
)
)
)
)
select
v.id as resource,
case
when v.diagnostic_settings is null then 'alarm'
when l.search_service_name is null then 'alarm'
else 'ok'
end as status,
case
when v.diagnostic_settings is null then v.name || ' logging not enabled.'
when l.search_service_name is null then v.name || ' logging not enabled.'
else v.name || ' logging enabled.'
end as reason
, v.resource_group as resource_group
, sub.display_name as subscription
from
azure_search_service as v
left join logging_details as l on v.name = l.search_service_name,
azure_subscription as sub
where
sub.subscription_id = v.subscription_id;

Controls

The query is being used by the following controls: