inspec-core 5.18.14 → 5.22.3

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.
Files changed (65) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +19 -17
  3. data/inspec-core.gemspec +22 -22
  4. data/lib/inspec/base_cli.rb +19 -17
  5. data/lib/inspec/cli.rb +27 -25
  6. data/lib/inspec/dependencies/dependency_set.rb +2 -2
  7. data/lib/inspec/dsl.rb +9 -5
  8. data/lib/inspec/enhanced_outcomes.rb +19 -0
  9. data/lib/inspec/env_printer.rb +1 -1
  10. data/lib/inspec/exceptions.rb +2 -0
  11. data/lib/inspec/formatters/base.rb +69 -16
  12. data/lib/inspec/plugin/v2/loader.rb +19 -8
  13. data/lib/inspec/plugin/v2/plugin_types/reporter.rb +1 -0
  14. data/lib/inspec/plugin/v2/plugin_types/streaming_reporter.rb +54 -0
  15. data/lib/inspec/profile.rb +9 -8
  16. data/lib/inspec/reporters/base.rb +1 -0
  17. data/lib/inspec/reporters/cli.rb +94 -3
  18. data/lib/inspec/reporters/json.rb +3 -1
  19. data/lib/inspec/reporters/yaml.rb +3 -1
  20. data/lib/inspec/reporters.rb +2 -1
  21. data/lib/inspec/resources/file.rb +1 -1
  22. data/lib/inspec/resources/http.rb +5 -5
  23. data/lib/inspec/resources/lxc.rb +65 -9
  24. data/lib/inspec/resources/mongodb_session.rb +5 -0
  25. data/lib/inspec/resources/nftables.rb +251 -0
  26. data/lib/inspec/resources/oracledb_session.rb +13 -4
  27. data/lib/inspec/resources/podman.rb +353 -0
  28. data/lib/inspec/resources/podman_container.rb +84 -0
  29. data/lib/inspec/resources/podman_image.rb +108 -0
  30. data/lib/inspec/resources/podman_network.rb +81 -0
  31. data/lib/inspec/resources/podman_pod.rb +101 -0
  32. data/lib/inspec/resources/podman_volume.rb +87 -0
  33. data/lib/inspec/resources/postgres_session.rb +2 -1
  34. data/lib/inspec/resources/service.rb +1 -1
  35. data/lib/inspec/resources.rb +1 -0
  36. data/lib/inspec/rule.rb +54 -17
  37. data/lib/inspec/run_data/control.rb +6 -0
  38. data/lib/inspec/run_data/statistics.rb +8 -2
  39. data/lib/inspec/runner.rb +18 -8
  40. data/lib/inspec/runner_rspec.rb +3 -2
  41. data/lib/inspec/schema/exec_json.rb +78 -2
  42. data/lib/inspec/schema/output_schema.rb +4 -1
  43. data/lib/inspec/schema/profile_json.rb +46 -0
  44. data/lib/inspec/schema.rb +91 -0
  45. data/lib/inspec/utils/convert.rb +8 -0
  46. data/lib/inspec/utils/podman.rb +24 -0
  47. data/lib/inspec/utils/simpleconfig.rb +10 -2
  48. data/lib/inspec/utils/waivers/csv_file_reader.rb +34 -0
  49. data/lib/inspec/utils/waivers/excel_file_reader.rb +39 -0
  50. data/lib/inspec/utils/waivers/json_file_reader.rb +15 -0
  51. data/lib/inspec/version.rb +1 -1
  52. data/lib/inspec/waiver_file_reader.rb +61 -0
  53. data/lib/matchers/matchers.rb +15 -2
  54. data/lib/plugins/inspec-init/templates/profiles/alicloud/README.md +27 -0
  55. data/lib/plugins/inspec-init/templates/profiles/alicloud/controls/example.rb +10 -0
  56. data/lib/plugins/inspec-init/templates/profiles/alicloud/inputs.yml +1 -0
  57. data/lib/plugins/inspec-init/templates/profiles/alicloud/inspec.yml +14 -0
  58. data/lib/plugins/inspec-reporter-html2/README.md +1 -1
  59. data/lib/plugins/inspec-reporter-html2/templates/body.html.erb +7 -1
  60. data/lib/plugins/inspec-reporter-html2/templates/control.html.erb +10 -6
  61. data/lib/plugins/inspec-reporter-html2/templates/default.css +12 -0
  62. data/lib/plugins/inspec-reporter-html2/templates/selector.html.erb +7 -1
  63. data/lib/plugins/inspec-sign/lib/inspec-sign/base.rb +5 -2
  64. data/lib/plugins/inspec-streaming-reporter-progress-bar/lib/inspec-streaming-reporter-progress-bar/streaming_reporter.rb +39 -13
  65. metadata +26 -9
