turbot/steampipe-mod-aws-compliance

Control: CloudTrail trails should be enabled in all regions

Description

AWS CloudTrail is a web service that records AWS API calls for your account and delivers log files to you. The recorded information includes the identity of the API caller, the time of the API call, the source IP address of the API caller, the request parameters, and the response elements returned by the AWS service. CloudTrail provides a history of AWS API calls for an account, including API calls made via the Management Console, SDKs, command line tools, and higher-level AWS services (such as CloudFormation).

Usage

Run the control in your terminal:

powerpipe control run aws_compliance.control.cloudtrail_multi_region_read_write_enabled

Snapshot and share results via Turbot Pipes:

powerpipe login
powerpipe control run aws_compliance.control.cloudtrail_multi_region_read_write_enabled --share

SQL

This control uses a named query:

with event_selectors_trail_details as (
select
distinct account_id
from
aws_cloudtrail_trail,
jsonb_array_elements(event_selectors) as e
where
(is_logging and is_multi_region_trail and e ->> 'ReadWriteType' = 'All')
),
advanced_event_selectors_trail_details as (
select
distinct account_id
from
aws_cloudtrail_trail,
jsonb_array_elements_text(advanced_event_selectors) as a
where
-- when readOnly = true, then it is readOnly, when readOnly = false then it is writeOnly, if advanced_event_selectors is not null then it is both ReadWriteType
(is_logging and is_multi_region_trail and advanced_event_selectors is not null and (not a like '%readOnly%'))
)
select
a.title as resource,
case
when d.account_id is null and ad.account_id is null then 'alarm'
else 'ok'
end as status,
case
when d.account_id is null and ad.account_id is null then 'cloudtrail disabled.'
else 'cloudtrail enabled.'
end as reason
, a.account_id
from
aws_account as a
left join event_selectors_trail_details as d on d.account_id = a.account_id
left join advanced_event_selectors_trail_details as ad on ad.account_id = a.account_id;

Tags