inspec 1.23.0 → 1.24.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +27 -2429
  3. data/Rakefile +1 -14
  4. data/docs/migration.md +1 -1
  5. data/docs/profiles.md +14 -12
  6. data/docs/resources/mssql_session.md.erb +79 -0
  7. data/docs/resources/oracledb_session.md.erb +71 -0
  8. data/docs/resources/postgres_session.md.erb +17 -10
  9. data/docs/resources/processes.md.erb +11 -1
  10. data/docs/resources/service.md.erb +1 -1
  11. data/examples/inheritance/inspec.lock +11 -0
  12. data/examples/meta-profile/README.md +2 -2
  13. data/examples/meta-profile/controls/example.rb +1 -1
  14. data/examples/meta-profile/inspec.lock +18 -0
  15. data/examples/meta-profile/inspec.yml +1 -1
  16. data/examples/meta-profile/vendor/4d5c9187409941b96f00fb25d0888c301ede999fd63149f35ad4594d698d6535.tar.gz +0 -0
  17. data/examples/meta-profile/vendor/79e6b9846ab539669bbfcf5adcd246f1be484d4b55acb7c1c3dbd852203e4fae.tar.gz +0 -0
  18. data/examples/meta-profile/vendor/dbb5602f09f58d86f8743dfb44327207e9a23a49ef34f65614f1c1d8cc145f6b.tar.gz +0 -0
  19. data/lib/bundles/inspec-habitat/profile.rb +1 -1
  20. data/lib/inspec.rb +1 -0
  21. data/lib/inspec/base_cli.rb +1 -1
  22. data/lib/inspec/dsl.rb +1 -3
  23. data/lib/inspec/exceptions.rb +8 -0
  24. data/lib/inspec/metadata.rb +12 -9
  25. data/lib/inspec/profile.rb +22 -0
  26. data/lib/inspec/resource.rb +1 -0
  27. data/lib/inspec/rspec_json_formatter.rb +9 -0
  28. data/lib/inspec/runner.rb +14 -9
  29. data/lib/inspec/schema.rb +11 -0
  30. data/lib/inspec/secrets/yaml.rb +5 -0
  31. data/lib/inspec/version.rb +1 -1
  32. data/lib/resources/mssql_session.rb +30 -9
  33. data/lib/resources/mysql_session.rb +5 -3
  34. data/lib/resources/oracledb_session.rb +42 -0
  35. data/lib/resources/postgres_session.rb +12 -9
  36. metadata +12 -2
data/Rakefile CHANGED
@@ -4,6 +4,7 @@
4
4
  require 'bundler'
5
5
  require 'bundler/gem_tasks'
6
6
  require 'rake/testtask'
7
+ require_relative 'tasks/changelog'
7
8
  require_relative 'tasks/maintainers'
8
9
 
9
10
  # The docs tasks rely on ruby-progressbar. If we can't load it, then don't
@@ -128,14 +129,6 @@ end
128
129
  # Check the requirements for running an update of this repository.
129
130
  def check_update_requirements
130
131
  require_command 'git'
131
- require_command 'github_changelog_generator', "\n"\
132
- "For more information on how to install it see:\n"\
133
- " https://github.com/skywinder/github-changelog-generator\n"
134
- require_env 'CHANGELOG_GITHUB_TOKEN', "\n"\
135
- "Please configure this token to make sure you can run all commands\n"\
136
- "against GitHub.\n\n"\
137
- "See github_changelog_generator homepage for more information:\n"\
138
- " https://github.com/skywinder/github-changelog-generator\n"
139
132
  end
140
133
 
141
134
  # Show the current version of this gem.
@@ -144,12 +137,6 @@ task :version do
144
137
  inspec_version
145
138
  end
146
139
 
147
- desc 'Generate the changelog'
148
- task :changelog do
149
- require_relative 'lib/inspec/version'
150
- system "github_changelog_generator -u chef -p inspec --future-release v#{Inspec::VERSION} --since-tag 0.7.0"
151
- end
152
-
153
140
  # Update the version of this gem and create an updated
154
141
  # changelog. It covers everything short of actually releasing
155
142
  # the gem.
