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

Add additional queries to 'Other Compliance Checks' #678

Merged
merged 48 commits into from
Jul 6, 2023
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
f6155a8
Add new extra check queries
Priyanka-Chatterjee-2000 Jun 5, 2023
a487262
Add extra queries
Priyanka-Chatterjee-2000 Jun 7, 2023
3650547
Add controls for queries added
Priyanka-Chatterjee-2000 Jun 9, 2023
6a62109
Minor updates
Priyanka-Chatterjee-2000 Jun 10, 2023
8b9e272
Suggestive Changes
Priyanka-Chatterjee-2000 Jun 12, 2023
e56c478
Apply suggestions from code review
Priyanka-Chatterjee-2000 Jun 12, 2023
2eec58a
Minor updates
Priyanka-Chatterjee-2000 Jun 12, 2023
72a55b6
Merge branch 'extra-check-queries' of https://github.com/turbot/steam…
Priyanka-Chatterjee-2000 Jun 12, 2023
f3c3297
drs_job_exists update
Priyanka-Chatterjee-2000 Jun 12, 2023
49eb296
Change query name
Priyanka-Chatterjee-2000 Jun 12, 2023
9ff2382
Apply suggestions from code review
Priyanka-Chatterjee-2000 Jun 13, 2023
69c9533
Suggestive changes
Priyanka-Chatterjee-2000 Jun 13, 2023
7b69f37
Vpc changes
Priyanka-Chatterjee-2000 Jun 13, 2023
d36544a
update backup_vault_exists
Priyanka-Chatterjee-2000 Jun 13, 2023
4f1ecde
Update backup.sp
khushboo9024 Jun 13, 2023
8cbfb5f
Add description change
Priyanka-Chatterjee-2000 Jun 13, 2023
15b15da
minor fix in query and control name
madhushreeray30 Jun 13, 2023
0bf9210
update
madhushreeray30 Jun 13, 2023
93df75d
Update
Priyanka-Chatterjee-2000 Jun 13, 2023
79f2227
Apply suggestions from code review
Priyanka-Chatterjee-2000 Jun 13, 2023
39f9390
Query name change
Priyanka-Chatterjee-2000 Jun 13, 2023
e39f6df
update
khushboo9024 Jun 15, 2023
f638f53
Merge branch 'release/v0.69' into extra-check-queries
khushboo9024 Jun 15, 2023
c5103bd
Add new extra check queries
khushboo9024 Jun 27, 2023
252e976
resolved merge conflict
khushboo9024 Jun 27, 2023
1825aa5
update
khushboo9024 Jun 27, 2023
464293b
update
khushboo9024 Jun 28, 2023
886b708
update
khushboo9024 Jun 28, 2023
2c7b432
update
khushboo9024 Jun 29, 2023
278d4f6
add extra check controls
khushboo9024 Jul 4, 2023
1fce46e
resolve merge conflict
khushboo9024 Jul 4, 2023
8201933
update
khushboo9024 Jul 4, 2023
caafdb6
update
khushboo9024 Jul 4, 2023
7f5e195
Tidy up
rajlearner17 Jul 4, 2023
00c8fcd
Tidy up
rajlearner17 Jul 4, 2023
2323057
Tidy up
rajlearner17 Jul 4, 2023
9cc5c7c
update
khushboo9024 Jul 4, 2023
11f8a7c
Update reason
rajlearner17 Jul 4, 2023
5b039be
update
khushboo9024 Jul 4, 2023
78835f7
update
khushboo9024 Jul 4, 2023
e51b5e2
update
khushboo9024 Jul 4, 2023
cd4e402
Update reason in autoscaling_ec2_launch_configuration_no_sensitive_data
rajlearner17 Jul 5, 2023
02138c3
Updated reason for lambda_function_restrict_public_url
rajlearner17 Jul 5, 2023
1f16116
update
khushboo9024 Jul 5, 2023
be4d1d2
update
khushboo9024 Jul 5, 2023
8e220bb
revert mod.sp changes
khushboo9024 Jul 5, 2023
0366a9a
update
khushboo9024 Jul 5, 2023
bd3c30d
update
khushboo9024 Jul 6, 2023
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
34 changes: 34 additions & 0 deletions conformance_pack/autoscaling.sp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,16 @@ control "autoscaling_launch_config_hop_limit" {
})
}

