inspec-core 4.41.20 → 4.52.9

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 (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +4 -0
  3. data/etc/deprecations.json +1 -1
  4. data/lib/bundles/inspec-supermarket/README.md +21 -2
  5. data/lib/bundles/inspec-supermarket/cli.rb +20 -3
  6. data/lib/bundles/inspec-supermarket/target.rb +3 -2
  7. data/lib/inspec/base_cli.rb +12 -0
  8. data/lib/inspec/cli.rb +21 -4
  9. data/lib/inspec/control_eval_context.rb +40 -39
  10. data/lib/inspec/dsl.rb +18 -3
  11. data/lib/inspec/globals.rb +5 -0
  12. data/lib/inspec/plugin/v1/registry.rb +1 -1
  13. data/lib/inspec/profile.rb +115 -2
  14. data/lib/inspec/resources/auditd.rb +5 -4
  15. data/lib/inspec/resources/cassandra.rb +64 -0
  16. data/lib/inspec/resources/cassandradb_conf.rb +47 -0
  17. data/lib/inspec/resources/cassandradb_session.rb +68 -0
  18. data/lib/inspec/resources/chrony_conf.rb +55 -0
  19. data/lib/inspec/resources/csv.rb +26 -3
  20. data/lib/inspec/resources/groups.rb +22 -3
  21. data/lib/inspec/resources/http.rb +135 -54
  22. data/lib/inspec/resources/ibmdb2_conf.rb +57 -0
  23. data/lib/inspec/resources/ibmdb2_session.rb +69 -0
  24. data/lib/inspec/resources/mssql_sys_conf.rb +48 -0
  25. data/lib/inspec/resources/opa.rb +4 -1
  26. data/lib/inspec/resources/oracle.rb +66 -0
  27. data/lib/inspec/resources/oracledb_conf.rb +40 -0
  28. data/lib/inspec/resources/oracledb_listener_conf.rb +123 -0
  29. data/lib/inspec/resources/oracledb_session.rb +25 -6
  30. data/lib/inspec/resources/packages.rb +21 -0
  31. data/lib/inspec/resources/postgres_session.rb +15 -4
  32. data/lib/inspec/resources/service.rb +59 -10
  33. data/lib/inspec/resources/ssl.rb +7 -0
  34. data/lib/inspec/resources/sybase_conf.rb +37 -0
  35. data/lib/inspec/resources/sybase_session.rb +111 -0
  36. data/lib/inspec/resources/users.rb +16 -2
  37. data/lib/inspec/resources/windows_firewall.rb +1 -1
  38. data/lib/inspec/resources.rb +9 -0
  39. data/lib/inspec/run_data/profile.rb +0 -2
  40. data/lib/inspec/version.rb +1 -1
  41. metadata +14 -2
@@ -0,0 +1,111 @@
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
+ # isql reuires that we have a matching locale set, but does not support C.UTF-8. en_US.UTF-8 is the least evil.
48
+ 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}"
49
+ isql_cmd = inspec.command(command)
50
+
51
+ # Check for isql errors
52
+ res = isql_cmd.exit_status
53
+ raise Inspec::Exceptions::ResourceFailed.new("isql exited with code #{res} and stderr '#{isql_cmd.stderr}', stdout '#{isql_cmd.stdout}'") unless res == 0
54
+ # isql is ill-behaved, and returns 0 on error
55
+ raise Inspec::Exceptions::ResourceFailed.new("isql exited with error '#{isql_cmd.stderr}', stdout '#{isql_cmd.stdout}'") unless isql_cmd.stderr == ""
56
+ # check stdout for error messages when stderr is empty "Msg 102, Level 15, State 181:\nServer 'SYBASE', Line 1:\nIncorrect syntax near '.'.\n"
57
+ 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+/)
58
+
59
+ # Clean up temporary file
60
+ rm_cmd = inspec.command("rm #{sql_file_path}")
61
+ res = rm_cmd.exit_status # TODO: handle
62
+ raise Inspec::Exceptions::ResourceFailed.new("Unable to delete temproary SQL input file at #{sql_file_path}: #{rm_cmd.stderr}") unless res == 0
63
+
64
+ DatabaseHelper::SQLQueryResult.new(isql_cmd, parse_csv_result(isql_cmd.stdout))
65
+ end
66
+
67
+ def to_s
68
+ "Sybase Session"
69
+ end
70
+
71
+ private
72
+
73
+ def parse_csv_result(stdout)
74
+ output = stdout.gsub(/\r/, "").strip
75
+ lines = output.lines
76
+ # Remove second row (all dashes) and last 2 rows (blank and summary lines)
77
+ trimmed_output = ([lines[0]] << lines.slice(2..-3)).join("")
78
+ header_converter = Proc.new do |header|
79
+ # This is here to suppress a warning from Hashie::Mash when it encounters a
80
+ # header column that ends up with the name "default", which happens when using the
81
+ # sybase_conf resource. It does mean that aly query whose output field includes the name
82
+ # Default (exactly) will get renamed to default_value, but that seems unlikely.
83
+ if header.match?(/^Default\s+$/)
84
+ "default_value"
85
+ else
86
+ header.downcase.strip
87
+ end
88
+ end
89
+ field_converter = ->(field) { field&.strip }
90
+ 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) }
91
+ end
92
+
93
+ def upload_sql_file(sql)
94
+ remote_temp_dir = "/tmp"
95
+ remote_file_path = nil
96
+ local_temp_file = Tempfile.new(["sybase", ".sql"])
97
+ begin
98
+ local_temp_file.write("#{sql}\n")
99
+ local_temp_file.write("go\n")
100
+ local_temp_file.flush
101
+ filename = File.basename(local_temp_file.path)
102
+ remote_file_path = "#{remote_temp_dir}/#{filename}"
103
+ inspec.backend.upload([local_temp_file.path], remote_temp_dir)
104
+ ensure
105
+ local_temp_file.close
106
+ local_temp_file.unlink
107
+ end
108
+ remote_file_path
109
+ end
110
+ end
111
+ end
@@ -204,7 +204,9 @@ module Inspec::Resources
204
204
  alias group groupname
