inspec 4.56.17 → 5.7.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/inspec.gemspec +4 -1
- data/lib/plugins/inspec-init/templates/profiles/aws/inspec.yml +1 -1
- metadata +19 -62
- data/lib/resource_support/aws/aws_backend_base.rb +0 -12
- data/lib/resource_support/aws/aws_backend_factory_mixin.rb +0 -12
- data/lib/resource_support/aws/aws_plural_resource_mixin.rb +0 -24
- data/lib/resource_support/aws/aws_resource_mixin.rb +0 -69
- data/lib/resource_support/aws/aws_singular_resource_mixin.rb +0 -27
- data/lib/resource_support/aws.rb +0 -76
- data/lib/resources/aws/aws_billing_report.rb +0 -105
- data/lib/resources/aws/aws_billing_reports.rb +0 -74
- data/lib/resources/aws/aws_cloudtrail_trail.rb +0 -97
- data/lib/resources/aws/aws_cloudtrail_trails.rb +0 -51
- data/lib/resources/aws/aws_cloudwatch_alarm.rb +0 -67
- data/lib/resources/aws/aws_cloudwatch_log_metric_filter.rb +0 -105
- data/lib/resources/aws/aws_config_delivery_channel.rb +0 -74
- data/lib/resources/aws/aws_config_recorder.rb +0 -99
- data/lib/resources/aws/aws_ebs_volume.rb +0 -127
- data/lib/resources/aws/aws_ebs_volumes.rb +0 -69
- data/lib/resources/aws/aws_ec2_instance.rb +0 -162
- data/lib/resources/aws/aws_ec2_instances.rb +0 -69
- data/lib/resources/aws/aws_ecs_cluster.rb +0 -87
- data/lib/resources/aws/aws_eks_cluster.rb +0 -105
- data/lib/resources/aws/aws_elb.rb +0 -85
- data/lib/resources/aws/aws_elbs.rb +0 -84
- data/lib/resources/aws/aws_flow_log.rb +0 -106
- data/lib/resources/aws/aws_iam_access_key.rb +0 -112
- data/lib/resources/aws/aws_iam_access_keys.rb +0 -153
- data/lib/resources/aws/aws_iam_group.rb +0 -62
- data/lib/resources/aws/aws_iam_groups.rb +0 -56
- data/lib/resources/aws/aws_iam_password_policy.rb +0 -121
- data/lib/resources/aws/aws_iam_policies.rb +0 -57
- data/lib/resources/aws/aws_iam_policy.rb +0 -311
- data/lib/resources/aws/aws_iam_role.rb +0 -60
- data/lib/resources/aws/aws_iam_root_user.rb +0 -82
- data/lib/resources/aws/aws_iam_user.rb +0 -145
- data/lib/resources/aws/aws_iam_users.rb +0 -160
- data/lib/resources/aws/aws_kms_key.rb +0 -100
- data/lib/resources/aws/aws_kms_keys.rb +0 -58
- data/lib/resources/aws/aws_rds_instance.rb +0 -74
- data/lib/resources/aws/aws_route_table.rb +0 -67
- data/lib/resources/aws/aws_route_tables.rb +0 -64
- data/lib/resources/aws/aws_s3_bucket.rb +0 -141
- data/lib/resources/aws/aws_s3_bucket_object.rb +0 -87
- data/lib/resources/aws/aws_s3_buckets.rb +0 -52
- data/lib/resources/aws/aws_security_group.rb +0 -314
- data/lib/resources/aws/aws_security_groups.rb +0 -71
- data/lib/resources/aws/aws_sns_subscription.rb +0 -82
- data/lib/resources/aws/aws_sns_topic.rb +0 -57
- data/lib/resources/aws/aws_sns_topics.rb +0 -60
- data/lib/resources/aws/aws_sqs_queue.rb +0 -66
- data/lib/resources/aws/aws_subnet.rb +0 -92
- data/lib/resources/aws/aws_subnets.rb +0 -56
- data/lib/resources/aws/aws_vpc.rb +0 -77
- data/lib/resources/aws/aws_vpcs.rb +0 -55
- data/lib/resources/azure/azure_backend.rb +0 -379
- data/lib/resources/azure/azure_generic_resource.rb +0 -55
- data/lib/resources/azure/azure_resource_group.rb +0 -151
- data/lib/resources/azure/azure_virtual_machine.rb +0 -262
- data/lib/resources/azure/azure_virtual_machine_data_disk.rb +0 -131
@@ -1,262 +0,0 @@
|
|
1
|
-
require "resources/azure/azure_backend"
|
2
|
-
|
3
|
-
module Inspec::Resources
|
4
|
-
class AzureVirtualMachine < AzureResourceBase
|
5
|
-
name "azure_virtual_machine"
|
6
|
-
|
7
|
-
desc '
|
8
|
-
InSpec Resource to test Azure Virtual Machines
|
9
|
-
'
|
10
|
-
|
11
|
-
supports platform: "azure"
|
12
|
-
|
13
|
-
# Constructor for the resource. This calls the parent constructor to
|
14
|
-
# get the generic resource for the specified machine. This will provide
|
15
|
-
# static methods that are documented
|
16
|
-
#
|
17
|
-
# @author Russell Seymour
|
18
|
-
def initialize(opts = {})
|
19
|
-
# The generic resource needs to pass back a Microsoft.Compute/virtualMachines object so force it
|
20
|
-
opts[:type] = "Microsoft.Compute/virtualMachines"
|
21
|
-
super(opts)
|
22
|
-
|
23
|
-
# Find the virtual machines
|
24
|
-
resources
|
25
|
-
|
26
|
-
create_tag_methods
|
27
|
-
end
|
28
|
-
|
29
|
-
# Method to catch calls that are not explicitly defined.
|
30
|
-
# This allows the simple attributes of the virtual machine to be read without having
|
31
|
-
# to define each one in turn.
|
32
|
-
#
|
33
|
-
# rubocop:disable Metrics/AbcSize
|
34
|
-
#
|
35
|
-
# @param symobl method_id The symbol of the method that has been called
|
36
|
-
#
|
37
|
-
# @return Value of attribute that has been called
|
38
|
-
def method_missing(method_id)
|
39
|
-
# Depending on the method that has been called, determine what value should be returned
|
40
|
-
# These are set as camel case methods to comply with rubocop
|
41
|
-
image_reference_attrs = %w{sku publisher offer}
|
42
|
-
osdisk_attrs = %w{os_type caching create_option disk_size_gb}
|
43
|
-
hardware_profile_attrs = %w{vm_size}
|
44
|
-
os_profile_attrs = %w{computer_name admin_username}
|
45
|
-
osdisk_managed_disk_attrs = %w{storage_account_type}
|
46
|
-
|
47
|
-
# determine the method name to call by converting the snake_case to camelCase
|
48
|
-
# method_name = self.camel_case(method_id.to_s)
|
49
|
-
method_name = method_id.to_s.split("_").inject([]) { |buffer, e| buffer.push(buffer.empty? ? e : e.capitalize) }.join
|
50
|
-
method_name.end_with?("Gb") ? method_name.gsub!(/Gb/, &:upcase) : false
|
51
|
-
|
52
|
-
if image_reference_attrs.include?(method_id.to_s)
|
53
|
-
properties.storageProfile.imageReference.send(method_name)
|
54
|
-
elsif osdisk_attrs.include?(method_id.to_s)
|
55
|
-
properties.storageProfile.osDisk.send(method_name)
|
56
|
-
elsif hardware_profile_attrs.include?(method_id.to_s)
|
57
|
-
properties.hardwareProfile.send(method_name)
|
58
|
-
elsif os_profile_attrs.include?(method_id.to_s)
|
59
|
-
properties.osProfile.send(method_name)
|
60
|
-
elsif osdisk_managed_disk_attrs.include?(method_id.to_s)
|
61
|
-
properties.storageProfile.osDisk.managedDisk.send(method_name)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
# Return the name of the os disk
|
66
|
-
#
|
67
|
-
# @return string Name of the OS disk
|
68
|
-
def os_disk_name
|
69
|
-
properties.storageProfile.osDisk.name
|
70
|
-
end
|
71
|
-
|
72
|
-
# Determine if the OS disk is a managed disk
|
73
|
-
#
|
74
|
-
# @return boolean
|
75
|
-
def has_managed_osdisk?
|
76
|
-
defined?(properties.storageProfile.osDisk.managedDisk)
|
77
|
-
end
|
78
|
-
|
79
|
-
# Does the machine have any NICs connected
|
80
|
-
#
|
81
|
-
# @return boolean
|
82
|
-
def has_nics?
|
83
|
-
properties.networkProfile.networkInterfaces.count != 0
|
84
|
-
end
|
85
|
-
|
86
|
-
# How many NICs are connected to the machine
|
87
|
-
#
|
88
|
-
# @return integer
|
89
|
-
def nic_count
|
90
|
-
properties.networkProfile.networkInterfaces.count
|
91
|
-
end
|
92
|
-
|
93
|
-
# Return an array of the connected NICs so that it can be tested to ensure
|
94
|
-
# the machine is connected properly
|
95
|
-
#
|
96
|
-
# @return array Array of NIC names connected to the machine
|
97
|
-
def connected_nics
|
98
|
-
nic_names = []
|
99
|
-
properties.networkProfile.networkInterfaces.each do |nic|
|
100
|
-
nic_names << nic.id.split(%r{/}).last
|
101
|
-
end
|
102
|
-
nic_names
|
103
|
-
end
|
104
|
-
|
105
|
-
# Whether the machine has data disks or not
|
106
|
-
#
|
107
|
-
# @return boolean
|
108
|
-
def has_data_disks?
|
109
|
-
properties.storageProfile.dataDisks.count != 0
|
110
|
-
end
|
111
|
-
|
112
|
-
# How many data disks are connected
|
113
|
-
#
|
114
|
-
# @return integer
|
115
|
-
def data_disk_count
|
116
|
-
properties.storageProfile.dataDisks.count
|
117
|
-
end
|
118
|
-
|
119
|
-
# Does the machine allow password authentication
|
120
|
-
#
|
121
|
-
# This allows the use of
|
122
|
-
# it { should have_password_authentication }
|
123
|
-
# within the InSpec profile
|
124
|
-
#
|
125
|
-
# @return boolean
|
126
|
-
def has_password_authentication?
|
127
|
-
password_authentication?
|
128
|
-
end
|
129
|
-
|
130
|
-
# Determine if the machine allows password authentication
|
131
|
-
#
|
132
|
-
# @return boolean
|
133
|
-
def password_authentication?
|
134
|
-
# if the osProfile property has a linuxConfiguration section then interrogate that
|
135
|
-
# otherwise it is a Windows machine and that always has password auth
|
136
|
-
if defined?(properties.osProfile.linuxConfiguration)
|
137
|
-
!properties.osProfile.linuxConfiguration.disablePasswordAuthentication
|
138
|
-
else
|
139
|
-
true
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
# Has the machine been given Custom Data at creation
|
144
|
-
#
|
145
|
-
# This allows the use of
|
146
|
-
# it { should have_custom_data }
|
147
|
-
# within the InSpec Profile
|
148
|
-
#
|
149
|
-
# @return boolean
|
150
|
-
def has_custom_data?
|
151
|
-
custom_data?
|
152
|
-
end
|
153
|
-
|
154
|
-
# Determine if custom data has been set
|
155
|
-
#
|
156
|
-
# @return boolean
|
157
|
-
def custom_data?
|
158
|
-
if defined?(properties.osProfile.CustomData)
|
159
|
-
true
|
160
|
-
else
|
161
|
-
false
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
# Are any SSH Keys assigned to the machine
|
166
|
-
#
|
167
|
-
# This allows the use of
|
168
|
-
# it { should have_ssh_keys }
|
169
|
-
# within the InSpec Profile
|
170
|
-
#
|
171
|
-
# @return boolean
|
172
|
-
def has_ssh_keys?
|
173
|
-
ssh_keys?
|
174
|
-
end
|
175
|
-
|
176
|
-
# Determine if any ssh keys have been asigned to the machine
|
177
|
-
#
|
178
|
-
# @return boolean
|
179
|
-
def ssh_keys?
|
180
|
-
if defined?(properties.osProfile.linuxConfiguration.ssh)
|
181
|
-
properties.osProfile.linuxConfiguration.ssh.publicKeys != 0
|
182
|
-
else
|
183
|
-
false
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
# Return the number of ssh keys that have been assigned to the machine
|
188
|
-
#
|
189
|
-
# @return integer
|
190
|
-
def ssh_key_count
|
191
|
-
if defined?(properties.osProfile.linuxConfiguration.ssh)
|
192
|
-
properties.osProfile.linuxConfiguration.ssh.publicKeys.count
|
193
|
-
else
|
194
|
-
0
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
# Determine is the specified key is in the ssh_keys list
|
199
|
-
#
|
200
|
-
# @return array Array of the public keys that are assigned to allow for testing of that key
|
201
|
-
def ssh_keys
|
202
|
-
# iterate around the keys
|
203
|
-
keys = []
|
204
|
-
properties.osProfile.linuxConfiguration.ssh.publicKeys.each do |key|
|
205
|
-
keys << key.keyData
|
206
|
-
end
|
207
|
-
keys
|
208
|
-
end
|
209
|
-
|
210
|
-
# Does the machine have boot diagnostics enabled
|
211
|
-
#
|
212
|
-
# @return boolean
|
213
|
-
def has_boot_diagnostics?
|
214
|
-
if defined?(properties.diagnosticsProfile)
|
215
|
-
properties.diagnosticsProfile.bootDiagnostics.enabled
|
216
|
-
else
|
217
|
-
false
|
218
|
-
end
|
219
|
-
end
|
220
|
-
|
221
|
-
# Return the URI that has been set for the boot diagnostics storage
|
222
|
-
#
|
223
|
-
# @return string
|
224
|
-
def boot_diagnostics_storage_uri
|
225
|
-
properties.diagnosticsProfile.bootDiagnostics.storageUri
|
226
|
-
end
|
227
|
-
|
228
|
-
# If this is a windows machine, returns whether the agent was provisioned or not
|
229
|
-
#
|
230
|
-
# @return boolean
|
231
|
-
def has_provision_vmagent?
|
232
|
-
if defined?(properties.osProfile.windowsConfiguration)
|
233
|
-
properties.osProfile.windowsConfiguration.provisionVMAgent
|
234
|
-
else
|
235
|
-
false
|
236
|
-
end
|
237
|
-
end
|
238
|
-
|
239
|
-
# If a windows machine see if automatic updates for the agent are enabled
|
240
|
-
#
|
241
|
-
# @return boolean
|
242
|
-
def has_automatic_agent_update?
|
243
|
-
if defined?(properties.osProfile.windowsConfiguration)
|
244
|
-
properties.osProfile.windowsConfiguration.enableAutomaticUpdates
|
245
|
-
else
|
246
|
-
false
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
# If this is a windows machine return a boolean to state of the WinRM options
|
251
|
-
# have been set
|
252
|
-
#
|
253
|
-
# @return boolean
|
254
|
-
def has_winrm_options?
|
255
|
-
if defined?(properties.osProfile.windowsConfiguration) && defined?(properties.osProfile.windowsConfiguration.winrm)
|
256
|
-
properties.osProfile.windowsConfiguration.winrm.protocol
|
257
|
-
else
|
258
|
-
false
|
259
|
-
end
|
260
|
-
end
|
261
|
-
end
|
262
|
-
end
|
@@ -1,131 +0,0 @@
|
|
1
|
-
require "resources/azure/azure_backend"
|
2
|
-
require "uri" unless defined?(URI)
|
3
|
-
|
4
|
-
module Inspec::Resources
|
5
|
-
class AzureVirtualMachineDataDisk < AzureResourceBase
|
6
|
-
name "azure_virtual_machine_data_disk"
|
7
|
-
|
8
|
-
desc '
|
9
|
-
InSpec Resource to ensure that the data disks attached to a machine are correct
|
10
|
-
'
|
11
|
-
|
12
|
-
supports platform: "azure"
|
13
|
-
|
14
|
-
# Create a filter table so that tests on the disk can be performed
|
15
|
-
filter = FilterTable.create
|
16
|
-
filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
|
17
|
-
filter.register_column(:disk, field: :disk)
|
18
|
-
.register_column(:number, field: :number)
|
19
|
-
.register_column(:name, field: :name)
|
20
|
-
.register_column(:size, field: :size)
|
21
|
-
.register_column(:vhd_uri, field: :vhd_uri)
|
22
|
-
.register_column(:storage_account_name, field: :storage_account_name)
|
23
|
-
.register_column(:lun, field: :lun)
|
24
|
-
.register_column(:caching, field: :caching)
|
25
|
-
.register_column(:create_option, field: :create_option)
|
26
|
-
.register_column(:is_managed_disk?, field: :is_managed_disk?)
|
27
|
-
.register_column(:storage_account_type, field: :storage_account_type)
|
28
|
-
.register_column(:subscription_id, field: :subscription_id)
|
29
|
-
.register_column(:resource_group, field: :resource_group)
|
30
|
-
filter.install_filter_methods_on_resource(self, :datadisk_details)
|
31
|
-
|
32
|
-
# Constructor for the resource. This calls the parent constructor to
|
33
|
-
# get the generic resource for the specified machine. This will provide
|
34
|
-
# static methods that are documented
|
35
|
-
#
|
36
|
-
# @author Russell Seymour
|
37
|
-
def initialize(opts = {})
|
38
|
-
# The generic resource needs to pass back a Microsoft.Compute/virtualMachines object so force it
|
39
|
-
opts[:type] = "Microsoft.Compute/virtualMachines"
|
40
|
-
super(opts)
|
41
|
-
|
42
|
-
# Get the data disks
|
43
|
-
resources
|
44
|
-
end
|
45
|
-
|
46
|
-
# Return information about the disks and add to the filter table so that
|
47
|
-
# assertions can be performed
|
48
|
-
#
|
49
|
-
# @author Russell Seymour
|
50
|
-
def datadisk_details
|
51
|
-
return if failed_resource?
|
52
|
-
|
53
|
-
# Iterate around the data disks on the machine
|
54
|
-
properties.storageProfile.dataDisks.each_with_index.map do |datadisk, index|
|
55
|
-
# Call function to parse the data disks and return an object based on the parameters
|
56
|
-
parse_datadisk(datadisk, index)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
# Return boolean to denote if the machine has data disks attached or not
|
61
|
-
def has_data_disks?
|
62
|
-
!entries.empty?
|
63
|
-
end
|
64
|
-
|
65
|
-
# Return an integer stating how many data disks are attached to the machine
|
66
|
-
def count
|
67
|
-
entries.count
|
68
|
-
end
|
69
|
-
|
70
|
-
# Return boolean to state if the machine is using managed disks for data disks
|
71
|
-
def has_managed_disks?
|
72
|
-
# iterate around the entries
|
73
|
-
result = entries.each.select { |e| e[:is_managed_disk?] }
|
74
|
-
result.empty? ? false : true
|
75
|
-
end
|
76
|
-
|
77
|
-
private
|
78
|
-
|
79
|
-
# Parse the data disk to determine if these are managed disks or in a storage account
|
80
|
-
# for example. The disk index, name and size will be returned
|
81
|
-
#
|
82
|
-
# params object disk Object containing the details of the disk
|
83
|
-
# params integer index Index denoting which disk number this is on the machine
|
84
|
-
#
|
85
|
-
# return hashtable
|
86
|
-
def parse_datadisk(disk, index)
|
87
|
-
# Configure parsed hashtable to hold the information
|
88
|
-
# Initialize this with common attributes from the different types of disk
|
89
|
-
parsed = {
|
90
|
-
disk: index,
|
91
|
-
number: index + 1,
|
92
|
-
lun: disk.lun,
|
93
|
-
name: disk.name,
|
94
|
-
size: disk.diskSizeGB,
|
95
|
-
caching: disk.caching,
|
96
|
-
create_option: disk.createOption,
|
97
|
-
}
|
98
|
-
|
99
|
-
# Determine if the current disk is a managed disk or not
|
100
|
-
if defined?(disk.vhd)
|
101
|
-
# As this is in a storage account this is not a managed disk
|
102
|
-
parsed[:is_managed_disk?] = false
|
103
|
-
|
104
|
-
# Set information about the disk
|
105
|
-
# Parse the uri of the disk URI so that the storage account can be retrieved
|
106
|
-
uri = URI.parse(disk.vhd.uri)
|
107
|
-
parsed[:vhd_uri] = disk.vhd.uri
|
108
|
-
parsed[:storage_account_name] = uri.host.split(".").first
|
109
|
-
|
110
|
-
elsif defined?(disk.managedDisk)
|
111
|
-
# State that this is a managed disk
|
112
|
-
parsed[:is_managed_disk?] = true
|
113
|
-
|
114
|
-
# Get information about the managed disk
|
115
|
-
parsed[:storage_account_type] = disk.managedDisk.storageAccountType
|
116
|
-
parsed[:id] = disk.managedDisk.id
|
117
|
-
|
118
|
-
# Break up the ID string so that the following information can get retrieved
|
119
|
-
# - subscription_id
|
120
|
-
# - resource_group
|
121
|
-
id_parts = parsed[:id].split(%r{/}).reject(&:empty?)
|
122
|
-
|
123
|
-
parsed[:subscription_id] = id_parts[1]
|
124
|
-
parsed[:resource_group] = id_parts[3]
|
125
|
-
end
|
126
|
-
|
127
|
-
# return the parsed object
|
128
|
-
parsed
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|