inspec-core 6.8.24 → 7.0.38.beta

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 (69) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +6 -6
  3. data/etc/deprecations.json +15 -6
  4. data/lib/inspec/base_cli.rb +3 -0
  5. data/lib/inspec/cached_fetcher.rb +16 -1
  6. data/lib/inspec/dependencies/cache.rb +48 -4
  7. data/lib/inspec/dsl.rb +40 -11
  8. data/lib/inspec/exceptions.rb +1 -0
  9. data/lib/inspec/fetcher/gem.rb +99 -0
  10. data/lib/inspec/fetcher/local.rb +1 -1
  11. data/lib/inspec/fetcher.rb +1 -0
  12. data/lib/inspec/file_provider.rb +46 -1
  13. data/lib/inspec/input_registry.rb +1 -1
  14. data/lib/inspec/plugin/v2/concerns/gem_spec_helper.rb +30 -0
  15. data/lib/inspec/plugin/v2/gem_source_manager.rb +43 -0
  16. data/lib/inspec/plugin/v2/installer.rb +42 -16
  17. data/lib/inspec/plugin/v2/loader.rb +34 -5
  18. data/lib/inspec/plugin/v2/plugin_types/resource_pack.rb +8 -0
  19. data/lib/inspec/plugin/v2.rb +1 -0
  20. data/lib/inspec/profile.rb +10 -0
  21. data/lib/inspec/profile_context.rb +10 -0
  22. data/lib/inspec/reporters/automate.rb +2 -2
  23. data/lib/inspec/resources/auditd.rb +1 -1
  24. data/lib/inspec/resources/groups.rb +52 -0
  25. data/lib/inspec/resources/port.rb +2 -2
  26. data/lib/inspec/resources/postgres_session.rb +5 -9
  27. data/lib/inspec/resources/yum.rb +1 -1
  28. data/lib/inspec/resources.rb +0 -14
  29. data/lib/inspec/runner.rb +7 -15
  30. data/lib/inspec/source_reader.rb +2 -0
  31. data/lib/inspec/ui.rb +1 -0
  32. data/lib/inspec/utils/deprecation/config_file.rb +39 -3
  33. data/lib/inspec/utils/deprecation/deprecator.rb +10 -3
  34. data/lib/inspec/utils/licensing_config.rb +1 -15
  35. data/lib/inspec/utils/parser.rb +9 -19
  36. data/lib/inspec/utils/telemetry.rb +1 -3
  37. data/lib/inspec/version.rb +1 -1
  38. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb +2 -4
  39. data/lib/source_readers/gem.rb +67 -0
  40. data/lib/source_readers/inspec.rb +1 -1
  41. metadata +9 -32
  42. data/lib/inspec/resources/docker.rb +0 -274
  43. data/lib/inspec/resources/docker_container.rb +0 -116
  44. data/lib/inspec/resources/docker_image.rb +0 -141
  45. data/lib/inspec/resources/docker_object.rb +0 -52
  46. data/lib/inspec/resources/docker_plugin.rb +0 -68
  47. data/lib/inspec/resources/docker_service.rb +0 -95
  48. data/lib/inspec/resources/elasticsearch.rb +0 -165
  49. data/lib/inspec/resources/ibmdb2_conf.rb +0 -65
  50. data/lib/inspec/resources/ibmdb2_session.rb +0 -78
  51. data/lib/inspec/resources/mongodb.rb +0 -69
  52. data/lib/inspec/resources/mongodb_conf.rb +0 -44
  53. data/lib/inspec/resources/mongodb_session.rb +0 -98
  54. data/lib/inspec/resources/podman.rb +0 -353
  55. data/lib/inspec/resources/podman_container.rb +0 -84
  56. data/lib/inspec/resources/podman_image.rb +0 -108
  57. data/lib/inspec/resources/podman_network.rb +0 -81
  58. data/lib/inspec/resources/podman_pod.rb +0 -101
  59. data/lib/inspec/resources/podman_volume.rb +0 -87
  60. data/lib/inspec/resources/rabbitmq_conf.rb +0 -2
  61. data/lib/inspec/resources/rabbitmq_config.rb +0 -56
  62. data/lib/inspec/resources/ssh_config.rb +0 -215
  63. data/lib/inspec/resources/ssh_key.rb +0 -124
  64. data/lib/inspec/resources/sshd_active_config.rb +0 -2
  65. data/lib/inspec/resources/sshd_config.rb +0 -2
  66. data/lib/inspec/resources/sybase_conf.rb +0 -41
  67. data/lib/inspec/resources/sybase_session.rb +0 -124
  68. data/lib/inspec/utils/deprecated_core_resources_list.rb +0 -25
  69. data/lib/inspec/utils/podman.rb +0 -24
