2018-02-08 04:23:05 +00:00
|
|
|
class AwsSecurityGroups < Inspec.resource(1)
|
|
|
|
name 'aws_security_groups'
|
2017-12-14 03:36:23 +00:00
|
|
|
desc 'Verifies settings for AWS Security Groups in bulk'
|
2018-02-06 18:14:17 +00:00
|
|
|
example <<-EOX
|
2017-12-20 17:20:09 +00:00
|
|
|
# Verify that you have security groups defined
|
2018-02-08 04:23:05 +00:00
|
|
|
describe aws_security_groups do
|
2017-12-14 03:36:23 +00:00
|
|
|
it { should exist }
|
|
|
|
end
|
2017-12-20 17:20:09 +00:00
|
|
|
|
|
|
|
# Verify you have more than the default security group
|
2018-02-08 04:23:05 +00:00
|
|
|
describe aws_security_groups do
|
2017-12-20 17:20:09 +00:00
|
|
|
its('entries.count') { should be > 1 }
|
|
|
|
end
|
2018-02-06 18:14:17 +00:00
|
|
|
EOX
|
2018-02-08 04:26:37 +00:00
|
|
|
supports platform: 'aws'
|
2017-12-14 03:36:23 +00:00
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
include AwsPluralResourceMixin
|
2017-12-14 03:36:23 +00:00
|
|
|
|
|
|
|
# Underlying FilterTable implementation.
|
|
|
|
filter = FilterTable.create
|
|
|
|
filter.add_accessor(:where)
|
|
|
|
.add_accessor(:entries)
|
|
|
|
.add(:exists?) { |x| !x.entries.empty? }
|
|
|
|
.add(:group_ids, field: :group_id)
|
2018-02-08 04:26:37 +00:00
|
|
|
filter.connect(self, :table)
|
2017-12-14 03:36:23 +00:00
|
|
|
|
|
|
|
def to_s
|
|
|
|
'EC2 Security Groups'
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
def validate_params(raw_criteria)
|
2017-12-14 03:36:23 +00:00
|
|
|
unless raw_criteria.is_a? Hash
|
|
|
|
raise 'Unrecognized criteria for fetching Security Groups. ' \
|
|
|
|
"Use 'criteria: value' format."
|
|
|
|
end
|
|
|
|
|
|
|
|
# No criteria yet
|
|
|
|
unless raw_criteria.empty?
|
2018-02-08 04:26:37 +00:00
|
|
|
raise ArgumentError, 'aws_ec2_security_groups does not currently accept resource parameters.'
|
2017-12-14 03:36:23 +00:00
|
|
|
end
|
2018-02-08 04:26:37 +00:00
|
|
|
raw_criteria
|
2017-12-14 03:36:23 +00:00
|
|
|
end
|
|
|
|
|
2018-02-08 04:26:37 +00:00
|
|
|
def fetch_from_api
|
2017-12-14 03:36:23 +00:00
|
|
|
@table = []
|
2018-02-08 04:26:37 +00:00
|
|
|
backend = BackendFactory.create(inspec_runner)
|
|
|
|
backend.describe_security_groups({}).security_groups.each do |sg_info|
|
2017-12-14 03:36:23 +00:00
|
|
|
@table.push({
|
|
|
|
group_id: sg_info.group_id,
|
|
|
|
group_name: sg_info.group_name,
|
|
|
|
vpc_id: sg_info.vpc_id,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class Backend
|
2018-02-08 04:26:37 +00:00
|
|
|
class AwsClientApi < AwsBackendBase
|
|
|
|
BackendFactory.set_default_backend self
|
|
|
|
self.aws_client_class = Aws::EC2::Client
|
2017-12-14 03:36:23 +00:00
|
|
|
|
|
|
|
def describe_security_groups(query)
|
2018-02-08 04:26:37 +00:00
|
|
|
aws_service_client.describe_security_groups(query)
|
2017-12-14 03:36:23 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|