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

feat!: Update aws to v23.3.1 #264

Merged
merged 55 commits into from
Dec 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
55 commits
Select commit Hold shift + click to select a range
221f04d
feat: Update `aws_cloudtrail_trail_event_selectors` schema
candiduslynx Nov 21, 2023
7ad758f
Merge branch 'main' into fix/aws_cloudtrail_trail_event_selectors/v23…
candiduslynx Dec 19, 2023
eac98bf
bump aws in data-resilience
candiduslynx Dec 21, 2023
e1018d9
Merge branch 'main' into fix/aws_cloudtrail_trail_event_selectors/v23…
candiduslynx Dec 21, 2023
482310a
bump aws in asset-free
candiduslynx Dec 21, 2023
b0aa0ce
bump aws-pg in compliance free
candiduslynx Dec 21, 2023
303dd10
bumop aws in compliance-free-bq
candiduslynx Dec 21, 2023
46914ba
bump aws in compliance-free snowflake
candiduslynx Dec 21, 2023
33b2ea2
Update bigquery.yml
candiduslynx Dec 21, 2023
c434921
Update postgres.yml
candiduslynx Dec 21, 2023
f560430
Update snowflake.yml
candiduslynx Dec 21, 2023
fb81760
Update postgres.yml
candiduslynx Dec 21, 2023
88d0ad5
Update postgres.yml
candiduslynx Dec 21, 2023
d5bfa30
Update bucket_access_logging.sql
candiduslynx Dec 21, 2023
e6d3f6e
Update detector_enabled.sql
candiduslynx Dec 21, 2023
7e86bb9
Update detector_enabled.sql
candiduslynx Dec 21, 2023
521a791
Update detector_enabled.sql
candiduslynx Dec 21, 2023
938b427
Update unused_directconntect_connections.sql
candiduslynx Dec 21, 2023
df1b25d
Update snowflake.yml
candiduslynx Dec 21, 2023
14a92a5
Update snowflake.yml
candiduslynx Dec 21, 2023
a8b7dc5
Update snowflake.yml
candiduslynx Dec 21, 2023
441e013
Update transformations/aws/compliance-free/tests/snowflake.yml
candiduslynx Dec 21, 2023
add1149
force migration inf compliance-free/bq
candiduslynx Dec 21, 2023
c7cc14b
upd sf for compliance-premium
candiduslynx Dec 21, 2023
a9df666
use request_ cols
candiduslynx Dec 21, 2023
6cd4b81
use aws_iam_policy_versions
candiduslynx Dec 21, 2023
75a11a7
use aws_s3_bucket_policies
candiduslynx Dec 21, 2023
1c49bc9
Merge branch 'main' into fix/aws_cloudtrail_trail_event_selectors/v23…
candiduslynx Dec 21, 2023
b7afc23
aws_s3_buckets relations
candiduslynx Dec 22, 2023
ab8b274
aws_s3_bucket_replications
candiduslynx Dec 22, 2023
935a032
aws_s3_bucket_policies
candiduslynx Dec 22, 2023
b705ea1
rm extra forced mode
candiduslynx Dec 22, 2023
80855d1
cloudtrail/bucket_access_logging:snowflake
candiduslynx Dec 23, 2023
b387f58
cloudtrail/enabled_in_all_regions:snowflake
candiduslynx Dec 23, 2023
cce6d8b
Updated log_metric and enabled_in_all_regions
ronsh12 Dec 26, 2023
b6fb421
change ref to [email protected]
candiduslynx Dec 27, 2023
fb9320e
Updated queries - no_star, policies_have_wildcard_actions, policies_w…
ronsh12 Dec 27, 2023
e26d2a5
Merge branch 'main' into fix/aws_cloudtrail_trail_event_selectors/v23…
candiduslynx Dec 27, 2023
005aab9
force migrate for tests
candiduslynx Dec 27, 2023
794808f
use v23.3.0
candiduslynx Dec 27, 2023
355ed43
use v23.3.0
candiduslynx Dec 27, 2023
46441bc
Revert "force migrate for tests"
candiduslynx Dec 27, 2023
a0c64e2
Updated queries cloudtrail_enabled_all_regions, bucket_access_logging
ronsh12 Dec 27, 2023
9c52378
Updated manifest compliances
ronsh12 Dec 27, 2023
191fdd2
Updated queries elastic_beanstalk_stream_logs_to_cloudwatch, s3_bucke…
ronsh12 Dec 28, 2023
4e5cc69
check query
ronsh12 Dec 28, 2023
35c0fd0
Update aws to `v23.3.1`
candiduslynx Dec 28, 2023
bdfb813
Updated query s3_bucket_logging_enabled
ronsh12 Dec 28, 2023
4bdcce2
Update transformations/aws/compliance-premium/tests/snowflake.yml
candiduslynx Dec 28, 2023
6b2f7cc
Updated query elastic_beanstalk_stream_logs_to_cloudwatch
ronsh12 Dec 28, 2023
3c80494
Update transformations/aws/compliance-premium/tests/snowflake.yml
candiduslynx Dec 28, 2023
2f9cf11
Merge branch 'main' into fix/aws_cloudtrail_trail_event_selectors/v23…
candiduslynx Dec 28, 2023
946f63f
tmp force migration
candiduslynx Dec 28, 2023
5be873d
no forced migration
candiduslynx Dec 28, 2023
a90cbd7
Merge branch 'main' into fix/aws_cloudtrail_trail_event_selectors/v23…
kodiakhq[bot] Dec 28, 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/

