inspec 0.16.4 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd9121f0f0fbdd3881f80534bb3fc91cb8256d9a
4
- data.tar.gz: d83f04403f4157f117dd9b9ed413217c8554bfc2
3
+ metadata.gz: 2454963fda63c4f4fbac8878277b21c1fc41d43a
4
+ data.tar.gz: acdaf6cd9432ff53d73a3140344c831d8fe7fa2f
5
5
  SHA512:
6
- metadata.gz: faa3803af3c3f9d516ccafe00e8abb988ab594e8f2294926333cc8e3d3c4ceaa12dda942fb6edcf4ac7343948bc4ed9f94bfba19909c7c0f53205a0b204e8fef
7
- data.tar.gz: a514b070ef2f9d72b631f5289b8d733000faf05fa9ae6538f31183599a72e582fb41c4a14fc819b69f6683db496a8f8995eaf9322e015de7ed621bb475f451ee
6
+ metadata.gz: b08a2835b8f86afca3167418009b38dbdd3196db983d26c4f72cf049cf66deb8efc7e35c58710417e1ffb72ef055755dcb76746e812018a6c6e15a7ee8c45f96
7
+ data.tar.gz: a815b5c316027b14c308642943e57aa8a88e176e7e5abcbb9d658c1e3b3a5626ba66f23fd292df0c5c5f258b7c3a4c339f203e38428c786ac202ba763d63a240
data/CHANGELOG.md CHANGED
@@ -1,7 +1,29 @@
1
1
  # Change Log
2
2
 