control "autoscaling_ec2_launch_configuration_no_sensitive_data" {
title = "EC2 auto scaling group launch configurations user data should not have any sensitive data"
description = "Ensure that sensitive information is not included in the user data of the launch configuration. It is recommended to utilize Secrets Manager as an alternative for securely managing sensitive data."
query = query.autoscaling_ec2_launch_configuration_no_sensitive_data

tags = merge(local.conformance_pack_autoscaling_common_tags, {
other_checks = "true"
})
}

query "autoscaling_launch_config_requires_imdsv2" {
sql = <<-EOQ
select
Expand Down Expand Up @@ -252,6 +262,30 @@ query "autoscaling_launch_config_hop_limit" {
EOQ
}

query "autoscaling_ec2_launch_configuration_no_sensitive_data" {
sql = <<-EOQ
select
launch_configuration_arn as resource,
case
when
user_data like any (array [ '%pass%', '%secret%', '%token%', '%key%' ])
or user_data ~ '(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]' then 'alarm'
else 'ok'
end as status,
case
when
user_data like any (array [ '%pass%', '%secret%', '%token%', '%key%' ])
or user_data ~ '(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]' then title || ' has potential secrets in user data.'
else title || ' does not have secrets in user data.'
end as reason
${local.tag_dimensions_sql}
${local.common_dimensions_sql}
from
aws_ec2_launch_configuration;
EOQ
}


# Non-Config rule query

query "autoscaling_group_uses_ec2_launch_template" {
Expand Down
31 changes: 31 additions & 0 deletions conformance_pack/eks.sp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ control "eks_cluster_with_latest_kubernetes_version" {
})
}

control "eks_cluster_endpoint_public_access_restircted" {
title = "EKS clusters endpoint public access should be restircted"
description = "EKS clusters endpoint with private access allows communication between your nodes and the API server stays within. This control is non-compliant if clusters endpoint public access is enabled as cluster API server is accessible from the internet."
query = query.eks_cluster_endpoint_public_access_restircted

tags = merge(local.conformance_pack_eks_common_tags, {
other_checks = "true"
})
}

query "eks_cluster_secrets_encrypted" {
sql = <<-EOQ
with eks_secrets_encrypted as (
Expand Down Expand Up @@ -194,3 +204,24 @@ query "eks_cluster_with_latest_kubernetes_version" {
aws_eks_cluster;
EOQ
}

query "eks_cluster_endpoint_public_access_restircted" {
sql = <<-EOQ
select
arn as resource,
case
when resources_vpc_config ->> 'EndpointPrivateAccess' = 'true' and resources_vpc_config ->> 'EndpointPublicAccess' = 'false' then 'ok'
when resources_vpc_config ->> 'EndpointPublicAccess' = 'true' and resources_vpc_config -> 'PublicAccessCidrs' @> '["0.0.0.0/0"]' then 'alarm'
else 'ok'
end as status,
case
when resources_vpc_config ->> 'EndpointPrivateAccess' = 'true' and resources_vpc_config ->> 'EndpointPublicAccess' = 'false' then title || ' endpoint access is private.'
when resources_vpc_config ->> 'EndpointPublicAccess' = 'true' and resources_vpc_config -> 'PublicAccessCidrs' @> '["0.0.0.0/0"]' then title || ' endpoint access is public.'
else title || ' endpoint public access is restricted.'
end as reason
${local.tag_dimensions_sql}
${local.common_dimensions_sql}
from
aws_eks_cluster;
EOQ
}
39 changes: 39 additions & 0 deletions conformance_pack/guardduty.sp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ control "guardduty_no_high_severity_findings" {
})
}

