-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dchakrav-github-parameterized-rules' into parameterized…
…-rules
- Loading branch information
Showing
44 changed files
with
16,014 additions
and
639 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
88 changes: 88 additions & 0 deletions
88
guard-examples/cross-account/sns-cross-account-t-parameterized-tests.yaml
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,88 @@ | ||
--- | ||
- name: Allowed from CORRECT, expected PASS | ||
input: | ||
Resources: | ||
snsPolicy: | ||
Type: AWS::SNS::TopicPolicy | ||
Properties: | ||
PolicyDocument: | ||
Statement: [ | ||
{ | ||
"Sid": "grant-1234-publish", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"AWS": "111122223333" | ||
}, | ||
"Action": ["sns:Publish"], | ||
"Resource": "arn:aws:sns:us-east-2:444455556666:MyTopic" | ||
}] | ||
expectations: | ||
rules: | ||
check_sns_topic_cross_account: PASS | ||
|
||
- name: 666677778888 account not in list, FAIL | ||
input: | ||
Resources: | ||
snsPolicy: | ||
Type: AWS::SNS::TopicPolicy | ||
Properties: | ||
PolicyDocument: | ||
Statement: [ | ||
{ | ||
"Sid": "grant-1234-publish", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"AWS": ["111122223333", "666677778888"] | ||
}, | ||
"Action": ["sns:Publish"], | ||
"Resource": "arn:aws:sns:us-east-2:444455556666:MyTopic" | ||
}] | ||
expectations: | ||
rules: | ||
check_sns_topic_cross_account: FAIL | ||
|
||
- name: Accesse via an AWS service, PASS expected as 444455556666 was allowed | ||
input: | ||
Resources: | ||
snsPolicy: | ||
Type: AWS::SNS::TopicPolicy | ||
Properties: | ||
PolicyDocument: | ||
Statement: [ | ||
{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "s3.amazonaws.com" | ||
}, | ||
"Action": "sns:Publish", | ||
"Resource": "arn:aws:sns:us-east-2:111122223333:MyTopic", | ||
"Condition": { | ||
"StringEquals": { | ||
"AWS:SourceAccount": "444455556666" | ||
} | ||
} | ||
}] | ||
expectations: | ||
rules: | ||
check_sns_topic_cross_account: PASS | ||
|
||
- name: Accesse via an AWS service, FAIL expected as no Condition was specified to narrow | ||
input: | ||
Resources: | ||
snsPolicy: | ||
Type: AWS::SNS::TopicPolicy | ||
Properties: | ||
PolicyDocument: | ||
Statement: [ | ||
{ | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": "s3.amazonaws.com" | ||
}, | ||
"Action": "sns:Publish", | ||
"Resource": "arn:aws:sns:us-east-2:111122223333:MyTopic", | ||
}] | ||
expectations: | ||
rules: | ||
check_sns_topic_cross_account: FAIL | ||
|
39 changes: 39 additions & 0 deletions
39
guard-examples/cross-account/sns-cross-account-t-parameterized.guard
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,39 @@ | ||
let allowed = [ | ||
/111122223333/, | ||
/444455556666/ | ||
] | ||
|
||
rule check_direct_principals(principals) { | ||
%principals in %allowed | ||
} | ||
|
||
rule check_aws_specified(principals) { | ||
%principals.AWS in %allowed | ||
} | ||
|
||
rule check_via_aws_service(statement) { | ||
when %statement.Principal.Service exists { | ||
%statement.Condition[ keys == /String(Equals|Like)|Arn(Equals|Like)/ ] not empty { | ||
let source_accounts = this[ keys == /(aws|AWS):[sS]ource(Account|Owner|Arn|ARN)/ ] | ||
%source_accounts in %allowed | ||
} | ||
} | ||
} | ||
|
||
rule check_only_allowed_aws_accounts(statement) { | ||
%statement | ||
{ | ||
when Effect == 'Allow' | ||
{ | ||
check_direct_principals(Principal) or | ||
check_aws_specified(Principal) or | ||
check_via_aws_service(this) | ||
} | ||
} | ||
} | ||
|
||
rule check_sns_topic_cross_account { | ||
Resources[ Type == 'AWS::SNS::TopicPolicy' ] { | ||
check_only_allowed_aws_accounts(Properties.PolicyDocument.Statement[*]) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[package] | ||
name = "cfn-guard" | ||
version = "2.0.3" | ||
version = "2.1.0" | ||
edition = "2018" | ||
authors = ["Diwakar Chakravarthy", "John Tompkins", "Omkar Hegde", "Priya Padmanaban", "aws-cloudformation-developers <[email protected]>"] | ||
description = "AWS CloudFormation Guard is an open-source general-purpose policy-as-code evaluation tool. It provides developers with a simple-to-use, yet powerful and expressive domain-specific language (DSL) to define policies and enables developers to validate JSON- or YAML- formatted structured data with those policies." | ||
|
@@ -33,9 +33,15 @@ itertools = "0.4.7" | |
string-builder = "0.2.0" | ||
enumflags2 = "0.7.1" | ||
enumflags2_derive = "0.7.0" | ||
Inflector = "0.11.4" | ||
urlencoding = "2.1.0" | ||
grep-searcher = "0.1.8" | ||
grep-matcher = "0.1.5" | ||
grep-regex = "0.1.9" | ||
yaml-rust = {git = "https://github.com/dchakrav-github/yaml-rust"} | ||
|
||
[dependencies.serde_json] | ||
version = "1.0.60" | ||
features = ["preserve_order"] | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
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.