3
- ## [0.16.4](https://github.com/chef/inspec/tree/0.16.4) (2016-03-25)
4
- [Full Changelog](https://github.com/chef/inspec/compare/v0.16.3...0.16.4)
3
+ ## [0.17.0](https://github.com/chef/inspec/tree/0.17.0) (2016-03-31)
4
+ [Full Changelog](https://github.com/chef/inspec/compare/v0.16.4...0.17.0)
5
+
6
+ **Implemented enhancements:**
7
+
8
+ - add advanced passwd filters \(experimental\) [\#602](https://github.com/chef/inspec/pull/602) ([arlimus](https://github.com/arlimus))
9
+
10
+ **Closed issues:**
11
+
12
+ - readable.by not working on RHEL7 [\#597](https://github.com/chef/inspec/issues/597)
13
+ - sshd\_config resource no method error [\#595](https://github.com/chef/inspec/issues/595)
14
+ - Update the readme.md file to include new cli output [\#590](https://github.com/chef/inspec/issues/590)
15
+
16
+ **Merged pull requests:**
17
+
18
+ - add file uid and gid accessors [\#603](https://github.com/chef/inspec/pull/603) ([arlimus](https://github.com/arlimus))
19
+ - fix errors introduced in \#593 [\#594](https://github.com/chef/inspec/pull/594) ([chris-rock](https://github.com/chris-rock))
20
+ - Updated documentation and examples to include tags and references [\#593](https://github.com/chef/inspec/pull/593) ([aaronlippold](https://github.com/aaronlippold))
21
+ - Ease removal of whitespace for Powershell Write-Output and VBScript Echo [\#592](https://github.com/chef/inspec/pull/592) ([chris-rock](https://github.com/chris-rock))
22
+ - Amazon linux support for service resource [\#580](https://github.com/chef/inspec/pull/580) ([jbussdieker](https://github.com/jbussdieker))
23
+ - Fixed API calls for inspec compliance [\#537](https://github.com/chef/inspec/pull/537) ([JTabel](https://github.com/JTabel))
24
+
25
+ ## [v0.16.4](https://github.com/chef/inspec/tree/v0.16.4) (2016-03-25)
26
+ [Full Changelog](https://github.com/chef/inspec/compare/v0.16.3...v0.16.4)
5
27
 
6
28
  **Implemented enhancements:**
7
29
 
@@ -19,6 +41,7 @@
19
41
 
20
42
  **Merged pull requests:**
21
43
 
44
+ - 0.16.4 [\#591](https://github.com/chef/inspec/pull/591) ([arlimus](https://github.com/arlimus))
22
45
  - Improvements to gordon example and docs [\#583](https://github.com/chef/inspec/pull/583) ([alexpop](https://github.com/alexpop))
23
46
  - bugfix: fix rare inspec shell missing all resources [\#582](https://github.com/chef/inspec/pull/582) ([alexpop](https://github.com/alexpop))
24
47
  - document tags and refs [\#561](https://github.com/chef/inspec/pull/561) ([chris-rock](https://github.com/chris-rock))
data/README.md CHANGED
@@ -74,13 +74,20 @@ You should now be able to run:
74
74
  ```bash
75
75
  $ inspec --help
76
76
  Commands:
77
- inspec check PATH # verify test structure in PATH
78
- inspec detect # detect the target OS
79
- inspec exec PATHS # run all test files
80
- inspec help [COMMAND] # Describe available commands or one specific command
81
- inspec json PATH # read all tests in PATH and generate a JSON profile
82
- inspec shell # open an interactive debugging shell
83
- inspec version # prints the version of this tool
77
+ inspec archive PATH # archive a profile to tar.gz (default) ...
78
+ inspec check PATH # verify all tests at the specified PATH
79
+ inspec compliance SUBCOMMAND ... # Chef Compliance commands
80
+ inspec detect # detect the target OS
81
+ inspec exec PATH(S) # run all test files at the specified PATH.
82
+ inspec help [COMMAND] # Describe available commands or one spe...
83
+ inspec init TEMPLATE ... # Scaffolds a new project
84
+ inspec json PATH # read all tests in PATH and generate a ...
85
+ inspec shell # open an interactive debugging shell
86
+ inspec supermarket SUBCOMMAND ... # Supermarket commands
87
+ inspec version # prints the version of this tool
88
+
89
+ Options:
90
+ [--diagnose], [--no-diagnose] # Show diagnostics (versions, configurations)
84
91
  ```
85
92
 
86
93
  # Examples
data/docs/ctl_inspec.rst CHANGED
@@ -106,19 +106,26 @@ This subcommand has the following syntax:
106
106
 
107
107
  .. code-block:: bash
108
108
 
109
- $ inspec exec PATHS (options)
109
+ $ inspec exec PATH(S) (options)
110
110
 
111
111
  where:
112
112
 
113
- * ``PATHS`` is one (or more) locations against which tests are run
113
+ * ``PATH(S)`` is one (or more) locations against which tests are run
114
114
 
115
115
  Options
116
116
  -----------------------------------------------------
117
117
  This subcommand has additional options:
118
118
 
119
- ``--id``
119
+ ``--id=``
120
120
  Use to attach a profile identifier to all test results.
121
121
 
122
+ ``--controls="a b c"``
123
+ A list of controls to run. Ignore all other tests.
124
+
125
+ ``--format=FORMAT``
126
+ Which formatter to use: progress, documentation, json
127
+
128
+
122
129
  Examples
123
130
  -----------------------------------------------------
124
131
  The following examples show how to use this subcommand.
@@ -129,6 +136,12 @@ The following examples show how to use this subcommand.
129
136
 
130
137
  $ inspec exec test.rb
131
138
 
139
+ **Run test 'tmp-01' locally and ignore other tests**
140
+
141
+ .. code-block:: bash
142
+
143
+ $ inspec exec test.rb --controls="tmp-01"
144
+
132
145
  **Run a test on a remote host using SSH**
133
146
 
134
147
  .. code-block:: bash
@@ -175,6 +188,9 @@ Options
175
188
  -----------------------------------------------------
176
189
  This subcommand has additional options:
177
190
 
191
+ ``--controls="a b c"``
192
+ Use to read only specific subset of controls in the PATH profile.
193
+
178
194
  ``--id``
179
195
  Use to attach a profile identifier to all test results.
180
196
 
@@ -16,10 +16,12 @@ A complete InSpec rule looks like:
16
16
  control "sshd-11" do
17
17
  impact 1.0
18
18
  title "Server: Set protocol version to SSHv2"
19
- desc "
20
- Set the SSH protocol version to 2. Don't use legacy
21
- insecure SSHv1 connections anymore.
22
- "
19
+ desc "Set the SSH protocol version to 2. Don't use legacy
20
+ insecure SSHv1 connections anymore."
21
+ tag security: "level-1"
22
+ tag "openssh-server"
23
+ ref "Server Security Guide v.1.0", url: "http://..."
24
+
23
25
  describe sshd_config do
24
26
  its('Protocol') { should eq('2') }
25
27
  end
@@ -59,10 +61,12 @@ One of the key differences is that InSpec targets more user groups. It is optimi
59
61
  control "sshd-11" do
60
62
  impact 1.0
61
63
  title "Server: Set protocol version to SSHv2"
62
- desc "
63
- Set the SSH protocol version to 2. Don't use legacy
64
- insecure SSHv1 connections anymore.
65
- "
64
+ desc "Set the SSH protocol version to 2. Don't use legacy
65
+ insecure SSHv1 connections anymore."
66
+ tag security: "level-1"
67
+ tag "openssh-server"
68
+ ref "Server Security Guide v.1.0" url: "http://..."
69
+
66
70
  describe sshd_config do
67
71
  its('Protocol') { should cmp 2 }
68
72
  end
data/docs/readme.rst CHANGED
@@ -24,6 +24,9 @@ We add a control to this file, to check the ``/tmp`` path in our system:
24
24
  impact 0.7 # The criticality, if this control fails.
25
25
  title "Create separate /tmp partition" # A human-readable title
26
26
  desc "An optional description..."
27
+ tag mygroup: "tag" # A tag can be a simple value or
28
+ tag "tag" # can have a more complex key/value pair.
29
+ ref "name", url: "http://..." # A reference to a document, uri: is optional
27
30
  describe file('/tmp') do # The actual test
28
31
  it { should be_mounted }
29
32
  end
@@ -50,10 +53,11 @@ It will contain:
50
53
  control "sshd-11" do
51
54
  impact 1.0
52
55
  title "Server: Set protocol version to SSHv2"
53
- desc "
54
- Set the SSH protocol version to 2. Don't use legacy
55
- insecure SSHv1 connections anymore.
56
- "
56
+ desc "Set the SSH protocol version to 2. Don't use legacy
57
+ insecure SSHv1 connections anymore."
58
+ tag security: "openssh-server"
59
+ ref "Document A-12"
60
+
57
61
  describe sshd_config do
58
62
  its('Protocol') { should eq('2') }
59
63
  end
@@ -62,11 +66,12 @@ It will contain:
62
66
  control "sshd-7" do
63
67
  impact 1.0
64
68
  title "Server: Do not permit root-based login with password."
65
- desc "
66
- To reduce the potential to gain full privileges
67
- of a system in the course of an attack (by either misconfiguration
68
- or vulnerabilities), do not allow login as root with password
69
- "
69
+ desc "To reduce the potential to gain full privileges
70
+ of a system in the course of an attack (by either misconfiguration
71
+ or vulnerabilities), do not allow login as root with password"
72
+ tag security: "openssh-server"
73
+ ref "Document A-12"
74
+
70
75
  describe sshd_config do
71
76
  its('PermitRootLogin') { should match(/no|without-password/) }
72
77
  end
@@ -9,6 +9,8 @@ control "tmp-1.0" do # A unique ID for this control
9
9
  impact 0.7 # The criticality, if this control fails.
10
10
  title "Create /tmp directory" # A human-readable title
11
11
  desc "An optional description..." # Describe why this is needed
12
+ tag data: "temp data" # A tag allows you to associate key information
13
+ tag "security" # to the test
12
14
  ref "Document A-12", url: 'http://...' # Additional references
13
15
 
14
16
  describe file('/tmp') do # The actual test
@@ -15,6 +15,9 @@ control 'gordon-1.0' do
15
15
  impact 0.7
16
16
  title 'Verify the version number of Gordon'
17
17
  desc 'An optional description...'
18
+ tag 'gordon'
19
+ ref 'Gordon Requirements 1.0', uri: 'http://...'
20
+
18
21
  describe gordon_config do
19
22
  its('version') { should eq('1.0') }
20
23
  its('size') { should <= 20 }
data/inspec.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
25
25
  spec.require_paths = ['lib']
26
26
 
27
- spec.add_dependency 'r-train', '~> 0.10.1'
27
+ spec.add_dependency 'r-train', '~> 0.10.4'
28
28
  spec.add_dependency 'thor', '~> 0.19'
29
29
  spec.add_dependency 'json', '~> 1.8'
30
30
  spec.add_dependency 'rainbow', '~> 2'
@@ -10,10 +10,10 @@ module Compliance
10
10
  # everything will be stored in local Configuration store
11
11
  class API # rubocop:disable Metrics/ClassLength
12
12
  # logs into the server, retrieves a token and stores it locally
13
- def self.login(server, username, password, insecure)
13
+ def self.login(server, username, password, insecure, apipath)
14
14
  config = Compliance::Configuration.new
15
- config['server'] = server
16
- url = "#{server}/oauth/token"
15
+ config['server'] = "#{server}#{apipath}"
16
+ url = "#{config['server']}/oauth/token"
17
17
 
18
18
  success, data = Compliance::API.post(url, username, password, insecure)
19
19
  if !data.nil?
@@ -16,8 +16,10 @@ module Compliance
16
16
  desc: 'Chef Compliance Password'
17
17
  option :insecure, aliases: :k, type: :boolean,
18
18
  desc: 'Explicitly allows InSpec to perform "insecure" SSL connections and transfers'
19
+ option :apipath, type: :string, default: '/api',
20
+ desc: 'Set the path to the API, defaults to /api'
19
21
  def login(server)
20
- success, msg = Compliance::API.login(server, options['user'], options['password'], options['insecure'])
22
+ success, msg = Compliance::API.login(server, options['user'], options['password'], options['insecure'], options['apipath'])
21
23
  if success
22
24
  puts 'Successfully authenticated'
23
25
  else
@@ -3,5 +3,5 @@
3
3
  # author: Christoph Hartmann
4
4
 
5
5
  module Inspec
6
- VERSION = '0.16.4'.freeze
6
+ VERSION = '0.17.0'.freeze
7
7
  end
@@ -4,6 +4,8 @@
4
4
  # author: Christoph Hartmann
5
5
  # license: All rights reserved
6
6
 
7
+ require 'shellwords'
8
+
7
9
  module Inspec::Resources
8
10
  class FileResource < Inspec.resource(1) # rubocop:disable Metrics/ClassLength
9
11
  name 'file'
@@ -89,6 +91,20 @@ module Inspec::Resources
89
91
  end
90
92
  end
91
93
 
94
+ # TODO: This is temporary and must be moved to train
95
+ def uid
96
+ res = inspec.command('stat '+Shellwords.escape(@path)+' -c %u')
97
+ return nil if res.exit_status != 0 || res.stdout.empty?
98
+ res.stdout.to_i
99
+ end
100
+
101
+ # TODO: This is temporary and must be moved to train
102
+ def gid
103
+ res = inspec.command('stat '+Shellwords.escape(@path)+' -c %u')
104
+ return nil if res.exit_status != 0 || res.stdout.empty?
105
+ res.stdout.to_i
106
+ end
107
+
92
108
  def to_s
93
109
  "File #{path}"
94
110
  end
@@ -16,7 +16,7 @@
16
16
  require 'utils/parser'
17
17
 
18
18
  module Inspec::Resources
19
- class Passwd < Inspec.resource(1)
19
+ class Passwd < Inspec.resource(1) # rubocop:disable Metrics/ClassLength
20
20
  name 'passwd'
21
21
  desc 'Use the passwd InSpec audit resource to test the contents of /etc/passwd, which contains the following information for users that may log into the system and/or as users that own running processes.'
22
22
  example "
@@ -56,16 +56,7 @@ module Inspec::Resources
56
56
  res = @params
57
57
  filters = ''
58
58
  hm.each do |attr, condition|
59
- condition = condition.to_s if condition.is_a? Integer
60
- filters += " #{attr} = #{condition.inspect}"
61
- res = res.find_all do |line|
62
- case line[attr.to_s]
63
- when condition
64
- true
65
- else
66
- false
67
- end
68
- end
59
+ res, filters = filter_attribute(attr, condition, res, filters)
69
60
  end
70
61
  content = res.map { |x| x.values.join(':') }.join("\n")
71
62
  Passwd.new(@path, content: content, filters: @filters + filters)
@@ -124,5 +115,43 @@ module Inspec::Resources
124
115
  def map_data(id)
125
116
  @params.map { |x| x[id] }
126
117
  end
118
+
119
+ def filter_res_line(item, matcher, condition, positive)
120
+ # TODO: REWORK ALL OF THESE, please don't depend on them except for simple equality!
121
+ case matcher
122
+ when '<'
123
+ item.to_i < condition
124
+ when '<='
125
+ item.to_i <= condition
126
+ when '>'
127
+ item.to_i > condition
128
+ when '>='
129
+ item.to_i >= condition
130
+ else
131
+ condition = condition.to_s if condition.is_a? Integer
132
+ case item
133
+ when condition
134
+ positive
135
+ else
136
+ !positive
137
+ end
138
+ end
139
+ end
140
+
141
+ def filter_attribute(attr, condition, res, filters)
142
+ matcher = '=='
143
+ positive = true
144
+ if condition.is_a?(Hash) && condition.length == 1
145
+ matcher = condition.keys[0].to_s
146
+ condition = condition.values[0]
147
+ end
148
+ positive = false if matcher == '!='
149
+
150
+ a = res.find_all do |line|
151
+ filter_res_line(line[attr.to_s], matcher, condition, positive)
152
+ end
153
+ b = filters + " #{attr} #{matcher} #{condition.inspect}"
154
+ [a, b]
155
+ end
127
156
  end
128
157
  end
@@ -36,6 +36,11 @@ module Inspec::Resources
36
36
  nil
37
37
  end
38
38
 
39
+ # Removes leading and trailing whitespace from stdout
40
+ def strip
41
+ result.stdout.strip unless result.stdout.nil?
42
+ end
43
+
39
44
  def to_s
40
45
  'Powershell'
41
46
  end
@@ -139,6 +139,8 @@ module Inspec::Resources
139
139
  Systemd.new(inspec, service_ctl)
140
140
  elsif %w{aix}.include?(family)
141
141
  SrcMstr.new(inspec)
142
+ elsif %w{amazon}.include?(family)
143
+ Upstart.new(inspec, service_ctl)
142
144
  elsif os.solaris?
143
145
  Svcs.new(inspec)
144
146
  end
@@ -121,7 +121,7 @@ describe 'inspec exec' do
121
121
  end
122
122
 
123
123
  it 'ref_line in json' do
124
- ex1['ref_line'].must_equal 14
124
+ ex1['ref_line'].must_equal 16
125
125
  end
126
126
 
127
127
  it 'run_time in json' do
@@ -9,6 +9,11 @@ describe powershell(script) do
9
9
  its('stderr') { should eq '' }
10
10
  end
11
11
 
12
+ # remove whitespace \r\n from stdout
13
+ describe powershell(script) do
14
+ its('strip') { should eq "hello" }
15
+ end
16
+
12
17
  # legacy test with `script` resource
13
18
  describe script(script) do
14
19
  its('stdout') { should eq "hello\r\n" }
@@ -9,6 +9,11 @@ describe vbscript(vbscript) do
9
9
  its('stdout') { should eq "hello\r\n" }
10
10
  end
11
11
 
12
+ # remove whitespace \r\n from stdout
13
+ describe vbscript(vbscript) do
14
+ its('strip') { should eq "hello" }
15
+ end
16
+
12
17
  # ensure that we do not require a newline
13
18
  describe vbscript("Wscript.Stdout.Write \"hello\"") do
14
19
  its('stdout') { should eq 'hello' }
@@ -42,7 +42,7 @@ describe 'Inspec::Resources::Passwd' do
42
42
  end
43
43
 
44
44
  it 'prints a nice to_s string' do
45
- _(child.to_s).must_equal '/etc/passwd with uid = "0"'
45
+ _(child.to_s).must_equal '/etc/passwd with uid == 0'
46
46
  end
47
47
 
48
48
  it 'retrieves singular elements instead of arrays when filter has only one entry' do
@@ -59,7 +59,7 @@ describe 'Inspec::Resources::Passwd' do
59
59
  end
60
60
 
61
61
  it 'prints a nice to_s string' do
62
- _(child.to_s).must_equal '/etc/passwd with user = /^www/'
62
+ _(child.to_s).must_equal '/etc/passwd with user == /^www/'
63
63
  end
64
64
  end
65
65
 
@@ -76,4 +76,37 @@ describe 'Inspec::Resources::Passwd' do
76
76
  _(passwd.usernames).must_equal ['root', 'www-data']
77
77
  end
78
78
  end
79
+
80
+ # TODO REWORK ALL OF THESE, please don't depend on them yet!
81
+ describe 'experimental features' do
82
+ it 'retrieves username via uids < x' do
83
+ _(passwd.uids({ :< => 33 }).count).must_equal 1
84
+ _(passwd.uids({ :< => 34 }).count).must_equal 2
85
+ end
86
+
87
+ it 'retrieves username via uids <= x' do
88
+ _(passwd.uids({ :<= => 32 }).count).must_equal 1
89
+ _(passwd.uids({ :<= => 33 }).count).must_equal 2
90
+ end
91
+
92
+ it 'retrieves username via uids > x' do
93
+ _(passwd.uids({ :> => 0 }).count).must_equal 1
94
+ _(passwd.uids({ :> => -1 }).count).must_equal 2
95
+ end
96
+
97
+ it 'retrieves username via uids >= x' do
98
+ _(passwd.uids({ :>= => 1 }).count).must_equal 1
99
+ _(passwd.uids({ :>= => 0 }).count).must_equal 2
100
+ end
101
+
102
+ it 'retrieves username via uids == x' do
103
+ _(passwd.uids({ :== => 0 }).count).must_equal 1
104
+ _(passwd.uids({ :== => 1 }).count).must_equal 0
105
+ end
106
+
107
+ it 'retrieves username via uids != x' do
108
+ _(passwd.uids({ :!= => 0 }).count).must_equal 1
109
+ _(passwd.uids({ :!= => 1 }).count).must_equal 2
110
+ end
111
+ end
79
112
  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: 0.16.4
4
+ version: 0.17.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-03-25 00:00:00.000000000 Z
11
+ date: 2016-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: r-train
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.10.1
19
+ version: 0.10.4
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.10.1
26
+ version: 0.10.4
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: thor
29
29
  requirement: !ruby/object:Gem::Requirement