inspec-core 6.8.24 → 7.0.95

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 (71) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +8 -8
  3. data/etc/deprecations.json +42 -4
  4. data/inspec-core.gemspec +14 -7
  5. data/lib/inspec/archive/tar.rb +1 -0
  6. data/lib/inspec/backend.rb +2 -0
  7. data/lib/inspec/base_cli.rb +15 -2
  8. data/lib/inspec/cached_fetcher.rb +17 -1
  9. data/lib/inspec/cli.rb +2 -0
  10. data/lib/inspec/dependencies/cache.rb +47 -7
  11. data/lib/inspec/dsl.rb +44 -10
  12. data/lib/inspec/exceptions.rb +1 -0
  13. data/lib/inspec/fetcher/gem.rb +117 -0
  14. data/lib/inspec/fetcher/git.rb +21 -1
  15. data/lib/inspec/fetcher/local.rb +1 -1
  16. data/lib/inspec/fetcher.rb +1 -0
  17. data/lib/inspec/file_provider.rb +47 -1
  18. data/lib/inspec/metadata.rb +2 -0
  19. data/lib/inspec/plugin/v2/concerns/gem_spec_helper.rb +30 -0
  20. data/lib/inspec/plugin/v2/gem_source_manager.rb +50 -0
  21. data/lib/inspec/plugin/v2/installer.rb +65 -18
  22. data/lib/inspec/plugin/v2/loader.rb +37 -6
  23. data/lib/inspec/plugin/v2/plugin_types/resource_pack.rb +8 -0
  24. data/lib/inspec/plugin/v2.rb +1 -0
  25. data/lib/inspec/profile.rb +22 -3
  26. data/lib/inspec/profile_context.rb +10 -0
  27. data/lib/inspec/resources/audit_policy.rb +8 -2
  28. data/lib/inspec/resources/groups.rb +52 -0
  29. data/lib/inspec/resources.rb +0 -14
  30. data/lib/inspec/rule.rb +2 -0
  31. data/lib/inspec/runner.rb +7 -1
  32. data/lib/inspec/source_reader.rb +2 -0
  33. data/lib/inspec/ui.rb +1 -0
  34. data/lib/inspec/utils/deprecated_core_resources_list.rb +2 -2
  35. data/lib/inspec/utils/deprecation/config_file.rb +39 -3
  36. data/lib/inspec/utils/deprecation/deprecator.rb +10 -3
  37. data/lib/inspec/utils/simpleconfig.rb +2 -0
  38. data/lib/inspec/utils/telemetry/run_context_probe.rb +5 -2
  39. data/lib/inspec/version.rb +1 -1
  40. data/lib/inspec/waiver_file_reader.rb +35 -18
  41. data/lib/inspec.rb +2 -0
  42. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb +1 -1
  43. data/lib/plugins/shared/core_plugin_test_helper.rb +1 -1
  44. data/lib/source_readers/gem.rb +67 -0
  45. metadata +82 -43
  46. data/lib/inspec/resources/docker.rb +0 -274
  47. data/lib/inspec/resources/docker_container.rb +0 -116
  48. data/lib/inspec/resources/docker_image.rb +0 -141
  49. data/lib/inspec/resources/docker_object.rb +0 -52
  50. data/lib/inspec/resources/docker_plugin.rb +0 -68
  51. data/lib/inspec/resources/docker_service.rb +0 -95
  52. data/lib/inspec/resources/elasticsearch.rb +0 -165
  53. data/lib/inspec/resources/ibmdb2_conf.rb +0 -65
  54. data/lib/inspec/resources/ibmdb2_session.rb +0 -78
  55. data/lib/inspec/resources/mongodb.rb +0 -69
  56. data/lib/inspec/resources/mongodb_conf.rb +0 -44
  57. data/lib/inspec/resources/mongodb_session.rb +0 -98
  58. data/lib/inspec/resources/opa.rb +0 -26
  59. data/lib/inspec/resources/opa_api.rb +0 -49
  60. data/lib/inspec/resources/opa_cli.rb +0 -57
  61. data/lib/inspec/resources/podman.rb +0 -353
  62. data/lib/inspec/resources/podman_container.rb +0 -84
  63. data/lib/inspec/resources/podman_image.rb +0 -108
  64. data/lib/inspec/resources/podman_network.rb +0 -81
  65. data/lib/inspec/resources/podman_pod.rb +0 -101
  66. data/lib/inspec/resources/podman_volume.rb +0 -87
  67. data/lib/inspec/resources/rabbitmq_conf.rb +0 -2
  68. data/lib/inspec/resources/rabbitmq_config.rb +0 -56
  69. data/lib/inspec/resources/sybase_conf.rb +0 -41
  70. data/lib/inspec/resources/sybase_session.rb +0 -124
  71. data/lib/inspec/utils/podman.rb +0 -24