control "guardduty_centrally_configured" {
title = "GuardDuty Detector should be centrally configured"
description = "Ensure that GuardDuty is centrally configured, if GuardDuty is not under central management, it becomes impossible to centrally manage GuardDuty findings, settings, and member accounts."
query = query.guardduty_centrally_configured

tags = merge(local.conformance_pack_guardduty_common_tags, {
other_checks = "true"
})
}

query "guardduty_enabled" {
sql = <<-EOQ
select
Expand Down Expand Up @@ -135,3 +145,32 @@ query "guardduty_finding_archived" {
aws_guardduty_finding;
EOQ
}

query "guardduty_centrally_configured" {
sql = <<-EOQ
select
'arn:' || r.partition || '::' || r.region || ':' || r.account_id as resource,
case
when r.region = any(array['af-south-1', 'ap-northeast-3', 'ap-southeast-3', 'eu-south-1', 'cn-north-1', 'cn-northwest-1', 'me-south-1', 'us-gov-east-1']) then 'skip'
-- Skip any regions that are disabled in the account.
when r.opt_in_status = 'not-opted-in' then 'skip'
when status is null then 'info'
when status = 'DISABLED' then 'alarm'
when status = 'ENABLED' and master_account ->> 'AccountId' is not null then 'ok'
else 'alarm'
end as status,
case
when r.region = any(array['af-south-1', 'ap-northeast-3', 'ap-southeast-3', 'eu-south-1', 'cn-north-1', 'cn-northwest-1', 'me-south-1', 'us-gov-east-1']) then r.region || ' region not supported.'
when r.opt_in_status = 'not-opted-in' then r.region || ' region is disabled.'
when status is null then 'No GuardDuty detector found in ' || r.region || '.'
when status = 'DISABLED' then r.region || ' detector ' || d.title || ' disabled.'
when status = 'ENABLED' and master_account ->> 'AccountId' is not null then r.region || ' detector ' || d.title || ' centrally configured.'
else r.region || ' detector ' || d.title || ' not centrally configured..'
end as reason
${replace(local.common_dimensions_qualifier_sql, "__QUALIFIER__", "r.")}
from
aws_region as r
left join aws_guardduty_detector d on r.account_id = d.account_id and r.name = d.region;
EOQ
}

158 changes: 155 additions & 3 deletions conformance_pack/iam.sp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -572,6 +572,36 @@ control "iam_policy_no_full_access_to_kms" {
})
}

control "iam_role_cross_account_readonlyaccess_policy" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
control "iam_role_cross_account_readonlyaccess_policy" {
control "iam_role_cross_account_read_only_access_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
Copy link
Contributor

@madhushreeray30 madhushreeray30 Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
query = query.iam_role_cross_account_readonlyaccess_policy
query = query.iam_role_cross_account_read_only_access_policy


tags = merge(local.conformance_pack_iam_common_tags, {
other_checks = "true"
})
}

control "iam_securityaudit_role" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
control "iam_securityaudit_role" {
control "iam_security_audit_role" {

title = "IAM Security Audit role shoulb 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
Copy link
Contributor

@madhushreeray30 madhushreeray30 Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
query = query.iam_securityaudit_role
query = query.iam_security_audit_role


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
Expand Down Expand Up @@ -1919,3 +1949,125 @@ query "iam_role_unused_60" {
aws_iam_role;
EOQ
}

query "iam_role_cross_account_readonlyaccess_policy" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
query "iam_role_cross_account_readonlyaccess_policy" {
query "iam_role_cross_account_read_only_access_policy" {

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" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
query "iam_securityaudit_role" {
query "iam_security_audit_role" {

sql = <<-EOQ
with securityaudit_role_count as(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
with securityaudit_role_count as(
with security_audit_role_count as(

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
securityaudit_role_count;
security_audit_role_count;

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
where
where

not is_aws_managed;
EOQ
}
Loading