inspec 2.1.54 → 2.1.59

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: 70091b75b95f9e09f83249bc3ed5de294da9989c
4
- data.tar.gz: c481fe8cdd37aae2eecc2ce18481924d0f9dcead
3
+ metadata.gz: d57f969266c045b09307eba2c128be6fbb77e3f7
4
+ data.tar.gz: 3feecd806c8a21b6f8ce3e37287e7905d0df86d9
5
5
  SHA512:
6
- metadata.gz: 43840caed0f0399d671b5514940f7c9dc2c73cdac09820609e9bd132cc0b7c30d4985690c8674638473aea52b5644a658eafb2feac4a399e3182078d4edd4693
7
- data.tar.gz: 3d1e4c52daf5a58b8ea2b1f0705e7fb375a1579d4b279cc774058e015c6dfe9efea650ba2400e6ee8ec0aa78427975e13abac78ace6c8885fc35567572a462d9
6
+ metadata.gz: cfd2b0a9cabfe3838b27d03c5dca5bd67bcca64c10e8bf48b628318a0fbe6cf118c98309f71ac0fce2fba65b10f06b28e821eeeb47b438b7f2559a00c6d29679
7
+ data.tar.gz: 5d61ddf3ddb8126c490c1536c28c99b1a6b93615b78c6a7a17023b86133a2818b6e673cd5ff21400441c9c07a4c925b61fec730ac88318d2f4bee571fdf5c678
data/CHANGELOG.md CHANGED
@@ -1,36 +1,50 @@
1
1
  # Change Log
2
2
  <!-- usage documentation: http://expeditor-docs.es.chef.io/configuration/changelog/ -->
3
- <!-- latest_release 2.1.54 -->
4
- ## [v2.1.54](https://github.com/chef/inspec/tree/v2.1.54) (2018-04-19)
3
+ <!-- latest_release 2.1.59 -->
4
+ ## [v2.1.59](https://github.com/chef/inspec/tree/v2.1.59) (2018-04-26)
5
5
 
6
6
  #### Bug Fixes