@@ -1,65 +0,0 @@
1
- module Inspec::Resources
2
- class Ibmdb2Conf < Inspec.resource(1)
3
- name "ibmdb2_conf"
4
-
5
- supports platform: "unix"
6
- supports platform: "windows"
7
-
8
- desc "Use the ibmdb2_conf InSpec audit resource to test the configuration values of IBM Db2 database."
9
- example <<~EXAMPLE
10
- describe ibmdb2_conf(db2_executable_file_path: "path_to_db2_binary", db_instance: "db2inst1") do
11
- its("output") { should_not be_empty }
12
- its("output") { should include("Audit buffer size (4KB) (AUDIT_BUF_SZ) = 0")}
13
- end
14
- EXAMPLE
15
-
16
- attr_reader :output
17
-
18
- def initialize(opts = {})
19
- if inspec.os.platform?("unix")
20
- @db2_executable_file_path = opts[:db2_executable_file_path]
21
- @db_instance = opts[:db_instance]
22
- raise Inspec::Exceptions::ResourceFailed, "Can't connect to IBM DB2 without db2_executable_file_path, db_instance options provided." if @db2_executable_file_path.nil? || @db_instance.nil?
23
- end
24
- @output = run_command
25
- end
26
-
27
- def resource_id
28
- if inspec.os.platform?("windows")
29
- "ibmdb2_conf"
30
- else
31
- "ibmdb2_conf:DatabaseInstance:#{@db_instance}"
32
- end
33
- end
34
-
35
- def to_s
36
- "IBM Db2 Conf"
37
- end
38
-
39
- private
40
-
41
- def run_command
42
- # attach to the db2 instance and get the configuration
43
- if inspec.os.platform?("unix")
44
- cmd = inspec.command("#{@db2_executable_file_path} attach to #{@db_instance}\; #{@db2_executable_file_path} get database manager configuration")
45
- out = cmd.stdout + "\n" + cmd.stderr
46
-
47
- # check if following specific error is there. Sourcing the db2profile to resolve the error.
48
- if cmd.exit_status != 0 && out =~ /SQL10007N Message "-1390" could not be retrieved. Reason code: "3"/
49
- cmd = inspec.command(". ~/sqllib/db2profile\; #{@db2_executable_file_path} attach to #{@db_instance}\; #{@db2_executable_file_path} get database manager configuration")
50
- out = cmd.stdout + "\n" + cmd.stderr
51
- end
52
- elsif inspec.os.platform?("windows")
53
- # set-item command set the powershell to run the db2 commands.
54
- cmd = inspec.command("set-item -path env:DB2CLP -value \"**$$**\"\; db2 get database manager configuration")
55
- out = cmd.stdout + "\n" + cmd.stderr
56
- end
57
-
58
- if cmd.exit_status != 0 || out =~ /Can't connect to IBM Db2 server/ || out.downcase =~ /^error:.*/
59
- raise Inspec::Exceptions::ResourceFailed, "IBM Db2 query with error: #{out}"
60
- else
61
- cmd.stdout.gsub(/\n|\r/, ",").split(",").reject { |n| n.nil? || n.empty? }.map { |n| n.strip.gsub!(/\s+/, " ") }
62
- end
63
- end
64
- end
65
- end
@@ -1,78 +0,0 @@
1
- module Inspec::Resources
2
- class Lines
3
- attr_reader :output, :exit_status
4
-
5
- def initialize(raw, desc, exit_status)
6
- @output = raw
7
- @desc = desc
8
- @exit_status = exit_status
9
- end
10
-
11
- def to_s
12
- @desc
13
- end
14
- end
15
-
16
- class Ibmdb2Session < Inspec.resource(1)
17
- name "ibmdb2_session"
18
-
19
- supports platform: "unix"
20
- supports platform: "windows"
21
-
22
- desc "Use the ibmdb2_session InSpec audit resource to test SQL commands run against a IBM Db2 database."
23
- example <<~EXAMPLE
24
- describe ibmdb2_session(db2_executable_file_path: "path_to_db2_binary", db_instance: "db2inst1", db_name: "sample").query('list database directory') do
25
- its('output') { should_not match(/sample/) }
26
- end
27
- EXAMPLE
28
-
29
- def initialize(opts = {})
30
- @db_name = opts[:db_name]
31
- if inspec.os.platform?("unix")
32
- @db2_executable_file_path = opts[:db2_executable_file_path]
33
- @db_instance = opts[:db_instance]
34
- raise Inspec::Exceptions::ResourceFailed, "Can't run IBM DB2 queries without db2_executable_file_path, db_instance, db_name options provided." if @db2_executable_file_path.nil? || @db_instance.nil? || @db_name.nil?
35
- elsif inspec.os.platform?("windows")
36
- raise Inspec::Exceptions::ResourceFailed, "Can't run IBM DB2 queries without db_name option provided." if @db_name.nil?
37
- end
38
- end
39
-
40
- def query(q)
41
- raise Inspec::Exceptions::ResourceFailed, "#{resource_exception_message}" if resource_failed?
42
-
43
- if inspec.os.platform?("unix")
44
- # connect to the db and query on the database
45
- cmd = inspec.command("#{@db2_executable_file_path} attach to #{@db_instance}\; #{@db2_executable_file_path} connect to #{@db_name}\; #{@db2_executable_file_path} #{q}\;")
46
- out = cmd.stdout + "\n" + cmd.stderr
47
-
48
- # check if following specific error is there. Sourcing the db2profile to resolve the error.
49
- if cmd.exit_status != 0 && out =~ /SQL10007N Message "-1390" could not be retrieved. Reason code: "3"/
50
- cmd = inspec.command(". ~/sqllib/db2profile\; #{@db2_executable_file_path} attach to #{@db_instance}\; #{@db2_executable_file_path} connect to #{@db_name}\; #{@db2_executable_file_path} \"#{q}\"\;")
51
- out = cmd.stdout + "\n" + cmd.stderr
52
- end
53
- elsif inspec.os.platform?("windows")
54
- # set-item command set the powershell to run the db2 commands.
55
- cmd = inspec.command("set-item -path env:DB2CLP -value \"**$$**\"\; db2 connect to #{@db_name}\; db2 \"#{q}\"\;")
56
- out = cmd.stdout + "\n" + cmd.stderr
57
- end
58
-
59
- if cmd.exit_status != 0 || out =~ /Can't connect to IBM Db2 / || out.downcase =~ /^error:.*/
60
- raise Inspec::Exceptions::ResourceFailed, "IBM Db2 connection error: #{out}"
61
- else
62
- Lines.new(cmd.stdout.strip, "IBM Db2 Query: #{q}", cmd.exit_status)
63
- end
64
- end
65
-
66
- def resource_id
67
- if inspec.os.platform?("windows")
68
- "ibmdb2_session:DatabaseName#{@db_name}"
69
- else
70
- "ibmdb2_session:DatabaseInstance:#{@db_instance}:DatabaseName#{@db_name}"
71
- end
72
- end
73
-
74
- def to_s
75
- "IBM Db2 Session"
76
- end
77
- end
78
- end
@@ -1,69 +0,0 @@
1
- module Inspec::Resources
2
- class Mongodb < Inspec.resource(1)
3
- name "mongodb"
4
- supports platform: "unix"
5
- supports platform: "windows"
6
-
7
- desc "The 'mongodb' resource is a helper for the 'mongodb_conf' & 'mongodb_session' resources. Please use those instead."
8
-
9
- attr_reader :conf_path
10
-
11
- def initialize
12
- case inspec.os[:family]
13
- when "debian", "fedora", "redhat", "linux", "suse"
14
- init_linux
15
- when "darwin"
16
- init_macos
17
- when "windows"
18
- init_windows
19
- end
20
- end
21
-
22
- def resource_id
23
- @conf_path
24
- end
25
-
26
- def to_s
27
- "MongoDB"
28
- end
29
-
30
- private
31
-
32
- def init_linux
33
- @conf_path = "/etc/mongod.conf"
34
- end
35
-
36
- def init_macos
37
- @conf_path = "/usr/local/etc/mongod.conf"
38
- end
39
-
40
- def init_windows
41
- dir = "C:\\Program Files\\MongoDB\\Server"
42
- @version = version_from_dir(dir)
43
- unless @version.to_s.empty?
44
- @conf_path = "#{dir}\\#{@version}\\bin\\mongod.cfg"
45
- end
46
- end
47
-
48
- def version_from_dir(dir)
49
- dirs = inspec.command("Get-ChildItem -Path \"#{dir}\" -Name").stdout
50
- entries = dirs.lines.count
51
- case entries
52
- when 0
53
- warn "Could not determine version of installed MongoDB by inspecting #{dir}"
54
- nil
55
- when 1
56
- dir_to_version(dirs)
57
- else
58
- warn "Multiple versions of MongoDB installed or incorrect base dir #{dir}"
59
- first = dir_to_version(dirs.lines.first)
60
- warn "Using the first version found: #{first}"
61
- first
62
- end
63
- end
64
-
65
- def dir_to_version(dir)
66
- dir.chomp.split("/").last
67
- end
68
- end
69
- end
@@ -1,44 +0,0 @@
1
- require "inspec/resources/json"
2
- require "inspec/resources/mongodb"
3
-
4
- module Inspec::Resources
5
- class MongodbConf < JsonConfig
6
- name "mongodb_conf"
7
- supports platform: "unix"
8
- supports platform: "windows"
9
- desc "Use the mongodb_conf InSpec audit resource to test the contents of the configuration file for MongoDB, typically located at `/etc/mongod.conf` or `C:\\Program Files\\MongoDB\\Server\\<version>\\bin\\mongod.cfg`, depending on the platform."
10
- example <<~EXAMPLE
11
- describe mongodb_conf do
12
- its(["storage", "dbPath"]) { should eq "/var/lib/mongodb" }
13
- its(["net", "port"]) { should eq 27017 }
14
- end
15
- EXAMPLE
16
-
17
- def initialize(conf_path = nil)
18
- @conf_path = conf_path || inspec.mongodb.conf_path
19
-
20
- if @conf_path.nil?
21
- return skip_resource "MongoDB conf path is not set."
22
- end
23
-
24
- super(@conf_path)
25
- end
26
-
27
- # set resource_id to "" if system is not able to determine the @conf_path
28
- def resource_id
29
- @conf_path || "mongodb_conf"
30
- end
31
-
32
- private
33
-
34
- def parse(content)
35
- YAML.load(content)
36
- rescue => e
37
- raise Inspec::Exceptions::ResourceFailed, "Unable to parse `mongod.conf` or `mongod.cfg` file: #{e.message}"
38
- end
39
-
40
- def resource_base_name
41
- "MongoDB Configuration"
42
- end
43
- end
44
- end
@@ -1,98 +0,0 @@
1
- require "mongo"
2
-
3
- module Inspec::Resources
4
- class Lines
5
- attr_reader :params
6
-
7
- def initialize(raw, desc, exit_status = nil)
8
- @params = raw
9
- @desc = desc
10
- @exit_status = exit_status
11
- end
12
-
13
- def to_s
14
- @desc
15
- end
16
- end
17
-
18
- class MongodbSession < Inspec.resource(1)
19
- name "mongodb_session"
20
- supports platform: "unix"
21
- supports platform: "windows"
22
-
23
- desc "Use the mongodb_session InSpec audit resource to run MongoDB command against a MongoDB Database."
24
- example <<~EXAMPLE
25
- # default values:
26
- # host: "127.0.0.1"
27
- # port: "27017"
28
- # auth_source - default to database name
29
- # auth_mech - :scram
30
-
31
- describe mongodb_session(user: "foo", password: "bar", database: "test").query(usersInfo: "ian").params["users"].first["roles"].first do
32
- its(["role"]) { should eq "readWrite" }
33
- end
34
- EXAMPLE
35
- attr_reader :user, :host, :port, :database, :params
36
-
37
- def initialize(opts = {})
38
- @user = opts[:user] || nil
39
- @password = opts[:password] || nil
40
- @host = opts[:host] || "127.0.0.1"
41
- @port = opts[:port] || "27017"
42
- @database = opts[:database] || nil
43
- @auth_mech = opts[:auth_mech] || :scram
44
- @auth_source = opts[:auth_source] || @database
45
- @ssl = opts[:ssl] || false
46
- @ssl_cert = opts[:ssl_cert] || nil
47
- @ssl_key = opts[:ssl_key] || nil
48
- @ssl_ca_cert = opts[:ssl_ca_cert] || nil
49
- @auth_mech_properties = opts[:auth_mech_properties] || {}
50
- @client = nil
51
-
52
- fail_resource "Can't run MongoDB checks without authentication." unless user && @password
53
- fail_resource "You must provide a database name for the session." unless database
54
-
55
- create_session
56
- end
57
-
58
- def query(command)
59
- raise Inspec::Exceptions::ResourceFailed, "#{resource_exception_message}" if resource_failed?
60
-
61
- Lines.new(@client.command(command).documents.first, "MongoDB query: #{command}")
62
- rescue => e
63
- raise Inspec::Exceptions::ResourceFailed, "Can't run MongoDB command Error: #{e.message}"
64
- end
65
-
66
- def resource_id
67
- "mongodb_session:User:#{@user}:Host:#{@host}:Database:#{@database}"
68
- end
69
-
70
- private
71
-
72
- def create_session
73
- raise Inspec::Exceptions::ResourceFailed, "#{resource_exception_message}" if resource_failed?
74
-
75
- options = { user: "#{user}",
76
- password: "#{@password}",
77
- database: "#{database}",
78
- auth_source: "#{@auth_source}",
79
- auth_mech: @auth_mech,
80
- }
81
- options[:auth_mech_properties] = @auth_mech_properties unless @auth_mech_properties.empty?
82
- options[:ssl] = @ssl
83
- opitons[:ssl_key] = @ssl_key unless @ssl_key.nil?
84
- options[:ssl_cert] = @ssl_cert unless @ssl_cert.nil?
85
- options[:ssl_ca_cert] = @ssl_ca_cert unless @ssl_ca_cert.nil?
86
-
87
- # Setting the logger level to INFO as mongo gem version 2.13.2 is using DEBUG as the log level Ref: https://github.com/mongodb/mongo-ruby-driver/blob/v2.13.2/lib/mongo/logger.rb#L79
88
- # Latest version of the mongo gem don't have this issue as it set to INFO level Ref: https://github.com/mongodb/mongo-ruby-driver/blob/master/lib/mongo/logger.rb#L82
89
- # We pinned the version to 2.13.2 as the latest version of the mongo gem has broken symlink https://jira.mongodb.org/browse/RUBY-2546 which causes omnibus build failure.
90
- # Once we get the latest version working we can remove logger level set here.
91
- Mongo::Logger.logger.level = Logger::INFO
92
- @client = Mongo::Client.new([ "#{host}:#{port}" ], options)
93
-
94
- rescue => e
95
- raise Inspec::Exceptions::ResourceFailed, "Can't run MongoDB command. Error: #{e.message}"
96
- end
97
- end
98
- end
@@ -1,26 +0,0 @@
1
- require "inspec/resources/json"
2
-
3
- module Inspec::Resources
4
- class Opa < JsonConfig
5
- name "opa"
6
- supports platform: "unix"
7
- supports platform: "windows"
8
-
9
- def initialize(content)
10
- @content = content
11
- super({ content: @content })
12
- end
13
-
14
- def result
15
- @content == {} || @content["result"].empty? ? nil : @content
16
- end
17
-
18
- private
19
-
20
- def parse(content)
21
- @content = YAML.load(content)
22
- rescue => e
23
- raise Inspec::Exceptions::ResourceFailed, "Unable to parse OPA query output: #{e.message}"
24
- end
25
- end
26
- end
@@ -1,49 +0,0 @@
1
- require "inspec/resources/opa"
2
-
3
- module Inspec::Resources
4
- class OpaApi < Opa
5
- name "opa_api"
6
- supports platform: "unix"
7
- supports platform: "windows"
8
-
9
- example <<~EXAMPLE
10
- describe opa_api(url: "localhost:8181/v1/data/example/violation", data: "input.json") do
11
- its(["result"]) { should eq 'value' }
12
- end
13
- EXAMPLE
14
-
15
- def initialize(opts = {})
16
- @url = opts[:url] || nil
17
- @data = opts[:data] || nil
18
- fail_resource "OPA url and data are mandatory." if @url.nil? || @url.empty? || @data.nil? || @data.empty?
19
- @content = load_result
20
- super(@content)
21
- end
22
-
23
- def allow
24
- @content["result"]
25
- end
26
-
27
- def resource_id
28
- @url || "opa_api"
29
- end
30
-
31
- def to_s
32
- "OPA api"
33
- end
34
-
35
- private
36
-
37
- def load_result
38
- raise Inspec::Exceptions::ResourceFailed, "#{resource_exception_message}" if resource_failed?
39
-
40
- result = inspec.command("curl -X POST #{@url} -d @#{@data} -H 'Content-Type: application/json'")
41
- if result.exit_status == 0
42
- result.stdout.gsub("\n", "")
43
- else
44
- error = result.stdout + "\n" + result.stderr
45
- raise Inspec::Exceptions::ResourceFailed, "Error while executing OPA query: #{error}"
46
- end
47
- end
48
- end
49
- end
@@ -1,57 +0,0 @@
1
- require "inspec/resources/opa"
2
-
3
- module Inspec::Resources
4
- class OpaCli < Opa
5
- name "opa_cli"
6
- supports platform: "unix"
7
- supports platform: "windows"
8
-
9
- example <<~EXAMPLE
10
- describe opa_cli(policy: "example.rego", data: "input.json", query: "data.example.allow") do
11
- its(["result"]) { should eq "value" }
12
- end
13
- EXAMPLE
14
-
15
- def initialize(opts = {})
16
- @opa_executable_path = opts[:opa_executable_path] || "opa" # if this path is not provided then we will assume that it's been set in the ENV PATH
17
- @policy = opts[:policy] || nil
18
- @data = opts[:data] || nil
19
- @query = opts[:query] || nil
20
- if (@policy.nil? || @policy.empty?) || (@data.nil? || @data.empty?) || (@query.nil? || @query.empty?)
21
- fail_resource "OPA policy, data and query are mandatory."
22
- end
23
- @content = load_result
24
- super(@content)
25
- end
26
-
27
- def allow
28
- @content["result"][0]["expressions"][0]["value"] if @content["result"][0]["expressions"][0]["text"].include?("allow")
29
- end
30
-
31
- def resource_id
32
- if @policy.nil? && @query.nil?
33
- "opa_cli"
34
- else
35
- "#{@policy}:#{@query}"
36
- end
37
- end
38
-
39
- def to_s
40
- "OPA cli"
41
- end
42
-
43
- private
44
-
45
- def load_result
46
- raise Inspec::Exceptions::ResourceFailed, "#{resource_exception_message}" if resource_failed?
47
-
48
- result = inspec.command("#{@opa_executable_path} eval -i '#{@data}' -d '#{@policy}' '#{@query}'")
49
- if result.exit_status == 0
50
- result.stdout.gsub("\n", "")
51
- else
52
- error = result.stdout + "\n" + result.stderr
53
- raise Inspec::Exceptions::ResourceFailed, "Error while executing OPA query: #{error}"
54
- end
55
- end
56
- end
57
- end