Control: Resource logs in Batch accounts should be enabled
Description
Audit enabling of resource logs. This enables you to recreate activity trails to use for investigation purposes; when a security incident occurs or when your network is compromised.
Usage
Run the control in your terminal:
powerpipe control run terraform_azure_compliance.control.batch_account_logging_enabled
Snapshot and share results via Turbot Pipes:
powerpipe loginpowerpipe control run terraform_azure_compliance.control.batch_account_logging_enabled --share
SQL
This control uses a named query:
with batch_accounts as ( select * from terraform_resource where type = 'azurerm_batch_account'), diagnostic_setting as ( select * from terraform_resource where type = 'azurerm_monitor_diagnostic_setting' and (attributes_std ->> 'target_resource_id') like '%azurerm_batch_account.%'), batch_account_logging as ( select ba.name as ba_name from batch_accounts as ba left join diagnostic_setting as ds on ba.name = (split_part((ds.attributes_std ->> 'target_resource_id'), '.', 2)) where (ds.attributes_std ->> 'storage_account_id') is not null and (ds.attributes_std -> 'log' ->> 'enabled')::boolean and (ds.attributes_std -> 'log' -> 'retention_policy' ->> 'enabled')::boolean)select type || ' ' || a.name as resource, case when s.ba_name is null then 'alarm' else 'ok' end as status, split_part(a.address, '.', 2) || case when s.ba_name is null then ' logging disabled' else ' logging enabled' end || '.' reason , a.path || ':' || a.start_linefrom batch_accounts as a left join batch_account_logging as s on a.name = s.ba_name;