Forked from myoung34/multiple ecr mixed missing true false
Last active
June 17, 2020 16:33
-
-
Save tsandall/f88d961af56cf02a9059c0dd648df508 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$ for file in *.json; do echo "$file"; opa eval -i "$file" -d main.rego 'data.main.deny'; done | |
multiple ecr mixed missing true false.json | |
{ | |
"result": [ | |
{ | |
"expressions": [ | |
{ | |
"value": [ | |
"(policy/ecr.rego) Image Scanning 'Scan on push' is required to be true for all ecr repositories." | |
], | |
"text": "data.main.deny", | |
"location": { | |
"row": 1, | |
"col": 1 | |
} | |
} | |
] | |
} | |
] | |
} | |
single ecr scan false.json | |
{ | |
"result": [ | |
{ | |
"expressions": [ | |
{ | |
"value": [ | |
"(policy/ecr.rego) Image Scanning 'Scan on push' is required to be true for all ecr repositories." | |
], | |
"text": "data.main.deny", | |
"location": { | |
"row": 1, | |
"col": 1 | |
} | |
} | |
] | |
} | |
] | |
} | |
single ecr scan true.json | |
{ | |
"result": [ | |
{ | |
"expressions": [ | |
{ | |
"value": [], | |
"text": "data.main.deny", | |
"location": { | |
"row": 1, | |
"col": 1 | |
} | |
} | |
] | |
} | |
] | |
} |
This file contains hidden or 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
package main | |
import input as tfplan | |
ecr_resource_types = {"aws_ecr_repository"} | |
any_invalid_scan_config { | |
after := all[_].change.after | |
not valid_scan_config(after) | |
} | |
valid_scan_config(after) { | |
after.image_scanning_configuration[_].scan_on_push == true | |
} | |
all := [change | change := tfplan.resource_changes[_]; ecr_resource_types[change.type]] | |
deny[msg] { | |
any_invalid_scan_config | |
msg := "(policy/ecr.rego) Image Scanning 'Scan on push' is required to be true for all ecr repositories." | |
} |
This file contains hidden or 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
{ | |
"format_version": "0.1", | |
"terraform_version": "0.12.9", | |
"variables": { | |
"region": { | |
"value": "us-east-1" | |
} | |
}, | |
"planned_values": { | |
"root_module": { | |
"resources": [ | |
{ | |
"address": "aws_ecr_repository.foo", | |
"mode": "managed", | |
"type": "aws_ecr_repository", | |
"name": "foo", | |
"provider_name": "aws", | |
"schema_version": 0, | |
"values": { | |
"image_scanning_configuration": [ | |
{ | |
"scan_on_push": false | |
} | |
], | |
"image_tag_mutability": "MUTABLE", | |
"name": "foo", | |
"tags": null, | |
"timeouts": null | |
} | |
}, | |
{ | |
"address": "aws_ecr_repository.foo2", | |
"mode": "managed", | |
"type": "aws_ecr_repository", | |
"name": "foo2", | |
"provider_name": "aws", | |
"schema_version": 0, | |
"values": { | |
"image_scanning_configuration": [ | |
{ | |
"scan_on_push": true | |
} | |
], | |
"image_tag_mutability": "MUTABLE", | |
"name": "foo", | |
"tags": null, | |
"timeouts": null | |
} | |
}, | |
{ | |
"address": "aws_ecr_repository.foo3", | |
"mode": "managed", | |
"type": "aws_ecr_repository", | |
"name": "foo3", | |
"provider_name": "aws", | |
"schema_version": 0, | |
"values": { | |
"image_scanning_configuration": [], | |
"image_tag_mutability": "MUTABLE", | |
"name": "foo", | |
"tags": null, | |
"timeouts": null | |
} | |
} | |
] | |
} | |
}, | |
"resource_changes": [ | |
{ | |
"address": "aws_ecr_repository.foo", | |
"mode": "managed", | |
"type": "aws_ecr_repository", | |
"name": "foo", | |
"provider_name": "aws", | |
"change": { | |
"actions": [ | |
"create" | |
], | |
"before": null, | |
"after": { | |
"image_scanning_configuration": [ | |
{ | |
"scan_on_push": false | |
} | |
], | |
"image_tag_mutability": "MUTABLE", | |
"name": "foo", | |
"tags": null, | |
"timeouts": null | |
}, | |
"after_unknown": { | |
"arn": true, | |
"id": true, | |
"image_scanning_configuration": [ | |
{} | |
], | |
"registry_id": true, | |
"repository_url": true | |
} | |
} | |
}, | |
{ | |
"address": "aws_ecr_repository.foo2", | |
"mode": "managed", | |
"type": "aws_ecr_repository", | |
"name": "foo2", | |
"provider_name": "aws", | |
"change": { | |
"actions": [ | |
"create" | |
], | |
"before": null, | |
"after": { | |
"image_scanning_configuration": [ | |
{ | |
"scan_on_push": true | |
} | |
], | |
"image_tag_mutability": "MUTABLE", | |
"name": "foo", | |
"tags": null, | |
"timeouts": null | |
}, | |
"after_unknown": { | |
"arn": true, | |
"id": true, | |
"image_scanning_configuration": [ | |
{} | |
], | |
"registry_id": true, | |
"repository_url": true | |
} | |
} | |
}, | |
{ | |
"address": "aws_ecr_repository.foo3", | |
"mode": "managed", | |
"type": "aws_ecr_repository", | |
"name": "foo3", | |
"provider_name": "aws", | |
"change": { | |
"actions": [ | |
"create" | |
], | |
"before": null, | |
"after": { | |
"image_scanning_configuration": [], | |
"image_tag_mutability": "MUTABLE", | |
"name": "foo", | |
"tags": null, | |
"timeouts": null | |
}, | |
"after_unknown": { | |
"arn": true, | |
"id": true, | |
"image_scanning_configuration": [], | |
"registry_id": true, | |
"repository_url": true | |
} | |
} | |
} | |
], | |
"configuration": { | |
"provider_config": { | |
"aws": { | |
"name": "aws", | |
"expressions": { | |
"region": { | |
"references": [ | |
"var.region" | |
] | |
} | |
} | |
} | |
}, | |
"root_module": { | |
"resources": [ | |
{ | |
"address": "aws_ecr_repository.foo", | |
"mode": "managed", | |
"type": "aws_ecr_repository", | |
"name": "foo", | |
"provider_config_key": "aws", | |
"expressions": { | |
"image_scanning_configuration": [ | |
{ | |
"scan_on_push": { | |
"constant_value": false | |
} | |
} | |
], | |
"name": { | |
"constant_value": "foo" | |
} | |
}, | |
"schema_version": 0 | |
}, | |
{ | |
"address": "aws_ecr_repository.foo2", | |
"mode": "managed", | |
"type": "aws_ecr_repository", | |
"name": "foo2", | |
"provider_config_key": "aws", | |
"expressions": { | |
"image_scanning_configuration": [ | |
{ | |
"scan_on_push": { | |
"constant_value": true | |
} | |
} | |
], | |
"name": { | |
"constant_value": "foo" | |
} | |
}, | |
"schema_version": 0 | |
}, | |
{ | |
"address": "aws_ecr_repository.foo3", | |
"mode": "managed", | |
"type": "aws_ecr_repository", | |
"name": "foo3", | |
"provider_config_key": "aws", | |
"expressions": { | |
"name": { | |
"constant_value": "foo" | |
} | |
}, | |
"schema_version": 0 | |
} | |
], | |
"variables": { | |
"region": { | |
"default": "us-east-1" | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or 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
{ | |
"format_version": "0.1", | |
"terraform_version": "0.12.9", | |
"variables": { | |
"region": { | |
"value": "us-east-1" | |
} | |
}, | |
"planned_values": { | |
"root_module": { | |
"resources": [ | |
{ | |
"address": "aws_ecr_repository.foo", | |
"mode": "managed", | |
"type": "aws_ecr_repository", | |
"name": "foo", | |
"provider_name": "aws", | |
"schema_version": 0, | |
"values": { | |
"image_scanning_configuration": [ | |
{ | |
"scan_on_push": false | |
} | |
], | |
"image_tag_mutability": "MUTABLE", | |
"name": "foo", | |
"tags": null, | |
"timeouts": null | |
} | |
} | |
] | |
} | |
}, | |
"resource_changes": [ | |
{ | |
"address": "aws_ecr_repository.foo", | |
"mode": "managed", | |
"type": "aws_ecr_repository", | |
"name": "foo", | |
"provider_name": "aws", | |
"change": { | |
"actions": [ | |
"create" | |
], | |
"before": null, | |
"after": { | |
"image_scanning_configuration": [ | |
{ | |
"scan_on_push": false | |
} | |
], | |
"image_tag_mutability": "MUTABLE", | |
"name": "foo", | |
"tags": null, | |
"timeouts": null | |
}, | |
"after_unknown": { | |
"arn": true, | |
"id": true, | |
"image_scanning_configuration": [ | |
{} | |
], | |
"registry_id": true, | |
"repository_url": true | |
} | |
} | |
} | |
], | |
"configuration": { | |
"provider_config": { | |
"aws": { | |
"name": "aws", | |
"expressions": { | |
"region": { | |
"references": [ | |
"var.region" | |
] | |
} | |
} | |
} | |
}, | |
"root_module": { | |
"resources": [ | |
{ | |
"address": "aws_ecr_repository.foo", | |
"mode": "managed", | |
"type": "aws_ecr_repository", | |
"name": "foo", | |
"provider_config_key": "aws", | |
"expressions": { | |
"image_scanning_configuration": [ | |
{ | |
"scan_on_push": { | |
"constant_value": false | |
} | |
} | |
], | |
"name": { | |
"constant_value": "foo" | |
} | |
}, | |
"schema_version": 0 | |
} | |
], | |
"variables": { | |
"region": { | |
"default": "us-east-1" | |
} | |
} | |
} | |
} | |
} |
This file contains hidden or 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
{ | |
"format_version": "0.1", | |
"terraform_version": "0.12.9", | |
"variables": { | |
"region": { | |
"value": "us-east-1" | |
} | |
}, | |
"planned_values": { | |
"root_module": { | |
"resources": [ | |
{ | |
"address": "aws_ecr_repository.foo2", | |
"mode": "managed", | |
"type": "aws_ecr_repository", | |
"name": "foo2", | |
"provider_name": "aws", | |
"schema_version": 0, | |
"values": { | |
"image_scanning_configuration": [ | |
{ | |
"scan_on_push": true | |
} | |
], | |
"image_tag_mutability": "MUTABLE", | |
"name": "foo", | |
"tags": null, | |
"timeouts": null | |
} | |
} | |
] | |
} | |
}, | |
"resource_changes": [ | |
{ | |
"address": "aws_ecr_repository.foo2", | |
"mode": "managed", | |
"type": "aws_ecr_repository", | |
"name": "foo2", | |
"provider_name": "aws", | |
"change": { | |
"actions": [ | |
"create" | |
], | |
"before": null, | |
"after": { | |
"image_scanning_configuration": [ | |
{ | |
"scan_on_push": true | |
} | |
], | |
"image_tag_mutability": "MUTABLE", | |
"name": "foo", | |
"tags": null, | |
"timeouts": null | |
}, | |
"after_unknown": { | |
"arn": true, | |
"id": true, | |
"image_scanning_configuration": [ | |
{} | |
], | |
"registry_id": true, | |
"repository_url": true | |
} | |
} | |
} | |
], | |
"configuration": { | |
"provider_config": { | |
"aws": { | |
"name": "aws", | |
"expressions": { | |
"region": { | |
"references": [ | |
"var.region" | |
] | |
} | |
} | |
} | |
}, | |
"root_module": { | |
"resources": [ | |
{ | |
"address": "aws_ecr_repository.foo2", | |
"mode": "managed", | |
"type": "aws_ecr_repository", | |
"name": "foo2", | |
"provider_config_key": "aws", | |
"expressions": { | |
"image_scanning_configuration": [ | |
{ | |
"scan_on_push": { | |
"constant_value": true | |
} | |
} | |
], | |
"name": { | |
"constant_value": "foo" | |
} | |
}, | |
"schema_version": 0 | |
} | |
], | |
"variables": { | |
"region": { | |
"default": "us-east-1" | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment