inspec 4.22.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Gemfile +63 -0
- data/inspec.gemspec +36 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/Gemfile +11 -0
- data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/inspec-plugin-template.gemspec +43 -0
- data/lib/plugins/inspec-init/templates/profiles/aws/README.md +192 -0
- data/lib/plugins/inspec-init/templates/profiles/aws/attributes.yml +2 -0
- data/lib/plugins/inspec-init/templates/profiles/aws/controls/example.rb +39 -0
- data/lib/plugins/inspec-init/templates/profiles/aws/inspec.yml +22 -0
- data/lib/plugins/inspec-init/templates/profiles/azure/README.md +56 -0
- data/lib/plugins/inspec-init/templates/profiles/azure/controls/example.rb +14 -0
- data/lib/plugins/inspec-init/templates/profiles/azure/inspec.yml +14 -0
- data/lib/plugins/inspec-init/templates/profiles/gcp/README.md +66 -0
- data/lib/plugins/inspec-init/templates/profiles/gcp/attributes.yml +2 -0
- data/lib/plugins/inspec-init/templates/profiles/gcp/controls/example.rb +27 -0
- data/lib/plugins/inspec-init/templates/profiles/gcp/inspec.yml +19 -0
- data/lib/resource_support/aws.rb +76 -0
- data/lib/resource_support/aws/aws_backend_base.rb +12 -0
- data/lib/resource_support/aws/aws_backend_factory_mixin.rb +12 -0
- data/lib/resource_support/aws/aws_plural_resource_mixin.rb +24 -0
- data/lib/resource_support/aws/aws_resource_mixin.rb +69 -0
- data/lib/resource_support/aws/aws_singular_resource_mixin.rb +27 -0
- data/lib/resources/aws/aws_billing_report.rb +107 -0
- data/lib/resources/aws/aws_billing_reports.rb +74 -0
- data/lib/resources/aws/aws_cloudtrail_trail.rb +97 -0
- data/lib/resources/aws/aws_cloudtrail_trails.rb +51 -0
- data/lib/resources/aws/aws_cloudwatch_alarm.rb +67 -0
- data/lib/resources/aws/aws_cloudwatch_log_metric_filter.rb +105 -0
- data/lib/resources/aws/aws_config_delivery_channel.rb +74 -0
- data/lib/resources/aws/aws_config_recorder.rb +99 -0
- data/lib/resources/aws/aws_ebs_volume.rb +127 -0
- data/lib/resources/aws/aws_ebs_volumes.rb +69 -0
- data/lib/resources/aws/aws_ec2_instance.rb +162 -0
- data/lib/resources/aws/aws_ec2_instances.rb +69 -0
- data/lib/resources/aws/aws_ecs_cluster.rb +88 -0
- data/lib/resources/aws/aws_eks_cluster.rb +105 -0
- data/lib/resources/aws/aws_elb.rb +85 -0
- data/lib/resources/aws/aws_elbs.rb +84 -0
- data/lib/resources/aws/aws_flow_log.rb +106 -0
- data/lib/resources/aws/aws_iam_access_key.rb +112 -0
- data/lib/resources/aws/aws_iam_access_keys.rb +153 -0
- data/lib/resources/aws/aws_iam_group.rb +62 -0
- data/lib/resources/aws/aws_iam_groups.rb +56 -0
- data/lib/resources/aws/aws_iam_password_policy.rb +121 -0
- data/lib/resources/aws/aws_iam_policies.rb +57 -0
- data/lib/resources/aws/aws_iam_policy.rb +311 -0
- data/lib/resources/aws/aws_iam_role.rb +60 -0
- data/lib/resources/aws/aws_iam_root_user.rb +82 -0
- data/lib/resources/aws/aws_iam_user.rb +145 -0
- data/lib/resources/aws/aws_iam_users.rb +160 -0
- data/lib/resources/aws/aws_kms_key.rb +100 -0
- data/lib/resources/aws/aws_kms_keys.rb +58 -0
- data/lib/resources/aws/aws_rds_instance.rb +74 -0
- data/lib/resources/aws/aws_route_table.rb +67 -0
- data/lib/resources/aws/aws_route_tables.rb +64 -0
- data/lib/resources/aws/aws_s3_bucket.rb +142 -0
- data/lib/resources/aws/aws_s3_bucket_object.rb +87 -0
- data/lib/resources/aws/aws_s3_buckets.rb +52 -0
- data/lib/resources/aws/aws_security_group.rb +314 -0
- data/lib/resources/aws/aws_security_groups.rb +71 -0
- data/lib/resources/aws/aws_sns_subscription.rb +82 -0
- data/lib/resources/aws/aws_sns_topic.rb +57 -0
- data/lib/resources/aws/aws_sns_topics.rb +60 -0
- data/lib/resources/aws/aws_sqs_queue.rb +66 -0
- data/lib/resources/aws/aws_subnet.rb +92 -0
- data/lib/resources/aws/aws_subnets.rb +56 -0
- data/lib/resources/aws/aws_vpc.rb +77 -0
- data/lib/resources/aws/aws_vpcs.rb +55 -0
- data/lib/resources/azure/azure_backend.rb +379 -0
- data/lib/resources/azure/azure_generic_resource.rb +55 -0
- data/lib/resources/azure/azure_resource_group.rb +151 -0
- data/lib/resources/azure/azure_virtual_machine.rb +262 -0
- data/lib/resources/azure/azure_virtual_machine_data_disk.rb +131 -0
- metadata +202 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
require "resource_support/aws/aws_plural_resource_mixin"
|
2
|
+
require "resource_support/aws/aws_backend_base"
|
3
|
+
require "aws-sdk-ec2"
|
4
|
+
|
5
|
+
class AwsEc2Instances < Inspec.resource(1)
|
6
|
+
name "aws_ec2_instances"
|
7
|
+
desc "Verifies settings for AWS EC2 Instances in bulk"
|
8
|
+
example <<~EXAMPLE
|
9
|
+
describe aws_ec2_instances do
|
10
|
+
it { should exist }
|
11
|
+
end
|
12
|
+
EXAMPLE
|
13
|
+
supports platform: "aws"
|
14
|
+
|
15
|
+
include AwsPluralResourceMixin
|
16
|
+
def validate_params(resource_params)
|
17
|
+
unless resource_params.empty?
|
18
|
+
raise ArgumentError, "aws_ec2_instances does not accept resource parameters."
|
19
|
+
end
|
20
|
+
|
21
|
+
resource_params
|
22
|
+
end
|
23
|
+
|
24
|
+
# Underlying FilterTable implementation.
|
25
|
+
filter = FilterTable.create
|
26
|
+
filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
|
27
|
+
filter.register_column(:instance_ids, field: :instance_id)
|
28
|
+
filter.install_filter_methods_on_resource(self, :table)
|
29
|
+
|
30
|
+
def to_s
|
31
|
+
"EC2 Instances"
|
32
|
+
end
|
33
|
+
|
34
|
+
def fetch_from_api
|
35
|
+
backend = BackendFactory.create(inspec_runner)
|
36
|
+
@table = []
|
37
|
+
pagination_opts = {}
|
38
|
+
loop do
|
39
|
+
api_result = backend.describe_instances(pagination_opts)
|
40
|
+
@table += unpack_describe_instances_response(api_result.reservations)
|
41
|
+
break unless api_result.next_token
|
42
|
+
|
43
|
+
pagination_opts = { next_token: api_result.next_token }
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def unpack_describe_instances_response(reservations)
|
48
|
+
instance_rows = []
|
49
|
+
reservations.each do |res|
|
50
|
+
instance_rows += res.instances.map do |instance_struct|
|
51
|
+
{
|
52
|
+
instance_id: instance_struct.instance_id,
|
53
|
+
}
|
54
|
+
end
|
55
|
+
end
|
56
|
+
instance_rows
|
57
|
+
end
|
58
|
+
|
59
|
+
class Backend
|
60
|
+
class AwsClientApi < AwsBackendBase
|
61
|
+
BackendFactory.set_default_backend(self)
|
62
|
+
self.aws_client_class = Aws::EC2::Client
|
63
|
+
|
64
|
+
def describe_instances(query)
|
65
|
+
aws_service_client.describe_instances(query)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require "resource_support/aws/aws_singular_resource_mixin"
|
2
|
+
require "resource_support/aws/aws_backend_base"
|
3
|
+
require "aws-sdk-ecs"
|
4
|
+
|
5
|
+
class AwsEcsCluster < Inspec.resource(1)
|
6
|
+
name "aws_ecs_cluster"
|
7
|
+
desc "Verifies settings for an ECS cluster"
|
8
|
+
|
9
|
+
example <<~EXAMPLE
|
10
|
+
describe aws_ecs_cluster('default') do
|
11
|
+
it { should exist }
|
12
|
+
end
|
13
|
+
EXAMPLE
|
14
|
+
supports platform: "aws"
|
15
|
+
|
16
|
+
include AwsSingularResourceMixin
|
17
|
+
attr_reader :cluster_arn, :cluster_name, :status,
|
18
|
+
:registered_container_instances_count, :running_tasks_count,
|
19
|
+
:pending_tasks_count, :active_services_count, :statistics
|
20
|
+
|
21
|
+
def to_s
|
22
|
+
"AWS ECS cluster #{cluster_name}"
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def validate_params(raw_params)
|
28
|
+
validated_params = check_resource_param_names(
|
29
|
+
raw_params: raw_params,
|
30
|
+
allowed_params: [:cluster_name],
|
31
|
+
allowed_scalar_name: :cluster_name,
|
32
|
+
allowed_scalar_type: String
|
33
|
+
)
|
34
|
+
|
35
|
+
validated_params
|
36
|
+
end
|
37
|
+
|
38
|
+
def fetch_from_api
|
39
|
+
backend = BackendFactory.create(inspec_runner)
|
40
|
+
begin
|
41
|
+
# Use default cluster if no cluster name is specified
|
42
|
+
params = cluster_name.nil? ? {} : { clusters: [cluster_name] }
|
43
|
+
clusters = backend.describe_clusters(params).clusters
|
44
|
+
|
45
|
+
# Cluster name is unique, we either get back one cluster, or none
|
46
|
+
if clusters.length == 1
|
47
|
+
@exists = true
|
48
|
+
unpack_describe_clusters_response(clusters.first)
|
49
|
+
else
|
50
|
+
@exists = false
|
51
|
+
populate_as_missing
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def unpack_describe_clusters_response(cluster_struct)
|
57
|
+
@cluster_arn = cluster_struct.cluster_arn
|
58
|
+
@cluster_name = cluster_struct.cluster_name
|
59
|
+
@status = cluster_struct.status
|
60
|
+
@registered_container_instances_count = cluster_struct.registered_container_instances_count
|
61
|
+
@running_tasks_count = cluster_struct.running_tasks_count
|
62
|
+
@pending_tasks_count = cluster_struct.pending_tasks_count
|
63
|
+
@active_services_count = cluster_struct.active_services_count
|
64
|
+
@statistics = cluster_struct.statistics
|
65
|
+
end
|
66
|
+
|
67
|
+
def populate_as_missing
|
68
|
+
@cluster_arn = ""
|
69
|
+
@cluster_name = ""
|
70
|
+
@status = ""
|
71
|
+
@registered_container_instances_count = 0
|
72
|
+
@running_tasks_count = 0
|
73
|
+
@pending_tasks_count = 0
|
74
|
+
@active_services_count = 0
|
75
|
+
@statistics = []
|
76
|
+
end
|
77
|
+
|
78
|
+
class Backend
|
79
|
+
class AwsClientApi < AwsBackendBase
|
80
|
+
BackendFactory.set_default_backend(self)
|
81
|
+
self.aws_client_class = Aws::ECS::Client
|
82
|
+
|
83
|
+
def describe_clusters(query = {})
|
84
|
+
aws_service_client.describe_clusters(query)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require "resource_support/aws/aws_singular_resource_mixin"
|
2
|
+
require "resource_support/aws/aws_backend_base"
|
3
|
+
require "aws-sdk-eks"
|
4
|
+
|
5
|
+
class AwsEksCluster < Inspec.resource(1)
|
6
|
+
name "aws_eks_cluster"
|
7
|
+
desc "Verifies settings for an EKS cluster"
|
8
|
+
|
9
|
+
example <<~EXAMPLE
|
10
|
+
describe aws_eks_cluster('default') do
|
11
|
+
it { should exist }
|
12
|
+
end
|
13
|
+
EXAMPLE
|
14
|
+
supports platform: "aws"
|
15
|
+
|
16
|
+
include AwsSingularResourceMixin
|
17
|
+
attr_reader :version, :arn, :cluster_name, :certificate_authority, :name,
|
18
|
+
:status, :endpoint, :subnets_count, :subnet_ids, :security_group_ids,
|
19
|
+
:created_at, :role_arn, :vpc_id, :security_groups_count, :creating,
|
20
|
+
:active, :failed, :deleting
|
21
|
+
# Use aliases for matchers
|
22
|
+
alias active? active
|
23
|
+
alias failed? failed
|
24
|
+
alias creating? creating
|
25
|
+
alias deleting? deleting
|
26
|
+
|
27
|
+
def to_s
|
28
|
+
"AWS EKS cluster #{cluster_name}"
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def validate_params(raw_params)
|
34
|
+
validated_params = check_resource_param_names(
|
35
|
+
raw_params: raw_params,
|
36
|
+
allowed_params: [:cluster_name],
|
37
|
+
allowed_scalar_name: :cluster_name,
|
38
|
+
allowed_scalar_type: String
|
39
|
+
)
|
40
|
+
|
41
|
+
if validated_params.empty?
|
42
|
+
raise ArgumentError, "You must provide a cluster_name to aws_eks_cluster."
|
43
|
+
end
|
44
|
+
|
45
|
+
validated_params
|
46
|
+
end
|
47
|
+
|
48
|
+
def fetch_from_api # rubocop:disable Metrics/AbcSize
|
49
|
+
backend = BackendFactory.create(inspec_runner)
|
50
|
+
begin
|
51
|
+
params = { name: cluster_name }
|
52
|
+
resp = backend.describe_cluster(params)
|
53
|
+
rescue Aws::EKS::Errors::ResourceNotFoundException
|
54
|
+
@exists = false
|
55
|
+
populate_as_missing
|
56
|
+
return
|
57
|
+
end
|
58
|
+
@exists = true
|
59
|
+
cluster = resp.to_h[:cluster]
|
60
|
+
@version = cluster[:version]
|
61
|
+
@name = cluster[:name]
|
62
|
+
@arn = cluster[:arn]
|
63
|
+
@certificate_authority = cluster[:certificate_authority][:data]
|
64
|
+
@created_at = cluster[:created_at]
|
65
|
+
@endpoint = cluster[:endpoint]
|
66
|
+
@security_group_ids = cluster[:resources_vpc_config][:security_group_ids]
|
67
|
+
@subnet_ids = cluster[:resources_vpc_config][:subnet_ids]
|
68
|
+
@subnets_count = cluster[:resources_vpc_config][:subnet_ids].length
|
69
|
+
@security_groups_count = cluster[:resources_vpc_config][:security_group_ids].length
|
70
|
+
@vpc_id = cluster[:resources_vpc_config][:vpc_id]
|
71
|
+
@role_arn = cluster[:role_arn]
|
72
|
+
@status = cluster[:status]
|
73
|
+
@active = cluster[:status] == "ACTIVE"
|
74
|
+
@failed = cluster[:status] == "FAILED"
|
75
|
+
@creating = cluster[:status] == "CREATING"
|
76
|
+
@deleting = cluster[:status] == "DELETING"
|
77
|
+
end
|
78
|
+
|
79
|
+
def populate_as_missing
|
80
|
+
@version = nil
|
81
|
+
@name = cluster_name # name is an alias for cluster_name, and it is retained on a miss
|
82
|
+
@arn = nil
|
83
|
+
@certificate_authority = nil
|
84
|
+
@created_at = nil
|
85
|
+
@endpoint = nil
|
86
|
+
@security_group_ids = []
|
87
|
+
@subnet_ids = []
|
88
|
+
@subnets_count = nil
|
89
|
+
@security_groups_count = nil
|
90
|
+
@vpc_id = nil
|
91
|
+
@role_arn = nil
|
92
|
+
@status = nil
|
93
|
+
end
|
94
|
+
|
95
|
+
class Backend
|
96
|
+
class AwsClientApi < AwsBackendBase
|
97
|
+
BackendFactory.set_default_backend(self)
|
98
|
+
self.aws_client_class = Aws::EKS::Client
|
99
|
+
|
100
|
+
def describe_cluster(query = {})
|
101
|
+
aws_service_client.describe_cluster(query)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require "resource_support/aws/aws_singular_resource_mixin"
|
2
|
+
require "resource_support/aws/aws_backend_base"
|
3
|
+
require "aws-sdk-elasticloadbalancing"
|
4
|
+
|
5
|
+
class AwsElb < Inspec.resource(1)
|
6
|
+
name "aws_elb"
|
7
|
+
desc "Verifies settings for AWS Elastic Load Balancer"
|
8
|
+
example <<~EXAMPLE
|
9
|
+
describe aws_elb('myelb') do
|
10
|
+
it { should exist }
|
11
|
+
end
|
12
|
+
EXAMPLE
|
13
|
+
supports platform: "aws"
|
14
|
+
|
15
|
+
include AwsSingularResourceMixin
|
16
|
+
attr_reader :availability_zones, :dns_name, :elb_name, :external_ports,
|
17
|
+
:instance_ids, :internal_ports, :security_group_ids,
|
18
|
+
:subnet_ids, :vpc_id
|
19
|
+
|
20
|
+
def to_s
|
21
|
+
"AWS ELB #{elb_name}"
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def validate_params(raw_params)
|
27
|
+
validated_params = check_resource_param_names(
|
28
|
+
raw_params: raw_params,
|
29
|
+
allowed_params: [:elb_name],
|
30
|
+
allowed_scalar_name: :elb_name,
|
31
|
+
allowed_scalar_type: String
|
32
|
+
)
|
33
|
+
|
34
|
+
if validated_params.empty?
|
35
|
+
raise ArgumentError, "You must provide a elb_name to aws_elb."
|
36
|
+
end
|
37
|
+
|
38
|
+
validated_params
|
39
|
+
end
|
40
|
+
|
41
|
+
def fetch_from_api
|
42
|
+
backend = BackendFactory.create(inspec_runner)
|
43
|
+
begin
|
44
|
+
lbs = backend.describe_load_balancers(load_balancer_names: [elb_name]).load_balancer_descriptions
|
45
|
+
@exists = true
|
46
|
+
# Load balancer names are uniq; we will either have 0 or 1 result
|
47
|
+
unpack_describe_elbs_response(lbs.first)
|
48
|
+
rescue Aws::ElasticLoadBalancing::Errors::LoadBalancerNotFound
|
49
|
+
@exists = false
|
50
|
+
populate_as_missing
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def unpack_describe_elbs_response(lb_struct)
|
55
|
+
@availability_zones = lb_struct.availability_zones
|
56
|
+
@dns_name = lb_struct.dns_name
|
57
|
+
@external_ports = lb_struct.listener_descriptions.map { |ld| ld.listener.load_balancer_port }
|
58
|
+
@instance_ids = lb_struct.instances.map(&:instance_id)
|
59
|
+
@internal_ports = lb_struct.listener_descriptions.map { |ld| ld.listener.instance_port }
|
60
|
+
@elb_name = lb_struct.load_balancer_name
|
61
|
+
@security_group_ids = lb_struct.security_groups
|
62
|
+
@subnet_ids = lb_struct.subnets
|
63
|
+
@vpc_id = lb_struct.vpc_id
|
64
|
+
end
|
65
|
+
|
66
|
+
def populate_as_missing
|
67
|
+
@availability_zones = []
|
68
|
+
@external_ports = []
|
69
|
+
@instance_ids = []
|
70
|
+
@internal_ports = []
|
71
|
+
@security_group_ids = []
|
72
|
+
@subnet_ids = []
|
73
|
+
end
|
74
|
+
|
75
|
+
class Backend
|
76
|
+
class AwsClientApi < AwsBackendBase
|
77
|
+
BackendFactory.set_default_backend(self)
|
78
|
+
self.aws_client_class = Aws::ElasticLoadBalancing::Client
|
79
|
+
|
80
|
+
def describe_load_balancers(query = {})
|
81
|
+
aws_service_client.describe_load_balancers(query)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require "resource_support/aws/aws_plural_resource_mixin"
|
2
|
+
require "resource_support/aws/aws_backend_base"
|
3
|
+
require "aws-sdk-elasticloadbalancing"
|
4
|
+
|
5
|
+
class AwsElbs < Inspec.resource(1)
|
6
|
+
name "aws_elbs"
|
7
|
+
desc "Verifies settings for AWS ELBs (classic Elastic Load Balancers) in bulk"
|
8
|
+
example <<~EXAMPLE
|
9
|
+
describe aws_elbs do
|
10
|
+
it { should exist }
|
11
|
+
end
|
12
|
+
EXAMPLE
|
13
|
+
supports platform: "aws"
|
14
|
+
|
15
|
+
include AwsPluralResourceMixin
|
16
|
+
def validate_params(resource_params)
|
17
|
+
unless resource_params.empty?
|
18
|
+
raise ArgumentError, "aws_elbs does not accept resource parameters."
|
19
|
+
end
|
20
|
+
|
21
|
+
resource_params
|
22
|
+
end
|
23
|
+
|
24
|
+
# Underlying FilterTable implementation.
|
25
|
+
filter = FilterTable.create
|
26
|
+
filter.add_accessor(:entries)
|
27
|
+
.add_accessor(:where)
|
28
|
+
.add(:exists?) { |table| !table.params.empty? }
|
29
|
+
.add(:count) { |table| table.params.count }
|
30
|
+
.add(:availability_zones, field: :availability_zones, style: :simple)
|
31
|
+
.add(:dns_names, field: :dns_name)
|
32
|
+
.add(:external_ports, field: :external_ports, style: :simple)
|
33
|
+
.add(:instance_ids, field: :instance_ids, style: :simple)
|
34
|
+
.add(:internal_ports, field: :internal_ports, style: :simple)
|
35
|
+
.add(:elb_names, field: :elb_name)
|
36
|
+
.add(:security_group_ids, field: :security_group_ids, style: :simple)
|
37
|
+
.add(:subnet_ids, field: :subnet_ids, style: :simple)
|
38
|
+
.add(:vpc_ids, field: :vpc_id, style: :simple)
|
39
|
+
filter.connect(self, :table)
|
40
|
+
|
41
|
+
def to_s
|
42
|
+
"AWS ELBs"
|
43
|
+
end
|
44
|
+
|
45
|
+
def fetch_from_api
|
46
|
+
backend = BackendFactory.create(inspec_runner)
|
47
|
+
@table = []
|
48
|
+
pagination_opts = {}
|
49
|
+
loop do
|
50
|
+
api_result = backend.describe_load_balancers(pagination_opts)
|
51
|
+
@table += unpack_describe_elbs_response(api_result.load_balancer_descriptions)
|
52
|
+
break unless api_result.next_marker
|
53
|
+
|
54
|
+
pagination_opts = { marker: api_result.next_marker }
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def unpack_describe_elbs_response(load_balancers)
|
59
|
+
load_balancers.map do |lb_struct|
|
60
|
+
{
|
61
|
+
availability_zones: lb_struct.availability_zones,
|
62
|
+
dns_name: lb_struct.dns_name,
|
63
|
+
external_ports: lb_struct.listener_descriptions.map { |ld| ld.listener.load_balancer_port },
|
64
|
+
instance_ids: lb_struct.instances.map(&:instance_id),
|
65
|
+
internal_ports: lb_struct.listener_descriptions.map { |ld| ld.listener.instance_port },
|
66
|
+
elb_name: lb_struct.load_balancer_name,
|
67
|
+
security_group_ids: lb_struct.security_groups,
|
68
|
+
subnet_ids: lb_struct.subnets,
|
69
|
+
vpc_id: lb_struct.vpc_id,
|
70
|
+
}
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class Backend
|
75
|
+
class AwsClientApi < AwsBackendBase
|
76
|
+
BackendFactory.set_default_backend(self)
|
77
|
+
self.aws_client_class = Aws::ElasticLoadBalancing::Client
|
78
|
+
|
79
|
+
def describe_load_balancers(query = {})
|
80
|
+
aws_service_client.describe_load_balancers(query)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
require "resource_support/aws/aws_singular_resource_mixin"
|
2
|
+
require "resource_support/aws/aws_backend_base"
|
3
|
+
require "aws-sdk-ec2"
|
4
|
+
|
5
|
+
class AwsFlowLog < Inspec.resource(1)
|
6
|
+
name "aws_flow_log"
|
7
|
+
supports platform: "aws"
|
8
|
+
desc "This resource is used to test the attributes of a Flow Log."
|
9
|
+
example <<~EXAMPLE
|
10
|
+
describe aws_flow_log('fl-9c718cf5') do
|
11
|
+
it { should exist }
|
12
|
+
end
|
13
|
+
EXAMPLE
|
14
|
+
|
15
|
+
include AwsSingularResourceMixin
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
"AWS Flow Log #{id}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def resource_type
|
22
|
+
case @resource_id
|
23
|
+
when /^eni/
|
24
|
+
@resource_type = "eni"
|
25
|
+
when /^subnet/
|
26
|
+
@resource_type = "subnet"
|
27
|
+
when /^vpc/
|
28
|
+
@resource_type = "vpc"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def attached_to_eni?
|
33
|
+
resource_type.eql?("eni") ? true : false
|
34
|
+
end
|
35
|
+
|
36
|
+
def attached_to_subnet?
|
37
|
+
resource_type.eql?("subnet") ? true : false
|
38
|
+
end
|
39
|
+
|
40
|
+
def attached_to_vpc?
|
41
|
+
resource_type.eql?("vpc") ? true : false
|
42
|
+
end
|
43
|
+
|
44
|
+
attr_reader :log_group_name, :resource_id, :flow_log_id
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def validate_params(raw_params)
|
49
|
+
validated_params = check_resource_param_names(
|
50
|
+
raw_params: raw_params,
|
51
|
+
allowed_params: %i{flow_log_id subnet_id vpc_id},
|
52
|
+
allowed_scalar_name: :flow_log_id,
|
53
|
+
allowed_scalar_type: String
|
54
|
+
)
|
55
|
+
|
56
|
+
if validated_params.empty?
|
57
|
+
raise ArgumentError,
|
58
|
+
"aws_flow_log requires a parameter: flow_log_id, subnet_id, or vpc_id"
|
59
|
+
end
|
60
|
+
|
61
|
+
validated_params
|
62
|
+
end
|
63
|
+
|
64
|
+
def fetch_from_api
|
65
|
+
backend = BackendFactory.create(inspec_runner)
|
66
|
+
|
67
|
+
resp = backend.describe_flow_logs(filter_args)
|
68
|
+
flow_log = resp.to_h[:flow_logs].first
|
69
|
+
@exists = !flow_log.nil?
|
70
|
+
unless flow_log.nil?
|
71
|
+
@log_group_name = flow_log[:log_group_name]
|
72
|
+
@resource_id = flow_log[:resource_id]
|
73
|
+
@flow_log_id = flow_log[:flow_log_id]
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def filter_args
|
78
|
+
if @flow_log_id
|
79
|
+
{ filter: [{ name: "flow-log-id", values: [@flow_log_id] }] }
|
80
|
+
elsif @subnet_id || @vpc_id
|
81
|
+
filter = @subnet_id || @vpc_id
|
82
|
+
{ filter: [{ name: "resource-id", values: [filter] }] }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def id
|
87
|
+
return @flow_log_id if @flow_log_id
|
88
|
+
return @subnet_id if @subnet_id
|
89
|
+
return @vpc_id if @vpc_id
|
90
|
+
end
|
91
|
+
|
92
|
+
def backend
|
93
|
+
BackendFactory.create(inspec_runner)
|
94
|
+
end
|
95
|
+
|
96
|
+
class Backend
|
97
|
+
class AwsClientApi < AwsBackendBase
|
98
|
+
AwsFlowLog::BackendFactory.set_default_backend(self)
|
99
|
+
self.aws_client_class = Aws::EC2::Client
|
100
|
+
|
101
|
+
def describe_flow_logs(query)
|
102
|
+
aws_service_client.describe_flow_logs(query)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|