inspec 1.37.6 → 1.38.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2deb0a13ed78e24b3fdc0b02b85e08934ed94498
4
- data.tar.gz: cc043ff4dbcc869b811e5a1cddfc982c3d167e96
3
+ metadata.gz: a11293dc2aaa9e66285a63b04a476b03ebe6a703
4
+ data.tar.gz: 5498bd736298eab2b16776a92ebb1921b848e4fd
5
5
  SHA512:
6
- metadata.gz: 2b24779c8fed6870015055c52b2aa2a0eac19b2adeb0324a322125c6fb77bee0f9a432d75825cf8c3f1e6672af8ca90392c96590a9e4351724b5fce446849442
7
- data.tar.gz: 316851c81278ba142874d01b3ab76ed2b8bc4005c5edd5f3c5a41d0756f010fabcfc612dd52ba2d1060aa6a5cd8af53f0d8773d9c0c3270bf3d01ff35bd320a6
6
+ metadata.gz: 001f1e34e039a7eb24f433ecb54fb2afab16f1b6ac4ed86658b9a71db66c958b4b24532feecb072d988d37e3be6a3b37821ab46cbd8457fcd6c1fae47ca0cd96
7
+ data.tar.gz: 35f44d8abafac513133c35844bc1f907263e6023acf5003a48000248d620095a755b2ccf4236e373c67c7273713460b2f930d0895e2db7e37e5a8096413eabae
@@ -1,32 +1,57 @@
1
1
  # Change Log
2
2
  <!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ -->
3
- <!-- latest_release 1.37.6 -->
4
- ## [v1.37.6](https://github.com/chef/inspec/tree/v1.37.6) (2017-09-14)
3
+ <!-- latest_release 1.38.8 -->
4
+ ## [v1.38.5](https://github.com/chef/inspec/tree/v1.38.5) (2017-09-23)
5
5
 
6
6
  #### Merged Pull Requests
