turbot/steampipe-mod-aws-compliance

Control: SNS topic policies should prohibit publishing access

Description

Manage access to resources in the AWS Cloud by ensuring SNS topics cannot be accessed publicly for publishing.

Usage

Run the control in your terminal:

powerpipe control run aws_compliance.control.sns_topic_policy_prohibit_publishing_access

Snapshot and share results via Turbot Pipes:

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

SQL

This control uses a named query:

with wildcard_action_policies as (
select
topic_arn,
count(*) as statements_num
from
aws_sns_topic,
jsonb_array_elements(policy_std -> 'Statement') as s,
jsonb_array_elements_text(s -> 'Action') as a
where
s ->> 'Effect' = 'Allow'
and (
( s -> 'Principal' -> 'AWS') = '["*"]'
or s ->> 'Principal' = '*'
)
and a = 'sns:publish'
and s -> 'Condition' is null
group by
topic_arn
)
select
t.topic_arn as resource,
case
when p.topic_arn is null then 'ok'
else 'alarm'
end as status,
case
when p.topic_arn is null then title || ' does not allow publish access without condition.'
else title || ' contains ' || coalesce(p.statements_num,0) || ' statements that allows publish access without condition.'
end as reason
, t.region, t.account_id
from
aws_sns_topic as t
left join wildcard_action_policies as p on p.topic_arn = t.topic_arn;

Tags