Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lambda_function_restrict_public_access.sql query not evaluating correctly Closes #421 #422

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions query/lambda/lambda_function_restrict_public_access.sql
Original file line number Diff line number Diff line change
@@ -1,25 +1,34 @@
with wildcard_action_policies as (
select
arn,
count(*) as statements_num
from
aws_lambda_function,
jsonb_array_elements(policy_std -> 'Statement') as s
where
s ->> 'Effect' = 'Allow'
and (
( s -> 'Principal' -> 'AWS') = '["*"]'
or s ->> 'Principal' = '*'
)
group by
arn
)
select
-- Required Columns
arn as resource,
f.arn as resource,
case
when policy_std -> 'Statement' ->> 'Effect' = 'Allow'
and (
policy_std -> 'Statement' ->> 'Principal' = '*'
or ( policy_std -> 'Principal' -> 'AWS' ) :: text = '*'
) then 'alarm'
else 'ok'
end status,
when p.arn is null then 'ok'
else 'alarm'
end as status,
case
when policy_std is null then title || ' has no policy.'
when policy_std -> 'Statement' ->> 'Effect' = 'Allow'
and (
policy_std -> 'Statement' ->> 'Principal' = '*'
or ( policy_std -> 'Principal' -> 'AWS' ) :: text = '*'
) then title || ' allows public access.'
else title || ' does not allow public access.'
end reason,
when p.arn is null then title || ' does not allow public access.'
else title || ' contains ' || coalesce(p.statements_num,0) ||
' statements that allows public access.'
end as reason,
-- Additional Dimensions
region,
account_id
f.region,
f.account_id
from
aws_lambda_function;
aws_lambda_function as f
left join wildcard_action_policies as p on p.arn = f.arn;