Skip to content

Commit 281132b

Browse files
authored
#500 Added new rule for Kendra Index KmsKeyId (#501)
1 parent 90fead8 commit 281132b

5 files changed

Lines changed: 103 additions & 0 deletions
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# frozen_string_literal: true
2+
3+
require 'cfn-nag/violation'
4+
require_relative 'base'
5+
6+
class KendraIndexServerSideEncryptionConfigurationKmsKeyIdRule < BaseRule
7+
def rule_text
8+
'Kendra Index ServerSideEncryptionConfiguration should specify a KmsKeyId value.'
9+
end
10+
11+
def rule_type
12+
Violation::WARNING
13+
end
14+
15+
def rule_id
16+
'W80'
17+
end
18+
19+
def audit_impl(cfn_model)
20+
violating_indices = cfn_model.resources_by_type('AWS::Kendra::Index').select do |index|
21+
index.serverSideEncryptionConfiguration.nil? ||
22+
index.serverSideEncryptionConfiguration['KmsKeyId'].nil?
23+
end
24+
25+
violating_indices.map(&:logical_resource_id)
26+
end
27+
end
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
require 'spec_helper'
2+
require 'password_rule_spec_helper'
3+
require 'cfn-model'
4+
require 'cfn-nag/custom_rules/KendraIndexServerSideEncryptionConfigurationKmsKeyIdRule'
5+
6+
describe KendraIndexServerSideEncryptionConfigurationKmsKeyIdRule do
7+
context 'Kendra Index without ServerSideConfiguration set' do
8+
it 'Returns the logical resource ID of the offending KendraIndex resource' do
9+
cfn_model = CfnParser.new.parse read_test_template(
10+
'yaml/kendra_index/kendra_index_server_side_encryption_configuration_not_set.yaml'
11+
)
12+
13+
actual_logical_resource_ids =
14+
KendraIndexServerSideEncryptionConfigurationKmsKeyIdRule.new.audit_impl cfn_model
15+
expected_logical_resource_ids = %w[KendraIndex]
16+
17+
expect(actual_logical_resource_ids).to eq expected_logical_resource_ids
18+
end
19+
end
20+
21+
context 'Kendra Index ServerSideConfiguration without KmsKeyId set' do
22+
it 'Returns the logical resource ID of the offending KendraIndex resource' do
23+
cfn_model = CfnParser.new.parse read_test_template(
24+
'yaml/kendra_index/kendra_index_server_side_encryption_configuration_kms_key_id_not_set.yaml'
25+
)
26+
27+
actual_logical_resource_ids =
28+
KendraIndexServerSideEncryptionConfigurationKmsKeyIdRule.new.audit_impl cfn_model
29+
expected_logical_resource_ids = %w[KendraIndex]
30+
31+
expect(actual_logical_resource_ids).to eq expected_logical_resource_ids
32+
end
33+
end
34+
35+
context 'Kendra Index ServerSideConfiguration with KmsKeyId set' do
36+
it 'Returns empty list' do
37+
cfn_model = CfnParser.new.parse read_test_template(
38+
'yaml/kendra_index/kendra_index_server_side_encryption_configuration_kms_key_id_set.yaml'
39+
)
40+
41+
actual_logical_resource_ids =
42+
KendraIndexServerSideEncryptionConfigurationKmsKeyIdRule.new.audit_impl cfn_model
43+
expected_logical_resource_ids = %w[]
44+
45+
expect(actual_logical_resource_ids).to eq expected_logical_resource_ids
46+
end
47+
end
48+
end
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
Resources:
3+
KendraIndex:
4+
Type: AWS::Kendra::Index
5+
Properties:
6+
Edition: ENTERPRISE_EDITION
7+
Name: KendraIndexWithoutKmsKeyId
8+
RoleArn: arn:aws:iam::123456789012:role/KendraIndex-foobar
9+
ServerSideEncryptionConfiguration:
10+
FooBar: foobar
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
Resources:
3+
KendraIndex:
4+
Type: AWS::Kendra::Index
5+
Properties:
6+
Edition: ENTERPRISE_EDITION
7+
Name: KendraIndexWithKmsKeyId
8+
RoleArn: arn:aws:iam::123456789012:role/KendraIndex-foobar
9+
ServerSideEncryptionConfiguration:
10+
KmsKeyId: alias/SuperSecureKey
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
Resources:
3+
KendraIndex:
4+
Type: AWS::Kendra::Index
5+
Properties:
6+
Edition: ENTERPRISE_EDITION
7+
Name: KendraIndexWithoutServerSideEncryptionConfiguration
8+
RoleArn: arn:aws:iam::123456789012:role/KendraIndex-foobar

0 commit comments

Comments
 (0)