.DS_Store
transformations/aws_compliance/.user.yml
Expand Down
2 changes: 1 addition & 1 deletion transformations/aws/asset-inventory-free/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"message": "@./changelog.md",
"doc": "./README.md",
"path": "./build/aws_asset_inventory_free.zip",
"plugin_deps": ["cloudquery/source/aws@v22.19.0"],
"plugin_deps": ["cloudquery/source/aws@v23.3.1"],
"addon_deps": []
}
5 changes: 3 additions & 2 deletions transformations/aws/asset-inventory-free/tests/postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ kind: source
spec:
name: aws
path: cloudquery/aws
version: "v22.19.2" # latest version of source aws plugin
registry: cloudquery
version: "v23.3.1" # latest version of source aws plugin
destinations: ["postgresql"]
tables: ["*"]
---
Expand All @@ -14,4 +15,4 @@ spec:
version: "v7.1.3" # latest version of postgresql plugin
spec:
batch_size: 10000
connection_string: ${CQ_DSN}
connection_string: ${CQ_DSN}
2 changes: 1 addition & 1 deletion transformations/aws/compliance-free/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"message": "@./changelog.md",
"doc": "./README.md",
"path": "./build/aws_compliance_free.zip",
"plugin_deps": ["cloudquery/source/aws@v22.18.0"],
"plugin_deps": ["cloudquery/source/aws@v23.3.1"],
"addon_deps": []
}
5 changes: 3 additions & 2 deletions transformations/aws/compliance-free/tests/bigquery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ kind: source
spec:
name: aws
path: cloudquery/aws
version: "v22.19.2" # latest version of source aws plugin
registry: cloudquery
version: "v23.3.1" # latest version of source aws plugin
destinations: ["bigquery"]
tables: ["*"]
---
Expand All @@ -15,4 +16,4 @@ spec:
write_mode: "append"
spec:
project_id: cq-integration-tests
dataset_id: policies_premium_ci_test
dataset_id: policies_premium_ci_test
5 changes: 3 additions & 2 deletions transformations/aws/compliance-free/tests/postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ kind: source
spec:
name: aws
path: cloudquery/aws
version: "v22.19.2" # latest version of source aws plugin
registry: cloudquery
version: "v23.3.1" # latest version of source aws plugin
destinations: ["postgresql"]
tables: ["*"]
---
Expand All @@ -14,4 +15,4 @@ spec:
version: "v7.1.3" # latest version of postgresql plugin
spec:
batch_size: 10000
connection_string: ${CQ_DSN}
connection_string: ${CQ_DSN}
3 changes: 2 additions & 1 deletion transformations/aws/compliance-free/tests/snowflake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ kind: source
spec:
name: aws
path: cloudquery/aws
version: "v22.19.2" # latest version of source aws plugin
registry: cloudquery
version: "v23.3.1" # latest version of source aws plugin
destinations: ["snowflake"]
tables: ["*"]
---
Expand Down
2 changes: 1 addition & 1 deletion transformations/aws/compliance-premium/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"message": "@./changelog.md",
"doc": "./README.md",
"path": "./build/aws_compliance_premium.zip",
"plugin_deps": ["cloudquery/source/aws@v22.18.0"],
"plugin_deps": ["cloudquery/source/aws@v23.3.1"],
"addon_deps": []
}
5 changes: 3 additions & 2 deletions transformations/aws/compliance-premium/tests/bigquery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ kind: source
spec:
name: aws
path: cloudquery/aws
version: "v22.19.2" # latest version of source aws plugin
registry: cloudquery
version: "v23.3.1" # latest version of source aws plugin
destinations: ["bigquery"]
tables: ["*"]
---
Expand All @@ -15,4 +16,4 @@ spec:
write_mode: "append"
spec:
project_id: cq-integration-tests
dataset_id: policies_premium_ci_test
dataset_id: policies_premium_ci_test
5 changes: 3 additions & 2 deletions transformations/aws/compliance-premium/tests/postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ kind: source
spec:
name: aws
path: cloudquery/aws
version: "v22.19.2" # latest version of source aws plugin
registry: cloudquery
version: "v23.3.1" # latest version of source aws plugin
destinations: ["postgresql"]
tables: ["*"]
---
Expand All @@ -14,4 +15,4 @@ spec:
version: "v7.1.3" # latest version of postgresql plugin
spec:
batch_size: 10000
connection_string: ${CQ_DSN}
connection_string: ${CQ_DSN}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ kind: source
spec:
name: aws
path: cloudquery/aws
version: "v22.19.2" # latest version of source aws plugin
registry: cloudquery
version: "v23.3.1" # latest version of source aws plugin
candiduslynx marked this conversation as resolved.
Show resolved Hide resolved
destinations: ["snowflake"]
tables: ["*"]
---
Expand Down
5 changes: 3 additions & 2 deletions transformations/aws/cost/tests/postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ kind: source
spec:
name: aws
path: cloudquery/aws
version: "v22.19.2" # latest version of source aws plugin
registry: cloudquery
version: "v23.3.1" # latest version of source aws plugin
destinations: ["postgresql"]
tables: ["*"]
---
Expand All @@ -14,4 +15,4 @@ spec:
version: "v7.1.3" # latest version of postgresql plugin
spec:
batch_size: 10000
connection_string: ${CQ_DSN}
connection_string: ${CQ_DSN}
2 changes: 1 addition & 1 deletion transformations/aws/data-resilience/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"message": "@./changelog.md",
"doc": "./README.md",
"path": "./build/aws_data_resilience.zip",
"plugin_deps": ["cloudquery/source/aws@v22.19.0"],
"plugin_deps": ["cloudquery/source/aws@v23.3.1"],
"addon_deps": []
}
5 changes: 3 additions & 2 deletions transformations/aws/data-resilience/tests/postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ kind: source
spec:
name: aws
path: cloudquery/aws
version: "v22.19.2" # latest version of source aws plugin
registry: cloudquery
version: "v23.3.1" # latest version of source aws plugin
destinations: ["postgresql"]
tables: ["*"]
---
Expand All @@ -14,4 +15,4 @@ spec:
version: "v7.1.3" # latest version of postgresql plugin
spec:
batch_size: 10000
connection_string: ${CQ_DSN}
connection_string: ${CQ_DSN}
2 changes: 1 addition & 1 deletion transformations/aws/encryption/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"message": "@./changelog.md",
"doc": "./README.md",
"path": "./build/aws_encryption.zip",
"plugin_deps": ["cloudquery/source/aws@v22.19.0"],
"plugin_deps": ["cloudquery/source/aws@v23.3.1"],
"addon_deps": []
}
5 changes: 3 additions & 2 deletions transformations/aws/encryption/tests/postgres.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ kind: source
spec:
name: aws
path: cloudquery/aws
version: "v22.19.2" # latest version of source aws plugin
registry: cloudquery
version: "v23.3.1" # latest version of source aws plugin
destinations: ["postgresql"]
tables: ["*"]
---
Expand All @@ -14,4 +15,4 @@ spec:
version: "v7.1.3" # latest version of postgresql plugin
spec:
batch_size: 10000
connection_string: ${CQ_DSN}
connection_string: ${CQ_DSN}
17 changes: 13 additions & 4 deletions transformations/aws/macros/cloudtrail/bucket_access_logging.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@ select
t.account_id,
t.arn as resource_id,
case
when b.logging_target_bucket is null or b.logging_target_prefix is null then 'fail'
when l.logging_enabled is null then 'fail'
when l.logging_enabled -> 'TargetBucket' is null then 'fail'
when l.logging_enabled -> 'TargetPrefix' is null then 'fail'
else 'pass'
end as status
from aws_cloudtrail_trails t
inner join aws_s3_buckets b on t.s3_bucket_name = b.name
inner join aws_s3_bucket_loggings l on b.arn = l.bucket_arn
{% endmacro %}