7
- - Bump Ruby to 2.3.5 [#2149](https://github.com/chef/inspec/pull/2149) ([adamleff](https://github.com/adamleff))
7
+ - Bump train to 0.27 [#2180](https://github.com/chef/inspec/pull/2180) ([adamleff](https://github.com/adamleff))
8
8
  <!-- latest_release -->
9
9
 
10
- <!-- release_rollup since=1.36.1 -->
11
- ### Changes since 1.36.1 release
10
+ <!-- release_rollup since=1.37.6 -->
11
+ ### Changes since 1.37.6 release
12
12
 
13
- #### Merged Pull Requests
14
- - Bump Ruby to 2.3.5 [#2149](https://github.com/chef/inspec/pull/2149) ([adamleff](https://github.com/adamleff)) <!-- 1.37.6 -->
13
+ #### Bug Fixes
14
+ - Modify Upstart enabled check to use config file [#2163](https://github.com/chef/inspec/pull/2163) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 1.38.2 -->
15
+ - Support `false` for attribute value [#2168](https://github.com/chef/inspec/pull/2168) ([adamleff](https://github.com/adamleff)) <!-- 1.38.1 -->
16
+ - quote username and hostname in mssql_session.rb [#2151](https://github.com/chef/inspec/pull/2151) ([bratdim](https://github.com/bratdim)) <!-- 1.37.11 -->
17
+ - Update method in which Pry hooks are removed [#2170](https://github.com/chef/inspec/pull/2170) ([adamleff](https://github.com/adamleff)) <!-- 1.37.13 -->
18
+
19
+ #### New Resources
20
+ - auditd resource: test active auditd configuration against the audit daemon [#2133](https://github.com/chef/inspec/pull/2133) ([jburns12](https://github.com/jburns12)) <!-- 1.37.9 -->
15
21
 
16
22
  #### Enhancements
17
- - Show versions for inspec compliance profiles [#2143](https://github.com/chef/inspec/pull/2143) ([alexpop](https://github.com/alexpop)) <!-- 1.37.5 -->
18
- - Support profile versions for automate profiles storage [#2128](https://github.com/chef/inspec/pull/2128) ([alexpop](https://github.com/alexpop)) <!-- 1.37.4 -->
23
+ - forgiving default attributes [#2177](https://github.com/chef/inspec/pull/2177) ([arlimus](https://github.com/arlimus)) <!-- 1.38.4 -->
24
+ - Support array syntax for registry_key resource [#2160](https://github.com/chef/inspec/pull/2160) ([adamleff](https://github.com/adamleff)) <!-- 1.37.12 -->
25
+ - Add wildcard/multiple server support to nginx_conf resource [#2141](https://github.com/chef/inspec/pull/2141) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 1.37.8 -->
19
26
 
20
- #### Bug Fixes
21
- - package resource: assume a default Homebrew path [#2140](https://github.com/chef/inspec/pull/2140) ([adamleff](https://github.com/adamleff)) <!-- 1.37.3 -->
22
- - Ignore linked container names when parsing docker containers [#2134](https://github.com/chef/inspec/pull/2134) ([adamleff](https://github.com/adamleff)) <!-- 1.37.2 -->
27
+ #### Merged Pull Requests
28
+ - Bump train to 0.27 [#2180](https://github.com/chef/inspec/pull/2180) ([adamleff](https://github.com/adamleff)) <!-- 1.38.8 -->
29
+ - Properly return postgres query errors on failure [#2179](https://github.com/chef/inspec/pull/2179) ([adamleff](https://github.com/adamleff)) <!-- 1.38.7 -->
30
+ - Add wildcard support to `Utils::FindFiles` [#2159](https://github.com/chef/inspec/pull/2159) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 1.38.6 -->
31
+ - Modify `DirProvider` to allow special characters [#2174](https://github.com/chef/inspec/pull/2174) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 1.38.5 -->
32
+ - Update changelog for v1.38.2 release [#2173](https://github.com/chef/inspec/pull/2173) ([adamleff](https://github.com/adamleff)) <!-- 1.37.13 -->
33
+ - Add deprecation warning to auditd_rules resource [#2156](https://github.com/chef/inspec/pull/2156) ([adamleff](https://github.com/adamleff)) <!-- 1.37.10 -->
34
+ <!-- release_rollup -->
35
+
36
+ <!-- latest_stable_release -->
37
+ ## [v1.37.6](https://github.com/chef/inspec/tree/v1.37.6) (2017-09-14)
23
38
 
24
39
  #### New Resources
25
- - nginx resource: audit the nginx binary and how it was compiled [#1958](https://github.com/chef/inspec/pull/1958) ([rx294](https://github.com/rx294)) <!-- 1.37.1 -->
26
- - etc_fstab resource: test contents of the /etc/fstab file [#2064](https://github.com/chef/inspec/pull/2064) ([dromazmj](https://github.com/dromazmj)) <!-- 1.37.0 -->
27
- <!-- release_rollup -->
40
+ - etc_fstab resource: test contents of the /etc/fstab file [#2064](https://github.com/chef/inspec/pull/2064) ([dromazmj](https://github.com/dromazmj))
41
+ - nginx resource: audit the nginx binary and how it was compiled [#1958](https://github.com/chef/inspec/pull/1958) ([rx294](https://github.com/rx294))
28
42
 
43
+ #### Enhancements
44
+ - Support profile versions for automate profiles storage [#2128](https://github.com/chef/inspec/pull/2128) ([alexpop](https://github.com/alexpop))
45
+ - Show versions for inspec compliance profiles [#2143](https://github.com/chef/inspec/pull/2143) ([alexpop](https://github.com/alexpop))
46
+
47
+ #### Bug Fixes
48
+ - Ignore linked container names when parsing docker containers [#2134](https://github.com/chef/inspec/pull/2134) ([adamleff](https://github.com/adamleff))
49
+ - package resource: assume a default Homebrew path [#2140](https://github.com/chef/inspec/pull/2140) ([adamleff](https://github.com/adamleff))
50
+
51
+ #### Merged Pull Requests
52
+ - Bump Ruby to 2.3.5 for Omnibus build [#2149](https://github.com/chef/inspec/pull/2149) ([adamleff](https://github.com/adamleff))
29
53
  <!-- latest_stable_release -->
54
+
30
55
  ## [v1.36.1](https://github.com/chef/inspec/tree/v1.36.1) (2017-09-07)
31
56
 
32
57
  #### Enhancements
@@ -36,7 +61,6 @@
36
61
  #### Bug Fixes
37
62
  - Modify linux regular expression to handle process names with spaces [#2117](https://github.com/chef/inspec/pull/2117) ([ChadScott](https://github.com/ChadScott))
38
63
  - Fix alternate path profile chaining [#2121](https://github.com/chef/inspec/pull/2121) ([trevor-vaughan](https://github.com/trevor-vaughan))
39
- <!-- latest_stable_release -->
40
64
 
41
65
  ## [v1.35.1](https://github.com/chef/inspec/tree/v1.35.1) (2017-08-31)
42
66
 
@@ -0,0 +1,93 @@
1
+ ---
2
+ title: About the auditd Resource
3
+ ---
4
+
5
+ # auditd
6
+
7
+ Use the `auditd` InSpec audit resource to test the rules for logging that exist on the system. The audit.rules file is typically located under /etc/audit/ and contains the list of rules that define what is captured in log files. These rules are output using the auditcl -l command. This resource supports versions of `audit` >= 2.3.
8
+
9
+ ## Syntax
10
+
11
+ An `auditd` resource block declares one (or more) rules to be tested, and then what that rule should do:
12
+
13
+ describe auditd do
14
+ its('lines') { should include %r(-w /etc/ssh/sshd_config) }
15
+ end
16
+
17
+ or test that multiple individual rules are defined:
18
+
19
+ describe auditd do
20
+ its('lines') { should include %r(-a always,exit -F arch=.* -S init_module,delete_module -F key=modules) }
21
+ its('lines') { should include %r(-a always,exit -F arch=.* -S chmod,fchmod,fchmodat -F auid>=1000 -F auid!=-1 -F key=.+) }
22
+ end
23
+
24
+ where each test must declare one (or more) rules to be tested.
25
+
26
+
27
+ ## Matchers
28
+
29
+ This InSpec audit resource has the following matchers:
30
+
31
+ ### be
32
+
33
+ <%= partial "/shared/matcher_be" %>
34
+
35
+ ### cmp
36
+
37
+ <%= partial "/shared/matcher_cmp" %>
38
+
39
+ ### eq
40
+
41
+ <%= partial "/shared/matcher_eq" %>
42
+
43
+ ### include
44
+
45
+ <%= partial "/shared/matcher_include" %>
46
+
47
+ ### match
48
+
49
+ <%= partial "/shared/matcher_match" %>
50
+
51
+ ## Examples
52
+
53
+ The following examples show how to use this InSpec audit resource.
54
+
55
+ ### Test if a rule contains a matching element that is identified by a regular expression
56
+
57
+ For `audit` >= 2.3:
58
+
59
+ describe auditd do
60
+ its('lines') { should include %r(-a always,exit -F arch=.* -S chown.* -F auid>=1000 -F auid!=-1 -F key=perm_mod) }
61
+ end
62
+
63
+ ### Query the audit daemon status
64
+
65
+ describe auditd.status('backlog') do
66
+ it { should cmp 0 }
67
+ end
68
+
69
+ ### Query properties of rules targeting specific syscalls or files - uniq is used to handle multiple rules for the same syscall with redundant field values
70
+
71
+ describe auditd.syscall('open') do
72
+ its('action.uniq') { should eq ['always'] }
73
+ its('list.uniq') { should eq ['exit'] }
74
+ end
75
+
76
+ describe auditd.file('/etc/sudoers') do
77
+ its('permissions') { should include ['x'] }
78
+ end
79
+
80
+ The where accessor can be used to filter on fields. For example:
81
+
82
+ describe auditd.syscall('chown').where { arch == "b32" } do
83
+ its('action') { should eq ['always'] }
84
+ its('list') { should eq ['exit'] }
85
+ its('exit') { should include ['-EACCES'] }
86
+ its('exit') { should include ['-EPERM'] }
87
+ end
88
+
89
+ The key filter may be useful in evaluating rules with particular key values:
90
+
91
+ describe auditd.where { key == "privileged" } do
92
+ its('permissions') { should include ['x'] }
93
+ end
@@ -61,6 +61,10 @@ an owner:
61
61
 
62
62
  it { should be_executable.by('owner') }
63
63
 
64
+ any user other than the owner or members of the file's group:
65
+
66
+ it { should be_executable.by('others') }
67
+
64
68
  a user:
65
69
 
66
70
  it { should be_executable.by_user('user') }
@@ -121,6 +125,10 @@ an owner:
121
125
 
122
126
  it { should be_readable.by('owner') }
123
127
 
128
+ any user other than the owner or members of the file's group:
129
+
130
+ it { should be_readable.by('others') }
131
+
124
132
  a user:
125
133
 
126
134
  it { should be_readable.by_user('user') }
@@ -175,6 +183,10 @@ an owner:
175
183
 
176
184
  it { should be_writable.by('owner') }
177
185
 
186
+ any user other than the owner or members of the file's group:
187
+
188
+ it { should be_writable.by('others') }
189
+
178
190
  a user:
179
191
 
180
192
  it { should be_writable.by_user('user') }
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.required_ruby_version = '>= 2.1'
28
28
 
29
- spec.add_dependency 'train', '~> 0.26'
29
+ spec.add_dependency 'train', '~> 0.27'
30
30
  spec.add_dependency 'thor', '~> 0.19'
31
31
  spec.add_dependency 'json', '>= 1.8', '< 3.0'
32
32
  spec.add_dependency 'rainbow', '~> 2'
@@ -72,7 +72,7 @@ module Inspec
72
72
  @files = if File.file?(path)
73
73
  [path]
74
74
  else
75
- Dir[File.join(path, '**', '*')]
75
+ Dir[File.join(Shellwords.shellescape(path), '**', '*')]
76
76
  end
77
77
  @path = path
78
78
  end
@@ -3,22 +3,31 @@
3
3
  module Inspec
4
4
  class Attribute
5
5
  attr_accessor :name
6
- def initialize(name, options)
6
+ attr_writer :value
7
+
8
+ DEFAULT_ATTRIBUTE = Class.new do
9
+ def method_missing(*_)
10
+ self
11
+ end
12
+
13
+ def respond_to_missing?(_, _)
14
+ true
15
+ end
16
+ end
17
+
18
+ def initialize(name, options = {})
7
19
  @name = name
8
20
  @opts = options
9
21
  @value = nil
10
22
  end
11
23
 
12
24
  # implicit call is done by inspec to determine the value of an attribute
13
- def value(newvalue = nil)
14
- unless newvalue.nil?
15
- @value = newvalue
16
- end
17
- @value || default
25
+ def value
26
+ @value.nil? ? default : @value
18
27
  end
19
28
 
20
29
  def default
21
- @opts[:default]
30
+ @opts[:default] || DEFAULT_ATTRIBUTE.new
22
31
  end
23
32
 
24
33
  def title
@@ -177,7 +177,7 @@ module Inspec
177
177
  # we need to return an attribute object, to allow dermination of default values
178
178
  attr = Attribute.new(name, options)
179
179
  # read value from given gived values
180
- attr.value(@conf['attributes'][attr.name]) unless @conf['attributes'].nil?
180
+ attr.value = @conf['attributes'][attr.name] unless @conf['attributes'].nil?
181
181
  @attributes.push(attr)
182
182
  attr.value
183
183
  end
@@ -77,6 +77,7 @@ require 'resources/apache'
77
77
  require 'resources/apache_conf'
78
78
  require 'resources/apt'
79
79
  require 'resources/audit_policy'
80
+ require 'resources/auditd'
80
81
  require 'resources/auditd_conf'
81
82
  require 'resources/auditd_rules'
82
83
  require 'resources/bash'
@@ -26,8 +26,13 @@ module Inspec
26
26
  end
27
27
 
28
28
  def configure_pry # rubocop:disable Metrics/AbcSize
29
- # Remove all hooks and checks
30
- Pry.hooks.clear_all
29
+ # Delete any before_session, before_eval, and after_eval hooks so we can
30
+ # replace them with our own. Pry 0.10 used to have a single method to clear
31
+ # all hooks, but this was removed in Pry 0.11.
32
+ [:before_session, :before_eval, :after_eval].each do |event|
33
+ Pry.hooks.get_hooks(event).keys.map { |hook| Pry.hooks.delete_hook(event, hook) }
34
+ end
35
+
31
36
  that = self
32
37
 
33
38
  # Add the help command
@@ -4,5 +4,5 @@
4
4
  # author: Christoph Hartmann
5
5
 
6
6
  module Inspec
7
- VERSION = '1.37.6'.freeze
7
+ VERSION = '1.38.8'.freeze
8
8
  end
@@ -0,0 +1,231 @@
1
+ # encoding: utf-8
2
+ # author: Christoph Hartmann
3
+ # author: Dominik Richter
4
+ # author: Jen Burns
5
+
6
+ require 'forwardable'
7
+ require 'utils/filter_array'
8
+ require 'utils/filter'
9
+ require 'utils/parser'
10
+
11
+ module Inspec::Resources
12
+ # rubocop:disable Metrics/ClassLength
13
+ class AuditDaemon < Inspec.resource(1)
14
+ extend Forwardable
15
+ attr_accessor :lines
16
+ attr_reader :params
17
+
18
+ name 'auditd'
19
+ desc 'Use the auditd InSpec audit resource to test the rules for logging that exist on the system. The audit.rules file is typically located under /etc/audit/ and contains the list of rules that define what is captured in log files. These rules are output using the auditcl -l command.'
20
+ example "
21
+ describe auditd.syscall('chown').where {arch == 'b32'} do
22
+ its('action') { should eq ['always'] }
23
+ its('list') { should eq ['exit'] }
24
+ end
25
+
26
+ describe auditd.where {key == 'privileged'} do
27
+ its('permissions') { should include ['x'] }
28
+ end
29
+
30
+ describe auditd do
31
+ its('lines') { should include %r(-w /etc/ssh/sshd_config) }
32
+ end
33
+ "
34
+
35
+ def initialize
36
+ @content = inspec.command('/sbin/auditctl -l').stdout.chomp
37
+ @params = []
38
+
39
+ if @content =~ /^LIST_RULES:/
40
+ return skip_resource 'The version of audit is outdated. The `auditd` resource supports versions of audit >= 2.3.'
41
+ end
42
+ parse_content
43
+ end
44
+
45
+ filter = FilterTable.create
46
+ filter.add_accessor(:where)
47
+ .add_accessor(:entries)
48
+ .add(:file, field: 'file')
49
+ .add(:list, field: 'list')
50
+ .add(:action, field: 'action')
51
+ .add(:fields, field: 'fields')
52
+ .add(:fields_nokey, field: 'fields_nokey')
53
+ .add(:syscall, field: 'syscall')
54
+ .add(:key, field: 'key')
55
+ .add(:arch, field: 'arch')
56
+ .add(:path, field: 'path')
57
+ .add(:permissions, field: 'permissions')
58
+ .add(:exit, field: 'exit')
59
+
60
+ filter.connect(self, :params)
61
+
62
+ def status(name = nil)
63
+ @status_content ||= inspec.command('/sbin/auditctl -s').stdout.chomp
64
+ @status_params ||= Hash[@status_content.scan(/^([^ ]+) (.*)$/)]
65
+
66
+ return @status_params[name] if name
67
+ @status_params
68
+ end
69
+
70
+ def parse_content
71
+ @lines = @content.lines.map(&:chomp)
72
+
73
+ lines.each do |line|
74
+ if is_file_syscall_syntax?(line)
75
+ file_syscall_syntax_rules_for(line)
76
+ end
77
+
78
+ if is_syscall?(line)
79
+ syscall_rules_for(line)
80
+
81
+ elsif is_file?(line)
82
+ file_rules_for(line)
83
+ end
84
+ end
85
+ end
86
+
87
+ def file_syscall_syntax_rules_for(line)
88
+ file = file_syscall_syntax_for(line)
89
+ action, list = action_list_for(line)
90
+ fields = rule_fields_for(line)
91
+ key_field, fields_nokey = remove_key_from(fields)
92
+ key = key_in(key_field.join(''))
93
+ perms = perms_in(fields)
94
+
95
+ @params.push(
96
+ {
97
+ 'file' => file,
98
+ 'list' => list,
99
+ 'action' => action,
100
+ 'fields' => fields,
101
+ 'permissions' => perms,
102
+ 'key' => key,
103
+ 'fields_nokey' => fields_nokey,
104
+ },)
105
+ end
106
+
107
+ def syscall_rules_for(line)
108
+ syscalls = syscalls_for(line)
109
+ action, list = action_list_for(line)
110
+ fields = rule_fields_for(line)
111
+ key_field, fields_nokey = remove_key_from(fields)
112
+ key = key_in(key_field.join(''))
113
+ arch = arch_in(fields)
114
+ path = path_in(fields)
115
+ perms = perms_in(fields)
116
+ exit_field = exit_in(fields)
117
+
118
+ syscalls.each do |s|
119
+ @params.push(
120
+ {
121
+ 'syscall' => s,
122
+ 'list' => list,
123
+ 'action' => action,
124
+ 'fields' => fields,
125
+ 'key' => key,
126
+ 'arch' => arch,
127
+ 'path' => path,
128
+ 'permissions' => perms,
129
+ 'exit' => exit_field,
130
+ 'fields_nokey' => fields_nokey,
131
+ },)
132
+ end
133
+ end
134
+
135
+ def file_rules_for(line)
136
+ file = file_for(line)
137
+ perms = permissions_for(line)
138
+ key = key_for(line)
139
+
140
+ @params.push(
141
+ {
142
+ 'file' => file,
143
+ 'key' => key,
144
+ 'permissions' => perms,
145
+ },)
146
+ end
147
+
148
+ def to_s
149
+ 'Auditd Rules'
150
+ end
151
+
152
+ private
153
+
154
+ def is_syscall?(line)
155
+ line.match(/-S /)
156
+ end
157
+
158
+ def is_file?(line)
159
+ line.match(/-w /)
160
+ end
161
+
162
+ def is_file_syscall_syntax?(line)
163
+ line.match(/-F path=/)
164
+ end
165
+
166
+ def syscalls_for(line)
167
+ line.scan(/-S ([^ ]+)\s?/).flatten.first.split(',')
168
+ end
169
+
170
+ def action_list_for(line)
171
+ line.scan(/-a ([^,]+),([^ ]+)\s?/).flatten
172
+ end
173
+
174
+ def key_for(line)
175
+ line.match(/-k ([^ ]+)\s?/)[1] if line.include?('-k ')
176
+ end
177
+
178
+ def file_for(line)
179
+ line.match(/-w ([^ ]+)\s?/)[1]
180
+ end
181
+
182
+ def file_syscall_syntax_for(line)
183
+ line.match(/-F path=(\S+)\s?/)[1]
184
+ end
185
+
186
+ def permissions_for(line)
187
+ line.match(/-p ([^ ]+)/)[1].scan(/\w/)
188
+ end
189
+
190
+ def rule_fields_for(line)
191
+ line.gsub(/-[aS] [^ ]+ /, '').split('-F ').map { |l| l.split(' ') }.flatten
192
+ end
193
+
194
+ def arch_in(fields)
195
+ fields.each do |field|
196
+ return field.match(/arch=(\S+)\s?/)[1] if field.start_with?('arch=')
197
+ end
198
+ nil
199
+ end
200
+
201
+ def perms_in(fields)
202
+ fields.each do |field|
203
+ return field.match(/perm=(\S+)\s?/)[1].scan(/\w/) if field.start_with?('perm=')
204
+ end
205
+ nil
206
+ end
207
+
208
+ def path_in(fields)
209
+ fields.each do |field|
210
+ return field.match(/path=(\S+)\s?/)[1] if field.start_with?('path=')
211
+ end
212
+ nil
213
+ end
214
+
215
+ def exit_in(fields)
216
+ fields.each do |field|
217
+ return field.match(/exit=(\S+)\s?/)[1] if field.start_with?('exit=')
218
+ end
219
+ nil
220
+ end
221
+
222
+ def key_in(field)
223
+ _, v = field.split('=')
224
+ v
225
+ end
226
+
227
+ def remove_key_from(fields)
228
+ fields.partition { |x| x.start_with? 'key' }
229
+ end
230
+ end
231
+ end
@@ -87,6 +87,8 @@ module Inspec::Resources
87
87
  parse_content
88
88
  @legacy = nil
89
89
  end
90
+
91
+ warn '[DEPRECATION] The `auditd_rules` resource is deprecated and will be removed in InSpec 2.0. Use the `auditd` resource instead.'
90
92
  end
91
93
 
92
94
  # non-legacy instances are not asked for `its('LIST_RULES')`
@@ -51,11 +51,11 @@ module Inspec::Resources
51
51
  escaped_query = q.gsub(/\\/, '\\\\').gsub(/"/, '\\"').gsub(/\$/, '\\$')
52
52
  # surpress 'x rows affected' in SQLCMD with 'set nocount on;'
53
53
  cmd_string = "sqlcmd -Q \"set nocount on; #{escaped_query}\" -W -w 1024 -s ','"
54
- cmd_string += " -U #{@user} -P '#{@password}'" unless @user.nil? || @password.nil?
54
+ cmd_string += " -U '#{@user}' -P '#{@password}'" unless @user.nil? || @password.nil?
55
55
  if @instance.nil?
56
- cmd_string += " -S #{@host}"
56
+ cmd_string += " -S '#{@host}'"
57
57
  else
58
- cmd_string += " -S #{@host}\\#{@instance}"
58
+ cmd_string += " -S '#{@host}\\#{@instance}'"
59
59
  end
60
60
  cmd = inspec.command(cmd_string)
61
61
  out = cmd.stdout + "\n" + cmd.stderr
@@ -3,6 +3,7 @@
3
3
  # author: Christoph Hartmann
4
4
 
5
5
  require 'utils/nginx_parser'
6
+ require 'utils/find_files'
6
7
  require 'forwardable'
7
8
 
8
9
  # STABILITY: Experimental
@@ -25,6 +26,8 @@ module Inspec::Resources
25
26
 
26
27
  extend Forwardable
27
28
 
29
+ include FindFiles
30
+
28
31
  attr_reader :contents
29
32
 
30
33
  def initialize(conf_path = nil)
@@ -93,13 +96,37 @@ module Inspec::Resources
93
96
  if data.key?('include')
94
97
  data.delete('include').flatten
95
98
  .map { |x| File.expand_path(x, rel_path) }
99
+ .map { |x| find_files(x) }.flatten
96
100
  .map { |path| parse_nginx(path) }
97
- .map { |e| data.merge!(e) }
101
+ .each { |conf| merge_config!(data, conf) }
98
102
  end
99
103
 
100
104
  # Walk through the remaining hash fields to find more references
101
105
  Hash[data.map { |k, v| [k, resolve_references(v, rel_path)] }]
102
106
  end
107
+
108
+ # Deep merge fields from NginxConfig.parse.
109
+ # A regular merge would overwrite values so a deep merge is needed.
110
+ # @param data [Hash] data structure from NginxConfig.parse
111
+ # @param conf [Hash] data structure to be deep merged into data
112
+ # @return [Hash] data structure with conf and data deep merged
113
+ def merge_config!(data, conf)
114
+ # Catch edge-cases
115
+ return if data.nil? || conf.nil?
116
+ # Step through all conf items and create combined return value
117
+ data.merge!(conf) do |_, v1, v2|
118
+ if v1.is_a?(Array) && v2.is_a?(Array)
119
+ # If both the data field and the conf field are arrays, then combine them
120
+ v1 + v2
121
+ elsif v1.is_a?(Hash) && v2.is_a?(Hash)
122
+ # If both the data field and the conf field are maps, then deep merge them
123
+ merge_config!(v1, v2)
124
+ else
125
+ # All other cases, just use the new value (regular merge behavior)
126
+ v2
127
+ end
128
+ end
129
+ end
103
130
  end
104
131
 
105
132
  class NginxConfHttp
@@ -52,7 +52,7 @@ module Inspec::Resources
52
52
  cmd = inspec.command(psql_cmd)
53
53
  out = cmd.stdout + "\n" + cmd.stderr
54
54
  if cmd.exit_status != 0 || out =~ /could not connect to .*/ || out.downcase =~ /^error:.*/
55
- skip_resource "Can't read run query #{query.inspect} on postgres_session: #{out}"
55
+ Lines.new(out, "PostgreSQL query with errors: #{query}")
56
56
  else
57
57
  Lines.new(cmd.stdout.strip, "PostgreSQL query: #{query}")
58
58
  end
@@ -106,10 +106,19 @@ module Inspec::Resources
106
106
  end
107
107
 
108
108
  # returns nil, if not existant or value
109
- def method_missing(meth)
109
+ def method_missing(*keys)
110
+ # allow the use of array syntax in an `its` block so that users
111
+ # can use it to query for keys with . characters in them
112
+ if keys.is_a?(Array)
113
+ keys.shift if keys[0] == :[]
114
+ key = keys.first
115
+ else
116
+ key = keys
117
+ end
118
+
110
119
  # get data
111
120
  val = registry_key(@options[:path])
112
- registry_property_value(val, meth)
121
+ registry_property_value(val, key)
113
122
  end
114
123
 
115
124
  def to_s
@@ -349,40 +349,21 @@ module Inspec::Resources
349
349
  description: nil,
350
350
  installed: true,
351
351
  running: running,
352
- enabled: info_enabled(status, service_name),
352
+ enabled: info_enabled(service_name),
353
353
  type: 'upstart',
354
354
  }
355
355
  end
356
356
 
357
357
  private
358
358
 
359
- def info_enabled(status, service_name)
359
+ def info_enabled(service_name)
360
360
  # check if a service is enabled
361
- # http://upstart.ubuntu.com/cookbook/#determine-if-a-job-is-disabled
362
- # $ initctl show-config $job | grep -q "^ start on" && echo enabled || echo disabled
363
- # Ubuntu 10.04 show-config is not supported
364
- # @see http://manpages.ubuntu.com/manpages/maverick/man8/initctl.8.html
365
- support_for_show_config = Gem::Version.new('1.3')
366
-
367
- if version >= support_for_show_config
368
- config = inspec.command("#{service_ctl} show-config #{service_name}").stdout
369
- else # use config file as fallback
370
- config = inspec.file("/etc/init/#{service_name}.conf").content
371
- end
361
+ config = inspec.file("/etc/init/#{service_name}.conf").content
372
362
 
373
363
  # disregard if the config does not exist
374
364
  return nil if config.nil?
375
- enabled = !config[/^\s*start on/].nil?
376
-
377
- # implement fallback for Ubuntu 10.04
378
- if inspec.os[:name] == 'ubuntu' &&
379
- inspec.os[:release].to_f >= 10.04 &&
380
- inspec.os[:release].to_f < 12.04 &&
381
- status.exit_status == 0
382
- enabled = true
383
- end
384
365
 
385
- enabled
366
+ !config.match(/^\s*start on/).nil?
386
367
  end
387
368
 
388
369
  def version
@@ -24,9 +24,10 @@ module FindFiles
24
24
  depth = opts[:depth]
25
25
  type = TYPES[opts[:type].to_sym] if opts[:type]
26
26
 
27
- cmd = "find #{path}"
27
+ cmd = "sh -c \'find #{path}"
28
28
  cmd += " -type #{type}" unless type.nil?
29
29
  cmd += " -maxdepth #{depth.to_i}" if depth.to_i > 0
30
+ cmd += "\'"
30
31
 
31
32
  result = inspec.command(cmd)
32
33
  exit_status = result.exit_status
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.37.6
4
+ version: 1.38.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Richter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-14 00:00:00.000000000 Z
11
+ date: 2017-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: train
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.26'
19
+ version: '0.27'
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.26'
26
+ version: '0.27'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: thor
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -316,6 +316,7 @@ files:
316
316
  - docs/resources/apache_conf.md.erb
317
317
  - docs/resources/apt.md.erb
318
318
  - docs/resources/audit_policy.md.erb
319
+ - docs/resources/auditd.md.erb
319
320
  - docs/resources/auditd_conf.md.erb
320
321
  - docs/resources/auditd_rules.md.erb
321
322
  - docs/resources/bash.md.erb
@@ -560,6 +561,7 @@ files:
560
561
  - lib/resources/apache_conf.rb
561
562
  - lib/resources/apt.rb
562
563
  - lib/resources/audit_policy.rb
564
+ - lib/resources/auditd.rb
563
565
  - lib/resources/auditd_conf.rb
564
566
  - lib/resources/auditd_rules.rb
565
567
  - lib/resources/bash.rb