-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(checks): migrate AWS ecr, efs and eks to Rego
Signed-off-by: Nikita Pivkin <[email protected]>
- Loading branch information
Showing
45 changed files
with
663 additions
and
774 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
# METADATA | ||
# title: ECR repository has image scans disabled. | ||
# description: | | ||
# Repository image scans should be enabled to ensure vulnerable software can be discovered and remediated as soon as possible. | ||
# scope: package | ||
# schemas: | ||
# - input: schema["cloud"] | ||
# related_resources: | ||
# - https://docs.aws.amazon.com/AmazonECR/latest/userguide/image-scanning.html | ||
# custom: | ||
# id: AVD-AWS-0030 | ||
# avd_id: AVD-AWS-0030 | ||
# provider: aws | ||
# service: ecr | ||
# severity: HIGH | ||
# short_code: enable-image-scans | ||
# recommended_action: Enable ECR image scanning | ||
# input: | ||
# selector: | ||
# - type: cloud | ||
# subtypes: | ||
# - service: ecr | ||
# provider: aws | ||
# terraform: | ||
# links: | ||
# - https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecr_repository#image_scanning_configuration | ||
# good_examples: checks/cloud/aws/ecr/enable_image_scans.tf.go | ||
# bad_examples: checks/cloud/aws/ecr/enable_image_scans.tf.go | ||
# cloudformation: | ||
# good_examples: checks/cloud/aws/ecr/enable_image_scans.cf.go | ||
# bad_examples: checks/cloud/aws/ecr/enable_image_scans.cf.go | ||
package builtin.aws.ecr.aws0030 | ||
|
||
import rego.v1 | ||
|
||
deny contains res if { | ||
some repo in input.aws.ecr.repositories | ||
repo.imagescanning.scanonpush.value == false | ||
|
||
res := result.new("Image scanning is not enabled", repo.imagescanning.scanonpush) | ||
} |
This file was deleted.
Oops, something went wrong.
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,18 @@ | ||
package builtin.aws.ecr.aws0030_test | ||
|
||
import rego.v1 | ||
|
||
import data.builtin.aws.ecr.aws0030 as check | ||
import data.lib.test | ||
|
||
test_allow_image_scanning_enabled if { | ||
inp := {"aws": {"ecr": {"repositories": [{"imagescanning": {"scanonpush": {"value": true}}}]}}} | ||
|
||
test.assert_empty(check.deny) with input as inp | ||
} | ||
|
||
test_deny_image_scanning_disabled if { | ||
inp := {"aws": {"ecr": {"repositories": [{"imagescanning": {"scanonpush": {"value": false}}}]}}} | ||
|
||
test.assert_equal_message("Image scanning is not enabled", check.deny) with input as inp | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# METADATA | ||
# title: ECR images tags shouldn't be mutable. | ||
# description: | | ||
# ECR images should be set to IMMUTABLE to prevent code injection through image mutation. | ||
# This can be done by setting <code>image_tab_mutability</code> to <code>IMMUTABLE</code> | ||
# scope: package | ||
# schemas: | ||
# - input: schema["cloud"] | ||
# related_resources: | ||
# - https://sysdig.com/blog/toctou-tag-mutability/ | ||
# custom: | ||
# id: AVD-AWS-0031 | ||
# avd_id: AVD-AWS-0031 | ||
# provider: aws | ||
# service: ecr | ||
# severity: HIGH | ||
# short_code: enforce-immutable-repository | ||
# recommended_action: Only use immutable images in ECR | ||
# input: | ||
# selector: | ||
# - type: cloud | ||
# subtypes: | ||
# - service: ecr | ||
# provider: aws | ||
# terraform: | ||
# links: | ||
# - https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/ecr_repository | ||
# good_examples: checks/cloud/aws/ecr/enforce_immutable_repository.tf.go | ||
# bad_examples: checks/cloud/aws/ecr/enforce_immutable_repository.tf.go | ||
# cloudformation: | ||
# good_examples: checks/cloud/aws/ecr/enforce_immutable_repository.cf.go | ||
# bad_examples: checks/cloud/aws/ecr/enforce_immutable_repository.cf.go | ||
package builtin.aws.ecr.aws0031 | ||
|
||
import rego.v1 | ||
|
||
deny contains res if { | ||
some repo in input.aws.ecr.repositories | ||
repo.imagetagsimmutable.value == false | ||
|
||
res := result.new("Repository tags are mutable.", repo.imagetagsimmutable) | ||
} |
This file was deleted.
Oops, something went wrong.
18 changes: 18 additions & 0 deletions
18
checks/cloud/aws/ecr/enforce_immutable_repository_test.rego
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,18 @@ | ||
package builtin.aws.ecr.aws0031_test | ||
|
||
import rego.v1 | ||
|
||
import data.builtin.aws.ecr.aws0031 as check | ||
import data.lib.test | ||
|
||
test_allow_immutable_repository if { | ||
inp := {"aws": {"ecr": {"repositories": [{"imagetagsimmutable": {"value": true}}]}}} | ||
|
||
test.assert_empty(check.deny) with input as inp | ||
} | ||
|
||
test_deny_immutable_repository if { | ||
inp := {"aws": {"ecr": {"repositories": [{"imagetagsimmutable": {"value": false}}]}}} | ||
|
||
test.assert_equal_message("Repository tags are mutable.", check.deny) with input as inp | ||
} |
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
Oops, something went wrong.