-
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.
Elasticsearch domain inside vpc (#528)
- Loading branch information
Showing
4 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
lib/cfn-nag/custom_rules/ElasticsearchDomainInsideVPCRule.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 'base' | ||
|
||
class ElasticsearchDomainInsideVPCRule < BaseRule | ||
def rule_text | ||
'ElasticsearchcDomain should be inside vpc, should specify VPCOptions' | ||
end | ||
|
||
def rule_type | ||
Violation::WARNING | ||
end | ||
|
||
def rule_id | ||
'W90' | ||
end | ||
|
||
def audit_impl(cfn_model) | ||
violating_domains = cfn_model.resources_by_type('AWS::Elasticsearch::Domain').select do |domain| | ||
domain.vPCOptions.nil? | ||
end | ||
|
||
violating_domains.map(&:logical_resource_id) | ||
end | ||
end |
31 changes: 31 additions & 0 deletions
31
spec/custom_rules/ElasticsearchDomainInsideVPCRule_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,31 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
require 'cfn-model' | ||
require 'cfn-nag/custom_rules/ElasticsearchDomainInsideVPCRule' | ||
|
||
describe ElasticsearchDomainInsideVPCRule do | ||
|
||
describe 'AWS::Elasticsearch::Domain' do | ||
context 'when Elasticsearch domain is inside VPC' do | ||
it 'does not return an offending logical resource id' do | ||
cfn_model = CfnParser.new.parse read_test_template('json/elasticsearch/elasticsearch_inside_vpc.json') | ||
actual_logical_resource_ids = ElasticsearchDomainInsideVPCRule.new.audit_impl cfn_model | ||
|
||
expect(actual_logical_resource_ids).to eq [] | ||
end | ||
end | ||
end | ||
|
||
describe 'AWS::Elasticsearch::Domain' do | ||
context 'when Elasticsearch domain is not inside VPC' do | ||
it 'does return an offending logical resource id' do | ||
cfn_model = CfnParser.new.parse read_test_template('json/elasticsearch/elasticsearch_not_inside_vpc.json') | ||
actual_logical_resource_ids = ElasticsearchDomainInsideVPCRule.new.audit_impl cfn_model | ||
|
||
expect(actual_logical_resource_ids).to eq ["ElasticsearchDomainNotInVPC"] | ||
end | ||
end | ||
end | ||
|
||
end |
14 changes: 14 additions & 0 deletions
14
spec/test_templates/json/elasticsearch/elasticsearch_inside_vpc.json
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,14 @@ | ||
{ | ||
"Resources": { | ||
"ElasticsearchDomainInVPC": { | ||
"Type": "AWS::Elasticsearch::Domain", | ||
"Properties": { | ||
"DomainName": "nameddomain", | ||
"VPCOptions" : { | ||
"SecurityGroupIds": ["secgroup"], | ||
"SubnetIds": ["subnetid"] | ||
} | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
spec/test_templates/json/elasticsearch/elasticsearch_not_inside_vpc.json
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,10 @@ | ||
{ | ||
"Resources": { | ||
"ElasticsearchDomainNotInVPC": { | ||
"Type": "AWS::Elasticsearch::Domain", | ||
"Properties": { | ||
"DomainName": "nameddomain" | ||
} | ||
} | ||
} | ||
} |