inspec-core 2.2.20 → 2.2.27

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
  SHA256:
3
- metadata.gz: 30bcedf19961b6e6f3d5c4866ce517d14042a5ba0c2cb492da68f94fe9284bac
4
- data.tar.gz: cee89f571ddb03d6cfef422cbd1dfb6380f639505c021ef8cda96ac3fc396aa5
3
+ metadata.gz: d3e83bd4753e30a6a8a6569f787a498373949f5f30a8e2f7ab7eb5b22bae1884
4
+ data.tar.gz: 432466ba45330e301284891409ba146bf23a050808671500a18cf9e269fc492b
5
5
  SHA512:
6
- metadata.gz: 22f243ab058aa7373298dab9c0604cce20a6490d9374a9dc39d27c575676cf6c1a27065c32e267c54cfa95d864767866464ac6565a8d95608838c140305111d4
7
- data.tar.gz: b031ce5c1e573e9652b6beff2055342e1cb0470fa51560589a5e37797cf0040a4d5a2b5cbbeca38e26c4c4860b58e41e751889360ce29934f905503a90b44727
6
+ metadata.gz: 5cac8683865c6beecafe39fbde05794da68f6bd6c60e6a713e3bcfb850c1c5b35cffcf50989ad12ddff6e3fc6271adbd3d7e0f4f6e66c0d11dd440ff470ce218
7
+ data.tar.gz: 76d9f5a01a5030a5b3cb08ffa5db1bef5545ae1ca35cd56e873d16bdff0f0cd79cc961badcc7380d128832215c633619c973565de8c6b9834de70faf875d9393
data/CHANGELOG.md CHANGED
@@ -1,25 +1,43 @@
1
1
  # Change Log
2
2
  <!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ -->
3
- <!-- latest_release 2.2.20 -->
4
- ## [v2.2.20](https://github.com/inspec/inspec/tree/v2.2.20) (2018-06-21)
3
+ <!-- latest_release 2.2.27 -->
4
+ ## [v2.2.27](https://github.com/inspec/inspec/tree/v2.2.27) (2018-06-29)
5
5
 