205
205
 
206
206
  def groups
207
- identity[:groups] unless identity.nil?
207
+ unless identity.nil?
208
+ inspec.os.windows? ? UserGroups.new(identity[:groups]) : identity[:groups]
209
+ end
208
210
  end
209
211
 
210
212
  def home
@@ -314,6 +316,18 @@ module Inspec::Resources
314
316
  end
315
317
  end
316
318
 
319
+ # Class defined to compare for groups without case-sensitivity
320
+ class UserGroups < Array
321
+ def initialize(user_groups)
322
+ @user_groups = user_groups
323
+ super
324
+ end
325
+
326
+ def include?(group)
327
+ !(@user_groups.select { |user_group| user_group.casecmp?(group) }.empty?)
328
+ end
329
+ end
330
+
317
331
  # This is an abstract class that every user provoider has to implement.
318
332
  # A user provider implements a system abstracts and helps the InSpec resource
319
333
  # hand-over system specific behavior to those providers
@@ -622,7 +636,7 @@ module Inspec::Resources
622
636
  name, _domain = parse_windows_account(username)
623
637
  return if collect_user_details.nil?
624
638
 
625
- res = collect_user_details.select { |user| user[:username] == name }
639
+ res = collect_user_details.select { |user| user[:username].casecmp? name }
626
640
  res[0] unless res.empty?
627
641
  end
628
642
 
@@ -77,7 +77,7 @@ module Inspec::Resources
77
77
 
78
78
  def load_firewall_profile(profile_name)
79
79
  <<-EOH
80
- Remove-TypeData System.Array # workaround for PS bug here: https://bit.ly/2SRMQ8M
80
+ Get-TypeData -TypeName System.Array | Remove-TypeData # workaround for PS bug here: https://bit.ly/2SRMQ8M
81
81
  $profile = Get-NetFirewallProfile -Name "#{profile_name}"
82
82
  $count = @($profile | Get-NetFirewallRule).Count
83
83
  ([PSCustomObject]@{
@@ -37,6 +37,9 @@ require "inspec/resources/chocolatey_package"
37
37
  require "inspec/resources/command"
38
38
  require "inspec/resources/cran"
39
39
  require "inspec/resources/cpan"
40
+ require "inspec/resources/cassandradb_session"
41
+ require "inspec/resources/cassandradb_conf"
42
+ require "inspec/resources/cassandra"
40
43
  require "inspec/resources/crontab"
41
44
  require "inspec/resources/dh_params"
42
45
  require "inspec/resources/directory"
@@ -58,6 +61,8 @@ require "inspec/resources/groups"
58
61
  require "inspec/resources/grub_conf"
59
62
  require "inspec/resources/host"
60
63
  require "inspec/resources/http"
64
+ require "inspec/resources/ibmdb2_conf"
65
+ require "inspec/resources/ibmdb2_session"
61
66
  require "inspec/resources/iis_app"
62
67
  require "inspec/resources/iis_app_pool"
63
68
  require "inspec/resources/iis_site"
@@ -76,6 +81,7 @@ require "inspec/resources/mongodb_conf"
76
81
  require "inspec/resources/mongodb_session"
77
82
  require "inspec/resources/mount"
78
83
  require "inspec/resources/mssql_session"
84
+ require "inspec/resources/mssql_sys_conf"
79
85
  require "inspec/resources/mysql"
80
86
  require "inspec/resources/mysql_conf"
81
87
  require "inspec/resources/mysql_session"
@@ -84,6 +90,9 @@ require "inspec/resources/nginx_conf"
84
90
  require "inspec/resources/npm"
85
91
  require "inspec/resources/ntp_conf"
86
92
  require "inspec/resources/oneget"
93
+ require "inspec/resources/oracle"
94
+ require "inspec/resources/oracledb_conf"
95
+ require "inspec/resources/oracledb_listener_conf"
87
96
  require "inspec/resources/opa_cli"
88
97
  require "inspec/resources/opa_api"
89
98
  require "inspec/resources/oracledb_session"
@@ -49,7 +49,6 @@ module Inspec
49
49
  end
50
50
 
51
51
  class Profile
52
- # Good candidate for keyword_init, but that is not in 2.4
53
52
  Dependency = Struct.new(
54
53
  :name, :path, :status, :status_message, :git, :url, :compliance, :supermarket, :branch, :tag, :commit, :version, :relative_path
55
54
  ) do
@@ -71,7 +70,6 @@ module Inspec
71
70
  end
72
71
  end
73
72
 
74
- # Good candidate for keyword_init, but that is not in 2.4
75
73
  Group = Struct.new(
76
74
  :title, :controls, :id
77
75
  ) do
@@ -1,3 +1,3 @@
1
1
  module Inspec
2
- VERSION = "4.41.20".freeze
2
+ VERSION = "4.52.9".freeze
3
3
  end
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: 4.41.20
4
+ version: 4.52.9
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: 2021-09-01 00:00:00.000000000 Z
11
+ date: 2021-12-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef-telemetry
@@ -505,7 +505,11 @@ files:
505
505
  - lib/inspec/resources/bond.rb
506
506
  - lib/inspec/resources/bridge.rb
507
507
  - lib/inspec/resources/bsd_service.rb
508
+ - lib/inspec/resources/cassandra.rb
509
+ - lib/inspec/resources/cassandradb_conf.rb
510
+ - lib/inspec/resources/cassandradb_session.rb
508
511
  - lib/inspec/resources/chocolatey_package.rb
512
+ - lib/inspec/resources/chrony_conf.rb
509
513
  - lib/inspec/resources/command.rb
510
514
  - lib/inspec/resources/cpan.rb
511
515
  - lib/inspec/resources/cran.rb
@@ -535,6 +539,8 @@ files:
535
539
  - lib/inspec/resources/grub_conf.rb
536
540
  - lib/inspec/resources/host.rb
537
541
  - lib/inspec/resources/http.rb
542
+ - lib/inspec/resources/ibmdb2_conf.rb
543
+ - lib/inspec/resources/ibmdb2_session.rb
538
544
  - lib/inspec/resources/iis_app.rb
539
545
  - lib/inspec/resources/iis_app_pool.rb
540
546
  - lib/inspec/resources/iis_site.rb
@@ -559,6 +565,7 @@ files:
559
565
  - lib/inspec/resources/mongodb_session.rb
560
566
  - lib/inspec/resources/mount.rb
561
567
  - lib/inspec/resources/mssql_session.rb
568
+ - lib/inspec/resources/mssql_sys_conf.rb
562
569
  - lib/inspec/resources/mysql.rb
563
570
  - lib/inspec/resources/mysql_conf.rb
564
571
  - lib/inspec/resources/mysql_session.rb
@@ -571,6 +578,9 @@ files:
571
578
  - lib/inspec/resources/opa.rb
572
579
  - lib/inspec/resources/opa_api.rb
573
580
  - lib/inspec/resources/opa_cli.rb
581
+ - lib/inspec/resources/oracle.rb
582
+ - lib/inspec/resources/oracledb_conf.rb
583
+ - lib/inspec/resources/oracledb_listener_conf.rb
574
584
  - lib/inspec/resources/oracledb_session.rb
575
585
  - lib/inspec/resources/os.rb
576
586
  - lib/inspec/resources/os_env.rb
@@ -604,6 +614,8 @@ files:
604
614
  - lib/inspec/resources/ssh_config.rb
605
615
  - lib/inspec/resources/sshd_config.rb
606
616
  - lib/inspec/resources/ssl.rb
617
+ - lib/inspec/resources/sybase_conf.rb
618
+ - lib/inspec/resources/sybase_session.rb
607
619
  - lib/inspec/resources/sys_info.rb
608
620
  - lib/inspec/resources/systemd_service.rb
609
621
  - lib/inspec/resources/sysv_service.rb