inspec-core 2.2.112 → 2.3.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +42 -19
- data/README.md +1 -1
- data/docs/dev/integration-testing.md +31 -0
- data/docs/dev/plugins.md +4 -2
- data/docs/dsl_inspec.md +104 -4
- data/docs/plugins.md +57 -0
- data/docs/style.md +178 -0
- data/examples/plugins/inspec-resource-lister/Gemfile +12 -0
- data/examples/plugins/inspec-resource-lister/LICENSE +13 -0
- data/examples/plugins/inspec-resource-lister/README.md +62 -0
- data/examples/plugins/inspec-resource-lister/Rakefile +40 -0
- data/examples/plugins/inspec-resource-lister/inspec-resource-lister.gemspec +45 -0
- data/examples/plugins/inspec-resource-lister/lib/inspec-resource-lister.rb +16 -0
- data/examples/plugins/inspec-resource-lister/lib/inspec-resource-lister/cli_command.rb +70 -0
- data/examples/plugins/inspec-resource-lister/lib/inspec-resource-lister/plugin.rb +55 -0
- data/examples/plugins/inspec-resource-lister/lib/inspec-resource-lister/version.rb +10 -0
- data/examples/plugins/inspec-resource-lister/test/fixtures/README.md +24 -0
- data/examples/plugins/inspec-resource-lister/test/functional/README.md +18 -0
- data/examples/plugins/inspec-resource-lister/test/functional/inspec_resource_lister_test.rb +110 -0
- data/examples/plugins/inspec-resource-lister/test/helper.rb +26 -0
- data/examples/plugins/inspec-resource-lister/test/unit/README.md +17 -0
- data/examples/plugins/inspec-resource-lister/test/unit/cli_args_test.rb +64 -0
- data/examples/plugins/inspec-resource-lister/test/unit/plugin_def_test.rb +51 -0
- data/examples/profile/controls/example.rb +9 -8
- data/inspec-core.gemspec +1 -1
- data/lib/inspec/attribute_registry.rb +1 -1
- data/lib/inspec/globals.rb +4 -0
- data/lib/inspec/objects/control.rb +18 -3
- data/lib/inspec/plugin/v2.rb +14 -3
- data/lib/inspec/plugin/v2/activator.rb +7 -2
- data/lib/inspec/plugin/v2/installer.rb +426 -0
- data/lib/inspec/plugin/v2/loader.rb +137 -30
- data/lib/inspec/plugin/v2/registry.rb +13 -4
- data/lib/inspec/profile.rb +2 -1
- data/lib/inspec/reporters/json.rb +11 -1
- data/lib/inspec/resource.rb +6 -15
- data/lib/inspec/rule.rb +18 -9
- data/lib/inspec/runner_rspec.rb +1 -1
- data/lib/inspec/schema.rb +1 -0
- data/lib/inspec/version.rb +1 -1
- data/lib/plugins/inspec-plugin-manager-cli/README.md +6 -0
- data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli.rb +18 -0
- data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb +420 -0
- data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/plugin.rb +12 -0
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/config_dirs/empty/.gitkeep +0 -0
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-egg-white-omelette/lib/inspec-egg-white-omelette.rb +2 -0
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-egg-white-omelette/lib/inspec-egg-white-omelette/.gitkeep +0 -0
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/inspec-wrong-structure/.gitkeep +0 -0
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name.rb +1 -0
- data/lib/plugins/inspec-plugin-manager-cli/test/fixtures/plugins/wrong-name/lib/wrong-name/.gitkeep +0 -0
- data/lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb +651 -0
- data/lib/plugins/inspec-plugin-manager-cli/test/unit/cli_args_test.rb +71 -0
- data/lib/plugins/inspec-plugin-manager-cli/test/unit/plugin_def_test.rb +20 -0
- data/lib/plugins/shared/core_plugin_test_helper.rb +101 -2
- data/lib/plugins/things-for-train-integration.rb +14 -0
- data/lib/resources/port.rb +10 -6
- metadata +38 -11
- data/docs/ruby_usage.md +0 -204
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e8f9909b462e77ca666275bb82308ea451a68ead2f5498aa111d74a55f5a6f64
|
4
|
+
data.tar.gz: 002c18ea92f6c1879f5e8abdc53231a673b0bac7b66ce9042363a10504ebb424
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 642c43b3305289773a3fe75d286c5c0eaae10fa2ff869541aed3eb683a0e04bbf2d839bf3665e11eca1f87fcdf909de99885c3822035c37db2e7b5ffc876da8a
|
7
|
+
data.tar.gz: 7df8c80861da7a4a252a47d02f50a1d3f138abf1cd4021c78462d3174176a623a81a0f1071ad8031b73dfd32f5f41eb3224c982a667a132d2ffefc569078a443
|
data/CHANGELOG.md
CHANGED
@@ -1,38 +1,61 @@
|
|
1
1
|
# Change Log
|
2
2
|
<!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ -->
|
3
|
-
<!-- latest_release 2.
|
4
|
-
## [v2.
|
3
|
+
<!-- latest_release 2.3.4 -->
|
4
|
+
## [v2.3.4](https://github.com/inspec/inspec/tree/v2.3.4) (2018-09-27)
|
5
5
|
|
6
|
-
####
|
7
|
-
-
|
6
|
+
#### New Features
|
7
|
+
- Plugins: Support for Train Plugins in InSpec [#3444](https://github.com/inspec/inspec/pull/3444) ([clintoncwolfe](https://github.com/clintoncwolfe))
|
8
8
|
<!-- latest_release -->
|
9
9
|
|
10
|
-
<!-- release_rollup since=2.2.
|
11
|
-
### Changes since 2.2.
|
10
|
+
<!-- release_rollup since=2.2.112 -->
|
11
|
+
### Changes since 2.2.112 release
|
12
12
|
|
13
13
|
#### Enhancements
|
14
|
-
-
|
15
|
-
- Plugins: Add support for 'bundles' migration [#3384](https://github.com/inspec/inspec/pull/3384) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.2.105 -->
|
16
|
-
|
17
|
-
#### New Features
|
18
|
-
- Update AWS Security Group to work with IPV6 rules. [#3394](https://github.com/inspec/inspec/pull/3394) ([MartinLogan](https://github.com/MartinLogan)) <!-- 2.2.111 -->
|
19
|
-
- Added db_name flag [#3383](https://github.com/inspec/inspec/pull/3383) ([kdoores](https://github.com/kdoores)) <!-- 2.2.104 -->
|
14
|
+
- Support the Busybox variant of netstat in the port resource [#3425](https://github.com/inspec/inspec/pull/3425) ([RoboticCheese](https://github.com/RoboticCheese)) <!-- 2.2.119 -->
|
20
15
|
|
21
16
|
#### Merged Pull Requests
|
22
|
-
-
|
23
|
-
-
|
24
|
-
-
|
25
|
-
-
|
26
|
-
-
|
27
|
-
-
|
17
|
+
- Plugins: Example CLI Plugin, a Resource Lister [#3421](https://github.com/inspec/inspec/pull/3421) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.3.3 -->
|
18
|
+
- Pin postgresql to a lower cookbook version [#3449](https://github.com/inspec/inspec/pull/3449) ([jquick](https://github.com/jquick)) <!-- 2.3.2 -->
|
19
|
+
- RFC inspec style guide [#3356](https://github.com/inspec/inspec/pull/3356) ([arlimus](https://github.com/arlimus)) <!-- 2.3.1 -->
|
20
|
+
- Bump minor version [#3448](https://github.com/inspec/inspec/pull/3448) ([jquick](https://github.com/jquick)) <!-- 2.3.0 -->
|
21
|
+
- Add support for multiple descriptions for controls [#3424](https://github.com/inspec/inspec/pull/3424) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 2.2.120 -->
|
22
|
+
- Plugins: Load all CLI commands on usage on empty invocation [#3428](https://github.com/inspec/inspec/pull/3428) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.2.118 -->
|
23
|
+
- Fix v2 loader appveyor issue [#3434](https://github.com/inspec/inspec/pull/3434) ([jquick](https://github.com/jquick)) <!-- 2.2.116 -->
|
24
|
+
- Add new resource: aws_ebs_volume [#3381](https://github.com/inspec/inspec/pull/3381) ([jmassardo](https://github.com/jmassardo)) <!-- 2.2.115 -->
|
25
|
+
|
26
|
+
#### Bug Fixes
|
27
|
+
- Grammar correction in error message: use "an" with attribute and unknown [#3439](https://github.com/inspec/inspec/pull/3439) ([alexpop](https://github.com/alexpop)) <!-- 2.2.117 -->
|
28
|
+
- Remove load locks for cloud resources [#3420](https://github.com/inspec/inspec/pull/3420) ([jquick](https://github.com/jquick)) <!-- 2.2.114 -->
|
29
|
+
|
30
|
+
#### New Features
|
31
|
+
- Plugins: Support for Train Plugins in InSpec [#3444](https://github.com/inspec/inspec/pull/3444) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.3.4 -->
|
32
|
+
- Plugins Installer API [#3352](https://github.com/inspec/inspec/pull/3352) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.2.113 -->
|
28
33
|
<!-- release_rollup -->
|
29
34
|
|
30
35
|
<!-- latest_stable_release -->
|
36
|
+
## [v2.2.112](https://github.com/inspec/inspec/tree/v2.2.112) (2018-09-19)
|
37
|
+
|
38
|
+
#### New Features
|
39
|
+
- Added db_name flag [#3383](https://github.com/inspec/inspec/pull/3383) ([kdoores](https://github.com/kdoores))
|
40
|
+
- Update AWS Security Group to work with IPV6 rules. [#3394](https://github.com/inspec/inspec/pull/3394) ([MartinLogan](https://github.com/MartinLogan))
|
41
|
+
|
42
|
+
#### Enhancements
|
43
|
+
- Plugins: Add support for 'bundles' migration [#3384](https://github.com/inspec/inspec/pull/3384) ([clintoncwolfe](https://github.com/clintoncwolfe))
|
44
|
+
- adding `versions` to the `gem` resource [#3398](https://github.com/inspec/inspec/pull/3398) ([majormoses](https://github.com/majormoses))
|
45
|
+
|
46
|
+
#### Merged Pull Requests
|
47
|
+
- Fix rendering of profiles docs [#3393](https://github.com/inspec/inspec/pull/3393) ([jquick](https://github.com/jquick))
|
48
|
+
- Move habitat to v2 plugin [#3404](https://github.com/inspec/inspec/pull/3404) ([jquick](https://github.com/jquick))
|
49
|
+
- Fix json automate tests and render call [#3408](https://github.com/inspec/inspec/pull/3408) ([jquick](https://github.com/jquick))
|
50
|
+
- Fix gem tests from recent merge [#3409](https://github.com/inspec/inspec/pull/3409) ([jquick](https://github.com/jquick))
|
51
|
+
- Move inspec init to v2 plugins [#3407](https://github.com/inspec/inspec/pull/3407) ([jquick](https://github.com/jquick))
|
52
|
+
- Move artifact to v2 plugin [#3406](https://github.com/inspec/inspec/pull/3406) ([jquick](https://github.com/jquick))
|
53
|
+
<!-- latest_stable_release -->
|
54
|
+
|
31
55
|
## [v2.2.102](https://github.com/inspec/inspec/tree/v2.2.102) (2018-09-17)
|
32
56
|
|
33
57
|
#### Merged Pull Requests
|
34
58
|
- Add json-automate to the report method [#3401](https://github.com/inspec/inspec/pull/3401) ([jquick](https://github.com/jquick))
|
35
|
-
<!-- latest_stable_release -->
|
36
59
|
|
37
60
|
## [v2.2.101](https://github.com/inspec/inspec/tree/v2.2.101) (2018-09-14)
|
38
61
|
|
data/README.md
CHANGED
@@ -452,4 +452,4 @@ Unless required by applicable law or agreed to in writing, software
|
|
452
452
|
distributed under the License is distributed on an "AS IS" BASIS,
|
453
453
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
454
454
|
See the License for the specific language governing permissions and
|
455
|
-
limitations under the License.
|
455
|
+
limitations under the License.
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# Integration Testing with InSpec
|
2
|
+
|
3
|
+
## Introduction
|
4
|
+
|
5
|
+
Inspec uses Test Kitchen for its integration testing. Our current testing uses Docker as our backend. You should install and have Docker running befor you run any tests.
|
6
|
+
|
7
|
+
### How to run specific integrations
|
8
|
+
|
9
|
+
To run a specific integration test use the following:
|
10
|
+
|
11
|
+
```bash
|
12
|
+
bundle exec rake test:integration[OS_NAME]
|
13
|
+
```
|
14
|
+
|
15
|
+
Example:
|
16
|
+
```bash
|
17
|
+
bundle exec rake test:integration[default-ubuntu-1604]
|
18
|
+
```
|
19
|
+
|
20
|
+
# Inspec Integrations
|
21
|
+
|
22
|
+
### Test Kitchen
|
23
|
+
|
24
|
+
We run the test/integration/default profile at the end of each integration test in the verify stage. This confirms that our current code is compatible with test kitchen.
|
25
|
+
|
26
|
+
### Audit Testing
|
27
|
+
|
28
|
+
For Audit cookbook testing InSpec sets up some special hooks. The integration rake command will bundle up the current checkout into a gem which is passed along to test kitchen in the os_prepare cookbook. When this cookbook is ran it will install the local inspec gem. Audit will then use this gem accordingly when running in the post chef-client validators. The .kitchen.yml is setup to export the audit report to a json file which we look for and confirm the structure in the test/integration/default/controls/audit_spec.rb file.
|
29
|
+
|
30
|
+
In the validation file we confirm that the file was created from audit and that the structure looks correct. We also validate that the inspec ran with audit is the same that the current branch is using. This validates that audit did not use a older version for some reason.
|
31
|
+
|
data/docs/dev/plugins.md
CHANGED
@@ -26,9 +26,11 @@ The software design of the InSpec Plugin v2 API is deeply inspired by the Vagran
|
|
26
26
|
|
27
27
|
The normal distribution and installation method is via gems, handled by the `inspec plugin` command.
|
28
28
|
|
29
|
-
|
29
|
+
`inspec plugin install inspec-myplugin` will fetch `inspec-myplugin` from rubygems.org, and install it and its gemspec dependencies under the user's `.inspec` directory. You may also provide a local gemfile. For local development, however, path-to-source is usually most convenient.
|
30
30
|
|
31
|
-
|
31
|
+
For more on the `plugin` CLI command, run `inspec plugin help`.
|
32
|
+
|
33
|
+
### Plugins may also be found by path to a source tree
|
32
34
|
|
33
35
|
For local development or site-specific installations, you can also 'install' a plugin by path using `inspec plugin`, or edit `~/.inspec/plugins.json` directly to add a plugin.
|
34
36
|
|
data/docs/dsl_inspec.md
CHANGED
@@ -26,10 +26,8 @@ In various use cases like implementing IT compliance across different department
|
|
26
26
|
control 'sshd-8' do
|
27
27
|
impact 0.6
|
28
28
|
title 'Server: Configure the service port'
|
29
|
-
desc '
|
30
|
-
|
31
|
-
Prevent unexpected settings.
|
32
|
-
'
|
29
|
+
desc 'Always specify which port the SSH server should listen.'
|
30
|
+
desc 'rationale', 'This ensures that there are no unexpected settings'
|
33
31
|
tag 'ssh','sshd','openssh-server'
|
34
32
|
tag cce: 'CCE-27072-8'
|
35
33
|
ref 'NSA-RH6-STIG - Section 3.5.2.1', url: 'https://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf'
|
@@ -44,6 +42,7 @@ where
|
|
44
42
|
|
45
43
|
* `'sshd-8'` is the name of the control
|
46
44
|
* `impact`, `title`, and `desc` define metadata that fully describes the importance of the control, its purpose, with a succinct and complete description
|
45
|
+
* `desc` when given only one argument it sets the default description. When given 2 arguments (see: `'rationale'`) it will use the first argument as a header when rendering in Automate
|
47
46
|
* `impact` is an float that measures the importance of the compliance results and must be a value between `0.0` and `1.0`. The value ranges are:
|
48
47
|
* `0.0 to <0.4` these are controls with minor criticality
|
49
48
|
* `0.4 to <0.7` these are controls with major criticality
|
@@ -252,3 +251,104 @@ control 'ssh-1' do
|
|
252
251
|
end
|
253
252
|
end
|
254
253
|
```
|
254
|
+
|
255
|
+
# Using Ruby in InSpec
|
256
|
+
|
257
|
+
The InSpec DSL is a Ruby based language. This allows you to be flexible with
|
258
|
+
Ruby code in controls:
|
259
|
+
|
260
|
+
```ruby
|
261
|
+
json_obj = json('/file.json')
|
262
|
+
json_obj['keys'].each do |value|
|
263
|
+
..
|
264
|
+
end
|
265
|
+
```
|
266
|
+
|
267
|
+
Ruby allows a lot of freedoms, but should be limited in controls so that they
|
268
|
+
remain portable and easy to understand. Please see our [profile style guide](./style).
|
269
|
+
|
270
|
+
Core and custom resources are written as regular Ruby classes which inherit from
|
271
|
+
`Inspec.resource`.
|
272
|
+
|
273
|
+
|
274
|
+
## Interactive Debugging with Pry
|
275
|
+
|
276
|
+
Here's a sample InSpec control that users Ruby variables to instantiate
|
277
|
+
an InSpec resource once and use the content in multiple tests.
|
278
|
+
|
279
|
+
```ruby
|
280
|
+
control 'check-perl' do
|
281
|
+
impact 0.3
|
282
|
+
title 'Check perl compiled options and permissions'
|
283
|
+
perl_out = command('perl -V')
|
284
|
+
#require 'pry'; binding.pry;
|
285
|
+
describe perl_out do
|
286
|
+
its('exit_status') { should eq 0 }
|
287
|
+
its('stdout') { should match /USE_64_BIT_ALL/ }
|
288
|
+
its('stdout') { should match /useposix=true/ }
|
289
|
+
its('stdout') { should match /-fstack-protector/ }
|
290
|
+
end
|
291
|
+
|
292
|
+
# extract an array of include directories
|
293
|
+
perl_inc = perl_out.stdout.partition('@INC:').last.strip.split("\n")
|
294
|
+
# ensure include directories are only writable by 'owner'
|
295
|
+
perl_inc.each do |path|
|
296
|
+
describe directory(path.strip) do
|
297
|
+
it { should_not be_writable.by 'group' }
|
298
|
+
it { should_not be_writable.by 'other' }
|
299
|
+
end
|
300
|
+
end
|
301
|
+
end
|
302
|
+
```
|
303
|
+
|
304
|
+
An **advanced** but very useful Ruby tip. In the previous example, I
|
305
|
+
commented out the `require 'pry'; binding.pry;` line. If you remove the
|
306
|
+
`#` prefix and run the control, the execution will stop at that line and
|
307
|
+
give you a `pry` shell. Use that to troubleshoot, print variables, see
|
308
|
+
methods available, etc. For the above example:
|
309
|
+
|
310
|
+
```ruby
|
311
|
+
[1] pry> perl_out.exit_status
|
312
|
+
=> 0
|
313
|
+
[2] pry> perl_out.stderr
|
314
|
+
=> ""
|
315
|
+
[3] pry> ls perl_out
|
316
|
+
Inspec::Plugins::Resource#methods: inspect
|
317
|
+
Inspec::Resources::Cmd#methods: command exist? exit_status result stderr stdout to_s
|
318
|
+
Inspec::Resource::Registry::Command#methods: inspec
|
319
|
+
instance variables: @__backend_runner__ @__resource_name__ @command @result
|
320
|
+
[4] pry> perl_out.stdout.partition('@INC:').last.strip.split("\n")
|
321
|
+
=> ["/Library/Perl/5.18/darwin-thread-multi-2level",
|
322
|
+
" /Library/Perl/5.18",
|
323
|
+
...REDACTED...
|
324
|
+
[5] pry> exit # or abort
|
325
|
+
```
|
326
|
+
|
327
|
+
You can use `pry` inside both the controls DSL and resources. Similarly,
|
328
|
+
for dev and test, you can use `inspec shell` which is based on `pry`,
|
329
|
+
for example:
|
330
|
+
|
331
|
+
```ruby
|
332
|
+
$ inspec shell
|
333
|
+
Welcome to the interactive InSpec Shell
|
334
|
+
To find out how to use it, type: help
|
335
|
+
|
336
|
+
inspec> command('ls /home/gordon/git/inspec/docs').stdout
|
337
|
+
=> "ctl_inspec.rst\ndsl_inspec.rst\ndsl_resource.rst\n"
|
338
|
+
inspec> command('ls').stdout.split("\n")
|
339
|
+
=> ["ctl_inspec.rst", "dsl_inspec.rst", "dsl_resource.rst"]
|
340
|
+
|
341
|
+
inspec> help command
|
342
|
+
Name: command
|
343
|
+
|
344
|
+
Description:
|
345
|
+
Use the command InSpec audit resource to test an arbitrary command that is run on the system.
|
346
|
+
|
347
|
+
Example:
|
348
|
+
describe command('ls -al /') do
|
349
|
+
it { should exist }
|
350
|
+
its('stdout') { should match /bin/ }
|
351
|
+
its('stderr') { should eq '' }
|
352
|
+
its('exit_status') { should eq 0 }
|
353
|
+
end
|
354
|
+
```
|
data/docs/plugins.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
---
|
2
|
+
title: About InSpec and Train Plugins
|
3
|
+
---
|
4
|
+
|
5
|
+
# InSpec and Train Plugins
|
6
|
+
|
7
|
+
## What are InSpec Plugins?
|
8
|
+
|
9
|
+
InSpec Plugins are optional software components that extend the capabilities of InSpec. For example, [`inspec-iggy`](https://github.com/inspec/inspec-iggy) is a Plugin project that aims to generate InSpec controls from infrastructure-as-code files. Plugins are distributed as RubyGems, and InSpec manages their installation. InSpec Plugins always begin with the prefix 'inspec-'.
|
10
|
+
|
11
|
+
## What are Train Plugins?
|
12
|
+
|
13
|
+
Train Plugins allow InSpec to speak to new kinds of targets (typically new remote targets or APIs, but you could treat the local system in a new way if you wished to). For example, if you wanted to audit a Kubernetes cluster, you might want a transport that can talk to the supervisor API. You'd develop a Train Plugin for that, and install it using the InSpec command line. Train Plugins always begin with the prefix 'train-'.
|
14
|
+
|
15
|
+
## What can plugins do?
|
16
|
+
|
17
|
+
Currently, each plugin can offer one or more of these capabilities:
|
18
|
+
|
19
|
+
* define a new command-line-interface (CLI) command suite
|
20
|
+
* connectivity to new types of hosts or cloud providers (`train` plugins)
|
21
|
+
|
22
|
+
Future work might include new capability types, such as:
|
23
|
+
|
24
|
+
* reporters (output generators)
|
25
|
+
* DSL extensions at the file, control, or test level
|
26
|
+
* attribute fetchers to allow reading InSpec attributes from new sources (for example, a remote, encrypted key-value store)
|
27
|
+
|
28
|
+
## How do I find out which plugins are available?
|
29
|
+
|
30
|
+
The InSpec CLI can tell you which plugins are available:
|
31
|
+
|
32
|
+
```bash
|
33
|
+
$ inspec plugin search
|
34
|
+
```
|
35
|
+
|
36
|
+
## How do I install and manage plugins?
|
37
|
+
|
38
|
+
The InSpec command line now offers a new subcommand just for managing plugins.
|
39
|
+
|
40
|
+
You can install a plugin by running:
|
41
|
+
|
42
|
+
```bash
|
43
|
+
$ inspec plugin install inspec-some-plugin
|
44
|
+
$ inspec plugin install train-some-plugin
|
45
|
+
```
|
46
|
+
|
47
|
+
For more details on what the `plugin` command can do, see the [online help](https://www.inspec.io/docs/reference/cli/#plugin), or run `inspec plugin help`.
|
48
|
+
|
49
|
+
## How do I write a plugin?
|
50
|
+
|
51
|
+
### InSpec Plugins
|
52
|
+
|
53
|
+
For details on how to author an InSpec Plugin, see the [developer documentation](https://github.com/inspec/inspec/blob/master/docs/dev/plugins.md)
|
54
|
+
|
55
|
+
### Train Plugins
|
56
|
+
|
57
|
+
For details on how to author a Train Plugin, see the [developer documentation](https://github.com/inspec/train/blob/master/docs/dev/plugins.md)
|
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
|
+
```
|