inspec 3.0.61 → 3.0.64

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile DELETED
@@ -1,57 +0,0 @@
1
- # encoding: utf-8
2
- source 'https://rubygems.org'
3
- gemspec name: 'inspec'
4
-
5
- if Gem::Version.new(RUBY_VERSION) < Gem::Version.new('2.2.2')
6
- gem 'json', '~> 1.8'
7
- gem 'rack', '< 2.0'
8
- end
9
-
10
- gem 'ffi', '>= 1.9.14'
11
- gem 'aws-sdk', '~> 2'
12
-
13
- group :test do
14
- gem 'bundler', '~> 1.5'
15
- gem 'minitest', '~> 5.5'
16
- gem 'rake', '>= 10'
17
- gem 'rubocop', '= 0.49.1'
18
- gem 'simplecov', '~> 0.10'
19
- gem 'concurrent-ruby', '~> 1.0'
20
- gem 'mocha', '~> 1.1'
21
- gem 'ruby-progressbar', '~> 1.8'
22
- gem 'webmock', '~> 2.3.2'
23
- gem 'jsonschema', '~> 2.0.2'
24
- gem 'passgen'
25
- gem 'm'
26
- gem 'pry-byebug'
27
- end
28
-
29
- group :integration do
30
- gem 'berkshelf', '~> 5.2'
31
- gem 'test-kitchen', '~> 1.6'
32
- gem 'kitchen-vagrant'
33
- # we need winrm v2 support >= 0.15.1
34
- gem 'kitchen-inspec', '>= 0.15.1'
35
- gem 'kitchen-ec2'
36
- gem 'kitchen-dokken'
37
- end
38
-
39
- group :tools do
40
- gem 'pry', '~> 0.10'
41
- gem 'rb-readline'
42
- gem 'license_finder'
43
- gem 'git', '~> 1.4'
44
- end
45
-
46
- # gems for Maintainers.md generation
47
- group :maintenance do
48
- gem 'tomlrb'
49
-
50
- # To sync maintainers with github
51
- gem 'octokit'
52
- gem 'netrc'
53
- end
54
-
55
- group :deploy do
56
- gem 'inquirer'
57
- end
data/MAINTAINERS.md DELETED
@@ -1,33 +0,0 @@
1
- <!-- This is a generated file. Please do not edit directly -->
2
-
3
- <!-- Modify MAINTAINERS.toml and run `rake maintainers:generate` to regenerate. -->
4
-
5
- # Maintainers
6
-
7
- This file lists how the InSpec project is maintained. When making changes to the
8
- system, this file tells you who needs to review your patch - you need at least
9
- two maintainers to provide a :+1: on your pull request. Additionally, you need
10
- to not receive a veto from a Lieutenant or the Project Lead.
11
- Check out [How Chef is Maintained](https://github.com/chef/chef-rfc/blob/master/rfc030-maintenance-policy.md#how-the-project-is-maintained)
12
- for details on the process, how to become a maintainer, lieutenant, or the
13
- project lead.
14
-
15
- ## Components
16
-
17
- ## InSpec
18
-
19
- Handles the [InSpec](https://github.com/chef/inspec) toolset.
20
-
21
- To mention the team, use @chef/inspec-maintainers
22
-
23
- ### Lieutenant
24
-
25
- * [Dominik Richter](https://github.com/arlimus)
26
-
27
- ### Maintainers
28
-
29
- * [Christoph Hartmann](https://github.com/chris-rock)
30
- * [Adam Leff](https://github.com/adamleff)
31
- * [Alex Pop](https://github.com/alexpop)
32
- * [Jared Quick](https://github.com/jquick)
33
-
data/Rakefile DELETED
@@ -1,392 +0,0 @@
1
- #!/usr/bin/env rake
2
- # encoding: utf-8
3
-
4
- require 'bundler'
5
- require 'bundler/gem_helper'
6
- require 'rake/testtask'
7
- require 'passgen'
8
- require 'train'
9
- require_relative 'tasks/maintainers'
10
- require_relative 'tasks/spdx'
11
-
12
- Bundler::GemHelper.install_tasks name: 'inspec'
13
-
14
- def prompt(message)
15
- print(message)
16
- STDIN.gets.chomp
17
- end
18
-
19
- # The docs tasks rely on ruby-progressbar. If we can't load it, then don't
20
- # load the docs tasks. This is necessary to allow this Rakefile to work
21
- # when the "tests" gem group in the Gemfile has been excluded, such as
22
- # during an appbundle-updater run.
23
- begin
24
- require 'ruby-progressbar'
25
- require_relative 'tasks/docs'
26
- rescue LoadError
27
- puts 'docs tasks are unavailable because the ruby-progressbar gem is not available.'
28
- end
29
-
30
- begin
31
- require 'git'
32
- require_relative 'tasks/contrib'
33
- rescue LoadError
34
- puts 'contrib tasks are unavailable because the git gem is not available.'
35
- end
36
-
37
- # Rubocop
38
- begin
39
- require 'rubocop/rake_task'
40
- RuboCop::RakeTask.new(:lint)
41
- rescue LoadError
42
- puts 'rubocop is not available. Install the rubocop gem to run the lint tests.'
43
- end
44
-
45
- # update command output for demo
46
- desc 'Run inspec commands and save results to www/app/responses'
47
- task :update_demo do
48
- ruby 'www/tutorial/scripts/build_simulator_runtime.rb'
49
- ruby 'www/tutorial/scripts/run_simulator_recording.rb'
50
- end
51
-
52
- # run tests
53
- task default: [:lint, :test]
54
-
55
- Rake::TestTask.new do |t|
56
- t.libs << 'test'
57
- t.test_files = Dir.glob([
58
- 'test/unit/**/*_test.rb',
59
- 'lib/plugins/inspec-*/test/unit/**/*_test.rb',
60
- ])
61
- t.warning = false
62
- t.verbose = true
63
- t.ruby_opts = ['--dev'] if defined?(JRUBY_VERSION)
64
- end
65
-
66
- namespace :test do
67
- task :isolated do
68
- Dir.glob('test/unit/*_test.rb').all? do |file|
69
- sh(Gem.ruby, '-w', '-Ilib:test', file)
70
- end or fail 'Failures'
71
- end
72
-
73
- Rake::TestTask.new(:functional) do |t|
74
- t.libs << 'test'
75
- t.test_files = Dir.glob([
76
- 'test/functional/**/*_test.rb',
77
- 'lib/plugins/inspec-*/test/functional/**/*_test.rb',
78
- ])
79
- t.warning = true
80
- t.verbose = true
81
- t.ruby_opts = ['--dev'] if defined?(JRUBY_VERSION)
82
- end
83
-
84
- # Functional tests on Windows take a bit to run. This
85
- # optionally takes a env to breake the tests up into 3 workers.
86
- Rake::TestTask.new(:'functional:windows') do |t, args|
87
- files = Dir.glob('test/functional/*_test.rb').sort
88
- if ENV['WORKER_NUMBER']
89
- count = (files.count / 3).abs+1
90
- start = (ENV['WORKER_NUMBER'].to_i - 1) * count
91
- files = files[start..start+count-1]
92
- end
93
-
94
- t.libs << 'test'
95
- t.test_files = files
96
- t.warning = true
97
- t.verbose = true
98
- t.ruby_opts = ['--dev'] if defined?(JRUBY_VERSION)
99
- end
100
-
101
- task :resources do
102
- tests = Dir['test/resource/*_test.rb']
103
- return if tests.empty?
104
- sh(Gem.ruby, 'test/docker_test.rb', *tests)
105
- end
106
-
107
- task :integration, [:os] do |task, args|
108
- concurrency = ENV['CONCURRENCY'] || 1
109
- os = args[:os] || ENV['OS'] || ''
110
- ENV['DOCKER'] = 'true' if ENV['docker'].nil?
111
- puts "Building current InSpec gem for audit cookbook testing..."
112
- output = %x[gem build inspec-core.gemspec]
113
- puts output
114
- gem_name = output.split("\n")[-1].split(':')[1].strip
115
- path = File.dirname(__FILE__)
116
- File.rename(File.join(path, gem_name), File.join(path, 'inspec-core-local.gem'))
117
- destination = File.join(path, 'test', 'cookbooks', 'os_prepare', 'files', 'inspec-core-local.gem')
118
- begin
119
- FileUtils.cp(File.join(path, 'inspec-core-local.gem'), destination)
120
- sh("bundle exec kitchen test -c #{concurrency} #{os}")
121
- ensure
122
- FileUtils.rm(destination)
123
- end
124
- end
125
-
126
- task :ssh, [:target] do |_t, args|
127
- tests_path = File.join(File.dirname(__FILE__), 'test', 'integration', 'test', 'integration', 'default')
128
- key_files = ENV['key_files'] || File.join(ENV['HOME'], '.ssh', 'id_rsa')
129
-
130
- sh_cmd = "bin/inspec exec #{tests_path}/"
131
- sh_cmd += ENV['test'] ? "#{ENV['test']}_spec.rb" : '*'
132
- sh_cmd += " --sudo" unless args[:target].split('@')[0] == 'root'
133
- sh_cmd += " -t ssh://#{args[:target]}"
134
- sh_cmd += " --key_files=#{key_files}"
135
- sh_cmd += " --format=#{ENV['format']}" if ENV['format']
136
-
137
- sh('sh', '-c', sh_cmd)
138
- end
139
-
140
- project_dir = File.dirname(__FILE__)
141
- namespace :aws do
142
- ['default', 'minimal'].each do |account|
143
- integration_dir = File.join(project_dir, 'test', 'integration', 'aws', account)
144
- attribute_file = File.join(integration_dir, '.attribute.yml')
145
-
146
- task :"setup:#{account}", :tf_workspace do |t, args|
147
- tf_workspace = args[:tf_workspace] || ENV['INSPEC_TERRAFORM_ENV']
148
- abort("You must either call the top-level test:aws:#{account} task, or set the INSPEC_TERRAFORM_ENV variable.") unless tf_workspace
149
- puts "----> Setup"
150
- abort("You must set the environment variable AWS_REGION") unless ENV['AWS_REGION']
151
- puts "----> Checking for required AWS profile..."
152
- sh("aws configure get aws_access_key_id --profile inspec-aws-test-#{account} > /dev/null")
153
- sh("cd #{integration_dir}/build/ && terraform init -upgrade")
154
- sh("cd #{integration_dir}/build/ && terraform workspace new #{tf_workspace}")
155
- sh("cd #{integration_dir}/build/ && AWS_PROFILE=inspec-aws-test-#{account} terraform plan -out inspec-aws-#{account}.plan")
156
- sh("cd #{integration_dir}/build/ && AWS_PROFILE=inspec-aws-test-#{account} terraform apply -auto-approve inspec-aws-#{account}.plan")
157
- Rake::Task["test:aws:dump_attrs:#{account}"].execute
158
- end
159
-
160
- task :"dump_attrs:#{account}" do
161
- sh("cd #{integration_dir}/build/ && AWS_PROFILE=inspec-aws-test-#{account} terraform output > #{attribute_file}")
162
- raw_output = File.read(attribute_file)
163
- yaml_output = raw_output.gsub(" = ", " : ")
164
- File.open(attribute_file, "w") {|file| file.puts yaml_output}
165
- end
166
-
167
- task :"run:#{account}" do
168
- puts "----> Run"
169
- sh("bundle exec inspec exec #{integration_dir}/verify -t aws://${AWS_REGION}/inspec-aws-test-#{account} --attrs #{attribute_file}")
170
- end
171
-
172
- task :"cleanup:#{account}", :tf_workspace do |t, args|
173
- tf_workspace = args[:tf_workspace] || ENV['INSPEC_TERRAFORM_ENV']
174
- abort("You must either call the top-level test:aws:#{account} task, or set the INSPEC_TERRAFORM_ENV variable.") unless tf_workspace
175
- puts "----> Cleanup"
176
- sh("cd #{integration_dir}/build/ && AWS_PROFILE=inspec-aws-test-#{account} terraform destroy -force")
177
- sh("cd #{integration_dir}/build/ && terraform workspace select default")
178
- sh("cd #{integration_dir}/build && terraform workspace delete #{tf_workspace}")
179
- end
180
-
181
- task :"#{account}" do
182
- tf_workspace = ENV['INSPEC_TERRAFORM_ENV'] || prompt("Please enter a workspace for your integration tests to run in: ")
183
- begin
184
- Rake::Task["test:aws:setup:#{account}"].execute({:tf_workspace => tf_workspace})
185
- Rake::Task["test:aws:run:#{account}"].execute
186
- rescue
187
- abort("Integration testing has failed for the #{account} account")
188
- ensure
189
- Rake::Task["test:aws:cleanup:#{account}"].execute({:tf_workspace => tf_workspace})
190
- end
191
- end
192
- end
193
- end
194
- desc "Perform AWS Integration Tests"
195
- task aws: [:'aws:default', :'aws:minimal']
196
-
197
- namespace :azure do
198
- # Specify the directory for the integration tests
199
- integration_dir = File.join(project_dir, 'test', 'integration', 'azure')
200
- tf_vars_file = File.join(integration_dir, 'build', 'terraform.tfvars')
201
- attribute_file = File.join(integration_dir, '.attribute.yml')
202
-
203
- task :setup, :tf_workspace do |t, args|
204
- tf_workspace = args[:tf_workspace] || ENV['INSPEC_TERRAFORM_ENV']
205
- abort("You must either call the top-level test:azure task, or set the INSPEC_TERRAFORM_ENV variable.") unless tf_workspace
206
-
207
- puts '----> Setup Terraform Workspace'
208
-
209
- sh("cd #{integration_dir}/build/ && terraform init -upgrade")
210
- sh("cd #{integration_dir}/build/ && terraform workspace new #{tf_workspace}")
211
-
212
- Rake::Task["test:azure:vars"].execute
213
- Rake::Task["test:azure:plan"].execute
214
- Rake::Task["test:azure:apply"].execute
215
- end
216
-
217
- desc "Generate terraform.tfvars file"
218
- task :vars do |t, args|
219
-
220
- next if File.exist?(tf_vars_file)
221
-
222
- puts '----> Generating Vars'
223
-
224
- # Generate Azure crendentials
225
- connection = Train.create('azure').connection
226
- creds = connection.options
227
-
228
- # Determine the storage account name and the admin password
229
- sa_name = (0...15).map { (65 + rand(26)).chr }.join.downcase
230
- admin_password = Passgen::generate(length: 12, uppercase: true, lowercase: true, symbols: true, digits: true)
231
-
232
- # Use the first 4 characters of the storage account to create a suffix
233
- suffix = sa_name[0..3]
234
-
235
- content = <<~VARS
236
- subscription_id = "#{creds[:subscription_id]}"
237
- client_id = "#{creds[:client_id]}"
238
- client_secret = "#{creds[:client_secret]}"
239
- tenant_id = "#{creds[:tenant_id]}"
240
- storage_account_name = "#{sa_name}"
241
- admin_password = "#{admin_password}"
242
- suffix = "#{suffix}"
243
- VARS
244
-
245
- content << "location = \"#{ENV['AZURE_LOCATION']}\"\n" if ENV['AZURE_LOCATION']
246
-
247
- File.write(tf_vars_file, content)
248
- end
249
-
250
- desc "generate plan from state using terraform.tfvars file"
251
- task :plan, [:tf_workspace] => [:vars] do |t, args|
252
- tf_workspace = args[:tf_workspace] || ENV['INSPEC_TERRAFORM_ENV']
253
- abort("You must set the INSPEC_TERRAFORM_ENV variable.") unless tf_workspace
254
-
255
- puts '----> Generating Plan'
256
-
257
- result = sh("cd #{integration_dir}/build/ && terraform workspace select #{tf_workspace}")
258
-
259
- sh("cd #{integration_dir}/build/ && terraform plan -out inspec-azure.plan")
260
- end
261
-
262
- desc "apply terraform plan"
263
- task :apply, [:tf_workspace] => [:plan] do |t, args|
264
- tf_workspace = args[:tf_workspace] || ENV['INSPEC_TERRAFORM_ENV']
265
- abort("You must set the INSPEC_TERRAFORM_ENV variable.") unless tf_workspace
266
- puts '----> Applying Plan'
267
-
268
- sh("cd #{integration_dir}/build/ && terraform workspace select #{tf_workspace}")
269
-
270
- sh("cd #{integration_dir}/build/ && terraform apply inspec-azure.plan")
271
-
272
- Rake::Task["test:azure:dump_attrs"].execute
273
- end
274
-
275
- task :"dump_attrs" do
276
- sh("cd #{integration_dir}/build/ && terraform output > #{attribute_file}")
277
- raw_output = File.read(attribute_file)
278
- yaml_output = raw_output.gsub(" = ", " : ")
279
- File.open(attribute_file, "w") {|file| file.puts yaml_output}
280
- end
281
-
282
- task :run do
283
- puts '----> Run'
284
- sh("bundle exec inspec exec #{integration_dir}/verify -t azure://1e0b427a-d58b-494e-ae4f-ee558463ebbf")
285
- end
286
-
287
- task :cleanup, :tf_workspace do |t, args|
288
- tf_workspace = args[:tf_workspace] || ENV['INSPEC_TERRAFORM_ENV']
289
- abort("You must either call the top-level test:azure task, or set the INSPEC_TERRAFORM_ENV variable.") unless tf_workspace
290
- puts '----> Cleanup'
291
-
292
- sh("cd #{integration_dir}/build/ && terraform destroy -force ")
293
-
294
- sh("cd #{integration_dir}/build/ && terraform workspace select default")
295
- sh("cd #{integration_dir}/build && terraform workspace delete #{tf_workspace}")
296
- File.delete(tf_vars_file)
297
- end
298
- end
299
-
300
- desc "Perform Azure Integration Tests"
301
- task :azure do
302
- tf_workspace = ENV['INSPEC_TERRAFORM_ENV'] || prompt("Please enter a workspace for your integration tests to run in: ")
303
- begin
304
- Rake::Task["test:azure:setup"].execute({:tf_workspace => tf_workspace})
305
- Rake::Task["test:azure:run"].execute
306
- rescue
307
- abort("Integration testing has failed")
308
- ensure
309
- Rake::Task["test:azure:cleanup"].execute({:tf_workspace => tf_workspace})
310
- end
311
- end
312
- end
313
-
314
- # Print the current version of this gem or update it.
315
- #
316
- # @param [Type] target the new version you want to set, or nil if you only want to show
317
- def inspec_version(target = nil)
318
- path = 'lib/inspec/version.rb'
319
- require_relative path.sub(/.rb$/, '')
320
-
321
- nu_version = target.nil? ? '' : " -> #{target}"
322
- puts "Inspec: #{Inspec::VERSION}#{nu_version}"
323
-
324
- unless target.nil?
325
- raw = File.read(path)
326
- nu = raw.sub(/VERSION.*/, "VERSION = '#{target}'.freeze")
327
- File.write(path, nu)
328
- load(path)
329
- end
330
- end
331
-
332
- # Check if a command is available
333
- #
334
- # @param [Type] x the command you are interested in
335
- # @param [Type] msg the message to display if the command is missing
336
- def require_command(x, msg = nil)
337
- return if system("command -v #{x} || exit 1")
338
- msg ||= 'Please install it first!'
339
- puts "\033[31;1mCan't find command #{x.inspect}. #{msg}\033[0m"
340
- exit 1
341
- end
342
-
343
- # Check if a required environment variable has been set
344
- #
345
- # @param [String] x the variable you are interested in
346
- # @param [String] msg the message you want to display if the variable is missing
347
- def require_env(x, msg = nil)
348
- exists = `env | grep "^#{x}="`
349
- return unless exists.empty?
350
- puts "\033[31;1mCan't find environment variable #{x.inspect}. #{msg}\033[0m"
351
- exit 1
352
- end
353
-
354
- # Check the requirements for running an update of this repository.
355
- def check_update_requirements
356
- require_command 'git'
357
- end
358
-
359
- # Show the current version of this gem.
360
- desc 'Show the version of this gem'
361
- task :version do
362
- inspec_version
363
- end
364
-
365
- desc 'Release a new docker image'
366
- task :release_docker do
367
- version = Inspec::VERSION
368
- cmd = "rm *.gem; gem build *gemspec && "\
369
- "mv *.gem inspec.gem && "\
370
- "docker build -t chef/inspec:#{version} . && "\
371
- "docker push chef/inspec:#{version} && "\
372
- "docker tag chef/inspec:#{version} chef/inspec:latest &&"\
373
- "docker push chef/inspec:latest"
374
- puts "--> #{cmd}"
375
- sh('sh', '-c', cmd)
376
- end
377
-
378
- desc 'Release the website [deprecated]'
379
- task :www do
380
- puts 'The Rake tasks for releasing the website are now in the www/ directory.'
381
- puts 'Run `cd www` and then `rake --tasks` for a list of the www-related tasks available.'
382
- exit(1)
383
- end
384
-
385
- namespace :www do
386
- desc 'Release the website [deprecated]'
387
- task :release do
388
- puts 'The Rake tasks for releasing the website are now in the www/ directory.'
389
- puts 'Run `cd www` and then `rake --tasks` for a list of the www-related tasks available.'
390
- exit(1)
391
- end
392
- end