7
- - Add missing `git` to Dockerfile. [#2969](https://github.com/chef/inspec/pull/2969) ([miah](https://github.com/miah))
7
+ - Catch exceptions in control blocks and fail the control [#2987](https://github.com/chef/inspec/pull/2987) ([clintoncwolfe](https://github.com/clintoncwolfe))
8
8
  <!-- latest_release -->
9
9
 
10
- <!-- release_rollup since=2.1.43 -->
11
- ### Changes since 2.1.43 release
10
+ <!-- release_rollup since=2.1.54 -->
11
+ ### Changes since 2.1.54 release
12
+
13
+ #### Bug Fixes
14
+ - Catch exceptions in control blocks and fail the control [#2987](https://github.com/chef/inspec/pull/2987) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.1.59 -->
12
15
 
13
16
  #### Merged Pull Requests
14
- - Add A2 support to the inspec-compliance toolset [#2963](https://github.com/chef/inspec/pull/2963) ([jquick](https://github.com/jquick)) <!-- 2.1.52 -->
17
+ - os_env resource returns only user&#39;s environment variable on Windows [#2945](https://github.com/chef/inspec/pull/2945) ([omar-irizarry](https://github.com/omar-irizarry)) <!-- 2.1.58 -->
18
+ - Fix case where res is nil in etc_group [#2984](https://github.com/chef/inspec/pull/2984) ([chris-rock](https://github.com/chris-rock)) <!-- 2.1.57 -->
19
+ - Makes JSON resource enumerable, despite method_missing magic [#2910](https://github.com/chef/inspec/pull/2910) ([TheLonelyGhost](https://github.com/TheLonelyGhost)) <!-- 2.1.56 -->
15
20
 
16
- #### New Features
17
- - Inline and attached policies for aws_iam_user and aws_iam_users [#2947](https://github.com/chef/inspec/pull/2947) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.1.48 -->
21
+ #### Enhancements
22
+ - Update shadow#to_s to return @path instead of hardcoded `/etc/shadow` [#2978](https://github.com/chef/inspec/pull/2978) ([miah](https://github.com/miah)) <!-- 2.1.55 -->
23
+ <!-- release_rollup -->
18
24
 
19
- #### Bug Fixes
20
- - Add missing `git` to Dockerfile. [#2969](https://github.com/chef/inspec/pull/2969) ([miah](https://github.com/miah)) <!-- 2.1.54 -->
21
- - updating kitchen-puppet example for the `puppet_apply` provisioner [#2972](https://github.com/chef/inspec/pull/2972) ([moutons](https://github.com/moutons)) <!-- 2.1.49 -->
22
- - Policy statement search: don&#39;t stacktrace on missing field [#2962](https://github.com/chef/inspec/pull/2962) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.1.47 -->
23
- - Fixed numerous naming errors in aws_iam_vpcs integration tests [#2961](https://github.com/chef/inspec/pull/2961) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.1.46 -->
24
- - aws_iam_policy statement search fix for degenerate policies [#2958](https://github.com/chef/inspec/pull/2958) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.1.45 -->
25
+ <!-- latest_stable_release -->
26
+ ## [v2.1.54](https://github.com/chef/inspec/tree/v2.1.54) (2018-04-19)
27
+
28
+ #### New Features
29
+ - Inline and attached policies for aws_iam_user and aws_iam_users [#2947](https://github.com/chef/inspec/pull/2947) ([clintoncwolfe](https://github.com/clintoncwolfe))
25
30
 
26
31
  #### Enhancements
27
- - Make names for AWS Config service objects optional [#2928](https://github.com/chef/inspec/pull/2928) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.1.53 -->
28
- - Upgrade Terraform version pins for integration testing [#2968](https://github.com/chef/inspec/pull/2968) ([clintoncwolfe](https://github.com/clintoncwolfe)) <!-- 2.1.51 -->
29
- - Amazon linux service mgmt detection [#2970](https://github.com/chef/inspec/pull/2970) ([meringu](https://github.com/meringu)) <!-- 2.1.50 -->
30
- - updating output for aws_iam_role to match other AWS resources [#2960](https://github.com/chef/inspec/pull/2960) ([tmonk42](https://github.com/tmonk42)) <!-- 2.1.44 -->
31
- <!-- release_rollup -->
32
+ - updating output for aws_iam_role to match other AWS resources [#2960](https://github.com/chef/inspec/pull/2960) ([tmonk42](https://github.com/tmonk42))
33
+ - Amazon linux service mgmt detection [#2970](https://github.com/chef/inspec/pull/2970) ([meringu](https://github.com/meringu))
34
+ - Upgrade Terraform version pins for integration testing [#2968](https://github.com/chef/inspec/pull/2968) ([clintoncwolfe](https://github.com/clintoncwolfe))
35
+ - Make names for AWS Config service objects optional [#2928](https://github.com/chef/inspec/pull/2928) ([clintoncwolfe](https://github.com/clintoncwolfe))
32
36
 
37
+ #### Bug Fixes
38
+ - aws_iam_policy statement search fix for degenerate policies [#2958](https://github.com/chef/inspec/pull/2958) ([clintoncwolfe](https://github.com/clintoncwolfe))
39
+ - Fixed numerous naming errors in aws_iam_vpcs integration tests [#2961](https://github.com/chef/inspec/pull/2961) ([clintoncwolfe](https://github.com/clintoncwolfe))
40
+ - Policy statement search: don&#39;t stacktrace on missing field [#2962](https://github.com/chef/inspec/pull/2962) ([clintoncwolfe](https://github.com/clintoncwolfe))
41
+ - updating kitchen-puppet example for the `puppet_apply` provisioner [#2972](https://github.com/chef/inspec/pull/2972) ([moutons](https://github.com/moutons))
42
+ - Add missing `git` to Dockerfile. [#2969](https://github.com/chef/inspec/pull/2969) ([miah](https://github.com/miah))
43
+
44
+ #### Merged Pull Requests
45
+ - Add A2 support to the inspec-compliance toolset [#2963](https://github.com/chef/inspec/pull/2963) ([jquick](https://github.com/jquick))
33
46
  <!-- latest_stable_release -->
47
+
34
48
  ## [v2.1.43](https://github.com/chef/inspec/tree/v2.1.43) (2018-04-12)
35
49
 
36
50
  #### New Features
@@ -51,7 +65,6 @@
51
65
  - Update filesystem.md.erb [#2909](https://github.com/chef/inspec/pull/2909) ([tlmikulski](https://github.com/tlmikulski))
52
66
  - Fixes configuration for Azure integrationt tests [#2941](https://github.com/chef/inspec/pull/2941) ([dmccown](https://github.com/dmccown))
53
67
  - powershell resource: Add support line for Unix [#2952](https://github.com/chef/inspec/pull/2952) ([jerryaldrichiii](https://github.com/jerryaldrichiii))
54
- <!-- latest_stable_release -->
55
68
 
56
69
  ## [v2.1.30](https://github.com/chef/inspec/tree/v2.1.30) (2018-04-05)
57
70
 
@@ -0,0 +1,62 @@
1
+ # What happens when a profile file is loaded
2
+
3
+ ## Consult with Harry Tuttle
4
+
5
+ [He's not from Central Services or anything.](https://youtu.be/VRfoIyx8KfU?t=2m41s)
6
+
7
+ ## Tips
8
+
9
+ * In the early days of InSpec / ServerSpec, controls were called "rules". Throughout various places in the code, the word "rule" is used to mean "control". Make the mental subsitution.
10
+ * InSpec supports reading profiles from tarballs, local files, git repos, etc. So, don't count on local file reading; instead it uses a special source reader to obtain the contents of the files.
11
+
12
+ ## The basics of the stack
13
+
14
+ #5 Inspec::Profile.collect_tests(include_list#Array) at lib/inspec/profile.rb:167
15
+ #4 Hash.each at lib/inspec/profile.rb:167
16
+ #3 block in Inspec::Profile.block in collect_tests(include_list#Array) at lib/inspec/profile.rb:170
17
+ #2 Inspec::ProfileContext.load_control_file(*args#Array) at lib/inspec/profile_context.rb:141
18
+ #1 Inspec::ProfileContext.control_eval_context at lib/inspec/profile_context.rb:58
19
+ #0 #<Class:Inspec::ControlEvalContext>.create(profile_context#Inspec::ProfileContext, resources_dsl#Module) at lib/inspec/control_eval_context.rb:41
20
+
21
+ ## A profile context is created
22
+
23
+ Like many things in InSpec core, a profile context is an anonymous class. (verify)
24
+
25
+ Additionally, a control_eval_context is created. It is an instance of an anonymous class; it has a class<->relationship with its profile context. See `lib/inspec/control_eval_context.rb`.
26
+
27
+ ## Each file's contents are instance eval'd against the control_eval_context
28
+
29
+ ### DSL methods are executed at this time
30
+
31
+ So, if you have a control file with `title` in it, that will call the title method that was defined at `lib/inspec/control_eval_context.rb:60`. Importantly, this also includes the `control` DSL keyword, and also the `describe` keyword (used for bare describes).
32
+
33
+ ### Each control and their block are wrapped in an anonymous class
34
+
35
+ The anonymous class generator is located at `lib/inspec/control_eval_context.rb:24`. At this point, the terminology switches from `control` to `rule`. Each context class inherits from Inspec::Rule, which provides the constructor.
36
+
37
+ The control context class also gets extended with the resource DSL, so anything in the source code for the control can use the resource DSL. This includes all resource names, but importantly, the `describe` DSL keyword.
38
+
39
+ Finally, Inspec::Rule provides the control DSL - impact, title, desc, ref, and tags.
40
+
41
+ ### The block is instance_eval'd against the control context class
42
+
43
+ See `lib/inspec/rule.rb:50`. We're now in two levels of instance eval'ing - the file is gradually being eval'd against the profile context anonymous class, and the current control's block is being instance eval'd against a control context anonymous class.
44
+
45
+ At this stage, control-level metadata (impact, title, refs, tags, desc) are evaluated and set as instance vars on the control.
46
+
47
+ Any "loose" ruby in the control is also executed at this point.
48
+
49
+ And, the describe and describe.one blocks are executed.
50
+
51
+ ### TODO: describe blocks are *not* instance-evaled
52
+
53
+ ### The control is registered with the profile
54
+
55
+ Using the method register_control (dynamically defined on the control eval context), we check for various skip conditions. If none of them apply, the control is then registered with the profile context using register_rule.
56
+
57
+ ProfileContext.register_rule's main job is to determine the full ID of the control (within the context of the profile) and either add it to the controls list, or (if another control with the same ID exists), merge it. (This is where overriding happens).
58
+
59
+ Note: can skip a control with:
60
+ Inspec::Rule.set_skip_rule(control, msg)
61
+
62
+ ## What else?
@@ -35,6 +35,19 @@ The following examples show how to use this InSpec audit resource.
35
35
  its('split') { should_not include('.') }
36
36
  end
37
37
 
38
+ ### Test the Path environment variable by specifying the target Environment (Windows)
39
+
40
+ On windows a User's environment variable may obscure the local machine (system) environment variable. The correct environment variable may be tested as follows:
41
+
42
+ describe os_env('PATH', 'target') do
43
+ its('split') { should_not include('') }
44
+ its('split') { should_not include('.') }
45
+ end
46
+
47
+ where
48
+
49
+ * `'target'` may be either `system` or `user`
50
+
38
51
  ### Test Habitat environment variables
39
52
 
40
53
  Habitat uses the `os_env` resource to test environment variables. The environment variables are first defined in a whitespace array, after which each environment variable is tested:
data/lib/inspec/rule.rb CHANGED
@@ -47,7 +47,21 @@ module Inspec
47
47
  @__skip_only_if_eval = opts[:skip_only_if_eval]
48
48
 
49
49
  # evaluate the given definition
50
- instance_eval(&block) if block_given?
50
+ return unless block_given?
51
+ begin
52
+ instance_eval(&block)
53
+ rescue StandardError => e
54
+ # We've encountered an exception while trying to eval the code inside the
55
+ # control block. We need to prevent the exception from bubbling up, and
56
+ # fail the control. Controls are failed by having a failed resource within
57
+ # them; but since our control block is unsafe (and opaque) to us, let's
58
+ # make a dummy and fail that.
59
+ location = block.source_location.compact.join(':')
60
+ describe 'Control Source Code Error' do
61
+ # Rubocop thinks we are raising an exception - we're actually calling RSpec's fail()
62
+ its(location) { fail e.message } # rubocop: disable Style/SignalException
63
+ end
64
+ end
51
65
  end
52
66
 
53
67
  def to_s
@@ -4,5 +4,5 @@
4
4
  # author: Christoph Hartmann
5
5
 
6
6
  module Inspec
7
- VERSION = '2.1.54'
7
+ VERSION = '2.1.59'
8
8
  end
@@ -78,10 +78,12 @@ module Inspec::Resources
78
78
  }
79
79
  res = entries
80
80
 
81
- conditions.each do |k, v|
82
- idx = fields[k.to_sym]
83
- next if idx.nil?
84
- res = res.select { |x| x[idx].to_s == v.to_s }
81
+ unless res.nil?
82
+ conditions.each do |k, v|
83
+ idx = fields[k.to_sym]
84
+ next if idx.nil?
85
+ res = res.select { |x| x[idx].to_s == v.to_s }
86
+ end
85
87
  end
86
88
 
87
89
  EtcGroupView.new(self, res)
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  require 'utils/object_traversal'
4
+ require 'utils/enumerable_delegation'
4
5
  require 'utils/file_reader'
5
6
 
6
7
  module Inspec::Resources
@@ -37,6 +38,9 @@ module Inspec::Resources
37
38
  # load the raw content from the source, and then parse it
38
39
  @raw_content = load_raw_content(opts)
39
40
  @params = parse(@raw_content)
41
+
42
+ # If the JSON content is enumerable, make this object enumerable too
43
+ extend EnumerableDelegation if @params.respond_to?(:each)
40
44
  end
41
45
 
42
46
  # Shorthand to retrieve a parameter name via `#its`.
@@ -22,8 +22,15 @@ module Inspec::Resources
22
22
  end
23
23
  "
24
24
 
25
- def initialize(env = nil)
25
+ def initialize(env = nil, target = nil)
26
26
  @osenv = env
27
+ @target = unless target.nil?
28
+ if target.casecmp('system') == 0
29
+ 'Machine'
30
+ else
31
+ 'User'
32
+ end
33
+ end
27
34
  end
28
35
 
29
36
  def split
@@ -37,7 +44,7 @@ module Inspec::Resources
37
44
 
38
45
  def content
39
46
  return @content if defined?(@content)
40
- @content = value_for(@osenv) unless @osenv.nil?
47
+ @content = value_for(@osenv, @target) unless @osenv.nil?
41
48
  end
42
49
 
43
50
  def to_s
@@ -50,9 +57,13 @@ module Inspec::Resources
50
57
 
51
58
  private
52
59
 
53
- def value_for(env)
60
+ def value_for(env, target = nil)
54
61
  command = if inspec.os.windows?
55
- "${Env:#{env}}"
62
+ if target.nil?
63
+ "${Env:#{env}}"
64
+ else
65
+ "[System.Environment]::GetEnvironmentVariable('#{env}', [System.EnvironmentVariableTarget]::#{target})"
66
+ end
56
67
  else
57
68
  'env'
58
69
  end
@@ -120,7 +120,7 @@ module Inspec::Resources
120
120
 
121
121
  def to_s
122
122
  f = @filters.empty? ? '' : ' with'+@filters
123
- "/etc/shadow#{f}"
123
+ "#{@path}#{f}"
124
124
  end
125
125
 
126
126
  private
@@ -0,0 +1,9 @@
1
+ # encoding: utf-8
2
+
3
+ module EnumerableDelegation
4
+ include Enumerable
5
+
6
+ def each(&block)
7
+ @params.each(&block)
8
+ end
9
+ 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: 2.1.54
4
+ version: 2.1.59
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-04-19 00:00:00.000000000 Z
11
+ date: 2018-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: train
@@ -290,6 +290,7 @@ files:
290
290
  - bin/inspec
291
291
  - docs/.gitignore
292
292
  - docs/README.md
293
+ - docs/dev/control-eval.md
293
294
  - docs/dsl_inspec.md
294
295
  - docs/dsl_resource.md
295
296
  - docs/glossary.md
@@ -766,6 +767,7 @@ files:
766
767
  - lib/utils/command_wrapper.rb
767
768
  - lib/utils/convert.rb
768
769
  - lib/utils/database_helpers.rb
770
+ - lib/utils/enumerable_delegation.rb
769
771
  - lib/utils/erlang_parser.rb
770
772
  - lib/utils/file_reader.rb
771
773
  - lib/utils/filter.rb