inspec 1.5.0 → 1.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -2
- data/Gemfile +1 -0
- data/Rakefile +2 -0
- data/docs/resources/registry_key.md.erb +1 -1
- data/docs/resources/windows_task.md.erb +103 -0
- data/inspec.gemspec +1 -0
- data/lib/inspec/resource.rb +1 -0
- data/lib/inspec/rspec_json_formatter.rb +24 -11
- data/lib/inspec/runner_rspec.rb +1 -0
- data/lib/inspec/version.rb +1 -1
- data/lib/resources/registry_key.rb +1 -1
- data/lib/resources/windows_task.rb +106 -0
- data/lib/source_readers/inspec.rb +1 -1
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd0cb42f326fa8d1e5c78e7cb2d190912f29dbe8
|
4
|
+
data.tar.gz: 1a6b9b13d1c21616d2ab9af800fac73fd573ff8f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 189769e535f062fb5bc6d8f1ea1f16f3fa24a0904f816216ea5cbf810ec38cc87eeb19171d80ce41fed1d52ebeb1a57e07d5aef3098132ee1ad39e0e0726a131
|
7
|
+
data.tar.gz: 9b456f2b72df9b323c1cb9a96a917bfafe2229aa5fabf8507694ba61d75b48477589a6047750c5cbf592f28e0d691a5c589149c44d554761b7008663abc58b49
|
data/CHANGELOG.md
CHANGED
@@ -1,7 +1,33 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
-
## [1.
|
4
|
-
[Full Changelog](https://github.com/chef/inspec/compare/v1.
|
3
|
+
## [1.6.0](https://github.com/chef/inspec/tree/1.6.0) (2016-11-28)
|
4
|
+
[Full Changelog](https://github.com/chef/inspec/compare/v1.5.0...1.6.0)
|
5
|
+
|
6
|
+
**Fixed bugs:**
|
7
|
+
|
8
|
+
- InSpec loads whichever \*.rb file it finds along the way causing itself to fail [\#1326](https://github.com/chef/inspec/issues/1326)
|
9
|
+
|
10
|
+
**Closed issues:**
|
11
|
+
|
12
|
+
- command resource check doesn't fail when it should [\#1318](https://github.com/chef/inspec/issues/1318)
|
13
|
+
- is this a typo.... inpsec? [\#1309](https://github.com/chef/inspec/issues/1309)
|
14
|
+
- support JUnit format [\#1301](https://github.com/chef/inspec/issues/1301)
|
15
|
+
- apt resource fails corner cases with optional second column [\#1261](https://github.com/chef/inspec/issues/1261)
|
16
|
+
|
17
|
+
**Merged pull requests:**
|
18
|
+
|
19
|
+
- do not load controls from test directory [\#1327](https://github.com/chef/inspec/pull/1327) ([chris-rock](https://github.com/chris-rock))
|
20
|
+
- Replaced Colors for output [\#1320](https://github.com/chef/inspec/pull/1320) ([hannah-radish](https://github.com/hannah-radish))
|
21
|
+
- Hannah vj/fix tests formatting [\#1319](https://github.com/chef/inspec/pull/1319) ([hannah-radish](https://github.com/hannah-radish))
|
22
|
+
- revert style changes temporarily [\#1317](https://github.com/chef/inspec/pull/1317) ([vjeffrey](https://github.com/vjeffrey))
|
23
|
+
- Updated color palettes, label colors and icons [\#1313](https://github.com/chef/inspec/pull/1313) ([hannah-radish](https://github.com/hannah-radish))
|
24
|
+
- Remove extra `'` in registry key examples [\#1308](https://github.com/chef/inspec/pull/1308) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
|
25
|
+
- also push docker latest tag with each release [\#1307](https://github.com/chef/inspec/pull/1307) ([chris-rock](https://github.com/chris-rock))
|
26
|
+
- Adding windows\_task resource [\#1306](https://github.com/chef/inspec/pull/1306) ([username-is-already-taken2](https://github.com/username-is-already-taken2))
|
27
|
+
- Adding JUnit formatter support [\#1304](https://github.com/chef/inspec/pull/1304) ([jkerry](https://github.com/jkerry))
|
28
|
+
|
29
|
+
## [v1.5.0](https://github.com/chef/inspec/tree/v1.5.0) (2016-11-21)
|
30
|
+
[Full Changelog](https://github.com/chef/inspec/compare/v1.4.1...v1.5.0)
|
5
31
|
|
6
32
|
**Implemented enhancements:**
|
7
33
|
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -164,6 +164,8 @@ task :release_docker do
|
|
164
164
|
"mv *.gem inspec.gem && "\
|
165
165
|
"docker build -t chef/inspec:#{version} . && "\
|
166
166
|
"docker push chef/inspec:#{version}"
|
167
|
+
"docker tag chef/inspec:#{version} chef/inspec:latest"
|
168
|
+
"docker push chef/inspec:latest"
|
167
169
|
puts "--> #{cmd}"
|
168
170
|
sh('sh', '-c', cmd)
|
169
171
|
end
|
@@ -27,7 +27,7 @@ Or use a Ruby Hash:
|
|
27
27
|
describe registry_key({
|
28
28
|
name: 'Task Scheduler',
|
29
29
|
hive: 'HKEY_LOCAL_MACHINE',
|
30
|
-
key: '
|
30
|
+
key: '\SYSTEM\CurrentControlSet\services\Schedule'
|
31
31
|
}) do
|
32
32
|
its('Start') { should eq 2 }
|
33
33
|
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
---
|
2
|
+
title: About the windows_task Resource
|
3
|
+
---
|
4
|
+
|
5
|
+
# windows_task
|
6
|
+
|
7
|
+
Use the `windows_task` Inspec audit resource to test a scheduled tasks configuration on a Windows platform.
|
8
|
+
Microsoft and application vendors use scheduled tasks to perform a varity of system maintaince tasks but system administrators can schedule their own.
|
9
|
+
|
10
|
+
## Syntax
|
11
|
+
|
12
|
+
A `windows_task` resource block declares the name of the task (as its full path) and tests its configuration:
|
13
|
+
|
14
|
+
describe windows_task('task name uri' do
|
15
|
+
its('parameter') { should eq 'value' }
|
16
|
+
it { should be_enabled }
|
17
|
+
end
|
18
|
+
|
19
|
+
where
|
20
|
+
|
21
|
+
* `'parameter'` must be a valid parameter defined within this resource ie `logon_mode`, `last_result`, `task_to_run`, `run_as_user`
|
22
|
+
* `'value'` will be used to compare the value gather from your chosen parameter
|
23
|
+
* `'be_enabled'` is an example of a valid matcher that checks the state of a task, other examples are `exist` or `be_disabled`
|
24
|
+
|
25
|
+
## Matchers
|
26
|
+
|
27
|
+
This InSpec audit resource has the following matchers:
|
28
|
+
|
29
|
+
### be
|
30
|
+
|
31
|
+
<%= partial "/shared/matcher_be" %>
|
32
|
+
|
33
|
+
### cmp
|
34
|
+
|
35
|
+
<%= partial "/shared/matcher_cmp" %>
|
36
|
+
|
37
|
+
### eq
|
38
|
+
|
39
|
+
<%= partial "/shared/matcher_eq" %>
|
40
|
+
|
41
|
+
### include
|
42
|
+
|
43
|
+
<%= partial "/shared/matcher_include" %>
|
44
|
+
|
45
|
+
### match
|
46
|
+
|
47
|
+
<%= partial "/shared/matcher_match" %>
|
48
|
+
|
49
|
+
## Examples
|
50
|
+
|
51
|
+
The following examples show how to use this InSpec resource.
|
52
|
+
|
53
|
+
### Test's that a task is enabled
|
54
|
+
```
|
55
|
+
describe windows_task('\Microsoft\Windows\Time Synchronization\SynchronizeTime') do
|
56
|
+
it { should be_enabled }
|
57
|
+
end
|
58
|
+
```
|
59
|
+
|
60
|
+
### Test's that a task is disabled
|
61
|
+
```
|
62
|
+
describe windows_task('\Microsoft\Windows\AppID\PolicyConverter') do
|
63
|
+
it { should be_disabled }
|
64
|
+
end
|
65
|
+
```
|
66
|
+
|
67
|
+
### Test's the configuration parameters of a task
|
68
|
+
```
|
69
|
+
describe windows_task('\Microsoft\Windows\AppID\PolicyConverter') do
|
70
|
+
its('logon_mode') { should eq 'Interactive/Background' }
|
71
|
+
its('last_result') { should eq '1' }
|
72
|
+
its('task_to_run') { should cmp '%Windir%\system32\appidpolicyconverter.exe' }
|
73
|
+
its('run_as_user') { should eq 'LOCAL SERVICE' }
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
### Test's that a task is defined
|
78
|
+
```
|
79
|
+
describe windows_task('\Microsoft\Windows\Defrag\ScheduledDefrag') do
|
80
|
+
it { should exist }
|
81
|
+
end
|
82
|
+
```
|
83
|
+
|
84
|
+
## Gathering Tasknames
|
85
|
+
Rather then use the GUI you can use the `schtasks.exe` to output a full list of tasks available on the system
|
86
|
+
|
87
|
+
`schtasks /query /FO list`
|
88
|
+
|
89
|
+
rather than use the `list` output you can use `CSV` if it is easier.
|
90
|
+
|
91
|
+
Please make sure you use the full TaskName (include the prefix `\`) within your control
|
92
|
+
|
93
|
+
```
|
94
|
+
C:\>schtasks /query /FO list
|
95
|
+
...
|
96
|
+
Folder: \Microsoft\Windows\Diagnosis
|
97
|
+
HostName: XPS15
|
98
|
+
TaskName: \Microsoft\Windows\Diagnosis\Scheduled
|
99
|
+
Next Run Time: N/A
|
100
|
+
Status: Ready
|
101
|
+
Logon Mode: Interactive/Background
|
102
|
+
...
|
103
|
+
```
|
data/inspec.gemspec
CHANGED
data/lib/inspec/resource.rb
CHANGED
@@ -125,6 +125,7 @@ require 'resources/sys_info'
|
|
125
125
|
require 'resources/users'
|
126
126
|
require 'resources/vbscript'
|
127
127
|
require 'resources/windows_feature'
|
128
|
+
require 'resources/windows_task'
|
128
129
|
require 'resources/xinetd'
|
129
130
|
require 'resources/wmi'
|
130
131
|
require 'resources/yum'
|
@@ -1,9 +1,11 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
# author: Dominik Richter
|
3
3
|
# author: Christoph Hartmann
|
4
|
+
# author: John Kerry
|
4
5
|
|
5
6
|
require 'rspec/core'
|
6
7
|
require 'rspec/core/formatters/json_formatter'
|
8
|
+
require 'rspec_junit_formatter'
|
7
9
|
|
8
10
|
# Vanilla RSpec JSON formatter with a slight extension to show example IDs.
|
9
11
|
# TODO: Remove these lines when RSpec includes the ID natively
|
@@ -254,21 +256,21 @@ class InspecRspecCli < InspecRspecJson # rubocop:disable Metrics/ClassLength
|
|
254
256
|
}.freeze
|
255
257
|
|
256
258
|
COLORS = {
|
257
|
-
'critical' => "\033[
|
258
|
-
'major' => "\033[
|
259
|
-
'minor' => "\033[
|
260
|
-
'failed' => "\033[
|
261
|
-
'passed' => "\033[
|
262
|
-
'skipped' => "\033[
|
259
|
+
'critical' => "\033[38;5;9m",
|
260
|
+
'major' => "\033[38;5;208m",
|
261
|
+
'minor' => "\033[0;36m",
|
262
|
+
'failed' => "\033[38;5;9m",
|
263
|
+
'passed' => "\033[38;5;41m",
|
264
|
+
'skipped' => "\033[38;5;247m",
|
263
265
|
'reset' => "\033[0m",
|
264
266
|
}.freeze
|
265
267
|
|
266
268
|
INDICATORS = {
|
267
|
-
'critical' => '
|
268
|
-
'major' => '
|
269
|
-
'minor' => '
|
270
|
-
'failed' => '
|
271
|
-
'skipped' => '
|
269
|
+
'critical' => ' × ',
|
270
|
+
'major' => ' ∅ ',
|
271
|
+
'minor' => ' ⊚ ',
|
272
|
+
'failed' => ' × ',
|
273
|
+
'skipped' => ' ↺ ',
|
272
274
|
'passed' => ' ✔ ',
|
273
275
|
'unknown' => ' ? ',
|
274
276
|
'empty' => ' ',
|
@@ -547,3 +549,14 @@ class InspecRspecCli < InspecRspecJson # rubocop:disable Metrics/ClassLength
|
|
547
549
|
data
|
548
550
|
end
|
549
551
|
end
|
552
|
+
|
553
|
+
class InspecRspecJUnit < RSpecJUnitFormatter
|
554
|
+
RSpec::Core::Formatters.register self, :close
|
555
|
+
|
556
|
+
def initialize(*args)
|
557
|
+
super(*args)
|
558
|
+
end
|
559
|
+
|
560
|
+
def close(_notification)
|
561
|
+
end
|
562
|
+
end
|
data/lib/inspec/runner_rspec.rb
CHANGED
data/lib/inspec/version.rb
CHANGED
@@ -20,7 +20,7 @@ require 'json'
|
|
20
20
|
# describe registry_key({
|
21
21
|
# name: 'Task Scheduler',
|
22
22
|
# hive: 'HKEY_LOCAL_MACHINE',
|
23
|
-
# key: '
|
23
|
+
# key: '\SYSTEM\CurrentControlSet\services\Schedule'
|
24
24
|
# }) do
|
25
25
|
# its('Start') { should eq 2 }
|
26
26
|
# end
|
@@ -0,0 +1,106 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# author: Gary Bright @username-is-already-taken2
|
3
|
+
# author: Chris Beard @cdbeard2016
|
4
|
+
module Inspec::Resources
|
5
|
+
class WindowsTasks < Inspec.resource(1)
|
6
|
+
name 'windows_task'
|
7
|
+
desc 'Use the windows_task InSpec audit resource to test task schedules on Microsoft Windows.'
|
8
|
+
example "
|
9
|
+
describe windows_task('\\Microsoft\\Windows\\Time Synchronization\\SynchronizeTime') do
|
10
|
+
it { should be_enabled }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe windows_task('\\Microsoft\\Windows\\AppID\\PolicyConverter') do
|
14
|
+
it { should be_disabled }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe windows_task('\\Microsoft\\Windows\\Defrag\\ScheduledDefrag') do
|
18
|
+
it { should exist }
|
19
|
+
end
|
20
|
+
|
21
|
+
describe windows_task('\\Microsoft\\Windows\\AppID\\PolicyConverter') do
|
22
|
+
its('logon_mode') { should eq 'Interactive/Background' }
|
23
|
+
its('last_result') { should eq '1' }
|
24
|
+
its('task_to_run') { should cmp '%Windir%\\system32\\appidpolicyconverter.exe' }
|
25
|
+
its('run_as_user') { should eq 'LOCAL SERVICE' }
|
26
|
+
end
|
27
|
+
"
|
28
|
+
|
29
|
+
def initialize(taskuri)
|
30
|
+
@taskuri = taskuri
|
31
|
+
@cache = nil
|
32
|
+
|
33
|
+
# verify that this resource is only supported on Windows
|
34
|
+
return skip_resource 'The `windows_task` resource is not supported on your OS.' unless inspec.os.windows?
|
35
|
+
end
|
36
|
+
|
37
|
+
def exists?
|
38
|
+
return true unless info.nil? || info[:uri].nil?
|
39
|
+
false
|
40
|
+
end
|
41
|
+
|
42
|
+
# rubocop:disable Style/WordArray
|
43
|
+
def enabled?
|
44
|
+
return false if info.nil? || info[:state].nil?
|
45
|
+
['Ready', 'Running'].include?(info[:state])
|
46
|
+
end
|
47
|
+
|
48
|
+
def disabled?
|
49
|
+
return false if info.nil? || info[:state].nil?
|
50
|
+
info[:scheduled_task_state] == 'Disabled' || info[:state] == 'Disabled'
|
51
|
+
end
|
52
|
+
|
53
|
+
def logon_mode
|
54
|
+
info[:logon_mode]
|
55
|
+
end
|
56
|
+
|
57
|
+
def last_result
|
58
|
+
info[:last_result]
|
59
|
+
end
|
60
|
+
|
61
|
+
def task_to_run
|
62
|
+
info[:task_to_run].to_s.strip
|
63
|
+
end
|
64
|
+
|
65
|
+
def run_as_user
|
66
|
+
info[:run_as_user]
|
67
|
+
end
|
68
|
+
|
69
|
+
def type
|
70
|
+
info[:type] unless info.nil?
|
71
|
+
end
|
72
|
+
|
73
|
+
def info
|
74
|
+
return @cache unless @cache.nil?
|
75
|
+
# PowerShell v5 has Get-ScheduledTask cmdlet,
|
76
|
+
# _using something with backward support to v3_
|
77
|
+
# script = "Get-ScheduledTask | ? { $_.URI -eq '#{@taskuri}' } | Select-Object URI,@{N='State';E={$_.State.ToString()}} | ConvertTo-Json"
|
78
|
+
|
79
|
+
# Using schtasks as suggested by @modille but aligning property names to match cmdlet to future proof.
|
80
|
+
script = "schtasks /query /v /fo csv /tn '#{@taskuri}' | ConvertFrom-Csv | Select @{N='URI';E={$_.TaskName}},@{N='State';E={$_.Status.ToString()}},'Logon Mode','Last Result','Task To Run','Run As User','Scheduled Task State' | ConvertTo-Json -Compress"
|
81
|
+
|
82
|
+
cmd = inspec.powershell(script)
|
83
|
+
|
84
|
+
begin
|
85
|
+
params = JSON.parse(cmd.stdout)
|
86
|
+
rescue JSON::ParserError => _e
|
87
|
+
return nil
|
88
|
+
end
|
89
|
+
|
90
|
+
@cache = {
|
91
|
+
uri: params['URI'],
|
92
|
+
state: params['State'],
|
93
|
+
logon_mode: params['Logon Mode'],
|
94
|
+
last_result: params['Last Result'],
|
95
|
+
task_to_run: params['Task To Run'],
|
96
|
+
run_as_user: params['Run As User'],
|
97
|
+
scheduled_task_state: params['Scheduled Task State'],
|
98
|
+
type: 'windows-task',
|
99
|
+
}
|
100
|
+
end
|
101
|
+
|
102
|
+
def to_s
|
103
|
+
"Windows Task '#{@taskuri}'"
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
@@ -44,7 +44,7 @@ module SourceReaders
|
|
44
44
|
|
45
45
|
def load_tests
|
46
46
|
tests = @target.files.find_all do |path|
|
47
|
-
path.start_with?('controls'
|
47
|
+
path.start_with?('controls') && path.end_with?('.rb')
|
48
48
|
end
|
49
49
|
Hash[tests.map { |x| [x, @target.read(x)] }]
|
50
50
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inspec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dominik Richter
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: train
|
@@ -204,6 +204,20 @@ dependencies:
|
|
204
204
|
- - "~>"
|
205
205
|
- !ruby/object:Gem::Version
|
206
206
|
version: '1.9'
|
207
|
+
- !ruby/object:Gem::Dependency
|
208
|
+
name: rspec_junit_formatter
|
209
|
+
requirement: !ruby/object:Gem::Requirement
|
210
|
+
requirements:
|
211
|
+
- - "~>"
|
212
|
+
- !ruby/object:Gem::Version
|
213
|
+
version: 0.2.3
|
214
|
+
type: :runtime
|
215
|
+
prerelease: false
|
216
|
+
version_requirements: !ruby/object:Gem::Requirement
|
217
|
+
requirements:
|
218
|
+
- - "~>"
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
version: 0.2.3
|
207
221
|
description: InSpec provides a framework for creating end-to-end infrastructure tests.
|
208
222
|
You can use it for integration or even compliance testing. Create fully portable
|
209
223
|
test profiles and use them in your workflow to ensure stability and security. Integrate
|
@@ -296,6 +310,7 @@ files:
|
|
296
310
|
- docs/resources/users.md.erb
|
297
311
|
- docs/resources/vbscript.md.erb
|
298
312
|
- docs/resources/windows_feature.md.erb
|
313
|
+
- docs/resources/windows_task.md.erb
|
299
314
|
- docs/resources/wmi.md.erb
|
300
315
|
- docs/resources/xinetd_conf.md.erb
|
301
316
|
- docs/resources/yaml.md.erb
|
@@ -495,6 +510,7 @@ files:
|
|
495
510
|
- lib/resources/users.rb
|
496
511
|
- lib/resources/vbscript.rb
|
497
512
|
- lib/resources/windows_feature.rb
|
513
|
+
- lib/resources/windows_task.rb
|
498
514
|
- lib/resources/wmi.rb
|
499
515
|
- lib/resources/xinetd.rb
|
500
516
|
- lib/resources/yaml.rb
|