-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate AWS cfn-authentication lambda opensource_service secrets_mana…
…ger resources to cfn-guard ruleset (#270)
- Loading branch information
Showing
18 changed files
with
842 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# | ||
##################################### | ||
## AWS Solutions ## | ||
##################################### | ||
# Rule Identifier: | ||
# CFN_AUTHENTICATION_RULE | ||
# | ||
# Description: | ||
# Specifying credentials in the template itself is probably not the safest thing. | ||
# | ||
# Reports on: | ||
# All Resources | ||
# | ||
# Evaluates: | ||
# AWS CloudFormation | ||
# | ||
# Rule Parameters: | ||
# NA | ||
# | ||
# CFN_NAG Rule Id: | ||
# W1 | ||
# | ||
# Scenarios: | ||
# a) SKIP: when there are no resource present | ||
# b) PASS: When no resources specifies credentials in template. | ||
# c) FAIL: When any resource specifies credentials in template. | ||
# d) SKIP: when metadata has rule suppression for CFN_AUTHENTICATION_RULE | ||
|
||
# | ||
# Select all Security Group resources from incoming template (payload) | ||
# | ||
let cfn_authentication_rule = Resources.Metadata | ||
let skip_cfn_authentication = %cfn_authentication_rule[ | ||
"AWS::CloudFormation::Authentication" exists | ||
Metadata.cfn_nag.rules_to_suppress not exists or | ||
Metadata.cfn_nag.rules_to_suppress.*.id != "W1" | ||
Metadata.guard.SuppressedRules not exists or | ||
Metadata.guard.SuppressedRules.* != "CFN_AUTHENTICATION_RULE" | ||
] | ||
|
||
rule CFN_AUTHENTICATION_RULE when | ||
%cfn_authentication_rule !empty | ||
%skip_cfn_authentication !empty | ||
{ | ||
let violation = %cfn_authentication_rule[ | ||
"AWS::CloudFormation::Authentication".*.accessKeyId exists | ||
OR | ||
"AWS::CloudFormation::Authentication".*.password exists | ||
OR | ||
"AWS::CloudFormation::Authentication".*.secretKey exists | ||
] | ||
|
||
%violation empty | ||
<< | ||
Violation: CFN template has sensitive credentials defined. | ||
Fix: Remove sensitive credentials. | ||
>> | ||
} |
279 changes: 279 additions & 0 deletions
279
rules/aws/all_resources/tests/cfn_authentication_rule_tests.yml
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,279 @@ | ||
### | ||
# CFN_AUTHENTICATION_RULE tests | ||
### | ||
--- | ||
- name: Empty | ||
input: {} | ||
expectations: | ||
rules: | ||
CFN_AUTHENTICATION_RULE: SKIP | ||
|
||
- name: No resources | ||
input: | ||
Resources: {} | ||
expectations: | ||
rules: | ||
CFN_AUTHENTICATION_RULE: SKIP | ||
|
||
- name: CFN Insensitive authentication | ||
input: | ||
Resources: | ||
RootRole: | ||
Type: "AWS::IAM::Role" | ||
Properties: | ||
AssumeRolePolicyDocument: | ||
Version: "2012-10-17" | ||
Statement: | ||
- Effect: "Allow" | ||
Principal: | ||
Service: | ||
- "ec2.amazonaws.com" | ||
AWS: "arn:aws:iam::324320755747:root" | ||
Action: | ||
- "sts:AssumeRole" | ||
EC2I4LBA1: | ||
Type: "AWS::EC2::Instance" | ||
Properties: | ||
ImageId: "ami-6df1e514" | ||
InstanceType: "t2.micro" | ||
SubnetId: | ||
"Ref": "subnetId" | ||
Metadata: | ||
Type: AWS::CloudFormation::Authentication | ||
AWS::CloudFormation::Authentication: | ||
testS3: | ||
type: "s3" | ||
roleName: !Ref RootRole | ||
buckets: | ||
- "somebucket333" | ||
expectations: | ||
rules: | ||
CFN_AUTHENTICATION_RULE: PASS | ||
|
||
- name: CFN Sensitive authentication | ||
input: | ||
Resources: | ||
RootRole: | ||
Type: "AWS::IAM::Role" | ||
Properties: | ||
AssumeRolePolicyDocument: | ||
Version: "2012-10-17" | ||
Statement: | ||
- Effect: "Allow" | ||
Principal: | ||
Service: | ||
- "ec2.amazonaws.com" | ||
AWS: "arn:aws:iam::324320755747:root" | ||
Action: | ||
- "sts:AssumeRole" | ||
EC2I4LBA1: | ||
Type: "AWS::EC2::Instance" | ||
Properties: | ||
ImageId: "ami-6df1e514" | ||
InstanceType: "t2.micro" | ||
SubnetId: | ||
"Ref": "subnetId" | ||
Metadata: | ||
Type: AWS::CloudFormation::Authentication | ||
AWS::CloudFormation::Authentication: | ||
testBasic: | ||
type: "basic" | ||
username: "testUsername1" | ||
password: "sensitive_password" | ||
uris: | ||
- "http://www.example.com/test" | ||
expectations: | ||
rules: | ||
CFN_AUTHENTICATION_RULE: FAIL | ||
|
||
- name: CFN does not contains Metadata Resource | ||
input: | ||
Resources: | ||
RootRole: | ||
Type: "AWS::IAM::Role" | ||
Properties: | ||
AssumeRolePolicyDocument: | ||
Version: "2012-10-17" | ||
Statement: | ||
- Effect: "Allow" | ||
Principal: | ||
Service: | ||
- "ec2.amazonaws.com" | ||
AWS: "arn:aws:iam::324320755747:root" | ||
Action: | ||
- "sts:AssumeRole" | ||
EC2I4LBA1: | ||
Type: "AWS::EC2::Instance" | ||
Properties: | ||
ImageId: "ami-6df1e514" | ||
InstanceType: "t2.micro" | ||
SubnetId: | ||
"Ref": "subnetId" | ||
expectations: | ||
rules: | ||
CFN_AUTHENTICATION_RULE: SKIP | ||
|
||
- name: CFN_NAG suppression for W1 | ||
input: | ||
Resources: | ||
RootRole: | ||
Type: "AWS::IAM::Role" | ||
Properties: | ||
AssumeRolePolicyDocument: | ||
Version: "2012-10-17" | ||
Statement: | ||
- Effect: "Allow" | ||
Principal: | ||
Service: | ||
- "ec2.amazonaws.com" | ||
AWS: "arn:aws:iam::324320755747:root" | ||
Action: | ||
- "sts:AssumeRole" | ||
Metadata: | ||
cfn_nag: | ||
rules_to_suppress: | ||
- id: W1 | ||
reason: Suppressed to test suppression works and skips this test | ||
guard: | ||
SuppressedRules: | ||
- CFN_AUTHENTICATION_RULE | ||
EC2I4LBA1: | ||
Type: "AWS::EC2::Instance" | ||
Properties: | ||
ImageId: "ami-6df1e514" | ||
InstanceType: "t2.micro" | ||
SubnetId: | ||
"Ref": "subnetId" | ||
Metadata: | ||
cfn_nag: | ||
rules_to_suppress: | ||
- id: W1 | ||
reason: Suppressed to test suppression works and skips this test | ||
guard: | ||
SuppressedRules: | ||
- CFN_AUTHENTICATION_RULE | ||
Metadata: | ||
Type: AWS::CloudFormation::Authentication | ||
AWS::CloudFormation::Authentication: | ||
testBasic: | ||
type: "basic" | ||
username: "testUsername1" | ||
password: "sensitive_password" | ||
uris: | ||
- "http://www.example.com/test" | ||
Metadata: | ||
cfn_nag: | ||
rules_to_suppress: | ||
- id: W1 | ||
reason: Suppressed to test suppression works and skips this test | ||
expectations: | ||
rules: | ||
CFN_AUTHENTICATION_RULE: SKIP | ||
|
||
- name: Guard suppression for CFN_AUTHENTICATION_RULE | ||
input: | ||
Resources: | ||
RootRole: | ||
Type: "AWS::IAM::Role" | ||
Properties: | ||
AssumeRolePolicyDocument: | ||
Version: "2012-10-17" | ||
Statement: | ||
- Effect: "Allow" | ||
Principal: | ||
Service: | ||
- "ec2.amazonaws.com" | ||
AWS: "arn:aws:iam::324320755747:root" | ||
Action: | ||
- "sts:AssumeRole" | ||
Metadata: | ||
guard: | ||
SuppressedRules: | ||
- CFN_AUTHENTICATION_RULE | ||
EC2I4LBA1: | ||
Type: "AWS::EC2::Instance" | ||
Properties: | ||
ImageId: "ami-6df1e514" | ||
InstanceType: "t2.micro" | ||
SubnetId: | ||
"Ref": "subnetId" | ||
Metadata: | ||
guard: | ||
SuppressedRules: | ||
- CFN_AUTHENTICATION_RULE | ||
Metadata: | ||
Type: AWS::CloudFormation::Authentication | ||
AWS::CloudFormation::Authentication: | ||
testBasic: | ||
type: "basic" | ||
username: "testUsername1" | ||
password: "sensitive_password" | ||
uris: | ||
- "http://www.example.com/test" | ||
Metadata: | ||
guard: | ||
SuppressedRules: | ||
- CFN_AUTHENTICATION_RULE | ||
expectations: | ||
rules: | ||
CFN_AUTHENTICATION_RULE: SKIP | ||
|
||
- name: Guard and CFN_NAG suppression for W1 & CFN_AUTHENTICATION_RULE | ||
input: | ||
Resources: | ||
RootRole: | ||
Type: "AWS::IAM::Role" | ||
Properties: | ||
AssumeRolePolicyDocument: | ||
Version: "2012-10-17" | ||
Statement: | ||
- Effect: "Allow" | ||
Principal: | ||
Service: | ||
- "ec2.amazonaws.com" | ||
AWS: "arn:aws:iam::324320755747:root" | ||
Action: | ||
- "sts:AssumeRole" | ||
Metadata: | ||
cfn_nag: | ||
rules_to_suppress: | ||
- id: W1 | ||
reason: Suppressed to test suppression works and skips this test | ||
guard: | ||
SuppressedRules: | ||
- CFN_AUTHENTICATION_RULE | ||
EC2I4LBA1: | ||
Type: "AWS::EC2::Instance" | ||
Properties: | ||
ImageId: "ami-6df1e514" | ||
InstanceType: "t2.micro" | ||
SubnetId: | ||
"Ref": "subnetId" | ||
Metadata: | ||
cfn_nag: | ||
rules_to_suppress: | ||
- id: W1 | ||
reason: Suppressed to test suppression works and skips this test | ||
guard: | ||
SuppressedRules: | ||
- CFN_AUTHENTICATION_RULE | ||
Metadata: | ||
Type: AWS::CloudFormation::Authentication | ||
AWS::CloudFormation::Authentication: | ||
testBasic: | ||
type: "basic" | ||
username: "testUsername1" | ||
password: "sensitive_password" | ||
uris: | ||
- "http://www.example.com/test" | ||
Metadata: | ||
cfn_nag: | ||
rules_to_suppress: | ||
- id: W1 | ||
reason: Suppressed to test suppression works and skips this test | ||
guard: | ||
SuppressedRules: | ||
- CFN_AUTHENTICATION_RULE | ||
expectations: | ||
rules: | ||
CFN_AUTHENTICATION_RULE: SKIP |
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
Oops, something went wrong.