-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #440 fix rubocop and use the common not_truth? method instead * #443 Add rule for explicit kms key in a secret. Make all booleans check for NoValue
- Loading branch information
Eric Kascic
authored
Apr 29, 2020
1 parent
49e67a4
commit 860f7ec
Showing
11 changed files
with
165 additions
and
37 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 |
---|---|---|
|
@@ -6,9 +6,7 @@ LABEL org.opencontainers.image.authors="[email protected]" | |
# override here for a real build process | ||
ARG version='' | ||
|
||
RUN gem install cfn-nag --version "$version" || true | ||
RUN sleep 30; gem install cfn-nag --version "$version" || true | ||
RUN sleep 30; gem install cfn-nag --version "$version" || true | ||
RUN gem install cfn-nag --version "$version" | ||
|
||
ENTRYPOINT ["cfn_nag"] | ||
CMD ["--help"] |
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,12 @@ | ||
FROM ruby:2.5-alpine3.9@sha256:f33782620b363575ad95d19d0f0f07f7d197e9ccfee51f20df39dd33d408cdb4 | ||
|
||
LABEL org.opencontainers.image.authors="[email protected]" | ||
|
||
ARG version | ||
|
||
ADD cfn-nag-${version}.gem | ||
|
||
RUN gem install cfn-nag-${version}.gem | ||
|
||
ENTRYPOINT ["cfn_nag"] | ||
CMD ["--help"] |
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
26 changes: 26 additions & 0 deletions
26
lib/cfn-nag/custom_rules/SecretsManagerSecretKmsKeyIdRule.rb
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'cfn-nag/violation' | ||
require_relative 'boolean_base_rule' | ||
|
||
class SecretsManagerSecretKmsKeyIdRule < BooleanBaseRule | ||
def rule_text | ||
'Secrets Manager Secret should explicitly specify KmsKeyId' | ||
end | ||
|
||
def rule_type | ||
Violation::FAILING_VIOLATION | ||
end | ||
|
||
def rule_id | ||
'F81' | ||
end | ||
|
||
def resource_type | ||
'AWS::SecretsManager::Secret' | ||
end | ||
|
||
def boolean_property | ||
:kmsKeyId | ||
end | ||
end |
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
26 changes: 26 additions & 0 deletions
26
spec/custom_rules/SecretsManagerSecretKmsKeyIdRule_spec.rb
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,26 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'cfn-model' | ||
require 'cfn-nag/custom_rules/SecretsManagerSecretKmsKeyIdRule' | ||
|
||
describe SecretsManagerSecretKmsKeyIdRule do | ||
context 'missing kms key id' do | ||
it 'returns offending logical resource id' do | ||
cfn_model = CfnParser.new.parse read_test_template('yaml/secretsmanager/conditional_properties.yml') | ||
|
||
actual_logical_resource_ids = SecretsManagerSecretKmsKeyIdRule.new.audit_impl cfn_model | ||
expected_logical_resource_ids = %w[AppDbSecret] | ||
|
||
expect(actual_logical_resource_ids).to eq expected_logical_resource_ids | ||
end | ||
end | ||
|
||
context 'has explicit kms key id' do | ||
it 'returns no logical resource ids' do | ||
cfn_model = CfnParser.new.parse read_test_template('yaml/secretsmanager/explicit_key.yml') | ||
|
||
expect(SecretsManagerSecretKmsKeyIdRule.new.audit(cfn_model)).to be nil | ||
end | ||
end | ||
end |
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,21 @@ | ||
{ | ||
"Resources": { | ||
"myCluster": { | ||
"Type": "AWS::Redshift::Cluster", | ||
"Properties": { | ||
"DBName": "mydb", | ||
"MasterUsername": "master", | ||
"NodeType": "ds2.xlarge", | ||
"ClusterType": "single-node", | ||
"Encrypted": "true", | ||
"KmsKeyId": "arn:aws:kms:us-east-1:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab", | ||
"Tags": [ | ||
{ | ||
"Key": "foo", | ||
"Value": "bar" | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
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,47 @@ | ||
AWSTemplateFormatVersion: 2010-09-09 | ||
Parameters: | ||
RestoreSecretString: | ||
Type: String | ||
NoEcho: true | ||
Default: none | ||
|
||
Resources: | ||
Key: | ||
Type: AWS::KMS::Key | ||
Properties: | ||
Description: An example CMK | ||
EnableKeyRotation: true | ||
KeyPolicy: | ||
Version: 2012-10-17 | ||
Id: key-default-1 | ||
Statement: | ||
- Sid: Enable IAM User Permissions | ||
Effect: Allow | ||
Principal: | ||
AWS: arn:aws:iam::111122223333:root | ||
Action: kms:* | ||
Resource: '*' | ||
- Sid: Allow administration of the key | ||
Effect: Allow | ||
Principal: | ||
AWS: arn:aws:iam::123456789012:user/Alice | ||
Action: | ||
- kms:Create* | ||
- kms:CancelKeyDeletion | ||
Resource: '*' | ||
- Sid: Allow use of the key | ||
Effect: Allow | ||
Principal: | ||
AWS: arn:aws:iam::123456789012:user/Bob | ||
Action: | ||
- kms:GenerateDataKey | ||
- kms:GenerateDataKeyWithoutPlaintext | ||
Resource: '*' | ||
|
||
AppDbSecret: | ||
Type: AWS::SecretsManager::Secret | ||
DeletionPolicy: Retain | ||
Properties: | ||
Description: 'Restore' | ||
SecretString: !Ref 'RestoreSecretString' | ||
KmsKeyId: !Ref Key |