-
Notifications
You must be signed in to change notification settings - Fork 63
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
Add additional queries to 'Other Compliance Checks' #678
Changes from 47 commits
f6155a8
a487262
3650547
6a62109
8b9e272
e56c478
2eec58a
72a55b6
f3c3297
49eb296
9ff2382
69c9533
7b69f37
d36544a
4f1ecde
8cbfb5f
15b15da
0bf9210
93df75d
79f2227
39f9390
e39f6df
f638f53
c5103bd
252e976
1825aa5
464293b
886b708
2c7b432
278d4f6
1fce46e
8201933
caafdb6
7f5e195
00c8fcd
2323057
9cc5c7c
11f8a7c
5b039be
78835f7
e51b5e2
cd4e402
02138c3
1f16116
be4d1d2
8e220bb
0366a9a
bd3c30d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -523,9 +523,9 @@ control "iam_policy_unused" { | |||||
} | ||||||
|
||||||
control "iam_access_analyzer_enabled_without_findings" { | ||||||
title = "IAM Access analyzer should be enabled without findings" | ||||||
description = "This control checks whether the IAM Access analyzer is enabled without findings. If you grant permissions to an S3 bucket in one of your organization member accounts to a principal in another organization member account, IAM Access Analyzer does not generate a finding. But if you grant permission to a principal in an account that is not a member of the organization, IAM Access Analyzer generates a finding." | ||||||
query = query.iam_access_analyzer_enabled_without_findings | ||||||
title = "IAM Access analyzer should be enabled without findings" | ||||||
description = "This control checks whether the IAM Access analyzer is enabled without findings. If you grant permissions to an S3 bucket in one of your organization member accounts to a principal in another organization member account, IAM Access Analyzer does not generate a finding. But if you grant permission to a principal in an account that is not a member of the organization, IAM Access Analyzer generates a finding." | ||||||
query = query.iam_access_analyzer_enabled_without_findings | ||||||
|
||||||
tags = merge(local.conformance_pack_iam_common_tags, { | ||||||
other_checks = "true" | ||||||
|
@@ -572,6 +572,36 @@ control "iam_policy_no_full_access_to_kms" { | |||||
}) | ||||||
} | ||||||
|
||||||
control "iam_role_cross_account_readonlyaccess_policy" { | ||||||
title = "IAM roles should not have read only access for external AWS accounts" | ||||||
description = "Ensure IAM Roles do not have ReadOnlyAccess access for external AWS account. The AWS-managed ReadOnlyAccess policy carries a high risk of potential data leakage, posing a significant threat to customer security and privacy." | ||||||
query = query.iam_role_cross_account_readonlyaccess_policy | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
tags = merge(local.conformance_pack_iam_common_tags, { | ||||||
other_checks = "true" | ||||||
}) | ||||||
} | ||||||
|
||||||
control "iam_securityaudit_role" { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
title = "IAM Security Audit role should be created to conduct security audits" | ||||||
description = "Ensure IAM Security Audit role is created. By creating an IAM role with a security audit policy, a distinct segregation of responsibilities is established between the security team and other teams within the organization." | ||||||
query = query.iam_securityaudit_role | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
tags = merge(local.conformance_pack_iam_common_tags, { | ||||||
other_checks = "true" | ||||||
}) | ||||||
} | ||||||
|
||||||
control "iam_policy_custom_no_permissive_role_assumption" { | ||||||
title = "IAM custom policy should not have overly permissive STS role assumption" | ||||||
description = "Ensure that no custom IAM policies exist which allow permissive role assumption." | ||||||
query = query.iam_policy_custom_no_permissive_role_assumption | ||||||
|
||||||
tags = merge(local.conformance_pack_iam_common_tags, { | ||||||
other_checks = "true" | ||||||
}) | ||||||
} | ||||||
|
||||||
query "iam_account_password_policy_strong_min_reuse_24" { | ||||||
sql = <<-EOQ | ||||||
select | ||||||
|
@@ -1919,3 +1949,125 @@ query "iam_role_unused_60" { | |||||
aws_iam_role; | ||||||
EOQ | ||||||
} | ||||||
|
||||||
query "iam_role_cross_account_readonlyaccess_policy" { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
sql = <<-EOQ | ||||||
with read_only_access_roles as ( | ||||||
select | ||||||
* | ||||||
from | ||||||
aws_iam_role, | ||||||
jsonb_array_elements_text(attached_policy_arns) as a | ||||||
where | ||||||
a = 'arn:aws:iam::aws:policy/ReadOnlyAccess' | ||||||
), read_only_access_roles_with_cross_account_access as ( | ||||||
select | ||||||
arn | ||||||
from | ||||||
read_only_access_roles, | ||||||
jsonb_array_elements(assume_role_policy_std -> 'Statement') as stmt, | ||||||
jsonb_array_elements_text( stmt -> 'Principal' -> 'AWS' ) as p | ||||||
where | ||||||
stmt ->> 'Effect' = 'Allow' | ||||||
and ( | ||||||
p = '*' | ||||||
or not (p like '%' || account_id || '%') | ||||||
) | ||||||
) | ||||||
select | ||||||
r.arn as resource, | ||||||
case | ||||||
when ar.arn is null then 'skip' | ||||||
when c.arn is not null then 'alarm' | ||||||
else 'ok' | ||||||
end as status, | ||||||
case | ||||||
when ar.arn is null then r.title || ' not associated with ReadOnlyAccess policy.' | ||||||
when c.arn is not null then r.title || ' associated with ReadOnlyAccess cross account access.' | ||||||
else r.title || ' associated ReadOnlyAccess without cross account access.' | ||||||
end as reason | ||||||
${replace(local.common_dimensions_qualifier_global_sql, "__QUALIFIER__", "r.")} | ||||||
from | ||||||
aws_iam_role as r | ||||||
left join read_only_access_roles as ar on r.arn = ar.arn | ||||||
left join read_only_access_roles_with_cross_account_access as c on c.arn = r.arn; | ||||||
EOQ | ||||||
} | ||||||
|
||||||
query "iam_securityaudit_role" { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
sql = <<-EOQ | ||||||
with securityaudit_role_count as( | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
select | ||||||
'arn:' || a.partition || ':::' || a.account_id as resource, | ||||||
count(policy_arn), | ||||||
a.account_id, | ||||||
a._ctx | ||||||
from | ||||||
aws_account as a | ||||||
left join aws_iam_role as r on r.account_id = a.account_id | ||||||
left join jsonb_array_elements_text(attached_policy_arns) as policy_arn on true | ||||||
where | ||||||
policy_arn = 'arn:aws:iam::aws:policy/SecurityAudit' | ||||||
group by | ||||||
a.account_id, | ||||||
a.partition, | ||||||
a._ctx | ||||||
) | ||||||
select | ||||||
resource, | ||||||
case | ||||||
when count > 0 then 'ok' | ||||||
else 'alarm' | ||||||
end as status, | ||||||
case | ||||||
when count = 1 then 'SecurityAudit policy attached to 1 role.' | ||||||
when count > 1 then 'SecurityAudit policy attached to ' || count || ' roles.' | ||||||
else 'SecurityAudit policy not attached to any role.' | ||||||
end as reason | ||||||
${local.common_dimensions_global_sql} | ||||||
from | ||||||
securityaudit_role_count; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
EOQ | ||||||
} | ||||||
|
||||||
query "iam_policy_custom_no_permissive_role_assumption" { | ||||||
sql = <<-EOQ | ||||||
with bad_policies as ( | ||||||
select | ||||||
arn, | ||||||
count(*) as num | ||||||
from | ||||||
aws_iam_policy, | ||||||
jsonb_array_elements(policy_std -> 'Statement') as s, | ||||||
jsonb_array_elements_text(s -> 'Resource') as resource, | ||||||
jsonb_array_elements_text(s -> 'Action') as action | ||||||
where | ||||||
not is_aws_managed | ||||||
and s ->> 'Effect' = 'Allow' | ||||||
and resource = '*' | ||||||
and ( | ||||||
( action = '*' | ||||||
or action = 'sts:*' | ||||||
or action = 'sts:AssumeRole' | ||||||
) | ||||||
) | ||||||
group by | ||||||
arn | ||||||
) | ||||||
select | ||||||
p.arn as resource, | ||||||
case | ||||||
when b.arn is not null then 'alarm' | ||||||
else 'ok' | ||||||
end as status, | ||||||
p.name || ' contains ' || coalesce(b.num, 0) || | ||||||
' statements that allow overly permissive STS role assumption.' as reason | ||||||
${replace(local.tag_dimensions_qualifier_sql, "__QUALIFIER__", "p.")} | ||||||
${replace(local.common_dimensions_qualifier_sql, "__QUALIFIER__", "p.")} | ||||||
from | ||||||
aws_iam_policy as p | ||||||
left join bad_policies as b on p.arn = b.arn | ||||||
where | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
not is_aws_managed; | ||||||
EOQ | ||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.