@@ -0,0 +1,27 @@
1
+ # Example InSpec Profile For AliCloud
2
+
3
+ This example shows the implementation of an InSpec profile for AliCloud.
4
+
5
+ The related control will simply be skipped if this is not provided. See the [InSpec DSL documentation](https://docs.chef.io/inspec/dsl_inspec/) for more details on conditional execution using `only_if`.
6
+
7
+ ## Run the test
8
+
9
+ ```bash
10
+ $ cd my-alicloud-sample-profile/
11
+ $ inspec exec . -t alicloud://
12
+ ```
13
+
14
+ ```
15
+ Profile: Ali Cloud InSpec Profile (my-alicloud-profile)
16
+ Version: 0.1.0
17
+ Target: alicloud://ap-south-1
18
+ ✔ ali-cloud-instances-1.0: Ensure AliCloud ECS Instances has correct attributes.
19
+ ✔ AliCloud ECS Instances (All) is expected to exist
20
+ ✔ AliCloud ECS Instances (All) entries.count is expected to be >= 1
21
+ Profile: AliCloud Resource Pack (inspec-alicloud)
22
+ Version: 0.10.8
23
+ Target: alicloud://ap-south-1
24
+ No tests executed.
25
+ Profile Summary: 1 successful controls, 0 control failures, 0 controls skipped
26
+ Test Summary: 1 successful, 0 failures, 0 skipped
27
+ ```
@@ -0,0 +1,10 @@
1
+ title "Test AliCloud Instances count"
2
+
3
+ control "ali-cloud-instances-1.0" do
4
+ impact 1.0
5
+ title "Ensure AliCloud ECS Instances Class has correct attributes."
6
+ describe alicloud_ecs_instances do
7
+ it { should exist }
8
+ its("entries.count") { should be >= 1 }
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ name: my-alicloud-sample-profile
2
+ title: Ali Cloud InSpec Profile
3
+ maintainer: The Authors
4
+ copyright: The Authors
5
+ copyright_email: you@example.com
6
+ license: Apache-2.0
7
+ summary: An InSpec Compliance Profile For Ali CLoud
8
+ version: 0.1.0
9
+ inspec_version: '~> 5'
10
+ depends:
11
+ - name: inspec-alicloud
12
+ url: https://github.com/inspec/inspec-alicloud/archive/main.tar.gz
13
+ supports:
14
+ - platform: alicloud
@@ -50,4 +50,4 @@ Specifies the full path to the location of a JavaScript file that will be read a
50
50
 
51
51
  ## Developing This Plugin
52
52
 
53
- This plugin is part of the Chef InSpec source code. While it has its own tests, the general contribution policy is dictated by the Chef InSpec project at https://github.com/inspec/inspec/blob/master/CONTRIBUTING.md
53
+ This plugin is part of the Chef InSpec source code. While it has its own tests, the general contribution policy is dictated by the Chef InSpec project at https://github.com/inspec/inspec/blob/main/CONTRIBUTING.md
@@ -36,8 +36,14 @@
36
36
  <caption>Control Statistics</caption>
37
37
  <tr><th colspan="2"><h4 id="statistics-label">Control Statistics</h4></th></tr>
38
38
  <tr class= "passed"><th>Passed:</th><td><%= run_data.statistics.controls.passed.total %></td></tr>
39
- <tr class= "skipped"><th>Skipped:</th><td><%= run_data.statistics.controls.skipped.total %></td></tr>
40
39
  <tr class= "failed"><th>Failed:</th><td><%= run_data.statistics.controls.failed.total %></td></tr>
40
+ <% if enhanced_outcomes %>
41
+ <tr class= "not_reviewed"><th>Not Reviewed:</th><td><%= run_data.statistics.controls.not_reviewed.total %></td></tr>
42
+ <tr class= "not_applicable"><th>Not Applicable:</th><td><%= run_data.statistics.controls.not_applicable.total %></td></tr>
43
+ <tr class= "error"><th>Error:</th><td><%= run_data.statistics.controls.error.total %></td></tr>
44
+ <% else %>
45
+ <tr class= "skipped"><th>Skipped:</th><td><%= run_data.statistics.controls.skipped.total %></td></tr>
46
+ <% end %>
41
47
  <tr class= "duration"><th>Duration:</th><td><%= run_data.statistics.duration %> seconds</td></tr>
42
48
  <tr class= "date"><th>Time Finished:</th><td><%= Time.now %></td></tr>
43
49
  </table>
@@ -1,11 +1,15 @@
1
1
  <% slugged_id = control.id.tr(" ", "_") %>
2
2
  <%
3
- # Determine status of control
4
- status = "passed"
5
- if control.results.any? { |r| r.status == "failed" }
6
- status = "failed"
7
- elsif control.results.any? { |r| r.status == "skipped" }
8
- status = "skipped"
3
+ if enhanced_outcomes
4
+ status = control.status
5
+ else
6
+ # Determine status of control
7
+ status = "passed"
8
+ if control.results.any? { |r| r.status == "failed" }
9
+ status = "failed"
10
+ elsif control.results.any? { |r| r.status == "skipped" }
11
+ status = "skipped"
12
+ end
9
13
  end
10
14
  %>
11
15
 
@@ -60,6 +60,18 @@ pre code {
60
60
  .result-metadata .status-skipped div {
61
61
  background-color: grey;
62
62
  }
63
+ .control-metadata .status-error div,
64
+ .result-metadata .status-error div {
65
+ background-color: rgb(63, 15, 183);
66
+ }
67
+ .control-metadata .status-not_applicable div,
68
+ .result-metadata .status-not_applicable div {
69
+ background-color: rgb(135, 206, 250);
70
+ }
71
+ .control-metadata .status-not_reviewed div,
72
+ .result-metadata .status-not_reviewed div {
73
+ background-color: rgb(255, 194, 0);
74
+ }
63
75
  .result-metadata,
64
76
  .control-metadata {
65
77
  margin: 0 0 0 5%;
@@ -1,8 +1,14 @@
1
1
  <div class="selector-panel">
2
2
  <p id="selector-instructions">Display controls that are:</p>
3
3
  <input class="selector-checkbox" id="passed-checkbox" type="checkbox" checked="checked"/><label for="passed-checkbox">Passed</label>
4
- <input class="selector-checkbox" id="skipped-checkbox" type="checkbox" checked="checked"/><label for="skipped-checkbox">Skipped</label>
5
4
  <input class="selector-checkbox" id="failed-checkbox" type="checkbox" checked="checked"/><label for="failed-checkbox">Failed</label>
5
+ <% if enhanced_outcomes %>
6
+ <input class="selector-checkbox" id="not_reviewed-checkbox" type="checkbox" checked="checked"/><label for="not_reviewed-checkbox">Not Reviewed</label>
7
+ <input class="selector-checkbox" id="not_applicable-checkbox" type="checkbox" checked="checked"/><label for="not_applicable-checkbox">Not Applicable</label>
8
+ <input class="selector-checkbox" id="error-checkbox" type="checkbox" checked="checked"/><label for="error-checkbox">Error</label>
9
+ <% else %>
10
+ <input class="selector-checkbox" id="skipped-checkbox" type="checkbox" checked="checked"/><label for="skipped-checkbox">Skipped</label>
11
+ <% end %>
6
12
  <p id="selector-instructions">Display profiles that are:</p>
7
13
  <input class="profile-selector-checkbox" id="child-profile-checkbox" type="checkbox" /><label for="child-profile-checkbox">Dependent Profiles</label>
8
14
  </div>
@@ -59,11 +59,14 @@ module InspecPlugins
59
59
  # Read name and version from metadata and use them to form the filename
60
60
  profile_md = artifact.read_profile_metadata(profile_path)
61
61
 
62
- artifact_filename = "#{profile_md["name"]}-#{profile_md["version"]}.#{SIGNED_PROFILE_SUFFIX}"
62
+ # Behave same as archive filename for iaf filename
63
+ slug = profile_md["name"].downcase.strip.tr(" ", "-").gsub(/[^\w-]/, "_")
64
+ filename = "#{slug}-#{profile_md["version"]}"
65
+ artifact_filename = "#{filename}.#{SIGNED_PROFILE_SUFFIX}"
63
66
 
64
67
  # Generating tar.gz file using archive method of Inspec Cli
65
68
  Inspec::InspecCLI.new.archive(profile_path, "error")
66
- tarfile = "#{profile_md["name"]}-#{profile_md["version"]}.tar.gz"
69
+ tarfile = "#{filename}.tar.gz"
67
70
  tar_content = IO.binread(tarfile)
68
71
  FileUtils.rm(tarfile)
69
72
 
@@ -20,6 +20,9 @@ module InspecPlugins::StreamingReporterProgressBar
20
20
  "passed" => "\033[0;1;32m",
21
21
  "skipped" => "\033[0;37m",
22
22
  "reset" => "\033[0m",
23
+ "error" => "\033[34m",
24
+ "not_applicable" => "\033[36m",
25
+ "not_reviewed" => "\033[33m",
23
26
  }.freeze
24
27
 
25
28
  # Most currently available Windows terminals have poor support
@@ -28,6 +31,9 @@ module InspecPlugins::StreamingReporterProgressBar
28
31
  "failed" => "[FAIL]",
29
32
  "skipped" => "[SKIP]",
30
33
  "passed" => "[PASS]",
34
+ "error" => " [ERROR] ",
35
+ "not_applicable" => " [N/A] ",
36
+ "not_reviewed" => " [N/R] ",
31
37
  }.freeze
32
38
  else
33
39
  # Extended colors for everyone else
@@ -36,6 +42,9 @@ module InspecPlugins::StreamingReporterProgressBar
36
42
  "passed" => "\033[38;5;41m",
37
43
  "skipped" => "\033[38;5;247m",
38
44
  "reset" => "\033[0m",
45
+ "error" => "\033[0;38;5;21m",
46
+ "not_applicable" => "\033[0;38;5;117m",
47
+ "not_reviewed" => "\033[0;38;5;214m",
39
48
  }.freeze
