inspec 2.2.112 → 2.3.4

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.
Files changed (66) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +8 -2
  3. data/CHANGELOG.md +42 -19
  4. data/README.md +1 -1
  5. data/Rakefile +16 -3
  6. data/docs/dev/integration-testing.md +31 -0
  7. data/docs/dev/plugins.md +4 -2
  8. data/docs/dsl_inspec.md +104 -4
  9. data/docs/plugins.md +57 -0
  10. data/docs/resources/aws_ebs_volume.md.erb +76 -0
  11. data/docs/resources/aws_ebs_volumes.md.erb +86 -0
  12. data/docs/style.md +178 -0
  13. data/examples/plugins/inspec-resource-lister/Gemfile +12 -0
  14. data/examples/plugins/inspec-resource-lister/LICENSE +13 -0
  15. data/examples/plugins/inspec-resource-lister/README.md +62 -0
  16. data/examples/plugins/inspec-resource-lister/Rakefile +40 -0
  17. data/examples/plugins/inspec-resource-lister/inspec-resource-lister.gemspec +45 -0
  18. data/examples/plugins/inspec-resource-lister/lib/inspec-resource-lister.rb +16 -0
  19. data/examples/plugins/inspec-resource-lister/lib/inspec-resource-lister/cli_command.rb +70 -0
  20. data/examples/plugins/inspec-resource-lister/lib/inspec-resource-lister/plugin.rb +55 -0
  21. data/examples/plugins/inspec-resource-lister/lib/inspec-resource-lister/version.rb +10 -0
  22. data/examples/plugins/inspec-resource-lister/test/fixtures/README.md +24 -0
  23. data/examples/plugins/inspec-resource-lister/test/functional/README.md +18 -0
  24. data/examples/plugins/inspec-resource-lister/test/functional/inspec_resource_lister_test.rb +110 -0
  25. data/examples/plugins/inspec-resource-lister/test/helper.rb +26 -0
  26. data/examples/plugins/inspec-resource-lister/test/unit/README.md +17 -0
  27. data/examples/plugins/inspec-resource-lister/test/unit/cli_args_test.rb +64 -0
  28. data/examples/plugins/inspec-resource-lister/test/unit/plugin_def_test.rb +51 -0
  29. data/examples/profile/controls/example.rb +9 -8
  30. data/inspec.gemspec +2 -1
  31. data/lib/inspec/attribute_registry.rb +1 -1
  32. data/lib/inspec/globals.rb +4 -0
  33. data/lib/inspec/objects/control.rb +18 -3
  34. data/lib/inspec/plugin/v2.rb +14 -3
  35. data/lib/inspec/plugin/v2/activator.rb +7 -2
  36. data/lib/inspec/plugin/v2/installer.rb +426 -0
  37. data/lib/inspec/plugin/v2/loader.rb +137 -30
  38. data/lib/inspec/plugin/v2/registry.rb +13 -4
  39. data/lib/inspec/profile.rb +2 -1
  40. data/lib/inspec/reporters/json.rb +11 -1
  41. data/lib/inspec/resource.rb +6 -15
  42. data/lib/inspec/rule.rb +18 -9
  43. data/lib/inspec/runner_rspec.rb +1 -1
  44. data/lib/inspec/schema.rb +1 -0
  45. data/lib/inspec/version.rb +1 -1
  46. data/lib/plugins/inspec-plugin-manager-cli/README.md +6 -0
  47. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli.rb +18 -0
  48. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb +420 -0
  49. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/plugin.rb +12 -0
  50. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/config_dirs/empty/.gitkeep +0 -0
  51. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-egg-white-omelette/lib/inspec-egg-white-omelette.rb +2 -0
  52. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-egg-white-omelette/lib/inspec-egg-white-omelette/.gitkeep +0 -0
  53. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-wrong-structure/.gitkeep +0 -0
  54. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name.rb +1 -0
  55. data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name/.gitkeep +0 -0
  56. data/lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb +651 -0
  57. data/lib/plugins/inspec-plugin-manager-cli/test/unit/cli_args_test.rb +71 -0
  58. data/lib/plugins/inspec-plugin-manager-cli/test/unit/plugin_def_test.rb +20 -0
  59. data/lib/plugins/shared/core_plugin_test_helper.rb +101 -2
  60. data/lib/plugins/things-for-train-integration.rb +14 -0
  61. data/lib/resource_support/aws.rb +2 -0
  62. data/lib/resources/aws/aws_ebs_volume.rb +122 -0
  63. data/lib/resources/aws/aws_ebs_volumes.rb +63 -0
  64. data/lib/resources/port.rb +10 -6
  65. metadata +56 -11
  66. data/docs/ruby_usage.md +0 -204
