inspec 1.13.0 → 1.14.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -2
  3. data/Gemfile +1 -1
  4. data/examples/meta-profile/inspec.lock +18 -0
  5. data/examples/meta-profile/vendor/3d473e72d8b70018386a53e0a105e92ccbb4115dc268cadc16ff53d550d2898e.tar.gz +0 -0
  6. data/examples/meta-profile/vendor/793adcbb91cfc2da0044bb9cbf0863773ae2cf89ce9b8343b4295b137f70897b.tar.gz +0 -0
  7. data/examples/meta-profile/vendor/e25d521fb1093b4c23b31a7dc8f41b5540236f4a433960b151bc427523662ab6.tar.gz +0 -0
  8. data/lib/bundles/inspec-artifact/cli.rb +6 -6
  9. data/lib/bundles/inspec-compliance/http.rb +11 -3
  10. data/lib/bundles/inspec-compliance/target.rb +2 -2
  11. data/lib/bundles/inspec-supermarket/cli.rb +1 -1
  12. data/lib/fetchers/git.rb +1 -1
  13. data/lib/inspec/backend.rb +2 -2
  14. data/lib/inspec/base_cli.rb +1 -1
  15. data/lib/inspec/cached_fetcher.rb +2 -2
  16. data/lib/inspec/cli.rb +1 -0
  17. data/lib/inspec/control_eval_context.rb +0 -2
  18. data/lib/inspec/dependencies/lockfile.rb +6 -4
  19. data/lib/inspec/dependencies/requirement.rb +1 -1
  20. data/lib/inspec/dependencies/resolver.rb +4 -4
  21. data/lib/inspec/dsl.rb +2 -2
  22. data/lib/inspec/fetcher.rb +1 -1
  23. data/lib/inspec/file_provider.rb +4 -4
  24. data/lib/inspec/library_eval_context.rb +1 -1
  25. data/lib/inspec/objects/list.rb +1 -1
  26. data/lib/inspec/plugins.rb +1 -1
  27. data/lib/inspec/plugins/fetcher.rb +4 -4
  28. data/lib/inspec/plugins/resource.rb +0 -1
  29. data/lib/inspec/plugins/source_reader.rb +3 -3
  30. data/lib/inspec/profile.rb +4 -4
  31. data/lib/inspec/profile_context.rb +1 -1
  32. data/lib/inspec/resource.rb +2 -2
  33. data/lib/inspec/runner.rb +4 -4
  34. data/lib/inspec/secrets.rb +1 -1
  35. data/lib/inspec/shell.rb +1 -1
  36. data/lib/inspec/source_reader.rb +1 -1
  37. data/lib/inspec/version.rb +1 -1
  38. data/lib/matchers/matchers.rb +7 -7
  39. data/lib/resources/apache_conf.rb +1 -1
  40. data/lib/resources/auditd_conf.rb +1 -1
  41. data/lib/resources/auditd_rules.rb +1 -1
  42. data/lib/resources/bridge.rb +1 -1
  43. data/lib/resources/etc_group.rb +2 -2
  44. data/lib/resources/file.rb +6 -6
  45. data/lib/resources/groups.rb +4 -4
  46. data/lib/resources/grub_conf.rb +3 -3
  47. data/lib/resources/host.rb +1 -1
  48. data/lib/resources/inetd_conf.rb +1 -1
  49. data/lib/resources/interface.rb +1 -1
  50. data/lib/resources/json.rb +1 -1
  51. data/lib/resources/limits_conf.rb +1 -1
  52. data/lib/resources/login_def.rb +1 -1
  53. data/lib/resources/mysql_conf.rb +1 -1
  54. data/lib/resources/ntp_conf.rb +1 -1
  55. data/lib/resources/packages.rb +2 -2
  56. data/lib/resources/parse_config.rb +1 -1
  57. data/lib/resources/port.rb +2 -2
  58. data/lib/resources/postgres_conf.rb +1 -1
  59. data/lib/resources/security_policy.rb +1 -1
  60. data/lib/resources/ssh_conf.rb +1 -1
  61. data/lib/resources/ssl.rb +1 -1
  62. data/lib/resources/users.rb +5 -5
  63. data/lib/resources/xinetd.rb +1 -1
  64. data/lib/utils/command_wrapper.rb +3 -3
  65. data/lib/utils/filter.rb +1 -1
  66. data/lib/utils/plugin_registry.rb +3 -3
  67. data/lib/utils/simpleconfig.rb +1 -1
  68. metadata +6 -2
