-
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
- Loading branch information
Showing
4 changed files
with
71 additions
and
0 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,27 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'cfn-nag/violation' | ||
require 'cfn-nag/util/truthy' | ||
require_relative 'base' | ||
|
||
class LogsLogGroupEncryptedRule < BaseRule | ||
def rule_text | ||
'CloudWatchLogs LogGroup should specify a KMS Key Id to encrypt the log data' | ||
end | ||
|
||
def rule_type | ||
Violation::WARNING | ||
end | ||
|
||
def rule_id | ||
'W84' | ||
end | ||
|
||
def audit_impl(cfn_model) | ||
violating_groups = cfn_model.resources_by_type('AWS::Logs::LogGroup').select do |group| | ||
group.kmsKeyId.nil? | ||
end | ||
|
||
violating_groups.map(&:logical_resource_id) | ||
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,31 @@ | ||
require 'spec_helper' | ||
require 'cfn-model' | ||
require 'cfn-nag/custom_rules/LogsLogGroupEncryptedRule' | ||
|
||
describe LogsLogGroupEncryptedRule do | ||
context 'CloudWatchLogs LogGroup without encryption' do | ||
it 'returns offending logical resource id' do | ||
cfn_model = CfnParser.new.parse read_test_template( | ||
'yaml/cloudwatchlogs_loggroup/cloudwatchlogs_loggroup_without_encryption.yaml' | ||
) | ||
|
||
actual_logical_resource_ids = LogsLogGroupEncryptedRule.new.audit_impl cfn_model | ||
expected_logical_resource_ids = %w[CWLogGroup] | ||
|
||
expect(actual_logical_resource_ids).to eq expected_logical_resource_ids | ||
end | ||
end | ||
|
||
context 'CloudWatchLogs LogGroup with encryption' do | ||
it 'returns empty list' do | ||
cfn_model = CfnParser.new.parse read_test_template( | ||
'yaml/cloudwatchlogs_loggroup/cloudwatchlogs_loggroup_with_encryption.yaml' | ||
) | ||
|
||
actual_logical_resource_ids = LogsLogGroupEncryptedRule.new.audit_impl cfn_model | ||
expected_logical_resource_ids = %w[] | ||
|
||
expect(actual_logical_resource_ids).to eq expected_logical_resource_ids | ||
end | ||
end | ||
end |
7 changes: 7 additions & 0 deletions
7
.../test_templates/yaml/cloudwatchlogs_loggroup/cloudwatchlogs_loggroup_with_encryption.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,7 @@ | ||
--- | ||
Resources: | ||
CWLogGroup: | ||
Type: AWS::Logs::LogGroup | ||
Properties: | ||
KmsKeyId: alias/SuperSecureKey | ||
RetentionInDays: 7 |
6 changes: 6 additions & 0 deletions
6
...st_templates/yaml/cloudwatchlogs_loggroup/cloudwatchlogs_loggroup_without_encryption.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,6 @@ | ||
--- | ||
Resources: | ||
CWLogGroup: | ||
Type: AWS::Logs::LogGroup | ||
Properties: | ||
RetentionInDays: 7 |