40
49
 
41
50
  # Groovy UTF-8 characters for everyone else...
@@ -44,6 +53,9 @@ module InspecPlugins::StreamingReporterProgressBar
44
53
  "failed" => "× [FAILED] ",
45
54
  "skipped" => "↺ [SKIPPED]",
46
55
  "passed" => "✔ [PASSED] ",
56
+ "error" => "× [ERROR] ",
57
+ "not_applicable" => " [N/A] ",
58
+ "not_reviewed" => " [N/R] ",
47
59
  }.freeze
48
60
  end
49
61
 
@@ -71,29 +83,43 @@ module InspecPlugins::StreamingReporterProgressBar
71
83
  control_id = notification.example.metadata[:id]
72
84
  title = notification.example.metadata[:title]
73
85
  full_description = notification.example.metadata[:full_description]
74
- control_impact = notification.example.metadata[:impact]
86
+
87
+ # No-op exception occurs in case of not_applicable_if
88
+ if (full_description.include? "No-op") && notification.example.exception
89
+ full_description += notification.example.exception.message
90
+ end
91
+
75
92
  set_status_mapping(control_id, status)
76
- show_progress(control_id, title, full_description, control_impact) if control_ended?(control_id)
93
+ collect_notifications(notification, control_id, status)
94
+ control_ended = control_ended?(control_id)
95
+ if control_ended
96
+ control_outcome = add_enhanced_outcomes(control_id) if enhanced_outcomes
97
+ show_progress(control_id, title, full_description, control_outcome)
98
+ end
77
99
  end