6
- #### Merged Pull Requests
7
- - Accept symbols and downcased criteria in aws_iam_policy have_statement matcher [#3129](https://github.com/inspec/inspec/pull/3129) ([clintoncwolfe](https://github.com/clintoncwolfe))
6
+ #### New Features
7
+ - Document exit codes for &#39;inspec exec&#39; and add --no-distinct-exit option [#3178](https://github.com/inspec/inspec/pull/3178) ([clintoncwolfe](https://github.com/clintoncwolfe))
8
8
  <!-- latest_release -->
9
9
 
10
- <!-- release_rollup since=2.2.16 -->
11
- ### Changes since 2.2.16 release
10
+ <!-- release_rollup since=2.2.20 -->
11
+ ### Changes since 2.2.20 release
12
12
 
13
- #### Merged Pull Requests
14
- - Accept symbols and downcased criteria in aws_iam_policy have_statement matcher [#3129](https://github.com/inspec/inspec/pull/3129) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.2.20 -->
13
+ #### New Features
14
+ - Document exit codes for &#39;inspec exec&#39; and add --no-distinct-exit option [#3178](https://github.com/inspec/inspec/pull/3178) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.2.27 -->
15
+ - Set parent_profile field on child profiles (json report) [#3164](https://github.com/inspec/inspec/pull/3164) ([jquick](https://github.com/jquick)) <!-- 2.2.25 -->
15
16
 
16
17
  #### Enhancements
17
- - Fix control merging when overriding child controls [#3155](https://github.com/inspec/inspec/pull/3155) ([jquick](https://github.com/jquick)) <!-- 2.2.19 -->
18
- - auditd resource: Add handling for sudo/no command [#3151](https://github.com/inspec/inspec/pull/3151) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 2.2.18 -->
19
- - updated skip message to reflect accurate version of audit support [#3153](https://github.com/inspec/inspec/pull/3153) ([jeremymv2](https://github.com/jeremymv2)) <!-- 2.2.17 -->
18
+ - Update core resources with filtertable API changes [#3117](https://github.com/inspec/inspec/pull/3117) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.2.26 -->
19
+ - apache_conf resource: Strip quotes from values [#3142](https://github.com/inspec/inspec/pull/3142) ([jerryaldrichiii](https://github.com/jerryaldrichiii)) <!-- 2.2.24 -->
20
+
21
+ #### Merged Pull Requests
22
+ - Add functional tests for nested attributes [#3157](https://github.com/inspec/inspec/pull/3157) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.2.23 -->
23
+
24
+ #### Bug Fixes
25
+ - Detect inspec-core mode and do not attempt to load cloud resources [#3163](https://github.com/inspec/inspec/pull/3163) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.2.22 -->
26
+ - Add support for shallow link paths [#3168](https://github.com/inspec/inspec/pull/3168) ([ColinHebert](https://github.com/ColinHebert)) <!-- 2.2.21 -->
20
27
  <!-- release_rollup -->
21
28
 
22
29
  <!-- latest_stable_release -->
30
+ ## [v2.2.20](https://github.com/inspec/inspec/tree/v2.2.20) (2018-06-21)
31
+
32
+ #### Enhancements
33
+ - updated skip message to reflect accurate version of audit support [#3153](https://github.com/inspec/inspec/pull/3153) ([jeremymv2](https://github.com/jeremymv2))
34
+ - auditd resource: Add handling for sudo/no command [#3151](https://github.com/inspec/inspec/pull/3151) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
35
+ - Fix control merging when overriding child controls [#3155](https://github.com/inspec/inspec/pull/3155) ([jquick](https://github.com/jquick))
36
+
37
+ #### Merged Pull Requests
38
+ - Accept symbols and downcased criteria in aws_iam_policy have_statement matcher [#3129](https://github.com/inspec/inspec/pull/3129) ([clintoncwolfe](https://github.com/clintoncwolfe))
39
+ <!-- latest_stable_release -->
40
+
23
41
  ## [v2.2.16](https://github.com/inspec/inspec/tree/v2.2.16) (2018-06-15)
24
42
 
25
43
  #### Enhancements
@@ -31,7 +49,6 @@
31
49
  - Add insecure option to the automate report json [#3124](https://github.com/inspec/inspec/pull/3124) ([jquick](https://github.com/jquick))
32
50
  - Bump train version for inspec [#3147](https://github.com/inspec/inspec/pull/3147) ([jquick](https://github.com/jquick))
33
51
  - deprecate azure_generic_resource [#3132](https://github.com/inspec/inspec/pull/3132) ([chris-rock](https://github.com/chris-rock))
34
- <!-- latest_stable_release -->
35
52
 
36
53
  ## [v2.2.10](https://github.com/inspec/inspec/tree/v2.2.10) (2018-06-08)
37
54
 
@@ -33,7 +33,7 @@ content, size, basename, path, owner, group, type
33
33
 
34
34
  ### Unix/Linux Properties
35
35
 
36
- symlink, mode, link_path, mtime, size, selinux\_label, md5sum, sha256sum, path, source, source\_path, uid, gid
36
+ symlink, mode, link_path, shallow_link_path, mtime, size, selinux\_label, md5sum, sha256sum, path, source, source\_path, uid, gid
37
37
 
38
38
  ### Windows Properties
39
39
 
@@ -74,10 +74,17 @@ The following examples show how to use this InSpec audit resource.
74
74
  ### link_path
75
75
 
76
76
  The `link_path` property tests if the file exists at the specified path. If the file is a symlink,
77
- InSpec will resolve the symlink and return the ultimate linked file.
77
+ InSpec will resolve the symlink recursively and return the ultimate linked file.
78
78
 
79
79
  its('link_path') { should eq '/some/path/to/file' }
80
80
 
81
+ ### shallow_link_path
82
+
83
+ The `shallow_link_path`` property returns the path that the file refers to, only resolving
84
+ it once (that is, it performs a readlink operation). If the file is not a symlink, nil is returned.
85
+
86
+ its('shallow_link_path') { should eq '/some/path/to/file' }
87
+
81
88
  ### md5sum
82
89
 
83
90
  The `md5sum` property tests if the MD5 checksum for a file matches the specified value.
@@ -316,7 +323,7 @@ The following example shows how to use the `file` audit resource to verify if th
316
323
 
317
324
  ### Test parameters of symlinked file
318
325
 
319
- If you need to test the parameters of the target file for a symlink, you can use the `link_path` method for the `file` resource.
326
+ If you need to test the parameters of the target file for a symlink, you can use the `link_path` (recursive resolution) or `shallow_link_path` (direct link) method for the `file` resource.
320
327
 
321
328
  For example, for the following symlink:
322
329
 
@@ -83,6 +83,8 @@ module Inspec
83
83
  desc: 'Allow caching for backend command output. (default: true)'
84
84
  option :show_progress, type: :boolean,
85
85
  desc: 'Show progress while executing tests.'
86
+ option :distinct_exit, type: :boolean, default: true,
87
+ desc: 'Exit with code 101 if any tests fail, and 100 if any are skipped (default). If disabled, exit 0 on skips and 1 for failures.'
86
88
  end
87
89
 
88
90
  def self.default_options
data/lib/inspec/cli.rb CHANGED
@@ -156,6 +156,9 @@ class Inspec::InspecCLI < Inspec::BaseCLI
156
156
  end
157
157
 
158
158
  desc 'exec PATHS', 'run all test files at the specified PATH.'
159
+ long_desc <<~EOT
160
+ Loads the given profile(s) and fetches their dependencies if needed. Then connects to the target and executes any controls contained in the profiles. One or more reporters are used to generate output. If all tests passed (no fails, no skips) exit code 0 is returned. If some tests skipped but none failed, exit code 101 is returned. If at least one test failed, exit code 100 is returned. If inspec failed for any other reason, exit code 1 is returned.
161
+ EOT
159
162
  exec_options
160
163
  def exec(*targets)
161
164
  o = opts(:exec).dup
@@ -204,6 +207,8 @@ class Inspec::InspecCLI < Inspec::BaseCLI
204
207
  desc: 'Enable one or more output reporters: cli, documentation, html, progress, json, json-min, json-rspec, junit'
205
208
  option :depends, type: :array, default: [],
206
209
  desc: 'A space-delimited list of local folders containing profiles whose libraries and resources will be loaded into the new shell'
210
+ option :distinct_exit, type: :boolean, default: true,
211
+ desc: 'Exit with code 101 if any tests fail, and 100 if any are skipped (default). If disabled, exit 0 on skips and 1 for failures.'
207
212
  def shell_func
208
213
  o = opts(:shell).dup
209
214
  diagnose(o)
@@ -14,13 +14,13 @@ module Inspec
14
14
  # @param cwd [String] Current working directory for relative path includes
15
15
  # @param vendor_path [String] Path to the vendor directory
16
16
  #
17
- def self.from_lockfile(lockfile, cwd, cache, backend, opts = {})
17
+ def self.from_lockfile(lockfile, config, opts = {})
18
18
  dep_tree = lockfile.deps.map do |dep|
19
- Inspec::Requirement.from_lock_entry(dep, cwd, cache, backend, opts)
19
+ Inspec::Requirement.from_lock_entry(dep, config, opts)
20
20
  end
21
21
 
22
22
  dep_list = flatten_dep_tree(dep_tree)
23
- new(cwd, cache, dep_list, backend)
23
+ new(config[:cwd], config[:cache], dep_list, config[:backend])
24
24
  end
25
25
 
26
26
  def self.from_array(dependencies, cwd, cache, backend)
@@ -17,37 +17,42 @@ module Inspec
17
17
  if dep[:path]
18
18
  req_path = File.expand_path(dep[:path], req_path)
19
19
  end
20
+ config = {
21
+ cache: cache,
22
+ cwd: req_path,
23
+ }
20
24
 
21
25
  new(dep[:name],
22
26
  dep[:version],
23
- cache,
24
- req_path,
27
+ config,
25
28
  opts.merge(dep))
26
29
  end
27
30
 
28
- def self.from_lock_entry(entry, cwd, cache, backend, opts = {})
31
+ def self.from_lock_entry(entry, config, opts = {})
29
32
  req = new(entry[:name],
30
33
  entry[:version_constraints],
31
- cache,
32
- cwd,
33
- entry[:resolved_source].merge(backend: backend).merge(opts))
34
+ config,
35
+ entry[:resolved_source].merge(backend: config[:backend]).merge(opts))
34
36
 
35
37
  locked_deps = []
36
38
  Array(entry[:dependencies]).each do |dep_entry|
37
- locked_deps << Inspec::Requirement.from_lock_entry(dep_entry, cwd, cache, backend, opts)
39
+ dep_config = config.dup
40
+ dep_config[:parent_profile] = entry[:name]
41
+ locked_deps << Inspec::Requirement.from_lock_entry(dep_entry, dep_config, opts)
38
42
  end
39
43
  req.lock_deps(locked_deps)
40
44
  req
41
45
  end
42
46
 
43
47
  attr_reader :cwd, :opts, :version_constraints
44
- def initialize(name, version_constraints, cache, cwd, opts)
48
+ def initialize(name, version_constraints, config, opts)
45
49
  @name = name
46
50
  @version_constraints = Array(version_constraints)
47
- @cache = cache
51
+ @cache = config[:cache]
48
52
  @backend = opts[:backend]
49
53
  @opts = opts
50
- @cwd = cwd
54
+ @cwd = config[:cwd]
55
+ @parent_profile = config[:parent_profile]
51
56
  end
52
57
 
53
58
  #
@@ -114,10 +119,12 @@ module Inspec
114
119
  return @profile unless @profile.nil?
115
120
  opts = @opts.dup
116
121
  opts[:backend] = @backend
117
- if !@dependencies.nil?
122
+ if !@dependencies.nil? && !@dependencies.empty?
118
123
  opts[:dependencies] = Inspec::DependencySet.from_array(@dependencies, @cwd, @cache, @backend)
119
124
  end
120
125
  @profile = Inspec::Profile.for_fetcher(fetcher, opts)
126
+ @profile.parent_profile = @parent_profile
127
+ @profile
121
128
  end
122
129
  end
123
130
  end
@@ -79,6 +79,7 @@ module Inspec
79
79
  end
80
80
 
81
81
  attr_reader :source_reader, :backend, :runner_context, :check_mode
82
+ attr_accessor :parent_profile
82
83
  def_delegator :@source_reader, :tests
83
84
  def_delegator :@source_reader, :libraries
84
85
  def_delegator :@source_reader, :metadata
@@ -230,6 +231,7 @@ module Inspec
230
231
  # add information about the required attributes
231
232
  res[:attributes] = res[:attributes].map(&:to_hash) unless res[:attributes].nil? || res[:attributes].empty?
232
233
  res[:sha256] = sha256
234
+ res[:parent_profile] = parent_profile unless parent_profile.nil?
233
235
  res
234
236
  end
235
237
 
@@ -414,7 +416,13 @@ module Inspec
414
416
  end
415
417
 
416
418
  def load_dependencies
417
- Inspec::DependencySet.from_lockfile(lockfile, cwd, @cache, @backend, { attributes: @attr_values })
419
+ config = {
420
+ cwd: cwd,
421
+ cache: @cache,
422
+ backend: @backend,
423
+ parent_profile: name,
424
+ }
425
+ Inspec::DependencySet.from_lockfile(lockfile, config, { attributes: @attr_values })
418
426
  end
419
427
 
420
428
  # Calculate this profile's SHA256 checksum. Includes metadata, dependencies,
@@ -105,6 +105,7 @@ module Inspec::Reporters
105
105
  copyright_email: p[:copyright_email],
106
106
  supports: p[:supports],
107
107
  attributes: p[:attributes],
108
+ parent_profile: p[:parent_profile],
108
109
  depends: p[:depends],
109
110
  groups: profile_groups(p),
110
111
  controls: profile_controls(p),
@@ -85,15 +85,27 @@ end
85
85
  # Many resources use FilterTable.
86
86
  require 'utils/filter'
87
87
 
88
- # AWS resources are included via their own file.
89
- require 'resource_support/aws' if Gem.loaded_specs.key?('aws-sdk')
90
-
91
- if Gem.loaded_specs.key?('azure_mgmt_resources')
92
- require 'resources/azure/azure_backend.rb'
93
- require 'resources/azure/azure_generic_resource.rb'
94
- require 'resources/azure/azure_resource_group.rb'
95
- require 'resources/azure/azure_virtual_machine.rb'
96
- require 'resources/azure/azure_virtual_machine_data_disk.rb'
88
+ # Detect if we are running the stripped-down inspec-core
89
+ # This relies on AWS being stripped from the inspec-core gem
90
+ inspec_core_only = !File.exist?(File.join(File.dirname(__FILE__), '..', 'resource_support', 'aws.rb'))
91
+
92
+ # Do not attempt to load cloud resources if we are in inspec-core mode
93
+ unless inspec_core_only
94
+ # AWS resources are included via their own file,
95
+ # but only consider loading them if we have the SDK available, and is v2.
96
+ # https://github.com/inspec/inspec/issues/2571
97
+ if Gem.loaded_specs.key?('aws-sdk') && Gem.loaded_specs['aws-sdk'].version < Gem::Version.new('3.0.0')
98
+ require 'resource_support/aws'
99
+ end
100
+
101
+ # Azure resources
102
+ if Gem.loaded_specs.key?('azure_mgmt_resources')
103
+ require 'resources/azure/azure_backend.rb'
104
+ require 'resources/azure/azure_generic_resource.rb'
105
+ require 'resources/azure/azure_resource_group.rb'
106
+ require 'resources/azure/azure_virtual_machine.rb'
107
+ require 'resources/azure/azure_virtual_machine_data_disk.rb'
108
+ end
97
109
  end
98
110
 
99
111
  require 'resources/aide_conf'
@@ -87,9 +87,9 @@ module Inspec
87
87
  if stats[:failed][:total] == 0 && stats[:skipped][:total] == 0
88
88
  0
89
89
  elsif stats[:failed][:total] > 0
90
- 100
90
+ @conf['distinct_exit'] ? 100 : 1
91
91
  elsif stats[:skipped][:total] > 0
92
- 101
92
+ @conf['distinct_exit'] ? 101 : 0
93
93
  else
94
94
  @rspec_exit_code
95
95
  end
@@ -4,5 +4,5 @@
4
4
  # author: Christoph Hartmann
5
5
 
6
6
  module Inspec
7
- VERSION = '2.2.20'
7
+ VERSION = '2.2.27'
8
8
  end
@@ -44,12 +44,10 @@ module Inspec::Resources
44
44
  end
45
45
 
46
46
  filter = FilterTable.create
47
- filter.add_accessor(:where)
48
- .add_accessor(:entries)
49
- .add(:selection_lines, field: 'selection_line')
50
- .add(:rules, field: 'rules')
47
+ filter.register_column(:selection_lines, field: 'selection_line')
48
+ .register_column(:rules, field: 'rules')
51
49
 
52
- filter.connect(self, :params)
50
+ filter.install_filter_methods_on_resource(self, :params)
53
51
 
54
52
  private
55
53
 
@@ -85,6 +85,14 @@ module Inspec::Resources
85
85
  assignment_regex: /^\s*(\S+)\s+((?=.*\s+$).*?|.*)\s*$/,
86
86
  multiple_values: true,
87
87
  ).params
88
+
89
+ # Capture any characters between quotes that are not escaped in values
90
+ params.values.map! do |value|
91
+ value.map! do |sub_value|
92
+ sub_value[/(?<=["|'])(?:\\.|[^"'\\])*(?=["|'])/] || sub_value
93
+ end
94
+ end
95
+
88
96
  @params.merge!(params)
89
97
 
90
98
  to_read = to_read.drop(1)
@@ -55,21 +55,19 @@ module Inspec::Resources
55
55
  end
56
56
 
57
57
  filter = FilterTable.create
58
- filter.add_accessor(:where)
59
- .add_accessor(:entries)
60
- .add(:file, field: 'file')
61
- .add(:list, field: 'list')
62
- .add(:action, field: 'action')
63
- .add(:fields, field: 'fields')
64
- .add(:fields_nokey, field: 'fields_nokey')
65
- .add(:syscall, field: 'syscall')
66
- .add(:key, field: 'key')
67
- .add(:arch, field: 'arch')
68
- .add(:path, field: 'path')
69
- .add(:permissions, field: 'permissions')
70
- .add(:exit, field: 'exit')
71
-
72
- filter.connect(self, :params)
58
+ filter.register_column(:file, field: 'file')
59
+ .register_column(:list, field: 'list')
60
+ .register_column(:action, field: 'action')
61
+ .register_column(:fields, field: 'fields')
62
+ .register_column(:fields_nokey, field: 'fields_nokey')
63
+ .register_column(:syscall, field: 'syscall')
64
+ .register_column(:key, field: 'key')
65
+ .register_column(:arch, field: 'arch')
66
+ .register_column(:path, field: 'path')
67
+ .register_column(:permissions, field: 'permissions')
68
+ .register_column(:exit, field: 'exit')
69
+
70
+ filter.install_filter_methods_on_resource(self, :params)
73
71
 
74
72
  def status(name = nil)
75
73
  @status_content ||= inspec.command('/sbin/auditctl -s').stdout.chomp
@@ -65,24 +65,22 @@ module Inspec::Resources
65
65
  end
66
66
 
67
67
  filter = FilterTable.create
68
- filter.add_accessor(:where)
69
- .add_accessor(:entries)
70
- .add(:minutes, field: 'minute')
71
- .add(:hours, field: 'hour')
72
- .add(:days, field: 'day')
73
- .add(:months, field: 'month')
74
- .add(:weekdays, field: 'weekday')
75
- .add(:user, field: 'user')
76
- .add(:commands, field: 'command')
68
+ filter.register_column(:minutes, field: 'minute')
69
+ .register_column(:hours, field: 'hour')
70
+ .register_column(:days, field: 'day')
71
+ .register_column(:months, field: 'month')
72
+ .register_column(:weekdays, field: 'weekday')
73
+ .register_column(:user, field: 'user')
74
+ .register_column(:commands, field: 'command')
77
75
 
78
76
  # rebuild the crontab line from raw content
79
- filter.add(:content) { |t, _|
77
+ filter.register_custom_property(:content) { |t, _|
80
78
  t.entries.map do |e|
81
79
  [e.minute, e.hour, e.day, e.month, e.weekday, e.user, e.command].compact.join(' ')
82
80
  end.join("\n")
83
81
  }
84
82
 
85
- filter.connect(self, :params)
83
+ filter.install_filter_methods_on_resource(self, :params)
86
84
 
87
85
  def to_s
88
86
  if is_system_crontab?
@@ -10,25 +10,23 @@ module Inspec::Resources
10
10
  class DockerContainerFilter
11
11
  # use filtertable for containers
12
12
  filter = FilterTable.create
13
- filter.add_accessor(:where)
14
- .add_accessor(:entries)
15
- .add(:commands, field: 'command')
16
- .add(:ids, field: 'id')
17
- .add(:images, field: 'image')
18
- .add(:labels, field: 'labels')
19
- .add(:local_volumes, field: 'localvolumes')
20
- .add(:mounts, field: 'mounts')
21
- .add(:names, field: 'names')
22
- .add(:networks, field: 'networks')
23
- .add(:ports, field: 'ports')
24
- .add(:running_for, field: 'runningfor')
25
- .add(:sizes, field: 'size')
26
- .add(:status, field: 'status')
27
- .add(:exists?) { |x| !x.entries.empty? }
28
- .add(:running?) { |x|
13
+ filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
14
+ filter.register_column(:commands, field: 'command')
15
+ .register_column(:ids, field: 'id')
16
+ .register_column(:images, field: 'image')
17
+ .register_column(:labels, field: 'labels')
18
+ .register_column(:local_volumes, field: 'localvolumes')
19
+ .register_column(:mounts, field: 'mounts')
20
+ .register_column(:names, field: 'names')
21
+ .register_column(:networks, field: 'networks')
22
+ .register_column(:ports, field: 'ports')
23
+ .register_column(:running_for, field: 'runningfor')
24
+ .register_column(:sizes, field: 'size')
25
+ .register_column(:status, field: 'status')
26
+ .register_custom_matcher(:running?) { |x|
29
27
  x.where { status.downcase.start_with?('up') }
30
28
  }
31
- filter.connect(self, :containers)
29
+ filter.install_filter_methods_on_resource(self, :containers)
32
30
 
33
31
  attr_reader :containers
34
32
  def initialize(containers)
@@ -38,17 +36,15 @@ module Inspec::Resources
38
36
 
39
37
  class DockerImageFilter
40
38
  filter = FilterTable.create
41
- filter.add_accessor(:where)
42
- .add_accessor(:entries)
43
- .add(:ids, field: 'id')
44
- .add(:repositories, field: 'repository')
45
- .add(:tags, field: 'tag')
46
- .add(:sizes, field: 'size')
47
- .add(:digests, field: 'digest')
48
- .add(:created, field: 'createdat')
49
- .add(:created_since, field: 'createdsize')
50
- .add(:exists?) { |x| !x.entries.empty? }
51
- filter.connect(self, :images)
39
+ filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
40
+ filter.register_column(:ids, field: 'id')
41
+ .register_column(:repositories, field: 'repository')
42
+ .register_column(:tags, field: 'tag')
43
+ .register_column(:sizes, field: 'size')
44
+ .register_column(:digests, field: 'digest')
45
+ .register_column(:created, field: 'createdat')
46
+ .register_column(:created_since, field: 'createdsize')
47
+ filter.install_filter_methods_on_resource(self, :images)
52
48
 
53
49
  attr_reader :images
54
50
  def initialize(images)
@@ -58,16 +54,14 @@ module Inspec::Resources
58
54
 
59
55
  class DockerServiceFilter
60
56
  filter = FilterTable.create
61
- filter.add_accessor(:where)
62
- .add_accessor(:entries)
63
- .add(:ids, field: 'id')
64
- .add(:names, field: 'name')
65
- .add(:modes, field: 'mode')
66
- .add(:replicas, field: 'replicas')
67
- .add(:images, field: 'image')
68
- .add(:ports, field: 'ports')
69
- .add(:exists?) { |x| !x.entries.empty? }
70
- filter.connect(self, :services)
57
+ filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
58
+ filter.register_column(:ids, field: 'id')
59
+ .register_column(:names, field: 'name')
60
+ .register_column(:modes, field: 'mode')
61
+ .register_column(:replicas, field: 'replicas')
62
+ .register_column(:images, field: 'image')
63
+ .register_column(:ports, field: 'ports')
64
+ filter.install_filter_methods_on_resource(self, :services)
71
65
 
72
66
  attr_reader :services
73
67
  def initialize(services)
@@ -24,35 +24,33 @@ module Inspec::Resources
24
24
  "
25
25
 
26
26
  filter = FilterTable.create
27
- filter.add_accessor(:where)
28
- .add_accessor(:entries)
29
- .add(:cluster_name, field: 'cluster_name')
30
- .add(:node_name, field: 'name')
31
- .add(:transport_address, field: 'transport_address')
32
- .add(:host, field: 'host')
33
- .add(:ip, field: 'ip')
34
- .add(:version, field: 'version')
35
- .add(:build_hash, field: 'build_hash')
36
- .add(:total_indexing_buffer, field: 'total_indexing_buffer')
37
- .add(:roles, field: 'roles')
38
- .add(:settings, field: 'settings')
39
- .add(:os, field: 'os')
40
- .add(:process, field: 'process')
41
- .add(:jvm, field: 'jvm')
42
- .add(:transport, field: 'transport')
43
- .add(:http, field: 'http')
44
- .add(:plugins, field: 'plugins')
45
- .add(:plugin_list, field: 'plugin_list')
46
- .add(:modules, field: 'modules')
47
- .add(:module_list, field: 'module_list')
48
- .add(:node_id, field: 'node_id')
49
- .add(:ingest, field: 'ingest')
50
- .add(:exists?) { |x| !x.entries.empty? }
51
- .add(:node_count) { |t, _|
27
+ filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
28
+ filter.register_column(:cluster_name, field: 'cluster_name')
29
+ .register_column(:node_name, field: 'name')
30
+ .register_column(:transport_address, field: 'transport_address')
31
+ .register_column(:host, field: 'host')
32
+ .register_column(:ip, field: 'ip')
33
+ .register_column(:version, field: 'version')
34
+ .register_column(:build_hash, field: 'build_hash')
35
+ .register_column(:total_indexing_buffer, field: 'total_indexing_buffer')
36
+ .register_column(:roles, field: 'roles')
37
+ .register_column(:settings, field: 'settings')
38
+ .register_column(:os, field: 'os')
39
+ .register_column(:process, field: 'process')
40
+ .register_column(:jvm, field: 'jvm')
41
+ .register_column(:transport, field: 'transport')
42
+ .register_column(:http, field: 'http')
43
+ .register_column(:plugins, field: 'plugins')
44
+ .register_column(:plugin_list, field: 'plugin_list')
45
+ .register_column(:modules, field: 'modules')
46
+ .register_column(:module_list, field: 'module_list')
47
+ .register_column(:node_id, field: 'node_id')
48
+ .register_column(:ingest, field: 'ingest')
49
+ .register_custom_property(:node_count) { |t, _|
52
50
  t.entries.length
53
51
  }
54
52
 
55
- filter.connect(self, :nodes)
53
+ filter.install_filter_methods_on_resource(self, :nodes)
56
54
 
57
55
  attr_reader :nodes, :url
58
56
 
@@ -38,17 +38,15 @@ module Inspec::Resources
38
38
  end
39
39
 
40
40
  filter = FilterTable.create
41
- filter.add_accessor(:where)
42
- .add_accessor(:entries)
43
- .add(:device_name, field: 'device_name')
44
- .add(:mount_point, field: 'mount_point')
45
- .add(:file_system_type, field: 'file_system_type')
46
- .add(:mount_options, field: 'mount_options')
47
- .add(:dump_options, field: 'dump_options')
48
- .add(:file_system_options, field: 'file_system_options')
49
- .add(:configured?) { |x| x.entries.any? }
41
+ filter.register_column(:device_name, field: 'device_name')
42
+ .register_column(:mount_point, field: 'mount_point')
43
+ .register_column(:file_system_type, field: 'file_system_type')
44
+ .register_column(:mount_options, field: 'mount_options')
45
+ .register_column(:dump_options, field: 'dump_options')
46
+ .register_column(:file_system_options, field: 'file_system_options')
47
+ .register_custom_matcher(:configured?) { |x| x.entries.any? }
50
48
 
51
- filter.connect(self, :params)
49
+ filter.install_filter_methods_on_resource(self, :params)
52
50
 
53
51
  def nfs_file_systems
54
52
  where { file_system_type.match(/nfs/) }
@@ -33,12 +33,10 @@ class EtcHosts < Inspec.resource(1)
33
33
  end
34
34
 
35
35
  FilterTable.create
36
- .add_accessor(:where)
37
- .add_accessor(:entries)
38
- .add(:ip_address, field: 'ip_address')
39
- .add(:primary_name, field: 'primary_name')
40
- .add(:all_host_names, field: 'all_host_names')
41
- .connect(self, :params)
36
+ .register_column(:ip_address, field: 'ip_address')
37
+ .register_column(:primary_name, field: 'primary_name')
38
+ .register_column(:all_host_names, field: 'all_host_names')
39
+ .install_filter_methods_on_resource(self, :params)
42
40
 
43
41
  private
44
42
 
@@ -29,13 +29,11 @@ module Inspec::Resources
29
29
  end
30
30
 
31
31
  filter = FilterTable.create
32
- filter.add_accessor(:where)
33
- .add_accessor(:entries)
34
- .add(:daemon, field: 'daemon')
35
- .add(:client_list, field: 'client_list')
36
- .add(:options, field: 'options')
32
+ filter.register_column(:daemon, field: 'daemon')
33
+ .register_column(:client_list, field: 'client_list')
34
+ .register_column(:options, field: 'options')
37
35
 
38
- filter.connect(self, :params)
36
+ filter.install_filter_methods_on_resource(self, :params)
39
37
 
40
38
  private
41
39
 
@@ -44,7 +44,7 @@ module Inspec::Resources
44
44
  %w{
45
45
  type exist? file? block_device? character_device? socket? directory?
46
46
  symlink? pipe? mode mode? owner owned_by? group grouped_into?
47
- link_path linked_to? mtime size selinux_label immutable?
47
+ link_path shallow_link_path linked_to? mtime size selinux_label immutable?
48
48
  product_version file_version version? md5sum sha256sum
49
49
  path basename source source_path uid gid
50
50
  }.each do |m|
@@ -28,14 +28,12 @@ module Inspec::Resources
28
28
  attr_reader :params
29
29
 
30
30
  filter = FilterTable.create
31
- filter.add_accessor(:where)
32
- .add_accessor(:entries)
33
- .add(:zone, field: 'zone')
34
- .add(:interfaces, field: 'interfaces')
35
- .add(:sources, field: 'sources')
36
- .add(:services, field: 'services')
37
-
38
- filter.connect(self, :params)
31
+ filter.register_column(:zone, field: 'zone')
32
+ .register_column(:interfaces, field: 'interfaces')
33
+ .register_column(:sources, field: 'sources')
34
+ .register_column(:services, field: 'services')
35
+
36
+ filter.install_filter_methods_on_resource(self, :params)
39
37
 
40
38
  def initialize
41
39
  @params = parse_active_zones(active_zones)
@@ -47,14 +47,12 @@ module Inspec::Resources
47
47
  end
48
48
 
49
49
  filter = FilterTable.create
50
- filter.add_accessor(:where)
51
- .add_accessor(:entries)
52
- .add(:names, field: 'name')
53
- .add(:gids, field: 'gid')
54
- .add(:domains, field: 'domain')
55
- .add(:members, field: 'members')
56
- .add(:exists?) { |x| !x.entries.empty? }
57
- filter.connect(self, :collect_group_details)
50
+ filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
51
+ filter.register_column(:names, field: 'name')
52
+ .register_column(:gids, field: 'gid')
53
+ .register_column(:domains, field: 'domain')
54
+ .register_column(:members, field: 'members')
55
+ filter.install_filter_methods_on_resource(self, :collect_group_details)
58
56
 
59
57
  def to_s
60
58
  'Groups'
@@ -156,9 +156,8 @@ module Inspec::Resources
156
156
  end
157
157
 
158
158
  filter = FilterTable.create
159
- filter.add_accessor(:where)
160
- .add(:servers, field: 'server')
161
- .connect(self, :server_table)
159
+ filter.register_column(:servers, field: 'server')
160
+ .install_filter_methods_on_resource(self, :server_table)
162
161
 
163
162
  def locations
164
163
  servers.map(&:locations).flatten
@@ -184,9 +183,8 @@ module Inspec::Resources
184
183
  end
185
184
 
186
185
  filter = FilterTable.create
187
- filter.add_accessor(:where)
188
- .add(:locations, field: 'location')
189
- .connect(self, :location_table)
186
+ filter.register_column(:locations, field: 'location')
187
+ .install_filter_methods_on_resource(self, :location_table)
190
188
 
191
189
  def to_s
192
190
  server = ''
@@ -42,13 +42,11 @@ module Inspec::Resources
42
42
  end
43
43
 
44
44
  filter = FilterTable.create
45
- filter.add_accessor(:where)
46
- .add_accessor(:entries)
47
- .add(:statuses, field: 'status', style: :simple)
48
- .add(:names, field: 'name')
49
- .add(:versions, field: 'version')
50
- .add(:architectures, field: 'architecture')
51
- .connect(self, :filtered_packages)
45
+ filter.register_column(:statuses, field: 'status', style: :simple)
46
+ .register_column(:names, field: 'name')
47
+ .register_column(:versions, field: 'version')
48
+ .register_column(:architectures, field: 'architecture')
49
+ .install_filter_methods_on_resource(self, :filtered_packages)
52
50
 
53
51
  private
54
52
 
@@ -50,24 +50,22 @@ module Inspec::Resources
50
50
  end
51
51
 
52
52
  filter = FilterTable.create
53
- filter.add_accessor(:where)
54
- .add_accessor(:entries)
55
- .add(:users, field: 'user')
56
- .add(:passwords, field: 'password')
57
- .add(:uids, field: 'uid')
58
- .add(:gids, field: 'gid')
59
- .add(:descs, field: 'desc')
60
- .add(:homes, field: 'home')
61
- .add(:shells, field: 'shell')
53
+ filter.register_column(:users, field: 'user')
54
+ .register_column(:passwords, field: 'password')
55
+ .register_column(:uids, field: 'uid')
56
+ .register_column(:gids, field: 'gid')
57
+ .register_column(:descs, field: 'desc')
58
+ .register_column(:homes, field: 'home')
59
+ .register_column(:shells, field: 'shell')
62
60
 
63
61
  # rebuild the passwd line from raw content
64
- filter.add(:content) { |t, _|
62
+ filter.register_custom_property(:content) { |t, _|
65
63
  t.entries.map do |e|
66
64
  [e.user, e.password, e.uid, e.gid, e.desc, e.home, e.shell].join(':')
67
65
  end.join("\n")
68
66
  }
69
67
 
70
- filter.connect(self, :params)
68
+ filter.install_filter_methods_on_resource(self, :params)
71
69
 
72
70
  def to_s
73
71
  '/etc/passwd'
@@ -39,15 +39,13 @@ module Inspec::Resources
39
39
  end
40
40
 
41
41
  filter = FilterTable.create
42
- filter.add_accessor(:where)
43
- .add_accessor(:entries)
44
- .add(:ports, field: 'port', style: :simple)
45
- .add(:addresses, field: 'address', style: :simple)
46
- .add(:protocols, field: 'protocol', style: :simple)
47
- .add(:processes, field: 'process', style: :simple)
48
- .add(:pids, field: 'pid', style: :simple)
49
- .add(:listening?) { |x| !x.entries.empty? }
50
- filter.connect(self, :info)
42
+ filter.register_column(:ports, field: 'port', style: :simple)
43
+ .register_column(:addresses, field: 'address', style: :simple)
44
+ .register_column(:protocols, field: 'protocol', style: :simple)
45
+ .register_column(:processes, field: 'process', style: :simple)
46
+ .register_column(:pids, field: 'pid', style: :simple)
47
+ .register_custom_matcher(:listening?) { |x| !x.entries.empty? }
48
+ filter.install_filter_methods_on_resource(self, :info)
51
49
 
52
50
  def to_s
53
51
  "Port #{@port}"
@@ -28,16 +28,14 @@ module Inspec::Resources
28
28
  end
29
29
 
30
30
  filter = FilterTable.create
31
- filter.add_accessor(:where)
32
- .add_accessor(:entries)
33
- .add(:type, field: 'type')
34
- .add(:database, field: 'database')
35
- .add(:user, field: 'user')
36
- .add(:address, field: 'address')
37
- .add(:auth_method, field: 'auth_method')
38
- .add(:auth_params, field: 'auth_params')
31
+ filter.register_column(:type, field: 'type')
32
+ .register_column(:database, field: 'database')
33
+ .register_column(:user, field: 'user')
34
+ .register_column(:address, field: 'address')
35
+ .register_column(:auth_method, field: 'auth_method')
36
+ .register_column(:auth_params, field: 'auth_params')
39
37
 
40
- filter.connect(self, :params)
38
+ filter.install_filter_methods_on_resource(self, :params)
41
39
 
42
40
  def to_s
43
41
  "Postgres Hba Config #{@conf_file}"
@@ -27,13 +27,11 @@ module Inspec::Resources
27
27
  end
28
28
 
29
29
  filter = FilterTable.create
30
- filter.add_accessor(:where)
31
- .add_accessor(:entries)
32
- .add(:map_name, field: 'map_name')
33
- .add(:system_username, field: 'system_username')
34
- .add(:pg_username, field: 'pg_username')
30
+ filter.register_column(:map_name, field: 'map_name')
31
+ .register_column(:system_username, field: 'system_username')
32
+ .register_column(:pg_username, field: 'pg_username')
35
33
 
36
- filter.connect(self, :params)
34
+ filter.install_filter_methods_on_resource(self, :params)
37
35
 
38
36
  def to_s
39
37
  "PostgreSQL Ident Config #{@conf_file}"
@@ -61,21 +61,19 @@ module Inspec::Resources
61
61
  end
62
62
 
63
63
  filter = FilterTable.create
64
- filter.add_accessor(:where)
65
- .add_accessor(:entries)
66
- .add(:labels, field: 'label')
67
- .add(:pids, field: 'pid')
68
- .add(:cpus, field: 'cpu')
69
- .add(:mem, field: 'mem')
70
- .add(:vsz, field: 'vsz')
71
- .add(:rss, field: 'rss')
72
- .add(:tty, field: 'tty')
73
- .add(:states, field: 'stat')
74
- .add(:start, field: 'start')
75
- .add(:time, field: 'time')
76
- .add(:users, field: 'user')
77
- .add(:commands, field: 'command')
78
- .connect(self, :filtered_processes)
64
+ filter.register_column(:labels, field: 'label')
65
+ .register_column(:pids, field: 'pid')
66
+ .register_column(:cpus, field: 'cpu')
67
+ .register_column(:mem, field: 'mem')
68
+ .register_column(:vsz, field: 'vsz')
69
+ .register_column(:rss, field: 'rss')
70
+ .register_column(:tty, field: 'tty')
71
+ .register_column(:states, field: 'stat')
72
+ .register_column(:start, field: 'start')
73
+ .register_column(:time, field: 'time')
74
+ .register_column(:users, field: 'user')
75
+ .register_column(:commands, field: 'command')
76
+ .install_filter_methods_on_resource(self, :filtered_processes)
79
77
 
80
78
  private
81
79
 
data/lib/resources/ssl.rb CHANGED
@@ -58,15 +58,13 @@ class SSL < Inspec.resource(1)
58
58
  end
59
59
 
60
60
  filter = FilterTable.create
61
- filter.add(:enabled?) do |x|
61
+ filter.register_custom_matcher(:enabled?) do |x|
62
62
  raise 'Cannot determine host for SSL test. Please specify it or use a different target.' if x.resource.host.nil?
63
63
  x.handshake.values.any? { |i| i['success'] }
64
64
  end
65
- filter.add_accessor(:where)
66
- .add_accessor(:entries)
67
- .add(:ciphers, field: 'cipher')
68
- .add(:protocols, field: 'protocol')
69
- .add(:handshake) { |x|
65
+ filter.register_column(:ciphers, field: 'cipher')
66
+ .register_column(:protocols, field: 'protocol')
67
+ .register_custom_property(:handshake) { |x|
70
68
  groups = x.entries.group_by(&:protocol)
71
69
  res = Parallel.map(groups, in_threads: 8) do |proto, e|
72
70
  [proto, SSLShake.hello(x.resource.host, port: x.resource.port,
@@ -75,7 +73,7 @@ class SSL < Inspec.resource(1)
75
73
  end
76
74
  Hash[res]
77
75
  }
78
- .connect(self, :scan_config)
76
+ .install_filter_methods_on_resource(self, :scan_config)
79
77
 
80
78
  def to_s
81
79
  "SSL/TLS on #{@host}:#{@port}"
@@ -70,23 +70,21 @@ module Inspec::Resources
70
70
  end
71
71
 
72
72
  filter = FilterTable.create
73
- filter.add_accessor(:where)
74
- .add_accessor(:entries)
75
- .add(:usernames, field: :username)
76
- .add(:uids, field: :uid)
77
- .add(:gids, field: :gid)
78
- .add(:groupnames, field: :groupname)
79
- .add(:groups, field: :groups)
80
- .add(:homes, field: :home)
81
- .add(:shells, field: :shell)
82
- .add(:mindays, field: :mindays)
83
- .add(:maxdays, field: :maxdays)
84
- .add(:warndays, field: :warndays)
85
- .add(:disabled, field: :disabled)
86
- .add(:exists?) { |x| !x.entries.empty? }
87
- .add(:disabled?) { |x| x.where { disabled == false }.entries.empty? }
88
- .add(:enabled?) { |x| x.where { disabled == true }.entries.empty? }
89
- filter.connect(self, :collect_user_details)
73
+ filter.register_custom_matcher(:exists?) { |x| !x.entries.empty? }
74
+ filter.register_column(:usernames, field: :username)
75
+ .register_column(:uids, field: :uid)
76
+ .register_column(:gids, field: :gid)
77
+ .register_column(:groupnames, field: :groupname)
78
+ .register_column(:groups, field: :groups)
79
+ .register_column(:homes, field: :home)
80
+ .register_column(:shells, field: :shell)
81
+ .register_column(:mindays, field: :mindays)
82
+ .register_column(:maxdays, field: :maxdays)
83
+ .register_column(:warndays, field: :warndays)
84
+ .register_column(:disabled, field: :disabled)
85
+ .register_custom_matcher(:disabled?) { |x| x.where { disabled == false }.entries.empty? }
86
+ .register_custom_matcher(:enabled?) { |x| x.where { disabled == true }.entries.empty? }
87
+ filter.install_filter_methods_on_resource(self, :collect_user_details)
90
88
 
91
89
  def to_s
92
90
  'Users'
@@ -37,17 +37,15 @@ module Inspec::Resources
37
37
  end
38
38
 
39
39
  filter = FilterTable.create
40
- filter.add_accessor(:where)
41
- .add_accessor(:entries)
42
- .add(:services, field: 'service')
43
- .add(:ids, field: 'id')
44
- .add(:socket_types, field: 'socket_type')
45
- .add(:types, field: 'type')
46
- .add(:protocols, field: 'protocol')
47
- .add(:wait, field: 'wait')
48
- .add(:disabled?) { |x| x.where('disable' => 'no').services.empty? }
49
- .add(:enabled?) { |x| x.where('disable' => 'yes').services.empty? }
50
- .connect(self, :service_lines)
40
+ filter.register_column(:services, field: 'service')
41
+ .register_column(:ids, field: 'id')
42
+ .register_column(:socket_types, field: 'socket_type')
43
+ .register_column(:types, field: 'type')
44
+ .register_column(:protocols, field: 'protocol')
45
+ .register_column(:wait, field: 'wait')
46
+ .register_custom_matcher(:disabled?) { |x| x.where('disable' => 'no').services.empty? }
47
+ .register_custom_matcher(:enabled?) { |x| x.where('disable' => 'yes').services.empty? }
48
+ .install_filter_methods_on_resource(self, :service_lines)
51
49
 
52
50
  private
53
51
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inspec-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.20
4
+ version: 2.2.27
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dominik Richter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-21 00:00:00.000000000 Z
11
+ date: 2018-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: train-core