@@ -1,124 +0,0 @@
1
- require "inspec/utils/file_reader"
2
- require "net/ssh" unless defined?(Net::SSH)
3
-
4
- # Change module if required
5
- module Inspec::Resources
6
- class SshKey < FileResource
7
- # Every resource requires an internal name.
8
- name "ssh_key"
9
-
10
- # Restrict to only run on the below platforms (if none were given,
11
- # all OS's and cloud API's supported)
12
- supports platform: "unix"
13
- supports platform: "windows"
14
-
15
- desc "public/private SSH key pair test"
16
-
17
- example <<~EXAMPLE
18
- describe ssh_key('path: ~/.ssh/id_rsa') do
19
- its('key_length') { should eq 4096 }
20
- its('type') { should cmp /rsa/ }
21
- it { should be_private }
22
- end
23
- EXAMPLE
24
-
25
- include FileReader
26
-
27
- def initialize(keypath, passphrase = nil)
28
- skip_resource "The `ssh_key` resource is not yet available on your OS." unless inspec.os.unix? || inspec.os.windows?
29
- @key_path = set_ssh_key_path(keypath)
30
- @passphrase = passphrase
31
- @key = read_ssh_key
32
- super(@key_path)
33
- end
34
-
35
- def public?
36
- return if @key.nil?
37
-
38
- @key[:public]
39
- end
40
-
41
- def private?
42
- return if @key.nil?
43
-
44
- @key[:private]
45
- end
46
-
47
- def key_length
48
- return if @key.nil?
49
-
50
- @key[:key_length]
51
- end
52
-
53
- def type
54
- return if @key.nil?
55
-
56
- @key[:type]
57
- end
58
-
59
- # Define a resource ID. This is used in reporting engines to uniquely identify the individual resource.
60
- # This might be a file path, or a process ID, or a cloud instance ID. Only meaningful to the implementation.
61
- # Must be a string. Defaults to the empty string if not implemented.
62
- def resource_id
63
- @key_path || "SSH key"
64
- end
65
-
66
- def to_s
67
- "ssh_key #{@key_path}"
68
- end
69
-
70
- private
71
-
72
- def set_ssh_key_path(keypath)
73
- if File.exist?(keypath)
74
- @key_path = keypath
75
- elsif File.exist?(File.join("#{Dir.home}/.ssh/", keypath))
76
- @key_path = File.join("#{Dir.home}/.ssh/", keypath)
77
- else
78
- raise Inspec::Exceptions::ResourceSkipped, "Can't find file: #{keypath}"
79
- end
80
- end
81
-
82
- def read_ssh_key
83
- key_data = {}
84
- key = nil
85
- filecontent = read_file_content((@key_path), @passphrase)
86
- raise Inspec::Exceptions::ResourceSkipped, "File is empty: #{@key_path}" if filecontent.split("\n").empty?
87
-
88
- if filecontent.split("\n")[0].include?("PRIVATE")
89
- # Net::SSH::KeyFactory does not have support to load private key for DSA
90
- key = Net::SSH::KeyFactory.load_private_key(@key_path, @passphrase, false)
91
- unless key.nil?
92
- key_data[:private] = true
93
- key_data[:public] = false
94
- # The data send for ssh type is not in same format so it's good to match on the string
95
- key_data[:type] = key.ssh_type
96
- key_data[:key_length] = key_lengh(key)
97
- end
98
- else
99
- key = Net::SSH::KeyFactory.load_public_key(@key_path)
100
- unless key.nil?
101
- key_data[:private] = false
102
- key_data[:public] = true
103
- # The data send for ssh type is not in same format so it's good to match on the string
104
- key_data[:type] = key.ssh_type
105
- key_data[:key_length] = key_lengh(key)
106
- end
107
- end
108
-
109
- key_data
110
- rescue OpenSSL::PKey::PKeyError => e
111
- raise Inspec::Exceptions::ResourceFailed, "#{e.message}"
112
- end
113
-
114
- def key_lengh(key)
115
- if key.class.to_s == "OpenSSL::PKey::RSA"
116
- key.public_key.n.num_bits
117
- else
118
- # Unable to get the key lenght data for other types of keys
119
- # TODO: Need to check if there is any method that will get this info.
120
- nil
121
- end
122
- end
123
- end
124
- end
@@ -1,2 +0,0 @@
1
- # This is just here to make the dynamic loader happy.
2
- require "inspec/resources/ssh_config"
@@ -1,2 +0,0 @@
1
- # This is just here to make the dynamic loader happy.
2
- require "inspec/resources/ssh_config"
@@ -1,41 +0,0 @@
1
- require "inspec/resources/sybase_session"
2
-
3
- module Inspec::Resources
4
- class SybaseConf < Inspec.resource(1)
5
- name "sybase_conf"
6
- supports platform: "unix"
7
- # supports platform: "windows" # TODO
8
- desc "Use the sybase_conf InSpec resource to test Sybase config settings"
9
- example <<~EXAMPLE
10
- describe sybase_conf("max memory", password: 'password', server: 'SYBASE') do
11
- its("run_value") { should cmp 180224 }
12
- end
13
- EXAMPLE
14
-
15
- attr_reader :conf_param, :sql_query
16
- def initialize(conf_param_name, opts = {})
17
- @conf_param = conf_param_name
18
- opts[:username] ||= "sa"
19
- opts[:database] ||= "master"
20
- sql_session = inspec.sybase_session(opts)
21
- @sql_query = sql_session.query("sp_configure \"#{conf_param}\"")
22
- end
23
-
24
- def run_value
25
- sql_query.row(0).column("Run Value").value
26
- end
27
-
28
- def config_value
29
- sql_query.row(0).column("Config Value").value
30
- end
31
-
32
- def resource_id
33
- conf_param || "Sybase config settings"
34
- end
35
-
36
- def to_s
37
- "Sybase Conf #{conf_param}"
38
- end
39
-
40
- end
41
- end
@@ -1,124 +0,0 @@
1
- require "inspec/resources/command"
2
- require "inspec/utils/database_helpers"
3
- require "hashie/mash"
4
- require "csv" unless defined?(CSV)
5
- require "tempfile" unless defined?(Tempfile)
6
-
7
- module Inspec::Resources
8
- # STABILITY: Experimental
9
- # This resource needs further testing and refinement
10
- #
11
- class SybaseSession < Inspec.resource(1)
12
- name "sybase_session"
13
- supports platform: "unix"
14
- # supports platform: "windows" # TODO
15
- desc "Use the sybase_session InSpec resource to test commands against an Sybase database"
16
- example <<~EXAMPLE
17
- sql = sybase_session(username: 'my_user', password: 'password', server: 'SYBASE', database: 'pubs2')
18
- describe sql.query(\"SELECT * FROM authors\").row(0).column('au_lname') do
19
- its('value') { should eq 'Smith' }
20
- end
21
- EXAMPLE
22
-
23
- # TODO: allow to set -I interfaces file
24
- # TODO: allow to customize -s column separator
25
- attr_reader :bin, :col_sep, :database, :password, :server, :sybase_home, :username
26
-
27
- def initialize(opts = {})
28
- @username = opts[:username]
29
- @password = opts[:password]
30
- @database = opts[:database]
31
- @server = opts[:server]
32
- @sybase_home = opts[:sybase_home] || "/opt/sap"
33
- @bin = opts[:bin] || "isql"
34
- @col_sep = "|"
35
-
36
- fail_resource "Can't run Sybase checks without authentication" unless username && password
37
- fail_resource "You must provide a server name for the session" unless server
38
- fail_resource "You must provide a database name for the session" unless database
39
- fail_resource "Cannot find #{bin} CLI tool" unless inspec.command(bin).exist?
40
- end
41
-
42
- def query(sql)
43
- # We must write the SQl to a temp file on the remote target
44
- # try to get a temp path
45
- sql_file_path = upload_sql_file(sql)
46
-
47
- # TODO: Find if there is better way to get the current shell
48
- current_shell = inspec.command("echo $SHELL")
49
-
50
- res = current_shell.exit_status
51
-
52
- # isql reuires that we have a matching locale set, but does not support C.UTF-8. en_US.UTF-8 is the least evil.
53
- if res == 0 && ( current_shell.stdout&.include?("/csh") || current_shell.stdout&.include?("/tcsh") )
54
- command = "source #{sybase_home}/SYBASE.csh; setenv LANG en_US.UTF-8; #{bin} -s\"#{col_sep}\" -w80000 -S #{server} -U #{username} -D #{database} -P \"#{password}\" < #{sql_file_path}"
55
- else
56
- command = "LANG=en_US.UTF-8 SYBASE=#{sybase_home} #{bin} -s\"#{col_sep}\" -w80000 -S #{server} -U #{username} -D #{database} -P \"#{password}\" < #{sql_file_path}"
57
- end
58
-
59
- isql_cmd = inspec.command(command)
60
- # Check for isql errors
61
- res = isql_cmd.exit_status
62
- raise Inspec::Exceptions::ResourceFailed.new("isql exited with code #{res} and stderr '#{isql_cmd.stderr}', stdout '#{isql_cmd.stdout}'") unless res == 0
63
- # isql is ill-behaved, and returns 0 on error
64
- raise Inspec::Exceptions::ResourceFailed.new("isql exited with error '#{isql_cmd.stderr}', stdout '#{isql_cmd.stdout}'") unless isql_cmd.stderr == ""
65
- # check stdout for error messages when stderr is empty "Msg 102, Level 15, State 181:\nServer 'SYBASE', Line 1:\nIncorrect syntax near '.'.\n"
66
- raise Inspec::Exceptions::ResourceFailed.new("isql exited with error #{isql_cmd.stdout}") if isql_cmd.stdout.match?(/Msg\s\d+,\sLevel\s\d+,\sState\s\d+/)
67
-
68
- # Clean up temporary file
69
- rm_cmd = inspec.command("rm #{sql_file_path}")
70
- res = rm_cmd.exit_status # TODO: handle
71
- raise Inspec::Exceptions::ResourceFailed.new("Unable to delete temproary SQL input file at #{sql_file_path}: #{rm_cmd.stderr}") unless res == 0
72
-
73
- DatabaseHelper::SQLQueryResult.new(isql_cmd, parse_csv_result(isql_cmd.stdout))
74
- end
75
-
76
- def resource_id
77
- @database || "Sybase Session"
78
- end
79
-
80
- def to_s
81
- "Sybase Session"
82
- end
83
-
84
- private
85
-
86
- def parse_csv_result(stdout)
87
- output = stdout.gsub(/\r/, "").strip
88
- lines = output.lines
89
- # Remove second row (all dashes) and last 2 rows (blank and summary lines)
90
- trimmed_output = ([lines[0]] << lines.slice(2..-3)).join("")
91
- header_converter = Proc.new do |header|
92
- # This is here to suppress a warning from Hashie::Mash when it encounters a
93
- # header column that ends up with the name "default", which happens when using the
94
- # sybase_conf resource. It does mean that aly query whose output field includes the name
95
- # Default (exactly) will get renamed to default_value, but that seems unlikely.
96
- if header.match?(/^Default\s+$/)
97
- "default_value"
98
- else
99
- header.downcase.strip
100
- end
101
- end
102
- field_converter = ->(field) { field&.strip }
103
- CSV.parse(trimmed_output, headers: true, header_converters: header_converter, converters: field_converter, col_sep: col_sep).map { |row| Hashie::Mash.new(row.to_h) }
104
- end
105
-
106
- def upload_sql_file(sql)
107
- remote_temp_dir = "/tmp"
108
- remote_file_path = nil
109
- local_temp_file = Tempfile.new(["sybase", ".sql"])
110
- begin
111
- local_temp_file.write("#{sql}\n")
112
- local_temp_file.write("go\n")
113
- local_temp_file.flush
114
- filename = File.basename(local_temp_file.path)
115
- remote_file_path = "#{remote_temp_dir}/#{filename}"
116
- inspec.backend.upload([local_temp_file.path], remote_temp_dir)
117
- ensure
118
- local_temp_file.close
119
- local_temp_file.unlink
120
- end
121
- remote_file_path
122
- end
123
- end
124
- end
@@ -1,25 +0,0 @@
1
- module DeprecatedCoreResourcesList
2
- CORE_RESOURCES_DEPRECATED = %i{
3
- docker_container
4
- docker_image
5
- docker_plugin
6
- docker_service
7
- elasticsearch
8
- ibmdb2_conf
9
- ibmdb2_session
10
- mongodb
11
- mongodb_conf
12
- mongodb_session
13
- podman
14
- podman_container
15
- podman_image
16
- podman_network
17
- podman_pod
18
- podman_volume
19
- rabbitmq_config
20
- ssh_config
21
- ssh_key
22
- sybase_conf
23
- sybase_session
24
- }.freeze
25
- end
@@ -1,24 +0,0 @@
1
- require "inspec/resources/command"
2
-
3
- module Inspec
4
- module Utils
5
- module Podman
6
- def podman_running?
7
- inspec.command("podman version").exit_status == 0
8
- end
9
-
10
- # Generates the template in this format using labels hash: "\"id\": {{json .ID}}, \"name\": {{json .Name}}",
11
- def generate_go_template(labels)
12
- (labels.map { |k, v| "\"#{k}\": {{json .#{v}}}" }).join(", ")
13
- end
14
-
15
- def parse_command_output(output)
16
- require "json" unless defined?(JSON)
17
- JSON.parse(output)
18
- rescue JSON::ParserError => _e
19
- warn "Could not parse the command output"
20
- {}
21
- end
22
- end
23
- end
24
- end