{% macro bigquery__bucket_access_logging(framework, check_id) %}
Expand All @@ -27,11 +30,14 @@ select
t.account_id,
t.arn as resource_id,
case
when b.logging_target_bucket is null or b.logging_target_prefix is null then 'fail'
when l.logging_enabled is null then 'fail'
when l.logging_enabled.TargetBucket is null then 'fail'
when l.logging_enabled.TargetPrefix is null then 'fail'
else 'pass'
end as status
from {{ full_table_name("aws_cloudtrail_trails") }} t
inner join {{ full_table_name("aws_s3_buckets") }} b on t.s3_bucket_name = b.name
inner join {{ full_table_name("aws_s3_bucket_loggings") }} l on b.arn = l.bucket_arn
{% endmacro %}

{% macro snowflake__bucket_access_logging(framework, check_id) %}
Expand All @@ -42,9 +48,12 @@ select
t.account_id,
t.arn as resource_id,
case
when b.logging_target_bucket is null or b.logging_target_prefix is null then 'fail'
when l.logging_enabled is null then 'fail'
when l.logging_enabled:TargetBucket is null then 'fail'
when l.logging_enabled:TargetPrefix is null then 'fail'
else 'pass'
end as status
from aws_cloudtrail_trails t
inner join aws_s3_buckets b on t.s3_bucket_name = b.name
{% endmacro %}
inner join aws_s3_bucket_loggings l on b.arn = l.bucket_arn
{% endmacro %}
55 changes: 43 additions & 12 deletions transformations/aws/macros/cloudtrail/enabled_in_all_regions.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,17 @@ select
aws_cloudtrail_trails.account_id,
arn as resource_id,
case
when is_multi_region_trail = FALSE or (
is_multi_region_trail = TRUE and (
read_write_type != 'All' or include_management_events = FALSE
)) then 'fail'
when aws_cloudtrail_trails.is_multi_region_trail = FALSE then 'fail'
when exists(select *
from jsonb_array_elements(aws_cloudtrail_trail_event_selectors.event_selectors) as es
where es ->>'ReadWriteType' != 'All' or (es->>'IncludeManagementEvents')::boolean = FALSE)
then 'fail'
when exists(select *
from jsonb_array_elements(aws_cloudtrail_trail_event_selectors.advanced_event_selectors) as aes
where exists(select *
from jsonb_array_elements(aes ->'FieldSelectors') as aes_fs
where aes_fs ->>'Field' = 'readOnly'))
then 'fail'
else 'pass'
end as status
from aws_cloudtrail_trails
Expand All @@ -32,10 +39,18 @@ select
aws_cloudtrail_trails.account_id,
arn as resource_id,
case
when is_multi_region_trail = FALSE or (
is_multi_region_trail = TRUE and (
read_write_type != 'All' or include_management_events = FALSE
)) then 'fail'
when aws_cloudtrail_trails.is_multi_region_trail = FALSE then 'fail'
when exists(select *
from UNNEST(JSON_QUERY_ARRAY(aws_cloudtrail_trail_event_selectors.event_selectors)) AS es
where JSON_VALUE(es.ReadWriteType) != 'All' or (CAST( JSON_VALUE(es.IncludeManagementEvents) AS BOOL)= FALSE )
)
then 'fail'
when exists(select *
from UNNEST(JSON_QUERY_ARRAY(aws_cloudtrail_trail_event_selectors.advanced_event_selectors)) AS aes
where exists(select *
from UNNEST(JSON_QUERY_ARRAY(aes.FieldSelectors)) as aes_fs
where JSON_VALUE(aes_fs.Field) = 'readOnly'))
then 'fail'
else 'pass'
end as status
from {{ full_table_name("aws_cloudtrail_trails") }}
Expand All @@ -47,17 +62,33 @@ inner join
{% endmacro %}

