inspec 0.35.0 → 1.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +83 -2
- data/Gemfile +6 -0
- data/Rakefile +3 -55
- data/docs/README.md +20 -0
- data/docs/cli.rst +6 -0
- data/docs/dsl_inspec.md +245 -0
- data/docs/dsl_resource.md +93 -0
- data/docs/inspec_and_friends.md +102 -0
- data/docs/matchers.md +136 -0
- data/docs/plugin_kitchen_inspec.html.md +55 -0
- data/docs/profiles.md +271 -0
- data/docs/resources.rst +1 -1
- data/docs/shell.md +150 -0
- data/inspec.gemspec +1 -1
- data/lib/bundles/inspec-compliance/api.rb +28 -18
- data/lib/bundles/inspec-compliance/cli.rb +19 -27
- data/lib/fetchers/git.rb +4 -0
- data/lib/fetchers/local.rb +16 -1
- data/lib/fetchers/mock.rb +4 -0
- data/lib/fetchers/url.rb +40 -12
- data/lib/inspec/base_cli.rb +4 -0
- data/lib/inspec/cli.rb +6 -8
- data/lib/inspec/control_eval_context.rb +8 -0
- data/lib/inspec/dependencies/{vendor_index.rb → cache.rb} +5 -4
- data/lib/inspec/dependencies/dependency_set.rb +8 -14
- data/lib/inspec/dependencies/requirement.rb +10 -20
- data/lib/inspec/dependencies/resolver.rb +2 -2
- data/lib/inspec/dsl.rb +9 -0
- data/lib/inspec/fetcher.rb +1 -1
- data/lib/inspec/objects/test.rb +8 -2
- data/lib/inspec/plugins/fetcher.rb +11 -12
- data/lib/inspec/plugins/resource.rb +3 -0
- data/lib/inspec/profile.rb +60 -14
- data/lib/inspec/profile_context.rb +28 -7
- data/lib/inspec/resource.rb +17 -2
- data/lib/inspec/rspec_json_formatter.rb +80 -35
- data/lib/inspec/runner.rb +42 -18
- data/lib/inspec/shell.rb +5 -16
- data/lib/inspec/version.rb +1 -1
- data/lib/resources/apache_conf.rb +1 -1
- data/lib/resources/gem.rb +1 -0
- data/lib/resources/oneget.rb +1 -0
- data/lib/resources/os.rb +1 -1
- data/lib/resources/package.rb +3 -1
- data/lib/resources/pip.rb +1 -1
- data/lib/resources/ssl.rb +9 -11
- metadata +15 -15
- data/docs/dsl_inspec.rst +0 -259
- data/docs/dsl_resource.rst +0 -90
- data/docs/inspec_and_friends.rst +0 -85
- data/docs/matchers.rst +0 -137
- data/docs/profiles.rst +0 -169
- data/docs/readme.rst +0 -105
- data/docs/shell.rst +0 -130
- data/docs/template.rst +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 714356a44147a3ea6f876aa73a6e51e1abac60b3
|
4
|
+
data.tar.gz: 83e1f5f89edea538de7027ab4d0e07e161f0ee5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebf142830517de967349b6fb1fea90f2b7d7beca3f7630903dd2d92259b78c9a28576f431091b929d96bd26ce89a66dd6ee8d02b25649232453966f2fd197665
|
7
|
+
data.tar.gz: d9bca14a669035a4729a6de6b2ca6b1d4498498080915a94084190b3c40a7bf75124a75fec60b15e3257ac46f6d5f03ae2ce1734bebb1aed06c86eca42e3c0b3
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,88 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [0.
|
4
|
-
[Full Changelog](https://github.com/chef/inspec/compare/
|
3
|
+
## [1.0.0.beta2](https://github.com/chef/inspec/tree/1.0.0.beta2) (2016-09-22)
|
4
|
+
[Full Changelog](https://github.com/chef/inspec/compare/v1.0.0.pre.beta1...1.0.0.beta2)
|
5
|
+
|
6
|
+
**Implemented enhancements:**
|
7
|
+
|
8
|
+
- kernel\_parameter does not show fully info when test fails [\#1093](https://github.com/chef/inspec/issues/1093)
|
9
|
+
- InSpec html demo [\#851](https://github.com/chef/inspec/issues/851)
|
10
|
+
- Counting and status of controls without tests [\#849](https://github.com/chef/inspec/issues/849)
|
11
|
+
- supports does not mark resources as skipped [\#354](https://github.com/chef/inspec/issues/354)
|
12
|
+
- `include Inspec::DSL` anywhere [\#271](https://github.com/chef/inspec/issues/271)
|
13
|
+
- Suse Support [\#113](https://github.com/chef/inspec/issues/113)
|
14
|
+
- Update the username and password login method [\#1095](https://github.com/chef/inspec/pull/1095) ([alexpop](https://github.com/alexpop))
|
15
|
+
|
16
|
+
**Fixed bugs:**
|
17
|
+
|
18
|
+
- InSpec in Workflow [\#1115](https://github.com/chef/inspec/issues/1115)
|
19
|
+
- uninstalled package shows as installed [\#1092](https://github.com/chef/inspec/issues/1092)
|
20
|
+
- undefined method `send\_request' for Compliance::API:Class [\#1088](https://github.com/chef/inspec/issues/1088)
|
21
|
+
- safari inspec online demo bug! [\#1086](https://github.com/chef/inspec/issues/1086)
|
22
|
+
- \[package\] Regression on Windows 2008R2 [\#998](https://github.com/chef/inspec/issues/998)
|
23
|
+
- \[script\] Is there a limit on the number of char's within a script block [\#539](https://github.com/chef/inspec/issues/539)
|
24
|
+
- Use parenthesis when passing regular expressions [\#1106](https://github.com/chef/inspec/pull/1106) ([alexpop](https://github.com/alexpop))
|
25
|
+
- Include code description in the output of failed controls [\#1096](https://github.com/chef/inspec/pull/1096) ([alexpop](https://github.com/alexpop))
|
26
|
+
- Update the username and password login method [\#1095](https://github.com/chef/inspec/pull/1095) ([alexpop](https://github.com/alexpop))
|
27
|
+
|
28
|
+
**Closed issues:**
|
29
|
+
|
30
|
+
- Package Resource isn't searching 64-bit Registry Hives [\#1100](https://github.com/chef/inspec/issues/1100)
|
31
|
+
- demo improvements [\#1089](https://github.com/chef/inspec/issues/1089)
|
32
|
+
- Dependencies: All resources are scoped [\#1058](https://github.com/chef/inspec/issues/1058)
|
33
|
+
- Improve InSpec tutorial [\#1045](https://github.com/chef/inspec/issues/1045)
|
34
|
+
- 1.10.2 has an extra space in pip package output [\#1043](https://github.com/chef/inspec/issues/1043)
|
35
|
+
- Follow up to 1013: find\_files\(\) errors still occurring for apache\_conf resource after 0.33.0 upgrade [\#1030](https://github.com/chef/inspec/issues/1030)
|
36
|
+
- MVP in-browser inspec demo [\#957](https://github.com/chef/inspec/issues/957)
|
37
|
+
- Failing tests in inherited tests are not displayed [\#899](https://github.com/chef/inspec/issues/899)
|
38
|
+
|
39
|
+
**Merged pull requests:**
|
40
|
+
|
41
|
+
- Use the gem version for the omnibus package version [\#1122](https://github.com/chef/inspec/pull/1122) ([yzl](https://github.com/yzl))
|
42
|
+
- Add legal pages [\#1121](https://github.com/chef/inspec/pull/1121) ([magwalk](https://github.com/magwalk))
|
43
|
+
- update docs to markdown [\#1120](https://github.com/chef/inspec/pull/1120) ([arlimus](https://github.com/arlimus))
|
44
|
+
- add readme to www-build [\#1118](https://github.com/chef/inspec/pull/1118) ([arlimus](https://github.com/arlimus))
|
45
|
+
- Always write lockfiles for local top-level profiles [\#1116](https://github.com/chef/inspec/pull/1116) ([stevendanna](https://github.com/stevendanna))
|
46
|
+
- Add `--cache` option to `inspec exec` [\#1113](https://github.com/chef/inspec/pull/1113) ([stevendanna](https://github.com/stevendanna))
|
47
|
+
- fix double-space in pip to\_s resource [\#1112](https://github.com/chef/inspec/pull/1112) ([chris-rock](https://github.com/chris-rock))
|
48
|
+
- fixes debian package manager and some of the code examples [\#1111](https://github.com/chef/inspec/pull/1111) ([Anirudh-Gupta](https://github.com/Anirudh-Gupta))
|
49
|
+
- Add main site footer [\#1110](https://github.com/chef/inspec/pull/1110) ([magwalk](https://github.com/magwalk))
|
50
|
+
- Add community and tutorials pages [\#1108](https://github.com/chef/inspec/pull/1108) ([magwalk](https://github.com/magwalk))
|
51
|
+
- Add homepage content and styles [\#1107](https://github.com/chef/inspec/pull/1107) ([magwalk](https://github.com/magwalk))
|
52
|
+
- Styling setup and main navigation [\#1105](https://github.com/chef/inspec/pull/1105) ([magwalk](https://github.com/magwalk))
|
53
|
+
- docs task and rst/md formatter separation [\#1104](https://github.com/chef/inspec/pull/1104) ([arlimus](https://github.com/arlimus))
|
54
|
+
- Fail if a remote source content doesn't match lockfile [\#1103](https://github.com/chef/inspec/pull/1103) ([stevendanna](https://github.com/stevendanna))
|
55
|
+
- Optimize tutorial [\#1101](https://github.com/chef/inspec/pull/1101) ([chris-rock](https://github.com/chris-rock))
|
56
|
+
- Build with master of omnibus [\#1099](https://github.com/chef/inspec/pull/1099) ([yzl](https://github.com/yzl))
|
57
|
+
- use Gem::Version instead of a regular expression for a test version bump [\#1098](https://github.com/chef/inspec/pull/1098) ([chris-rock](https://github.com/chris-rock))
|
58
|
+
- fix demo instructions [\#1094](https://github.com/chef/inspec/pull/1094) ([vjeffrey](https://github.com/vjeffrey))
|
59
|
+
- Allow users to reference resources from dependencies [\#1080](https://github.com/chef/inspec/pull/1080) ([stevendanna](https://github.com/stevendanna))
|
60
|
+
- In ApacheConf\#include\_files, check for abs paths [\#1042](https://github.com/chef/inspec/pull/1042) ([davidcpell](https://github.com/davidcpell))
|
61
|
+
|
62
|
+
## [v1.0.0.pre.beta1](https://github.com/chef/inspec/tree/v1.0.0.pre.beta1) (2016-09-19)
|
63
|
+
[Full Changelog](https://github.com/chef/inspec/compare/v0.35.0...v1.0.0.pre.beta1)
|
64
|
+
|
65
|
+
**Implemented enhancements:**
|
66
|
+
|
67
|
+
- InSpec output for summary needs to count controls [\#852](https://github.com/chef/inspec/issues/852)
|
68
|
+
- ssl resource to use inspec.backend.hostname and require train 0.19.1 [\#1084](https://github.com/chef/inspec/pull/1084) ([alexpop](https://github.com/alexpop))
|
69
|
+
- optimize command simulator auto-generation [\#1078](https://github.com/chef/inspec/pull/1078) ([chris-rock](https://github.com/chris-rock))
|
70
|
+
|
71
|
+
**Closed issues:**
|
72
|
+
|
73
|
+
- proper scrolling of terminal [\#1053](https://github.com/chef/inspec/issues/1053)
|
74
|
+
|
75
|
+
**Merged pull requests:**
|
76
|
+
|
77
|
+
- fix inspec shell handling [\#1090](https://github.com/chef/inspec/pull/1090) ([vjeffrey](https://github.com/vjeffrey))
|
78
|
+
- update responses [\#1087](https://github.com/chef/inspec/pull/1087) ([vjeffrey](https://github.com/vjeffrey))
|
79
|
+
- print profile summary and test summary [\#1083](https://github.com/chef/inspec/pull/1083) ([vjeffrey](https://github.com/vjeffrey))
|
80
|
+
- Fix minor typo in documentation [\#1082](https://github.com/chef/inspec/pull/1082) ([Dispader](https://github.com/Dispader))
|
81
|
+
- uglify wepack content, kudos @chris-rock [\#1081](https://github.com/chef/inspec/pull/1081) ([arlimus](https://github.com/arlimus))
|
82
|
+
- Static keys in all json [\#811](https://github.com/chef/inspec/pull/811) ([arlimus](https://github.com/arlimus))
|
83
|
+
|
84
|
+
## [v0.35.0](https://github.com/chef/inspec/tree/v0.35.0) (2016-09-16)
|
85
|
+
[Full Changelog](https://github.com/chef/inspec/compare/v0.34.1...v0.35.0)
|
5
86
|
|
6
87
|
**Fixed bugs:**
|
7
88
|
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -6,6 +6,7 @@ require 'bundler/gem_tasks'
|
|
6
6
|
require 'rake/testtask'
|
7
7
|
require 'rubocop/rake_task'
|
8
8
|
require_relative 'tasks/maintainers'
|
9
|
+
require_relative 'tasks/docs'
|
9
10
|
|
10
11
|
# Rubocop
|
11
12
|
desc 'Run Rubocop lint checks'
|
@@ -20,8 +21,8 @@ task lint: [:rubocop]
|
|
20
21
|
# update command output for demo
|
21
22
|
desc 'Run inspec commands and save results to www/app/responses'
|
22
23
|
task :update_demo do
|
23
|
-
|
24
|
-
ruby
|
24
|
+
ruby 'www/tutorial/scripts/build_simulator_runtime.rb'
|
25
|
+
ruby 'www/tutorial/scripts/run_simulator_recording.rb'
|
25
26
|
end
|
26
27
|
|
27
28
|
# run tests
|
@@ -165,56 +166,3 @@ task :release_docker do
|
|
165
166
|
puts "--> #{cmd}"
|
166
167
|
sh('sh', '-c', cmd)
|
167
168
|
end
|
168
|
-
|
169
|
-
namespace :docs do
|
170
|
-
desc 'Create cli docs'
|
171
|
-
task :cli do
|
172
|
-
res = "=====================================================\n"\
|
173
|
-
"InSpec CLI\n"\
|
174
|
-
"=====================================================\n\n"\
|
175
|
-
"Use the InSpec CLI to run tests and audits against targets "\
|
176
|
-
"using local, SSH, WinRM, or Docker connections.\n\n"
|
177
|
-
|
178
|
-
require 'inspec/cli'
|
179
|
-
cmds = Inspec::InspecCLI.all_commands
|
180
|
-
cmds.keys.sort.each do |key|
|
181
|
-
cmd = cmds[key]
|
182
|
-
|
183
|
-
res << "#{cmd.usage.split.first}\n"\
|
184
|
-
"=====================================================\n\n"
|
185
|
-
|
186
|
-
res << cmd.description.capitalize
|
187
|
-
res << "\n\n"
|
188
|
-
|
189
|
-
res << "Syntax\n"\
|
190
|
-
"-----------------------------------------------------\n\n"
|
191
|
-
|
192
|
-
res << "This subcommand has the following syntax:\n\n"\
|
193
|
-
".. code-block:: bash\n\n"\
|
194
|
-
" $ inspec #{cmd.usage}\n\n"
|
195
|
-
|
196
|
-
opts = cmd.options.select { |_, o| !o.hide }
|
197
|
-
unless opts.empty?
|
198
|
-
res << "Options\n"\
|
199
|
-
"-----------------------------------------------------\n\n"\
|
200
|
-
"This subcommand has additional options:\n\n"
|
201
|
-
|
202
|
-
opts.keys.sort.each do |option|
|
203
|
-
opt = cmd.options[option]
|
204
|
-
# TODO: remove when UX of help is reworked 1.0
|
205
|
-
usage = opt.usage.split(', ')
|
206
|
-
.map { |x| x.tr('[]', '') }
|
207
|
-
.map { |x| x.start_with?('-') ? x : '-'+x }
|
208
|
-
.map { |x| '``' + x + '``' }
|
209
|
-
res << "#{usage.join(', ')}\n #{opt.description}\n\n"
|
210
|
-
end
|
211
|
-
|
212
|
-
end
|
213
|
-
res << "\n\n"
|
214
|
-
end
|
215
|
-
|
216
|
-
dst = 'docs/cli.rst'
|
217
|
-
File.write(dst, res)
|
218
|
-
puts "Documentation generated in #{dst.inspect}"
|
219
|
-
end
|
220
|
-
end
|
data/docs/README.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# InSpec documentation
|
2
|
+
|
3
|
+
This is the home of the InSpec documentation. This documentation provides an introduction to this mechanism and shows how to write custom tests.
|
4
|
+
|
5
|
+
The goal of this folder is for any community member to clone these docs, make the changes, check if they are valid, and contribute to the project.
|
6
|
+
|
7
|
+
## How to build docs
|
8
|
+
|
9
|
+
TODO
|
10
|
+
|
11
|
+
## Stability Index
|
12
|
+
|
13
|
+
Every available InSpec resource will indicate its stability. As InSpec matures, certain parts are more reliable than others. Brand new features are likely to be redesigned and marked as such.
|
14
|
+
|
15
|
+
The stability indices are as follows:
|
16
|
+
|
17
|
+
* `Stability: Deprecated` - This features will be removed in future versions, because its known for being problematic. Do not rely on it.
|
18
|
+
* `Stability: Experimental` - New features may change or are removed in future versions
|
19
|
+
* `Stability: Stable` - API is well established and proofed. Maintaining compatibility is a high priority
|
20
|
+
* `Stability: Locked` - Only security and performance fixes are allowed
|
data/docs/cli.rst
CHANGED
@@ -199,12 +199,18 @@ This subcommand has additional options:
|
|
199
199
|
``-b``, ``--backend=BACKEND``
|
200
200
|
Choose a backend: local, ssh, winrm, docker.
|
201
201
|
|
202
|
+
``--cache=CACHE``
|
203
|
+
Use the given path for caching dependencies. (default: ~/.inspec/cache)
|
204
|
+
|
202
205
|
``--color``, ``--no-color``
|
203
206
|
Use colors in output.
|
204
207
|
|
205
208
|
``--controls=one two three``
|
206
209
|
A list of controls to run. Ignore all other tests.
|
207
210
|
|
211
|
+
``--create-lockfile``, ``--no-create-lockfile``
|
212
|
+
Write out a lockfile based on this execution (unless one already exists)
|
213
|
+
|
208
214
|
``--format=FORMAT``
|
209
215
|
Which formatter to use: cli, progress, documentation, json, json-min
|
210
216
|
|
data/docs/dsl_inspec.md
ADDED
@@ -0,0 +1,245 @@
|
|
1
|
+
---
|
2
|
+
title: InSpec DSL
|
3
|
+
---
|
4
|
+
|
5
|
+
# InSpec DSL
|
6
|
+
|
7
|
+
InSpec is a run-time framework and rule language used to specify compliance, security, and policy requirements. It includes a collection of resources that help you write auditing controls quickly and easily. The syntax used by both open source and |chef compliance| auditing is the same. The open source |inspec resource| framework is compatible with |chef compliance|.
|
8
|
+
|
9
|
+
The InSpec DSL is a Ruby DSL for writing audit controls, which includes audit resources that you can invoke.
|
10
|
+
|
11
|
+
The following sections describe the syntax and show some simple examples of using the InSpec resources.
|
12
|
+
|
13
|
+
## Syntax
|
14
|
+
|
15
|
+
The following resource tests |ssh| server configuration. For example, a simple control may described as:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
describe sshd_config do
|
19
|
+
its('Port') { should eq('22') }
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
In various use cases like implementing IT compliance across different departments, it becomes handy to extend the control with metadata. Each control may define an additional ``impact``, ``title`` or ``desc``. An example looks like:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
control 'sshd-8' do
|
27
|
+
impact 0.6
|
28
|
+
title 'Server: Configure the service port'
|
29
|
+
desc '
|
30
|
+
Always specify which port the SSH server should listen to.
|
31
|
+
Prevent unexpected settings.
|
32
|
+
'
|
33
|
+
tag 'ssh','sshd','openssh-server'
|
34
|
+
tag cce: 'CCE-27072-8'
|
35
|
+
ref 'NSA-RH6-STIG - Section 3.5.2.1', url: 'https://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf'
|
36
|
+
|
37
|
+
describe sshd_config do
|
38
|
+
its('Port') { should eq('22') }
|
39
|
+
end
|
40
|
+
end
|
41
|
+
```
|
42
|
+
|
43
|
+
where
|
44
|
+
|
45
|
+
* `'sshd-8'` is the name of the control
|
46
|
+
* `impact`, `title`, and `desc` define metadata that fully describes the importance of the control, its purpose, with a succinct and complete description
|
47
|
+
* `impact` is an float that measures the importance of the compliance results and must be a value between `0.0` and `1.0`.
|
48
|
+
* `tag` is optional meta-information with with key or key-value pairs
|
49
|
+
* `ref` is a reference to an external document
|
50
|
+
* `describe` is a block that contains at least one test. A `control` block must contain at least one `describe` block, but may contain as many as required
|
51
|
+
* `sshd_config` is an InSpec resource. For the full list of InSpec resources, see InSpec resource documentation
|
52
|
+
* `its('Port')` is the matcher; `{ should eq('22') }` is the test. A `describe` block must contain at least one matcher, but may contain as many as required
|
53
|
+
|
54
|
+
|
55
|
+
## Advanced concepts
|
56
|
+
|
57
|
+
With inspec it is possible to check if at least one of a collection of checks is true. For example: If a setting is configured in two different locations, you may want to test if either configuration A or configuration B have been set. This is accomplished via `describe.one`. It defines a block of tests with at least one valid check.
|
58
|
+
|
59
|
+
```ruby
|
60
|
+
describe.one do
|
61
|
+
describe ConfigurationA do
|
62
|
+
its('setting_1') { should eq true }
|
63
|
+
end
|
64
|
+
|
65
|
+
describe ConfigurationB do
|
66
|
+
its('setting_2') { should eq true }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
```
|
70
|
+
|
71
|
+
## Examples
|
72
|
+
|
73
|
+
The following examples show simple compliance tests using a single `control` block.
|
74
|
+
|
75
|
+
## Test System Event Log
|
76
|
+
|
77
|
+
The following test shows how to audit machines running Windows 2012 R2 that pwassword complexity is enabled:
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
control 'windows-account-102' do
|
81
|
+
impact 1.0
|
82
|
+
title 'Windows Password Complexity is Enabled'
|
83
|
+
desc 'Password must meet complexity requirement'
|
84
|
+
describe security_policy do
|
85
|
+
its('PasswordComplexity') { should eq 1 }
|
86
|
+
end
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
## Are PosgtreSQL passwords empty?
|
91
|
+
|
92
|
+
The following test shows how to audit machines running PostgerSQL to ensure that passwords are not empty.
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
control 'postgres-7' do
|
96
|
+
impact 1.0
|
97
|
+
title 'Don't allow empty passwords'
|
98
|
+
describe postgres_session('user', 'pass').query("SELECT * FROM pg_shadow WHERE passwd IS NULL;") do
|
99
|
+
its('output') { should eq('') }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
## Are MySQL passwords in ENV?
|
105
|
+
|
106
|
+
The following test shows how to audit machines running MySQL to ensure that passwords are not stored in `ENV`:
|
107
|
+
|
108
|
+
```ruby
|
109
|
+
control 'mysql-3' do
|
110
|
+
impact 1.0
|
111
|
+
title 'Do not store your MySQL password in your ENV'
|
112
|
+
desc '
|
113
|
+
Storing credentials in your ENV may easily expose
|
114
|
+
them to an attacker. Prevent this at all costs.
|
115
|
+
'
|
116
|
+
describe command('env') do
|
117
|
+
its('stdout') { should_not match(/^MYSQL_PWD=/) }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
```
|
121
|
+
|
122
|
+
## Is `/etc/ssh` a Directory?
|
123
|
+
|
124
|
+
The following test shows how to audit machines to ensure that `/etc/ssh` is a directory:
|
125
|
+
|
126
|
+
```ruby
|
127
|
+
control 'basic-1' do
|
128
|
+
impact 1.0
|
129
|
+
title '/etc/ssh should be a directory'
|
130
|
+
desc '
|
131
|
+
In order for OpenSSH to function correctly, its
|
132
|
+
configuration path must be a folder.
|
133
|
+
'
|
134
|
+
describe file('/etc/ssh') do
|
135
|
+
it { should be_directory }
|
136
|
+
end
|
137
|
+
end
|
138
|
+
```
|
139
|
+
|
140
|
+
## Is Apache running?
|
141
|
+
|
142
|
+
The following test shows how to audit machines to ensure that Apache is enabled and running:
|
143
|
+
|
144
|
+
```ruby
|
145
|
+
control 'apache-1' do
|
146
|
+
impact 0.3
|
147
|
+
title 'Apache2 should be configured and running'
|
148
|
+
describe service(apache.service) do
|
149
|
+
it { should be_enabled }
|
150
|
+
it { should be_running }
|
151
|
+
end
|
152
|
+
end
|
153
|
+
```
|
154
|
+
|
155
|
+
## Are insecure packages installed ?
|
156
|
+
|
157
|
+
The following test shows how to audit machines for insecure packages:
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
control 'cis-os-services-5.1.3' do
|
161
|
+
impact 0.7
|
162
|
+
title '5.1.3 Ensure rsh client is not installed'
|
163
|
+
|
164
|
+
describe package('rsh') do
|
165
|
+
it { should_not be_installed }
|
166
|
+
end
|
167
|
+
|
168
|
+
describe package('rsh-redone-client') do
|
169
|
+
it { should_not be_installed }
|
170
|
+
end
|
171
|
+
end
|
172
|
+
```
|
173
|
+
|
174
|
+
## Test Windows Registry Keys
|
175
|
+
|
176
|
+
The following test shows how to audit machines to ensure Safe DLL Seach Mode is enabled:
|
177
|
+
|
178
|
+
```ruby
|
179
|
+
control 'windows-base-101' do
|
180
|
+
impact 1.0
|
181
|
+
title 'Safe DLL Search Mode is Enabled'
|
182
|
+
desc '
|
183
|
+
@link: https://msdn.microsoft.com/en-us/library/ms682586(v=vs.85).aspx
|
184
|
+
'
|
185
|
+
describe registry_key('HKLM\\System\\CurrentControlSet\\Control\\Session Manager') do
|
186
|
+
it { should exist }
|
187
|
+
it { should_not have_property_value('SafeDllSearchMode', :type_dword, '0') }
|
188
|
+
end
|
189
|
+
end
|
190
|
+
```
|
191
|
+
|
192
|
+
## Exclude specific test
|
193
|
+
|
194
|
+
This shows how to allow skipping certain tests if conditions are not met, by using `only_if`.
|
195
|
+
In this example the test will not be performed if `redis-cli` command does not exist, because for example package on remote host was not installed.
|
196
|
+
|
197
|
+
```ruby
|
198
|
+
control 'nutcracker-connect-redis-001' do
|
199
|
+
impact 1.0
|
200
|
+
title 'Check if nutcracker can pass commands to redis'
|
201
|
+
desc 'execute redis-cli set key command, to check connectivity of the service'
|
202
|
+
|
203
|
+
only_if do
|
204
|
+
command('redis-cli').exist?
|
205
|
+
end
|
206
|
+
|
207
|
+
describe command('redis-cli SET test_inspec "HELLO"') do
|
208
|
+
its(:stdout) { should match(/OK/) }
|
209
|
+
end
|
210
|
+
end
|
211
|
+
```
|
212
|
+
|
213
|
+
Mixing this with other conditionals (like checking existence of the files etc.) can help to test different test paths using inspec. This way you can skip certain tests which would 100% fail due to the way servers are prepared, but you know that the same test suites are reused later in different circumstances by different teams.
|
214
|
+
|
215
|
+
## Additional metadata for controls
|
216
|
+
|
217
|
+
|
218
|
+
The following example illustrates various ways to add tags and references to `control`
|
219
|
+
|
220
|
+
```ruby
|
221
|
+
control 'ssh-1' do
|
222
|
+
impact 1.0
|
223
|
+
|
224
|
+
title 'Allow only SSH Protocol 2'
|
225
|
+
desc 'Only SSH protocol version 2 connections should be permitted.
|
226
|
+
The default setting in /etc/ssh/sshd_config is correct, and can be
|
227
|
+
verified by ensuring that the following line appears: Protocol 2'
|
228
|
+
|
229
|
+
tag 'production','development'
|
230
|
+
tag 'ssh','sshd','openssh-server'
|
231
|
+
|
232
|
+
tag cce: 'CCE-27072-8'
|
233
|
+
tag disa: 'RHEL-06-000227'
|
234
|
+
|
235
|
+
tag remediation: 'stig_rhel6/recipes/sshd-config.rb'
|
236
|
+
tag remediation: 'https://supermarket.chef.io/cookbooks/ssh-hardening'
|
237
|
+
|
238
|
+
ref 'NSA-RH6-STIG - Section 3.5.2.1', url: 'https://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf'
|
239
|
+
ref 'http://people.redhat.com/swells/scap-security-guide/RHEL/6/output/ssg-centos6-guide-C2S.html'
|
240
|
+
|
241
|
+
describe ssh_config do
|
242
|
+
its ('Protocol') { should eq '2'}
|
243
|
+
end
|
244
|
+
end
|
245
|
+
```
|