78
100
 
79
- def show_progress(control_id, title, full_description, control_impact)
101
+ def show_progress(control_id, title, full_description, control_outcome)
80
102
  @bar ||= ProgressBar.new(controls_count, :bar, :counter, :percentage)
81
103
  sleep 0.1
82
104
  @bar.increment!
83
- @bar.puts format_it(control_id, title, full_description, control_impact)
105
+ @bar.puts format_it(control_id, title, full_description, control_outcome)
84
106
  rescue StandardError => e
85
107
  raise "Exception in Progress Bar streaming reporter: #{e}"
86
108
  end
87
109
 
88
- def format_it(control_id, title, full_description, control_impact)
89
- control_status = if @status_mapping[control_id].include? "failed"
90
- "failed"
91
- elsif @status_mapping[control_id].include? "passed"
92
- "passed"
93
- else
94
- @status_mapping[control_id].include? "skipped"
95
- "skipped"
96
- end
110
+ def format_it(control_id, title, full_description, control_outcome)
111
+ if control_outcome
112
+ control_status = control_outcome
113
+ else
114
+ control_status = if @status_mapping[control_id].include? "failed"
115
+ "failed"
116
+ elsif @status_mapping[control_id].include? "passed"
117
+ "passed"
118
+ else
119
+ @status_mapping[control_id].include? "skipped"
120
+ "skipped"
121
+ end
122
+ end
97
123
  indicator = INDICATORS[control_status]