@@ -38,7 +38,6 @@ module Inspec
38
38
  end
39
39
 
40
40
  def __register(name, obj)
41
- # rubocop:disable Lint/NestedMethodDefinition
42
41
  cl = Class.new(obj) do
43
42
  def initialize(backend, name, *args)
44
43
  # attach the backend to this instance
@@ -15,7 +15,7 @@ module Inspec
15
15
  #
16
16
  # @return [Inspec::Metadata] profile metadata
17
17
  def metadata
18
- fail "SourceReader #{self} does not implement `metadata()`. This method is required"
18
+ raise "SourceReader #{self} does not implement `metadata()`. This method is required"
19
19
  end
20
20
 
21
21
  # Retrieve this profile's tests
@@ -26,14 +26,14 @@ module Inspec
26
26
  #
27
27
  # @return [Hash] Collection with references pointing to test contents
28
28
  def tests
29
- fail "SourceReader #{self} does not implement `tests()`. This method is required"
29
+ raise "SourceReader #{self} does not implement `tests()`. This method is required"
30
30
  end
31
31
 
32
32
  # Retrieve this profile's libraries
33
33
  #
34
34
  # @return [Hash] Collection with references pointing to library contents
35
35
  def libraries
36
- fail "SourceReader #{self} does not implement `libraries()`. This method is required"
36
+ raise "SourceReader #{self} does not implement `libraries()`. This method is required"
37
37
  end
38
38
  end
39
39
  end
@@ -57,7 +57,7 @@ module Inspec
57
57
 
58
58
  reader = Inspec::SourceReader.resolve(rp)
59
59
  if reader.nil?