@@ -46,7 +46,7 @@ The following resources are available in InSpec:
46
46
  | [`yumrepo`](http://serverspec.org/resource_types.html#yumrepo) | [`yum`](https://www.inspec.io/docs/reference/resources/yum/) |
47
47
  | [`zfs`](http://serverspec.org/resource_types.html#zfs) | [`zfs_pool`](https://www.inspec.io/docs/reference/resources/zfs_pool/) |
48
48
 
49
- Some Serverspec resources are not available yet. We implement those resources based on user feedback. If you need a resource that is not available in InSpec, please open an [Github issue](https://github.com/chef/inspec/issues). The list of resources that are not available in InSpec:
49
+ Some Serverspec resources are not available yet. We will implement those resources based on user feedback. If you need a resource that is not available in InSpec, please open an [Github issue](https://github.com/chef/inspec/issues). The list of resources that are not available in InSpec:
50
50
 
51
51
  * [`cgroup`](http://serverspec.org/resource_types.html#cgroup)
52
52
  * [`default_gateway`](http://serverspec.org/resource_types.html#default_gateway)
@@ -157,31 +157,33 @@ For example:
157
157
 
158
158
  ## Chef Supermarket
159
159
 
160
- A `supermarket` setting specifies a profile that is located in a cookbook hosted on Chef Supermarket, with optional settings for branch, tag, commit, and version. The source location is translated into a URL upon resolution. This type of dependency supports version indexing via semantic versioning as git tags.
160
+ A `supermarket` setting specifies a profile that is located in a cookbook hosted on Chef Supermarket. The source location is translated into a URL upon resolution.
161
161
 
162
162
  For example:
163
163
 
164
164
  depends:
165
165
  - name: supermarket-profile
166
- git: username/profile
167
- branch: desired_branch
168
- tag: desired_version
169
- commit: pinned_commit
170
- version: semver_via_tags
166
+ supermarket: supermarket-username/supermarket-profile
167
+
168
+ Available Supermarket profiles can be listed with `inspec supermarket profiles`.
171
169
 
172
170
  ## GitHub
173
171
 
174
- A `github` setting specifies a profile that is located in a repository hosted on GitHub, with optional settings for branch, tag, commit, and version. The source location is translated into a URL upon resolution. This type of dependency supports version indexing via semantic versioning as git tags.
172
+ A `github` setting specifies a profile that is located in a repository hosted on GitHub. The source location is translated into a URL upon resolution.
175
173
 
176
174
  For example:
177
175
 
178
176
  depends:
179
177
  - name: gh-profile
180
- git: username/project
181
- branch: desired_branch
182
- tag: desired_version
183
- commit: pinned_commit
184
- version: semver_via_tags
178
+ github: username/project
179
+
180
+ A path to a Git commit or tag on GitHub can also be used:
181
+
182
+ dev-sec/linux-baseline
183
+ dev-sec/linux-baseline/tree/2.0
184
+ dev-sec/linux-baseline/tree/48bd4388ddffde68badd83aefa654e7af3231876
185
+
186
+ would all download profiles corresponding to the GitHub URL, https://github.com/dev-sec/linux-baseline/tree/48bd4388ddffde68badd83aefa654e7af3231876, for example.
185
187
 
186
188
  ## Chef Compliance
187
189
 
@@ -0,0 +1,79 @@
1
+ ---
2
+ title: About the mssql_session Resource
3
+ ---
4
+
5
+ # mssql_session
6
+
7
+ Use the `mssql_session` InSpec audit resource to test SQL commands run against a Microsoft SQL database.
8
+
9
+ ## Syntax
10
+
11
+ A `mssql_session` resource block declares the username and password to use for the session, and then the command to be run:
12
+
13
+ describe mssql_session(user: 'username', pass: 'password').query('QUERY') do
14
+ its('output') { should eq('') }
15
+ end
16
+
17
+ where
18
+
19
+ * `mssql_session` declares a username and password with permission to run the query. Omitting the username or password parameters results in the use of Windows authentication as the user InSpec is executing as. You may also optionally pass a host and instance name. If omitted, they will default to host: localhost and the default instance.
20
+ * `query('QUERY')` contains the query to be run
21
+ * `its('output') { should eq('') }` compares the results of the query against the expected result in the test
22
+
23
+ ## Matchers
24
+
25
+ This InSpec audit resource has the following matchers:
26
+
27
+ ### be
28
+
29
+ <%= partial "/shared/matcher_be" %>
30
+
31
+ ### cmp
32
+
33
+ <%= partial "/shared/matcher_cmp" %>
34
+
35
+ ### eq
36
+
37
+ <%= partial "/shared/matcher_eq" %>
38
+
39
+ ### include
40
+
41
+ <%= partial "/shared/matcher_include" %>
42
+
43
+ ### match
44
+
45
+ <%= partial "/shared/matcher_match" %>
46
+
47
+ ### output
48
+
49
+ The `output` matcher tests the results of the query:
50
+
51
+ its('output') { should eq(/^0/) }
52
+
53
+ ## Examples
54
+
55
+ The following examples show how to use this InSpec audit resource.
56
+
57
+ ### Test for matching databases
58
+
59
+ sql = mssql_session(user: 'my_user', pass: 'password')
60
+
61
+ describe sql.query('show databases like \'test\';') do
62
+ its('stdout') { should_not match(/test/) }
63
+ end
64
+
65
+ ### Test using Windows authentication
66
+
67
+ sql = mssql_session
68
+
69
+ describe sql.query('show databases like \'test\';') do
70
+ its('stdout') { should_not match(/test/) }
71
+ end
72
+
73
+ ### Test a specific host and instance
74
+
75
+ sql = mssql_session(user: 'my_user', pass: 'password', host: 'mssqlserver', instance: 'foo')
76
+
77
+ describe sql.query('show databases like \'test\';') do
78
+ its('stdout') { should_not match(/test/) }
79
+ end
@@ -0,0 +1,71 @@
1
+ ---
2
+ title: About the oracledb_session Resource
3
+ ---
4
+
5
+ # oracledb_session
6
+
7
+ Use the `oracledb_session` InSpec audit resource to test SQL commands run against a Oracle database.
8
+
9
+ ## Syntax
10
+
11
+ A `oracledb_session` resource block declares the username and password to use for the session with an optional service to connect to, and then the command to be run:
12
+
13
+ describe oracledb_session(user: 'username', pass: 'password').query('QUERY') do
14
+ its('output') { should eq('') }
15
+ end
16
+
17
+ where
18
+
19
+ * `oracledb_session` declares a username and password with permission to run the query (required), and an optional parameters for host (default: `localhost`), SID (default: `nil`, which uses the default SID, and path to the sqlplus binary (default: `sqlplus`).
20
+ * `query('QUERY')` contains the query to be run
21
+ * `its('output') { should eq('') }` compares the results of the query against the expected result in the test
22
+
23
+ ## Matchers
24
+
25
+ This InSpec audit resource has the following matchers:
26
+
27
+ ### be
28
+
29
+ <%= partial "/shared/matcher_be" %>
30
+
31
+ ### cmp
32
+
33
+ <%= partial "/shared/matcher_cmp" %>
34
+
35
+ ### eq
36
+
37
+ <%= partial "/shared/matcher_eq" %>
38
+
39
+ ### include
40
+
41
+ <%= partial "/shared/matcher_include" %>
42
+
43
+ ### match
44
+
45
+ <%= partial "/shared/matcher_match" %>
46
+
47
+ ### output
48
+
49
+ The `output` matcher tests the results of the query:
50
+
51
+ its('output') { should eq(/^0/) }
52
+
53
+ ## Examples
54
+
55
+ The following examples show how to use this InSpec audit resource.
56
+
57
+ ### Test for matching databases
58
+
59
+ sql = oracledb_session(user: 'my_user', pass: 'password')
60
+
61
+ describe sql.query('SELECT NAME FROM v$database;') do
62
+ its('stdout') { should_not match(/test/) }
63
+ end
64
+
65
+ ### Test for matching databases with custom host, SID and sqlplus binary location
66
+
67
+ sql = oracledb_session(user: 'my_user', pass: 'password', host: 'oraclehost', sid: 'mysid', sqlplus_bin: '/u01/app/oracle/product/12.1.0/dbhome_1/bin/sqlplus')
68
+
69
+ describe sql.query('SELECT NAME FROM v$database;') do
70
+ its('stdout') { should_not match(/test/) }
71
+ end
@@ -10,17 +10,24 @@ Use the `postgres_session` InSpec audit resource to test SQL commands run agains
10
10
 
11
11
  A `postgres_session` resource block declares the username and password to use for the session, and then the command to be run:
12
12
 
13
- sql = postgres_session('username', 'password')
13
+ # Create a PostgreSQL session:
14
+ sql = postgres_session('username', 'password', 'host')
14
15
 
16
+ # default values:
17
+ # username: 'postgres'
18
+ # host: 'localhost'
19
+
20
+ # Run an SQL query with an optional database to execute
21
+ sql.query('sql_query', ['database_name'])`
22
+
23
+ A full example is:
24
+
25
+ sql = postgres_session('username', 'password', 'host')
15
26
  describe sql.query('SELECT * FROM pg_shadow WHERE passwd IS NULL;') do
16
- its('output') { should eq('') }
27
+ its('output') { should eq '' }
17
28
  end
18
29
 
19
- where
20
-
21
- * `sql = postgres_session` declares a username and password with permission to run the query
22
- * `sql.query('')` contains the query to be run
23
- * `its('output') { should eq('') }` compares the results of the query against the expected result in the test
30
+ where `its('output') { should eq '' }` compares the results of the query against the expected result in the test
24
31
 
25
32
  ## Matchers
26
33
 
@@ -58,9 +65,9 @@ The following examples show how to use this InSpec audit resource.
58
65
 
59
66
  ### Test the PostgreSQL shadow password
60
67
 
61
- sql = postgres_session('my_user', 'password')
68
+ sql = postgres_session('my_user', 'password', '192.168.1.2')
62
69
 
63
- describe sql.query('SELECT * FROM pg_shadow WHERE passwd IS NULL;') do
70
+ describe sql.query('SELECT * FROM pg_shadow WHERE passwd IS NULL;', ['testdb']) do
64
71
  its('output') { should eq('') }
65
72
  end
66
73
 
@@ -70,6 +77,6 @@ The following examples show how to use this InSpec audit resource.
70
77
  FROM pg_language
71
78
  WHERE lanpltrusted = \'f\'
72
79
  AND lanname!=\'internal\'
73
- AND lanname!=\'c\';') do
80
+ AND lanname!=\'c\';', ['postgres']) do
74
81
  its('output') { should eq '0' }
75
82
  end
@@ -16,7 +16,7 @@ A `processes` resource block declares the name of the process to be tested, and
16
16
 
17
17
  where
18
18
 
19
- * `processes('process_name')` must specify the name of a process that is running on the system
19
+ * `processes('process_name')` specifies the name of a process to check. If this is a string, it will be converted to a Regexp. For more specificity, pass a Regexp directly.
20
20
  * `property_name` may be used to test user (`its('users')`) and state properties (`its('states')`)
21
21
 
22
22
 
@@ -71,3 +71,13 @@ The following examples show how to use this InSpec audit resource.
71
71
  describe processes('some_process') do
72
72
  its('states') { should eq ['R<'] }
73
73
  end
74
+
75
+ ### Test for a process using a specific Regexp
76
+
77
+ If the process name is too common for a string to uniquely find it,
78
+ you may use a regexp. Inclusion of whitespace characters may be
79
+ needed.
80
+
81
+ describe processes(Regexp.new("/usr/local/bin/swap -d")) do
82
+ its('list.length') { should eq 1 }
83
+ end
@@ -6,7 +6,7 @@ title: About the service Resource
6
6
 
7
7
  Use the `service` InSpec audit resource to test if the named service is installed, running and/or enabled.
8
8
 
9
- Under some circumstances, it may be necessary to specify the service manager by using one of the following service manager-specific resources: `bsd_service`, `launchd_service`, `runit_service`, `systemd_service`, `sysv_service`, oe `upstart_service`. These resources are based on the `service` resource.
9
+ Under some circumstances, it may be necessary to specify the service manager by using one of the following service manager-specific resources: `bsd_service`, `launchd_service`, `runit_service`, `systemd_service`, `sysv_service`, or `upstart_service`. These resources are based on the `service` resource.
10
10
 
11
11
  ## Syntax
12
12
 
@@ -0,0 +1,11 @@
1
+ ---
2
+ lockfile_version: 1
3
+ depends:
4
+ - name: profile
5
+ resolved_source:
6
+ path: "/Users/aleff/projects/inspec/examples/profile"
7
+ version_constraints: ">= 0"
8
+ - name: profile-attribute
9
+ resolved_source:
10
+ path: "/Users/aleff/projects/inspec/examples/profile-attribute"
11
+ version_constraints: ">= 0"
@@ -15,7 +15,7 @@ depends:
15
15
  - name: os-hardening
16
16
  url: https://github.com/dev-sec/tests-os-hardening/archive/master.zip
17
17
  # git
18
- - git: https://github.com/dev-sec/ssl-benchmark.git
18
+ - git: https://github.com/dev-sec/ssl-baseline.git
19
19
  - name: windows-patch-benchmark
20
20
  git: https://github.com/chris-rock/windows-patch-benchmark.git
21
21
  # Chef Compliance
@@ -29,7 +29,7 @@ You could use those dependencies in your `exmaple.rb`:
29
29
 
30
30
  include_controls 'hardening/ssh-hardening'
31
31
  include_controls 'os-hardening'
32
- include_controls 'ssl-benchmark'
32
+ include_controls 'ssl-baseline'
33
33
  include_controls 'linux'
34
34
  include_controls 'windows-patch-benchmark'
35
35
  ```
@@ -6,7 +6,7 @@
6
6
  include_controls 'dev-sec/ssh-baseline'
7
7
 
8
8
  # select only individual controls
9
- include_controls 'ssl-benchmark' do
9
+ include_controls 'ssl-baseline' do
10
10
  control "tls1.2"
11
11
  end
12
12
 
@@ -0,0 +1,18 @@
1
+ ---
2
+ lockfile_version: 1
3
+ depends:
4
+ - name: dev-sec/ssh-baseline
5
+ resolved_source:
6
+ url: https://github.com/dev-sec/ssh-baseline/archive/master.tar.gz
7
+ sha256: 79e6b9846ab539669bbfcf5adcd246f1be484d4b55acb7c1c3dbd852203e4fae
8
+ version_constraints: ">= 0"
9
+ - name: ssl-benchmark
10
+ resolved_source:
11
+ url: https://github.com/dev-sec/ssl-benchmark/archive/master.tar.gz
12
+ sha256: 4d5c9187409941b96f00fb25d0888c301ede999fd63149f35ad4594d698d6535
13
+ version_constraints: ">= 0"
14
+ - name: windows-patch-benchmark
15
+ resolved_source:
16
+ url: https://github.com/chris-rock/windows-patch-benchmark/archive/master.tar.gz
17
+ sha256: dbb5602f09f58d86f8743dfb44327207e9a23a49ef34f65614f1c1d8cc145f6b
18
+ version_constraints: ">= 0"
@@ -8,6 +8,6 @@ summary: InSpec Profile that is only consuming dependencies
8
8
  version: 0.2.0
9
9
  depends:
10
10
  - name: dev-sec/ssh-baseline # defaults to supermarket
11
- - url: https://github.com/dev-sec/ssl-benchmark
11
+ - url: https://github.com/dev-sec/ssl-baseline
12
12
  - name: windows-patch-benchmark
13
13
  url: https://github.com/chris-rock/windows-patch-benchmark
@@ -346,7 +346,7 @@ mkdir -p {{pkg.svc_var_path}}/inspec_results
346
346
 
347
347
  while true; do
348
348
  echo "Executing InSpec for ${PROFILE_IDENT}"
349
- hab pkg exec chef/inspec inspec exec {{pkg.path}}/dist --format=json > ${RESULTS_FILE} 2>${ERROR_FILE}
349
+ inspec exec {{pkg.path}}/dist --format=json > ${RESULTS_FILE} 2>${ERROR_FILE}
350
350
 
351
351
  if [ $? -eq 0 ]; then
352
352
  echo "InSpec run completed successfully."
@@ -8,6 +8,7 @@ libdir = File.dirname(__FILE__)
8
8
  $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
9
9
 
10
10
  require 'inspec/version'
11
+ require 'inspec/exceptions'
11
12
  require 'inspec/profile'
12
13
  require 'inspec/rspec_json_formatter'
13
14
  require 'inspec/rule'
@@ -81,7 +81,7 @@ module Inspec
81
81
  runner = Inspec::Runner.new(o)
82
82
  targets.each { |target| runner.add_target(target) }
83
83
  exit runner.run
84
- rescue RuntimeError, Train::UserError => e
84
+ rescue ArgumentError, RuntimeError, Train::UserError => e
85
85
  $stderr.puts e.message
86
86
  exit 1
87
87
  end
@@ -34,11 +34,9 @@ module Inspec::DSL
34
34
  dep_entry = dependencies.list[profile_id]
35
35
  if dep_entry.nil?
36
36
  raise <<EOF
37
- Cannot load #{profile_id} since it is not listed as a dependency
38
- of #{bind_context.profile_name}.
37
+ Cannot load #{profile_id} since it is not listed as a dependency of #{bind_context.profile_name}.
39
38
 
40
39
  Dependencies available from this context are:
41
-
42
40
  #{dependencies.list.keys.join("\n ")}
43
41
  EOF
44
42
  end
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+ # copyright: 2017, Chef Software Inc.
3
+
4
+ module Inspec
5
+ module Exceptions
6
+ class SecretsBackendNotFound < ArgumentError; end
7
+ end
8
+ end