98
124
  message_to_format = ""
99
125
  message_to_format += "#{indicator} "
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: 5.18.14
4
+ version: 5.22.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef InSpec Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-11 00:00:00.000000000 Z
11
+ date: 2023-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-telemetry
@@ -226,34 +226,34 @@ dependencies:
226
226
  requirements:
227
227
  - - ">="
228
228
  - !ruby/object:Gem::Version
229
- version: 0.9.0
229
+ version: '1'
230
230
  - - "<"
231
231
  - !ruby/object:Gem::Version
232
- version: '1.5'
232
+ version: '3'
233
233
  type: :runtime
234
234
  prerelease: false
235
235
  version_requirements: !ruby/object:Gem::Requirement
236
236
  requirements:
237
237
  - - ">="
238
238
  - !ruby/object:Gem::Version
239
- version: 0.9.0
239
+ version: '1'
240
240
  - - "<"
241
241
  - !ruby/object:Gem::Version
242
- version: '1.5'
242
+ version: '3'
243
243
  - !ruby/object:Gem::Dependency
244
- name: faraday_middleware
244
+ name: faraday-follow_redirects
245
245
  requirement: !ruby/object:Gem::Requirement
246
246
  requirements:
247
247
  - - "~>"
248
248
  - !ruby/object:Gem::Version
249
- version: '1.0'
249
+ version: '0.3'
250
250
  type: :runtime
251
251
  prerelease: false
252
252
  version_requirements: !ruby/object:Gem::Requirement
253
253
  requirements:
254
254
  - - "~>"
255
255
  - !ruby/object:Gem::Version