60
- fail("Don't understand inspec profile in #{path}, it " \
60
+ raise("Don't understand inspec profile in #{path}, it " \
61
61
  "doesn't look like a supported profile structure.")
62
62
  end
63
63
  new(reader, opts)
@@ -108,7 +108,7 @@ module Inspec
108
108
  metadata.params[:version]
109
109
  end
110
110
 
111
- def writable? # rubocop:disable Style/TrivialAccessors
111
+ def writable?
112
112
  @writable
113
113
  end
114
114
 
@@ -397,10 +397,10 @@ module Inspec
397
397
  end
398
398
 
399
399
  name = params[:name] ||
400
- fail('Cannot create an archive without a profile name! Please '\
400
+ raise('Cannot create an archive without a profile name! Please '\
401
401
  'specify the name in metadata or use --output to create the archive.')
402
402
  version = params[:version] ||
403
- fail('Cannot create an archive without a profile version! Please '\
403
+ raise('Cannot create an archive without a profile version! Please '\
404
404
  'specify the version in metadata or use --output to create the archive.')
405
405
  ext = opts[:zip] ? 'zip' : 'tar.gz'
406
406
  slug = name.downcase.strip.tr(' ', '-').gsub(/[^\w-]/, '_')
@@ -21,7 +21,7 @@ module Inspec
21
21
  attr_accessor :rules
22
22
  def initialize(profile_id, backend, conf)
23
23
  if backend.nil?
24
- fail 'ProfileContext is initiated with a backend == nil. ' \
24
+ raise 'ProfileContext is initiated with a backend == nil. ' \
25
25
  'This is a backend error which must be fixed upstream.'
26
26
  end
27
27
  @profile_id = profile_id
@@ -39,7 +39,7 @@ module Inspec
39
39
  profile_context.subcontext_by_name(profile_name)
40
40
  end
41
41
 
42
- fail ProfileNotFound, "Cannot find profile named: #{profile_name}" if inner_context.nil?
42
+ raise ProfileNotFound, "Cannot find profile named: #{profile_name}" if inner_context.nil?
43
43
  inner_context.resource_registry[resource_name]
44
44
  end
45
45
 
@@ -64,7 +64,7 @@ module Inspec
64
64
 
65
65
  def self.validate_resource_dsl_version!(version)
66
66
  if version != 1
67
- fail 'Only resource version 1 is supported!'
67
+ raise 'Only resource version 1 is supported!'
68
68
  end
69
69
  end
70
70
  end
@@ -166,7 +166,7 @@ module Inspec
166
166
  backend: @backend,
167
167
  controls: @controls,
168
168
  attributes: @conf[:attributes])
169
- fail "Could not resolve #{target} to valid input." if profile.nil?
169
+ raise "Could not resolve #{target} to valid input." if profile.nil?
170
170
  @target_profiles << profile if supports_profile?(profile)
171
171
  end
172
172
 
@@ -174,13 +174,13 @@ module Inspec
174
174
  return true if @ignore_supports
175
175
 
176
176
  if !profile.supports_runtime?
177
- fail 'This profile requires InSpec version '\
177
+ raise 'This profile requires InSpec version '\
178
178
  "#{profile.metadata.inspec_requirement}. You are running "\
179
179
  "InSpec v#{Inspec::VERSION}.\n"
180
180
  end
181
181
 
182
182
  if !profile.supports_os?
183
- fail "This OS/platform (#{@backend.os[:name]}) is not supported by this profile."
183
+ raise "This OS/platform (#{@backend.os[:name]}) is not supported by this profile."
184
184
  end
185
185
 
186
186
  true
@@ -249,7 +249,7 @@ module Inspec
249
249
  # otherwise return all working tests
250
250
  return ok_tests
251
251
  else
252
- fail "A rule was registered with #{method_name.inspect}, "\
252
+ raise "A rule was registered with #{method_name.inspect}, "\
253
253
  "which isn't understood and cannot be processed."
254
254
  end
255
255
  end
@@ -10,7 +10,7 @@ module Inspec
10
10
 
11
11
  def self.secrets(version)
12
12
  if version != 1
13
- fail 'Only secrets version 1 is supported!'
13
+ raise 'Only secrets version 1 is supported!'
14
14
  end
15
15
  Inspec::Plugins::Secret
16
16
  end
@@ -79,7 +79,7 @@ module Inspec
79
79
  # determine min whitespace that can be removed
80
80
  min = nil
81
81
  example.lines.each do |line|
82
- if line.strip.length > 0 # ignore empty lines
82
+ if !line.strip.empty? # ignore empty lines
83
83
  line_whitespace = line.length - line.lstrip.length
84
84
  min = line_whitespace if min.nil? || line_whitespace < min
85
85
  end
@@ -19,7 +19,7 @@ module Inspec
19
19
 
20
20
  def self.source_reader(version)
21
21
  if version != 1
22
- fail 'Only source readers version 1 is supported!'
22
+ raise 'Only source readers version 1 is supported!'
23
23
  end
24
24
  Inspec::Plugins::SourceReader
25
25
  end
@@ -4,5 +4,5 @@
4
4
  # author: Christoph Hartmann
5
5
 
6
6
  module Inspec
7
- VERSION = '1.13.0'.freeze
7
+ VERSION = '1.14.0'.freeze
8
8
  end
@@ -105,7 +105,7 @@ RSpec::Matchers.define :be_installed do
105
105
  end
106
106
 
107
107
  chain :by do
108
- fail "[UNSUPPORTED] Please use the new resources 'gem', 'npm' or 'pip'."
108
+ raise "[UNSUPPORTED] Please use the new resources 'gem', 'npm' or 'pip'."
109
109
  end
110
110
 
111
111
  chain :with_version do |version|
@@ -121,7 +121,7 @@ RSpec::Matchers.define :be_enabled do
121
121
  end
122
122
 
123
123
  chain :with_level do |_level|
124
- fail '[UNSUPPORTED] with level is not supported'
124
+ raise '[UNSUPPORTED] with level is not supported'
125
125
  end
126
126
 
127
127
  failure_message do |service|
@@ -137,7 +137,7 @@ RSpec::Matchers.define :be_running do
137
137
  end
138
138
 
139
139
  chain :under do |_under|
140
- fail '[UNSUPPORTED] under is not supported'
140
+ raise '[UNSUPPORTED] under is not supported'
141
141
  end
142
142
 
143
143
  failure_message do |service|
@@ -178,7 +178,7 @@ RSpec::Matchers.define :be_reachable do
178
178
  end
179
179
 
180
180
  chain :with do |_attr|
181
- fail '[UNSUPPORTED] `with` is not supported in combination with `be_reachable`'
181
+ raise '[UNSUPPORTED] `with` is not supported in combination with `be_reachable`'
182
182
  end
183
183
 
184
184
  failure_message do |host|
@@ -193,7 +193,7 @@ RSpec::Matchers.define :be_resolvable do
193
193
  end
194
194
 
195
195
  chain :by do |_type|
196
- fail "[UNSUPPORTED] `by` is not supported in combination with `be_resolvable`. Please use the following syntax `host('example.com', port: 53, proto: 'udp')`."
196
+ raise "[UNSUPPORTED] `by` is not supported in combination with `be_resolvable`. Please use the following syntax `host('example.com', port: 53, proto: 'udp')`."
197
197
  end
198
198
 
199
199
  failure_message do |host|
@@ -208,11 +208,11 @@ RSpec::Matchers.define :have_rule do |rule|
208
208
  end
209
209
 
210
210
  chain :with_table do |_table|
211
- fail "[UNSUPPORTED] `with_table` is not supported in combination with `have_rule`. Please use the following syntax `iptables(table:'mangle', chain: 'input')`."
211
+ raise "[UNSUPPORTED] `with_table` is not supported in combination with `have_rule`. Please use the following syntax `iptables(table:'mangle', chain: 'input')`."
212
212
  end
213
213
 
214
214
  chain :with_chain do |_chain|
215
- fail "[UNSUPPORTED] `with_table` is not supported in combination with `with_chain`. Please use the following syntax `iptables(table:'mangle', chain: 'input')`."
215
+ raise "[UNSUPPORTED] `with_table` is not supported in combination with `with_chain`. Please use the following syntax `iptables(table:'mangle', chain: 'input')`."
216
216
  end
217
217
  end
218
218
 
@@ -70,7 +70,7 @@ module Inspec::Resources
70
70
  end
71
71
 
72
72
  raw_conf = file.content
73
- if raw_conf.empty? && file.size > 0
73
+ if raw_conf.empty? && !file.empty?
74
74
  return skip_resource("Can't read file \"#{@conf_path}\"")
75
75
  end
76
76
 
@@ -41,7 +41,7 @@ module Inspec::Resources
41
41
  end
42
42
 
43
43
  content = file.content
44
- if content.empty? && file.size > 0
44
+ if content.empty? && !file.empty?
45
45
  skip_resource "Can't read file '#{@conf_path}'"
46
46
  return @params = {}
47
47
  end
@@ -93,7 +93,7 @@ module Inspec::Resources
93
93
  # rubocop:disable Style/MethodName
94
94
  def LIST_RULES
95
95
  return @legacy.LIST_RULES if @legacy
96
- fail 'Using legacy auditd_rules LIST_RULES interface with non-legacy audit package. Please use the new syntax.'
96
+ raise 'Using legacy auditd_rules LIST_RULES interface with non-legacy audit package. Please use the new syntax.'
97
97
  end
98
98
 
99
99
  def status(name = nil)
@@ -115,7 +115,7 @@ module Inspec::Resources
115
115
  adapter_collection.push(info) if info[:name].casecmp(bridge_name) == 0
116
116
  end
117
117
 
118
- return nil if bridges.size == 0
118
+ return nil if bridges.empty?
119
119
  warn "[Possible Error] detected multiple bridges interfaces with the name #{bridge_name}" if bridges.size > 1
120
120
  bridges[0]
121
121
  end
@@ -107,7 +107,7 @@ module Inspec::Resources
107
107
  # iterate over each line and filter comments
108
108
  @content.split("\n").each_with_object([]) do |line, lines|
109
109
  grp_info = parse_group_line(line)
110
- lines.push(grp_info) if !grp_info.nil? && grp_info.size > 0
110
+ lines.push(grp_info) if !grp_info.nil? && !grp_info.empty?
111
111
  end
112
112
  end
113
113
 
@@ -119,7 +119,7 @@ module Inspec::Resources
119
119
  line, _idx_nl = parse_comment_line(line, opts)
120
120
  x = line.split(':')
121
121
  # abort if we have an empty or comment line
122
- return nil if x.size == 0
122
+ return nil if x.empty?
123
123
  # map data
124
124
  {
125
125
  'name' => x.at(0), # Name of the group.
@@ -61,7 +61,7 @@ module Inspec::Resources
61
61
  end
62
62
 
63
63
  def contain(*_)
64
- fail 'Contain is not supported. Please use standard RSpec matchers.'
64
+ raise 'Contain is not supported. Please use standard RSpec matchers.'
65
65
  end
66
66
 
67
67
  def readable?(by_usergroup, by_specific_user)
@@ -128,7 +128,7 @@ module Inspec::Resources
128
128
  private
129
129
 
130
130
  def file_permission_granted?(access_type, by_usergroup, by_specific_user)
131
- fail '`file_permission_granted?` is not supported on your OS' if @perms_provider.nil?
131
+ raise '`file_permission_granted?` is not supported on your OS' if @perms_provider.nil?
132
132
  if by_specific_user.nil? || by_specific_user.empty?
133
133
  @perms_provider.check_file_permission_by_mask(file, access_type, by_usergroup, by_specific_user)
134
134
  else
@@ -154,7 +154,7 @@ module Inspec::Resources
154
154
  when 'execute'
155
155
  'x'
156
156
  else
157
- fail 'Invalid access_type provided'
157
+ raise 'Invalid access_type provided'
158
158
  end
159
159
  end
160
160
 
@@ -172,7 +172,7 @@ module Inspec::Resources
172
172
  usergroup = usergroup_for(usergroup, specific_user)
173
173
  flag = permission_flag(access_type)
174
174
  mask = file.unix_mode_mask(usergroup, flag)
175
- fail 'Invalid usergroup/owner provided' if mask.nil?
175
+ raise 'Invalid usergroup/owner provided' if mask.nil?
176
176
  (file.mode & mask) != 0
177
177
  end
178
178
 
@@ -197,7 +197,7 @@ module Inspec::Resources
197
197
 
198
198
  class WindowsFilePermissions < FilePermissions
199
199
  def check_file_permission_by_mask(_file, _access_type, _usergroup, _specific_user)
200
- fail '`check_file_permission_by_mask` is not supported on Windows'
200
+ raise '`check_file_permission_by_mask` is not supported on Windows'
201
201
  end
202
202
 
203
203
  def check_file_permission_by_user(access_type, user, path)
@@ -209,7 +209,7 @@ module Inspec::Resources
209
209
  when 'execute'
210
210
  '@(\'FullControl\', \'Modify\', \'ReadAndExecute\', \'ExecuteFile\')'
211
211
  else
212
- fail 'Invalid access_type provided'
212
+ raise 'Invalid access_type provided'
213
213
  end
214
214
  cmd = inspec.command("@(@((Get-Acl '#{path}').access | Where-Object {$_.AccessControlType -eq 'Allow' -and $_.IdentityReference -eq '#{user}' }) | Where-Object {($_.FileSystemRights.ToString().Split(',') | % {$_.trim()} | ? {#{access_rule} -contains $_}) -ne $null}) | measure | % { $_.Count }")
215
215
  cmd.stdout.chomp == '0' ? false : true
@@ -99,18 +99,18 @@ module Inspec::Resources
99
99
 
100
100
  # verifies if a group exists
101
101
  def exists?
102
- group_info.entries.size > 0
102
+ !group_info.entries.empty?
103
103
  end
104
104
 
105
105
  def gid
106
106
  gids = group_info.gids
107
- if gids.size == 0
107
+ if gids.empty?
108
108
  nil
109
109
  # the default case should be one group
110
110
  elsif gids.size == 1
111
111
  gids.entries[0]
112
112
  else
113
- fail 'found more than one group with the same name, please use `groups` resource'
113
+ raise 'found more than one group with the same name, please use `groups` resource'
114
114
  end
115
115
  end
116
116
 
@@ -144,7 +144,7 @@ module Inspec::Resources
144
144
  end
145
145
 
146
146
  def groups
147
- fail 'group provider must implement the `groups` method'
147
+ raise 'group provider must implement the `groups` method'
148
148
  end
149
149
  end
150
150
 
@@ -38,11 +38,11 @@ class GrubConfig < Inspec.resource(1) # rubocop:disable Metrics/ClassLength
38
38
  @conf_path = path || '/boot/grub/grub.cfg'
39
39
  @defaults_path = '/etc/default/grub'
40
40
  @version = 'grub2'
41
- elsif os[:name] == 'amazon' # rubocop:disable Style/GuardClause
41
+ elsif os[:name] == 'amazon'
42
42
  @conf_path = path || '/etc/grub.conf'
43
43
  @version = 'legacy'
44
44
  else
45
- fail UnknownGrubConfig
45
+ raise UnknownGrubConfig
46
46
  end
47
47
  end
48
48
 
@@ -145,7 +145,7 @@ class GrubConfig < Inspec.resource(1) # rubocop:disable Metrics/ClassLength
145
145
 
146
146
  content = file.content
147
147
 
148
- if content.empty? && file.size > 0
148
+ if content.empty? && !file.empty?
149
149
  skip_resource "Can't read file '#{@conf_path}'"
150
150
  return @params = {}
151
151
  end
@@ -60,7 +60,7 @@ module Inspec::Resources
60
60
  end
61
61
 
62
62
  def reachable?(port = nil, proto = nil, timeout = nil)
63
- fail "Use `host` resource with host('#{@hostname}', port: #{port}, proto: '#{proto}') parameters." if !port.nil? || !proto.nil? || !timeout.nil?
63
+ raise "Use `host` resource with host('#{@hostname}', port: #{port}, proto: '#{proto}') parameters." if !port.nil? || !proto.nil? || !timeout.nil?
64
64
  ping.nil? ? false : ping
65
65
  end
66
66
 
@@ -43,7 +43,7 @@ module Inspec::Resources
43
43
  end
44
44
 
45
45
  content = file.content
46
- if content.empty? && file.size > 0
46
+ if content.empty? && !file.empty?
47
47
  skip_resource "Can't read file \"#{@conf_path}\""
48
48
  return @params = {}
49
49
  end
@@ -121,7 +121,7 @@ module Inspec::Resources
121
121
  adapter_collection.push(info) if info[:name].casecmp(iface) == 0
122
122
  end
123
123
 
124
- return nil if adapters.size == 0
124
+ return nil if adapters.empty?
125
125
  warn "[Possible Error] detected multiple network interfaces with the name #{iface}" if adapters.size > 1
126
126
  adapters[0]
127
127
  end
@@ -49,7 +49,7 @@ module Inspec::Resources
49
49
  end
50
50
 
51
51
  # check if file is readable
52
- if @file_content.nil? && @file.size > 0
52
+ if @file_content.nil? && !@file.empty?
53
53
  skip_resource "Can't read file \"#{@path}\""
54
54
  return @params = {}
55
55
  end
@@ -35,7 +35,7 @@ module Inspec::Resources
35
35
  end
36
36
 
37
37
  content = file.content
38
- if content.empty? && file.size > 0
38
+ if content.empty? && !file.empty?
39
39
  skip_resource "Can't read file \"#{@conf_path}\""
40
40
  return @params = {}
41
41
  end
@@ -47,7 +47,7 @@ module Inspec::Resources
47
47
  end
48
48
 
49
49
  content = file.content
50
- if content.empty? && file.size > 0
50
+ if content.empty? && !file.empty?
51
51
  skip_resource "Can't read file \"#{@conf_path}\""
52
52
  return @params = {}
53
53
  end
@@ -73,7 +73,7 @@ module Inspec::Resources
73
73
  return skip_resource "Can't find file \"#{@conf_path}\""
74
74
  end
75
75
  raw_conf = read_file(@conf_path)
76
- if raw_conf.empty? && inspec.file(@conf_path).size > 0
76
+ if raw_conf.empty? && !inspec.file(@conf_path).empty?
77
77
  return skip_resource("Can't read file \"#{@conf_path}\"")
78
78
  end
79
79