@@ -0,0 +1,86 @@
1
+ ---
2
+ title: About the aws_ebs_volumes Resource
3
+ platform: aws
4
+ ---
5
+
6
+ # aws\_ebs\_volumes
7
+
8
+ Use the `aws_ebs_volumes` InSpec audit resource to test properties of some or all AWS EBS volumes. To audit a single EBS volume, use `aws_ebs_volume` (singular).
9
+
10
+ EBS volumes are persistent block storage volumes for use with Amazon EC2 instances in the AWS Cloud.
11
+
12
+ Each EBS volume is uniquely identified by its ID.
13
+
14
+ <br>
15
+
16
+ ## Availability
17
+
18
+ ### Installation
19
+
20
+ This resource is distributed along with InSpec itself. You can use it automatically.
21
+
22
+ ## Syntax
23
+
24
+ An `aws_ebs_volumes` resource block collects a group of EBS volumes and then tests that group.
25
+
26
+ # Ensure you have exactly 3 volumes
27
+ describe aws_ebs_volumes do
28
+ its('volume_ids.count') { should cmp 3 }
29
+ end
30
+
31
+ # Use the InSpec resource to enumerate IDs, then test in-depth using `aws_ebs_volume`.
32
+ aws_ebs_volumes.volume_ids.each do |volume_id|
33
+ describe aws_ebs_volume(volume_id) do
34
+ it { should exist }
35
+ it { should be_encrypted }
36
+ its('size') { should cmp 8 }
37
+ its('iops') { should cmp 100 }
38
+ end
39
+ end
40
+
41
+ <br>
42
+
43
+ ## Examples
44
+
45
+ As this is the initial release of `aws_ebs_volumes`, its limited functionality precludes examples.
46
+
47
+ <br>
48
+
49
+ ## Filter Criteria
50
+
51
+ This resource currently does not support any filter criteria; it will always fetch all volumes in the region.
52
+
53
+ ## Properties
54
+
55
+ ### entries
56
+
57
+ Provides access to the raw results of the query, which can be treated as an array of hashes. This can be useful for checking counts and other advanced operations.
58
+
59
+ # Allow at most 100 EBS volumes on the account
60
+ describe aws_ebs_volumes do
61
+ its('entries.count') { should be <= 100 }
62
+ end
63
+
64
+ ### volume_ids
65
+
66
+ Provides a list of the volume ids that were found in the query.
67
+
68
+ describe aws_ebs_volumes do
69
+ its('volume_ids') { should include 'vol-12345678' }
70
+ its('volume_ids.count') { should cmp 3 }
71
+ end
72
+
73
+ <br>
74
+
75
+ ## Matchers
76
+
77
+ For a full list of available matchers, please visit our [Universal Matchers page](https://www.inspec.io/docs/reference/matchers/).
78
+
79
+ ### exist
80
+
81
+ The control will pass if the filter returns at least one result. Use `should_not` if you expect zero matches.
82
+
83
+ # Verify that at least one EBS volume exists
84
+ describe aws_ebs_volumes do
85
+ it { should exist }
86
+ end
data/docs/style.md ADDED
@@ -0,0 +1,178 @@
1
+ # InSpec profile style guide
2
+
3
+ This is a set of recommended InSpec rules you should use when writing controls.
4
+
5
+ ## Control files
6
+
7
+ ### 1. All controls should be located in the "controls" directory and end in ".rb"
8
+
9
+ Reason: Most syntax highlighters will render InSpec files correctly across a wide list of tools.
10
+
11
+ Avoid: `controls/ssh_config`
12
+ Use: `controls/ssh_config.rb`
13
+
14
+ Avoid: `controls/ssh/config.rb`
15
+ Use: `controls/ssh_config.rb`
16
+
17
+ ### 2. Avoid using "controls" or "control" in the name of your control files
18
+
19
+ Reason: Using `controls` in the filename again duplicates it and creates unnecessary clutter when reading it. Keep the names short and concise.
20
+
21
+ Avoid: `controls/ssh_controls.rb`
22
+ Use: `controls/ssh.rb`
23
+
24
+
25
+ ## Code style
26
+
27
+ ### 3. Avoid unnecessary parentheses in matchers
28
+
29
+ Adding additional parentheses is not required and provides more readability if it is not used:
30
+
31
+ Avoid: `it { should eq(value) }`
32
+ Use: `it { should eq value }`
33
+
34
+ The exception are matchers that require additional arguments or named arguments.
35
+
36
+
37
+ ## Controls
38
+
39
+ ### 4. Do not wrap controls in conditional statements
40
+
41
+ Reason: This will create dynamic profiles whose controls depend on the execution. The problem here is that we cannot render the profile or provide its information before scanning a system. We want to be able to inform users of the contents of their profiles before they run them. It is valid to skip controls that are not necessary for a system, as long as you do it via `only_if` conditions. Ruby's internal conditionals will hide parts of the profile to static analysis and should thus be avoided.
42
+
43
+ Avoid:
44
+ ```ruby
45
+ if package('..').installed?
46
+ control "package-test1" do
47
+ ..
48
+ end
49
+ end
50
+ ```
51
+
52
+ Use:
53
+ ```ruby
54
+ control "package-test1" do
55
+ only_if { package('..').installed? }
56
+ end
57
+ ```
58
+
59
+ Avoid:
60
+ ```ruby
61
+ case inspec.platform.name
62
+ when /centos/
63
+ include_controls 'centos-profile'
64
+ ...
65
+ ```
66
+
67
+ Use: The `supports` attribute in `inspec.yml` files of the profile you want to include:
68
+
69
+ ```ruby
70
+ supports:
71
+ - platform-name: centos
72
+ ```
73
+
74
+ Now whenever you run the base profile you can just `include_controls 'centos-profile'`.
75
+ It will only run the included profiles is the platform matches the supported platform.
76
+
77
+
78
+ ### 5. Do not include dynamic elements in the control IDs
79
+
80
+ Reason: Control IDs are used to map test results to the tests and profiles. Dynamic control IDs make it impossible to map results back, since the identifier which connects tests and results may change in the process.
81
+
82
+ Avoid:
83
+ ```ruby
84
+ control "test-file-#{name}" do
85
+ ..
86
+ end
87
+ ```
88
+
89
+ Use:
90
+ ```ruby
91
+ control "test-all-files" do
92
+ ..
93
+ end
94
+ ```
95
+
96
+ Sometimes you may create controls from a static list of elements. If this list stays the same no matter what system is scanned, it may be ok to do so and use it as a generator for static controls.
97
+
98
+
99
+ ### 6. Avoid Ruby system calls
100
+
101
+ Reason: Ruby code is executed on the system that runs InSpec. This allows
102
+ InSpec to work without Ruby and rubygems being required on remote
103
+ targets (servers or containers). System calls are often used to interact with
104
+ the local OS or remote endpoints from a local installation.
105
+ InSpec tests, however, are designed to be universally executable on all
106
+ types of runtimes, including local and remote execution. We want to give
107
+ users the ability to take an OS profile and execute it remotely or locally.
108
+
109
+ **Avoid shelling out**
110
+
111
+ Avoid: `` `ls``\`
112
+ Avoid: `system("ls")`
113
+ Avoid: `IO.popen("ls")`
114
+ Use: `command("ls")` or `powershell("..")`
115
+
116
+ Ruby's command executors will only run localy. Imagine a test like this:
117
+
118
+ ```ruby
119
+ describe `whoami` do
120
+ it { should eq "bob\n" }
121
+ end
122
+ ```
123
+
124
+ If you run this test on your local system and happen to be using Bob's account
125
+ it will succeed. But if you were to run it against `--target alice@remote-host.com`
126
+ it will still report that the user is bob instead of alice.
127
+
128
+ Instead, do this:
129
+
130
+ ```ruby
131
+ describe command('whoami') do
132
+ its('stdout') { should eq "bob\n" }
133
+ end
134
+ ```
135
+
136
+ If the profile is pointed to a remote endpoint using the `command` resource
137
+ will run it on the remote OS.
138
+
139
+ **Avoid Ruby IO on files**
140
+
141
+ Avoid: `File.new("filename").read`
142
+ Avoid: `File.read("filename")`
143
+ Avoid: `IO.read("filename")`
144
+ Use: `file("filename")`
145
+
146
+ Similar to the command interactions these files will only be read localy
147
+ with Ruby's internal calls. If you run this test against a remote target it won't
148
+ read the file from the remote endpoint, but from the local OS instead.
149
+ Use the `file` resource to read files on the target system.
150
+
151
+ In general, try to avoid Ruby's IO calls from within InSpec controls and
152
+ use InSpec resources instead.
153
+
154
+
155
+ ### 7. Avoid Ruby gem dependencies in controls
156
+
157
+ In addition to avoiding system-level gems and modules you should also limit
158
+ the use of external dependencies to resource packs or plugins. Gems need to be
159
+ resolved, installed, vendored, and protected from conflicts. We aim to avoid
160
+ exposing this complexity to users of InSpec, to make it a great tool even if
161
+ you are not a developer.
162
+
163
+ Developers may still use external gem dependencies but should vendor it
164
+ with their plugins or resource packs.
165
+
166
+
167
+ ### 8. Avoid debugging calls (in production)
168
+
169
+ Reason: One of the best way to develop and explore tests is the interactive debugging shell `pry` (see the section on "Interactive Debugging with Pry" at the end of this page). However, after you finish your profile make sure you have no interactive statements included anymore. Sometimes interactive calls are hidden behind conditionals (`if` statements) that are harder to reach. These calls can easily cause trouble when an automated profiles runs into an interactive `pry` call that stops the execution and waits for user input.
170
+
171
+ Avoid: `binding.pry` in production profiles
172
+ Use: Use debugging calls during development only
173
+
174
+ Also you may find it helpful to use the inspec logging interface:
175
+
176
+ ```ruby
177
+ Inspec::Log.info('Hi')
178
+ ```
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+ source 'https://rubygems.org'
3
+
4
+ gemspec
5
+
6
+ group :development do
7
+ gem 'bundler'
8
+ gem 'byebug'
9
+ gem 'minitest'
10
+ gem 'rake'
11
+ gem 'rubocop', '= 0.49.1' # Need to keep in sync with main InSpec project, so config files will work
12
+ end
@@ -0,0 +1,13 @@
1
+ Copyright (c) 2018 Chef Software Inc.
2
+
3
+ Licensed under the Apache License, Version 2.0 (the "License");
4
+ you may not use this file except in compliance with the License.
5
+ You may obtain a copy of the License at
6
+
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
+
9
+ Unless required by applicable law or agreed to in writing, software
10
+ distributed under the License is distributed on an "AS IS" BASIS,
11
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ See the License for the specific language governing permissions and
13
+ limitations under the License.
@@ -0,0 +1,62 @@
1
+ # InSpec Plugin Example - Resource Lister
2
+
3
+ This plugin provides an example of building a plugin for use with [InSpec](https://inspec.io). Its functionality is simple, but useful: list resources included with InSpec.
4
+
5
+ ## To Install this as a User
6
+
7
+ You will need InSpec v2.3 or later.
8
+
9
+ If you want to just use this (not learn how to write a plugin), you can do so by simply running:
10
+
11
+ ```
12
+ you@machine $ inspec plugin install inspec-resource-lister
13
+ ```
14
+
15
+ You can then run:
16
+
17
+ ```
18
+ you@machine $ inspec plugin help listresources
19
+ # ... Usage info
20
+
21
+ you@machine $ inspec plugin listresources core
22
+ aide_conf
23
+ apache
24
+ apache_conf
25
+ ... snip ...
26
+ yumrepo
27
+ zfs_dataset
28
+ zfs_pool
29
+ ------------------------------
30
+ 160 resources total
31
+ ```
32
+
33
+ ## Features of This Example Kit
34
+
35
+ This example plugin is a full-fledged plugin example, with everything a real-world, industrial grade plugin would have, including:
36
+
37
+ * an implementation of an InSpec CLI Command, using the InSpec PluginV2 API
38
+ * documentation (you are reading it now)
39
+ * tests, at the unit and functional level
40
+ * a .gemspec, for packaging and publishing it as a gem
41
+ * a Gemfile, for managing its dependencies
42
+ * a Rakefile, for running development tasks
43
+ * Rubocop linting support for using the base InSpec project rubocop.yml (See Rakefile)
44
+
45
+ You are encouraged to use this plugin as a starting point for real plugins.
46
+
47
+ ## Development of a Plugin
48
+
49
+ [Plugin Development](https://github.com/inspec/inspec/blob/master/docs/dev/plugins.md) is documented on the `inspec` project on GitHub. Additionally, this example
50
+ plugin has extensive comments explaining what is happening, and why.
51
+
52
+ ### A Tour of the Plugin
53
+
54
+ One nice circuit of the plugin might be:
55
+ * look at the gemspec, to see what the plugin thinks it does
56
+ * look at the functional tests, to see the plugin proving it does what it says
57
+ * look at the unit tests, to see how the plugin claims it is internally structured
58
+ * look at the Rakefile, to see how to interact with the project
59
+ * look at lib/inspec-resource-lister.rb, the entry point which InSpec will always load if the plugin is installed
60
+ * look at lib/inspec-resource-lister/plugin.rb, the plugin definition which InSpec uses to understand what the plugin _can_ do.
61
+ * look at lib/inspec-resource-lister/cli_command.rb, the CLI Command implementation itself.
62
+
@@ -0,0 +1,40 @@
1
+ # A Rakefile defines tasks to help maintain your project.
2
+ # Rake provides several task templates that are useful.
3
+
4
+ #------------------------------------------------------------------#
5
+ # Test Runner Tasks
6
+ #------------------------------------------------------------------#
7
+
8
+ # This task template will make a task named 'test', and run
9
+ # the tests that it finds.
10
+ require 'rake/testtask'
11
+
12
+ Rake::TestTask.new do |t|
13
+ t.libs.push 'lib'
14
+ t.test_files = FileList[
15
+ 'test/unit/*_test.rb',
16
+ 'test/functional/*_test.rb',
17
+ ]
18
+ t.verbose = true
19
+ # Ideally, we'd run tests with warnings enabled,
20
+ # but the dependent gems have many warnings. As this
21
+ # is an example, let's disable them so the testing
22
+ # experience is cleaner.
23
+ t.warning = false
24
+ end
25
+
26
+ #------------------------------------------------------------------#
27
+ # Code Style Tasks
28
+ #------------------------------------------------------------------#
29
+ require 'rubocop/rake_task'
30
+
31
+ RuboCop::RakeTask.new(:lint) do |t|
32
+ # Choices of rubocop rules to enforce are deeply personal.
33
+ # Here, we set things up so that your plugin will use the Bundler-installed
34
+ # inspec gem's copy of the InSpec project's rubocop.yml file (which
35
+ # is indeed packaged with the inspec gem).
36
+ require 'inspec/globals'
37
+ inspec_rubocop_yml = File.join(Inspec.src_root, '.rubocop.yml')
38
+
39
+ t.options = ['--display-cop-names', '--config', inspec_rubocop_yml]
40
+ end
@@ -0,0 +1,45 @@
1
+ # coding: utf-8
2
+
3
+ # As plugins are usually packaged and distributed as a RubyGem,
4
+ # we have to provide a .gemspec file, which controls the gembuild
5
+ # and publish process. This is a fairly generic gemspec.
6
+
7
+ # It is traditional in a gemspec to dynamically load the current version
8
+ # from a file in the source tree. The next three lines make that happen.
9
+ lib = File.expand_path('../lib', __FILE__)
10
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
11
+ require 'inspec-resource-lister/version'
12
+
13
+ Gem::Specification.new do |spec|
14
+ # Importantly, all InSpec plugins must be prefixed with `inspec-` (most
15
+ # plugins) or `train-` (plugins which add new connectivity features).
16
+ spec.name = 'inspec-resource-lister'
17
+
18
+ # It is polite to namespace your plugin under InspecPlugins::YourPluginInCamelCase
19
+ spec.version = InspecPlugins::ResourceLister::VERSION
20
+ spec.authors = ['Clinton Wolfe']
21
+ spec.email = ['cwolfe@chef.io']
22
+ spec.summary = 'InSpec Plugin example, lists available resources'
23
+ spec.description = 'Example for implementing an InSpec Plugin. This simply lists available resources.'
24
+ spec.homepage = 'https://github.com/inspec/inspec/tree/master/examples/plugin'
25
+ spec.license = 'Apache-2.0'
26
+
27
+ # Though complicated-looking, this is pretty standard for a gemspec.
28
+ # It just filters what will actually be packaged in the gem (leaving
29
+ # out tests, etc)
30
+ spec.files = %w{
31
+ README.md inspec-resource-lister.gemspec Gemfile
32
+ } + Dir.glob(
33
+ 'lib/**/*', File::FNM_DOTMATCH
34
+ ).reject { |f| File.directory?(f) }
35
+ spec.require_paths = ['lib']
36
+
37
+ # If you rely on any other gems, list them here with any constraints.
38
+ # This is how `inspec plugin install` is able to manage your dependencies.
39
+ # For example, perhaps you are writing a thing that talks to AWS, and you
40
+ # want to ensure you have `aws-sdk` in a certain version.
41
+
42
+ # All plugins should mention inspec, > 2.2.78
43
+ # 2.2.78 included the v2 Plugin API
44
+ spec.add_dependency 'inspec', '>=2.2.78', '<4.0.0'
45
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ # This file is known as the "entry point."
4
+ # This is the file InSpec will try to load if it
5
+ # thinks your plugin is installed.
6
+
7
+ # The *only* thing this file should do is setup the
8
+ # load path, then load the plugin definition file.
9
+
10
+ # Next two lines simply add the path of the gem to the load path.
11
+ # This is not needed when being loaded as a gem; but when doing
12
+ # plugin development, you may need it. Either way, it's harmless.
13
+ libdir = File.dirname(__FILE__)
14
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
15
+
16
+ require 'inspec-resource-lister/plugin'