256
- version: '1.0'
256
+ version: '0.3'
257
257
  - !ruby/object:Gem::Dependency
258
258
  name: tty-table
259
259
  requirement: !ruby/object:Gem::Requirement
@@ -429,6 +429,7 @@ files:
429
429
  - lib/inspec/dist.rb
430
430
  - lib/inspec/dsl.rb
431
431
  - lib/inspec/dsl_shared.rb
432
+ - lib/inspec/enhanced_outcomes.rb
432
433
  - lib/inspec/env_printer.rb
433
434
  - lib/inspec/errors.rb
434
435
  - lib/inspec/exceptions.rb
@@ -583,6 +584,7 @@ files:
583
584
  - lib/inspec/resources/mysql.rb
584
585
  - lib/inspec/resources/mysql_conf.rb
585
586
  - lib/inspec/resources/mysql_session.rb
587
+ - lib/inspec/resources/nftables.rb
586
588
  - lib/inspec/resources/nginx.rb
587
589
  - lib/inspec/resources/nginx_conf.rb
588
590
  - lib/inspec/resources/noop.rb
@@ -606,6 +608,12 @@ files:
606
608
  - lib/inspec/resources/php_config.rb
607
609
  - lib/inspec/resources/pip.rb
608
610
  - lib/inspec/resources/platform.rb
611
+ - lib/inspec/resources/podman.rb
612
+ - lib/inspec/resources/podman_container.rb
613
+ - lib/inspec/resources/podman_image.rb
614
+ - lib/inspec/resources/podman_network.rb
615
+ - lib/inspec/resources/podman_pod.rb
616
+ - lib/inspec/resources/podman_volume.rb
609
617
  - lib/inspec/resources/port.rb
610
618
  - lib/inspec/resources/postfix_conf.rb
611
619
  - lib/inspec/resources/postgres.rb
@@ -707,6 +715,7 @@ files:
707
715
  - lib/inspec/utils/object_traversal.rb
708
716
  - lib/inspec/utils/parser.rb
709
717
  - lib/inspec/utils/pkey_reader.rb
718
+ - lib/inspec/utils/podman.rb
710
719
  - lib/inspec/utils/run_data_filters.rb
711
720
  - lib/inspec/utils/simpleconfig.rb
712
721
  - lib/inspec/utils/spdx.rb
@@ -716,8 +725,12 @@ files:
716
725
  - lib/inspec/utils/telemetry/data_series.rb
717
726
  - lib/inspec/utils/telemetry/global_methods.rb
718
727
  - lib/inspec/utils/telemetry/run_context_probe.rb
728
+ - lib/inspec/utils/waivers/csv_file_reader.rb
729
+ - lib/inspec/utils/waivers/excel_file_reader.rb
730
+ - lib/inspec/utils/waivers/json_file_reader.rb
719
731
  - lib/inspec/utils/yaml_profile_summary.rb
720
732
  - lib/inspec/version.rb
733
+ - lib/inspec/waiver_file_reader.rb
721
734
  - lib/matchers/matchers.rb
722
735
  - lib/plugins/README.md
723
736
  - lib/plugins/inspec-compliance/README.md
@@ -758,6 +771,10 @@ files:
758
771
  - lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/reporter.erb
759
772
  - lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/streaming_reporter.erb
760
773
  - lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/version.erb
774
+ - lib/plugins/inspec-init/templates/profiles/alicloud/README.md
775
+ - lib/plugins/inspec-init/templates/profiles/alicloud/controls/example.rb
776
+ - lib/plugins/inspec-init/templates/profiles/alicloud/inputs.yml
777
+ - lib/plugins/inspec-init/templates/profiles/alicloud/inspec.yml
761
778
  - lib/plugins/inspec-init/templates/profiles/aws/README.md
762
779
  - lib/plugins/inspec-init/templates/profiles/aws/controls/example.rb
763
780
  - lib/plugins/inspec-init/templates/profiles/aws/inputs.yml