{% macro snowflake__cloudtrail_enabled_all_regions(framework, check_id) %}
with aes as
(
select *
from aws_cloudtrail_trail_event_selectors,
LATERAL FLATTEN (advanced_event_selectors) as aes
)
select
'{{framework}}' as framework,
'{{check_id}}' as check_id,
'Ensure CloudTrail is enabled in all regions' as title,
aws_cloudtrail_trails.account_id,
arn as resource_id,
case
when is_multi_region_trail = FALSE or (
is_multi_region_trail = TRUE and (
read_write_type != 'All' or include_management_events = FALSE
)) then 'fail'
when aws_cloudtrail_trails.is_multi_region_trail = FALSE then 'fail'
when exists(select *
from aws_cloudtrail_trail_event_selectors,
LATERAL FLATTEN(event_selectors) as es
where es.value:ReadWriteType != 'All' or (es.value:IncludeManagementEvents)::boolean = FALSE
)
then 'fail'
when exists(
select *
from aes,
LATERAL FLATTEN (value:FieldSelectors) as aes_fs
where aes_fs.value:Field = 'readOnly'
)
then 'fail'
else 'pass'
end as status
from aws_cloudtrail_trails
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% macro elastic_beanstalk_stream_logs_to_cloudwatch(framework, check_id) %}
with flat_configs as (
select
c.environment_id,
c.environment_arn,
f.value:Namespace:Value::string as is_log_streaming

from
Expand All @@ -26,5 +26,5 @@ SELECT
END as status
FROM aws_elasticbeanstalk_environments e
JOIN flat_configs as fc
ON e.environment_id = fc.environment_id
ON e.arn = fc.environment_arn
{% endmacro %}
14 changes: 7 additions & 7 deletions transformations/aws/macros/guardduty/detector_enabled.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% macro snowflake__detector_enabled(framework, check_id) %}
with enabled_detector_regions as (
select account_id, region
select request_account_id as account_id, request_region as region
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we using the request_* values here? For services that can aggregate across region and account this can flag wouldn't this flag detectors in other accounts and regions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Previously we used account_id & region columns that were propagated with the same data.
We could, however, parse account_id & region values from the arn column, but IDK if that's in the scope of this upgrade or not.

Copy link
Contributor

Choose a reason for hiding this comment

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

I might be mistaken, but I believe we used account_id and region I believe at the time of our plugin release Guard Duty didn't support cross region/ cross account aggregation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the PK in cloudquery/cloudquery#15468.
I might've misinterpreted cloudquery/cloudquery#15468 (comment) as a suggestion to include request_ columns to the PK, as we already had ARN there...

Copy link
Contributor

Choose a reason for hiding this comment

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

The ARN should contain the region/account of the resource that actually owns the resource, while the request_* should contain information about where the request was made... If we didn't add the request_* fields to the PK it would be non-deterministic about which requests actually made it to the DB

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Judging by the docs we could parse ARN instead. Do we want this?
cc: @jsonpr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Additionally, it doesn't seem that the request_ prefix is required here: https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_concepts.html
It seems to me that each acc/region will have its own detector ID

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So maybe there should be a fix moving back to acocunt_id & region + actually including them into ARN: https://github.com/cloudquery/cloudquery/blob/main/plugins/source/aws/resources/services/guardduty/detectors.go#L97-L101

from aws_guardduty_detectors
where status = 'ENABLED'
)
Expand All @@ -26,8 +26,8 @@ select
'{{framework}}' As framework,
'{{check_id}}' As check_id,
'GuardDuty should be enabled (detectors)' AS title,
account_id,
region AS resource_id,
request_account_id as account_id,
request_region AS resource_id,
case when
data_sources:S3Logs:Status != 'ENABLED' AND
data_sources:DNSLogs:Status != 'ENABLED' AND
Expand All @@ -41,7 +41,7 @@ where

{% macro postgres__detector_enabled(framework, check_id) %}
with enabled_detector_regions as (
select account_id, region
select request_account_id as account_id, request_region as region
from aws_guardduty_detectors
where status = 'ENABLED'
)
Expand All @@ -63,8 +63,8 @@ select
'{{framework}}' as framework,
'{{check_id}}' as check_id,
'GuardDuty should be enabled (detectors)' AS title,
account_id,
region AS resource_id,
request_account_id as account_id,
request_region AS resource_id,
case when
data_sources->'S3Logs'->>'Status' != 'ENABLED' AND
data_sources->'DNSLogs'->>'Status' != 'ENABLED' AND
Expand All @@ -77,4 +77,4 @@ where
{% endmacro %}

{% macro default__detector_enabled(framework, check_id) %}{% endmacro %}


Loading