-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added queries for free AWS Compliance - Snowflake (#410)
- Loading branch information
Showing
14 changed files
with
240 additions
and
29 deletions.
There are no files selected for viewing
1 change: 1 addition & 0 deletions
1
transformations/aws/compliance-free/models/aws_compliance__api_gateway_method_settings.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{{ api_gateway_method_settings() }} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
transformations/aws/macros/networks_acls_ingress_rules.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
{% macro networks_acls_ingress_rules(framework, check_id) %} | ||
{{ return(adapter.dispatch('networks_acls_ingress_rules')()) }} | ||
{% endmacro %} | ||
|
||
{% macro default__networks_acls_ingress_rules() %}{% endmacro %} | ||
|
||
{% macro postgres__networks_acls_ingress_rules() %} | ||
WITH rules AS (SELECT aena.arn, | ||
aena.account_id, | ||
(jsonb_array_elements(entries) -> 'PortRange' ->> 'From')::int AS port_range_from, | ||
(jsonb_array_elements(entries) -> 'PortRange' ->> 'To')::int AS port_range_to, | ||
jsonb_array_elements(entries) ->> 'Protocol' AS protocol, | ||
jsonb_array_elements(entries) ->> 'CidrBlock' AS cidr_block, | ||
jsonb_array_elements(entries) ->> 'Ipv6CidrBlock' AS ipv6_cidr_block, | ||
jsonb_array_elements(entries) ->> 'Egress' AS egress, | ||
jsonb_array_elements(entries) ->> 'RuleAction' AS rule_action | ||
FROM aws_ec2_network_acls aena) | ||
SELECT arn, account_id, port_range_from, port_range_to, protocol, cidr_block, ipv6_cidr_block | ||
FROM rules | ||
WHERE egress IS DISTINCT FROM 'true' | ||
AND rule_action = 'allow' | ||
{% endmacro %} | ||
|
||
{% macro snowflake__networks_acls_ingress_rules() %} | ||
WITH rules AS ( | ||
SELECT | ||
aena.arn, | ||
aena.account_id, | ||
(v.value:PortRange:From)::int as port_range_from, | ||
(v.value:PortRange:To)::int as port_range_to, | ||
v.value:Protocol as protocol, | ||
v.value:CidrBlock as cidr_block, | ||
v.value:Ipv6CidrBlock as ipv6_cidr_block, | ||
v.value:Egress as egress, | ||
v.value:RuleAction as rule_action | ||
FROM aws_ec2_network_acls aena, | ||
LATERAL FLATTEN(ENTRIES) v | ||
) | ||
SELECT arn, account_id, port_range_from, port_range_to, protocol, cidr_block, ipv6_cidr_block | ||
FROM rules | ||
WHERE egress IS DISTINCT FROM 'true' | ||
AND rule_action = 'allow' | ||
{% endmacro %} |
41 changes: 41 additions & 0 deletions
41
transformations/aws/macros/security_group_egress_rules.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{% macro security_group_egress_rules(framework, check_id) %} | ||
{{ return(adapter.dispatch('security_group_egress_rules')()) }} | ||
{% endmacro %} | ||
|
||
{% macro default__security_group_egress_rules() %}{% endmacro %} | ||
|
||
{% macro postgres__security_group_egress_rules() %} | ||
select | ||
account_id, | ||
region, | ||
group_name, | ||
arn, | ||
group_id as id, | ||
vpc_id, | ||
(i->>'FromPort')::integer AS from_port, | ||
(i->>'ToPort')::integer AS to_port, | ||
i->>'IpProtocol' AS ip_protocol, | ||
ip_ranges->>'CidrIp' AS ip, | ||
ip6_ranges->>'CidrIpv6' AS ip6 | ||
from aws_ec2_security_groups, JSONB_ARRAY_ELEMENTS(aws_ec2_security_groups.ip_permissions_egress) as i | ||
LEFT JOIN JSONB_ARRAY_ELEMENTS(i->'IpRanges') as ip_ranges ON true | ||
LEFT JOIN JSONB_ARRAY_ELEMENTS(i->'Ipv6Ranges') as ip6_ranges ON true | ||
{% endmacro %} | ||
|
||
{% macro snowflake__security_group_egress_rules() %} | ||
select | ||
account_id, | ||
region, | ||
group_name, | ||
arn, | ||
group_id as id, | ||
vpc_id, | ||
i.value:FromPort::number AS from_port, | ||
i.value:ToPort::number AS to_port, | ||
i.value:IpProtocol AS ip_protocol, | ||
ip_ranges.value:CidrIp AS ip, | ||
ip6_ranges.value:CidrIpv6 AS ip6 | ||
from aws_ec2_security_groups, lateral flatten(input => parse_json(aws_ec2_security_groups.ip_permissions_egress)) as i, | ||
lateral flatten(input => i.value:IpRanges, OUTER => TRUE) as ip_ranges, | ||
lateral flatten(input => i.value:Ipv6Ranges, OUTER => TRUE) as ip6_ranges | ||
{% endmacro %} |
19 changes: 5 additions & 14 deletions
19
transformations/aws/models/aws_compliance__networks_acls_ingress_rules.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,5 @@ | ||
WITH rules AS (SELECT aena.arn, | ||
aena.account_id, | ||
(jsonb_array_elements(entries) -> 'PortRange' ->> 'From')::int AS port_range_from, | ||
(jsonb_array_elements(entries) -> 'PortRange' ->> 'To')::int AS port_range_to, | ||
jsonb_array_elements(entries) ->> 'Protocol' AS protocol, | ||
jsonb_array_elements(entries) ->> 'CidrBlock' AS cidr_block, | ||
jsonb_array_elements(entries) ->> 'Ipv6CidrBlock' AS ipv6_cidr_block, | ||
jsonb_array_elements(entries) ->> 'Egress' AS egress, | ||
jsonb_array_elements(entries) ->> 'RuleAction' AS rule_action | ||
FROM aws_ec2_network_acls aena) | ||
SELECT arn, account_id, port_range_from, port_range_to, protocol, cidr_block, ipv6_cidr_block | ||
FROM rules | ||
WHERE egress IS DISTINCT FROM 'true' | ||
AND rule_action = 'allow' | ||
with | ||
aggregated as ( | ||
({{ networks_acls_ingress_rules() }}) | ||
) | ||
select * from aggregated |
20 changes: 5 additions & 15 deletions
20
transformations/aws/models/aws_compliance__security_group_egress_rules.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,5 @@ | ||
select | ||
account_id, | ||
region, | ||
group_name, | ||
arn, | ||
group_id as id, | ||
vpc_id, | ||
(i->>'FromPort')::integer AS from_port, | ||
(i->>'ToPort')::integer AS to_port, | ||
i->>'IpProtocol' AS ip_protocol, | ||
ip_ranges->>'CidrIp' AS ip, | ||
ip6_ranges->>'CidrIpv6' AS ip6 | ||
from aws_ec2_security_groups, JSONB_ARRAY_ELEMENTS(aws_ec2_security_groups.ip_permissions_egress) as i | ||
LEFT JOIN JSONB_ARRAY_ELEMENTS(i->'IpRanges') as ip_ranges ON true | ||
LEFT JOIN JSONB_ARRAY_ELEMENTS(i->'Ipv6Ranges') as ip6_ranges ON true | ||
with | ||
aggregated as ( | ||
({{ security_group_egress_rules() }}) | ||
) | ||
select * from aggregated |