inspec-core 5.17.4 → 5.18.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -1
  3. data/etc/deprecations.json +4 -0
  4. data/inspec-core.gemspec +1 -1
  5. data/lib/inspec/base_cli.rb +5 -0
  6. data/lib/inspec/cli.rb +62 -9
  7. data/lib/inspec/dependencies/dependency_set.rb +6 -2
  8. data/lib/inspec/dsl.rb +18 -5
  9. data/lib/inspec/errors.rb +2 -0
  10. data/lib/inspec/exceptions.rb +2 -0
  11. data/lib/inspec/fetcher/url.rb +1 -1
  12. data/lib/inspec/file_provider.rb +36 -0
  13. data/lib/inspec/iaf_file.rb +127 -0
  14. data/lib/inspec/profile.rb +17 -7
  15. data/lib/inspec/resources/aide_conf.rb +4 -0
  16. data/lib/inspec/resources/apache.rb +4 -0
  17. data/lib/inspec/resources/apache_conf.rb +4 -0
  18. data/lib/inspec/resources/apt.rb +6 -1
  19. data/lib/inspec/resources/audit_policy.rb +5 -0
  20. data/lib/inspec/resources/auditd_conf.rb +4 -0
  21. data/lib/inspec/resources/bash.rb +4 -0
  22. data/lib/inspec/resources/bond.rb +4 -0
  23. data/lib/inspec/resources/bridge.rb +4 -0
  24. data/lib/inspec/resources/cassandradb_conf.rb +5 -0
  25. data/lib/inspec/resources/cassandradb_session.rb +8 -3
  26. data/lib/inspec/resources/chocolatey_package.rb +4 -0
  27. data/lib/inspec/resources/chrony_conf.rb +4 -0
  28. data/lib/inspec/resources/command.rb +5 -0
  29. data/lib/inspec/resources/cpan.rb +4 -0
  30. data/lib/inspec/resources/cran.rb +4 -0
  31. data/lib/inspec/resources/cron.rb +5 -0
  32. data/lib/inspec/resources/csv.rb +6 -1
  33. data/lib/inspec/resources/dh_params.rb +4 -0
  34. data/lib/inspec/resources/docker_container.rb +4 -0
  35. data/lib/inspec/resources/docker_image.rb +4 -0
  36. data/lib/inspec/resources/docker_plugin.rb +4 -0
  37. data/lib/inspec/resources/docker_service.rb +4 -0
  38. data/lib/inspec/resources/etc_group.rb +4 -0
  39. data/lib/inspec/resources/etc_hosts_allow_deny.rb +5 -0
  40. data/lib/inspec/resources/file.rb +6 -1
  41. data/lib/inspec/resources/filesystem.rb +4 -0
  42. data/lib/inspec/resources/gem.rb +4 -0
  43. data/lib/inspec/resources/groups.rb +4 -0
  44. data/lib/inspec/resources/grub_conf.rb +4 -0
  45. data/lib/inspec/resources/host.rb +4 -0
  46. data/lib/inspec/resources/http.rb +4 -0
  47. data/lib/inspec/resources/ibmdb2_conf.rb +8 -0
  48. data/lib/inspec/resources/ibmdb2_session.rb +12 -3
  49. data/lib/inspec/resources/iis_app.rb +4 -0
  50. data/lib/inspec/resources/iis_app_pool.rb +4 -0
  51. data/lib/inspec/resources/iis_site.rb +4 -0
  52. data/lib/inspec/resources/inetd_conf.rb +4 -0
  53. data/lib/inspec/resources/interface.rb +4 -0
  54. data/lib/inspec/resources/ip6tables.rb +4 -0
  55. data/lib/inspec/resources/ipfilter.rb +4 -0
  56. data/lib/inspec/resources/ipnat.rb +4 -0
  57. data/lib/inspec/resources/iptables.rb +4 -0
  58. data/lib/inspec/resources/json.rb +4 -0
  59. data/lib/inspec/resources/kernel_module.rb +4 -0
  60. data/lib/inspec/resources/kernel_parameter.rb +4 -0
  61. data/lib/inspec/resources/key_rsa.rb +4 -0
  62. data/lib/inspec/resources/ksh.rb +4 -0
  63. data/lib/inspec/resources/limits_conf.rb +4 -0
  64. data/lib/inspec/resources/login_defs.rb +4 -0
  65. data/lib/inspec/resources/mongodb.rb +4 -0
  66. data/lib/inspec/resources/mongodb_conf.rb +5 -0
  67. data/lib/inspec/resources/mongodb_session.rb +6 -1
  68. data/lib/inspec/resources/mount.rb +4 -0
  69. data/lib/inspec/resources/mssql_session.rb +4 -0
  70. data/lib/inspec/resources/mssql_sys_conf.rb +7 -0
  71. data/lib/inspec/resources/mysql_conf.rb +4 -0
  72. data/lib/inspec/resources/mysql_session.rb +8 -1
  73. data/lib/inspec/resources/nginx.rb +6 -1
  74. data/lib/inspec/resources/nginx_conf.rb +4 -0
  75. data/lib/inspec/resources/noop.rb +4 -0
  76. data/lib/inspec/resources/npm.rb +4 -0
  77. data/lib/inspec/resources/ntp_conf.rb +4 -0
  78. data/lib/inspec/resources/oneget.rb +4 -0
  79. data/lib/inspec/resources/opa_api.rb +10 -0
  80. data/lib/inspec/resources/opa_cli.rb +14 -0
  81. data/lib/inspec/resources/oracledb_conf.rb +5 -0
  82. data/lib/inspec/resources/oracledb_listener_conf.rb +4 -0
  83. data/lib/inspec/resources/oracledb_session.rb +10 -0
  84. data/lib/inspec/resources/os.rb +4 -0
  85. data/lib/inspec/resources/os_env.rb +4 -0
  86. data/lib/inspec/resources/package.rb +4 -0
  87. data/lib/inspec/resources/parse_config.rb +10 -1
  88. data/lib/inspec/resources/pip.rb +4 -0
  89. data/lib/inspec/resources/platform.rb +4 -0
  90. data/lib/inspec/resources/postfix_conf.rb +4 -0
  91. data/lib/inspec/resources/postgres_conf.rb +4 -0
  92. data/lib/inspec/resources/postgres_session.rb +8 -4
  93. data/lib/inspec/resources/powershell.rb +4 -0
  94. data/lib/inspec/resources/processes.rb +6 -4
  95. data/lib/inspec/resources/rabbitmq_config.rb +4 -0
  96. data/lib/inspec/resources/registry_key.rb +4 -0
  97. data/lib/inspec/resources/security_identifier.rb +4 -0
  98. data/lib/inspec/resources/security_policy.rb +4 -0
  99. data/lib/inspec/resources/service.rb +4 -0
  100. data/lib/inspec/resources/ssh_config.rb +4 -0
  101. data/lib/inspec/resources/sybase_conf.rb +4 -0
  102. data/lib/inspec/resources/sybase_session.rb +4 -0
  103. data/lib/inspec/resources/sys_info.rb +4 -0
  104. data/lib/inspec/resources/timezone.rb +4 -0
  105. data/lib/inspec/resources/users.rb +4 -0
  106. data/lib/inspec/resources/vbscript.rb +5 -0
  107. data/lib/inspec/resources/virtualization.rb +4 -0
  108. data/lib/inspec/resources/windows_feature.rb +5 -1
  109. data/lib/inspec/resources/windows_firewall.rb +4 -0
  110. data/lib/inspec/resources/windows_firewall_rule.rb +4 -0
  111. data/lib/inspec/resources/windows_hotfix.rb +4 -0
  112. data/lib/inspec/resources/windows_task.rb +4 -0
  113. data/lib/inspec/resources/wmi.rb +4 -0
  114. data/lib/inspec/resources/x509_certificate.rb +59 -0
  115. data/lib/inspec/resources/yum.rb +4 -0
  116. data/lib/inspec/resources/zfs_dataset.rb +4 -0
  117. data/lib/inspec/resources/zfs_pool.rb +4 -0
  118. data/lib/inspec/rule.rb +1 -1
  119. data/lib/inspec/secrets/yaml.rb +7 -1
  120. data/lib/inspec/ui.rb +1 -0
  121. data/lib/inspec/utils/yaml_profile_summary.rb +34 -0
  122. data/lib/inspec/version.rb +1 -1
  123. data/lib/plugins/inspec-reporter-html2/templates/body.html.erb +4 -4
  124. data/lib/plugins/inspec-reporter-html2/templates/control.html.erb +1 -1
  125. data/lib/plugins/inspec-reporter-html2/templates/profile.html.erb +1 -1
  126. data/lib/plugins/{inspec-artifact/inspec-artifact.gemspec → inspec-sign/inspec-sign.gemspec} +2 -2
  127. data/lib/plugins/inspec-sign/lib/inspec-sign/base.rb +161 -0
  128. data/lib/plugins/{inspec-artifact/lib/inspec-artifact → inspec-sign/lib/inspec-sign}/cli.rb +14 -23
  129. data/lib/plugins/inspec-sign/lib/inspec-sign.rb +12 -0
  130. data/lib/source_readers/inspec.rb +8 -2
  131. metadata +10 -8
  132. data/lib/plugins/inspec-artifact/lib/inspec-artifact/base.rb +0 -187
  133. data/lib/plugins/inspec-artifact/lib/inspec-artifact.rb +0 -12
@@ -1,187 +0,0 @@
1
- require "base64" unless defined?(Base64)
2
- require "openssl" unless defined?(OpenSSL)
3
- require "pathname" unless defined?(Pathname)
4
- require "set" unless defined?(Set)
5
- require "tempfile" unless defined?(Tempfile)
6
- require "yaml"
7
- require "inspec/dist"
8
- require "inspec/utils/json_profile_summary"
9
-
10
- module InspecPlugins
11
- module Artifact
12
- class Base
13
- include Inspec::Dist
14
-
15
- KEY_BITS = 2048
16
- KEY_ALG = OpenSSL::PKey::RSA
17
-
18
- INSPEC_PROFILE_VERSION_1 = "INSPEC-PROFILE-1".freeze
19
- INSPEC_REPORT_VERSION_1 = "INSPEC-REPORT-1".freeze
20
-
21
- ARTIFACT_DIGEST = OpenSSL::Digest::SHA512
22
- ARTIFACT_DIGEST_NAME = "SHA512".freeze
23
-
24
- VALID_PROFILE_VERSIONS = Set.new [INSPEC_PROFILE_VERSION_1]
25
- VALID_PROFILE_DIGESTS = Set.new [ARTIFACT_DIGEST_NAME]
26
-
27
- SIGNED_PROFILE_SUFFIX = "iaf".freeze
28
- SIGNED_REPORT_SUFFIX = "iar".freeze
29
-
30
- def self.keygen(options)
31
- key = KEY_ALG.new KEY_BITS
32
- puts "Generating private key"
33
- open "#{options["keyname"]}.pem.key", "w" do |io|
34
- io.write key.to_pem
35
- end
36
- puts "Generating public key"
37
- open "#{options["keyname"]}.pem.pub", "w" do |io|
38
- io.write key.public_key.to_pem
39
- end
40
- end
41
-
42
- def self.profile_sign(options)
43
- artifact = new
44
- path_to_profile = options["profile"]
45
-
46
- # Write inspec.json file within artifact
47
- write_inspec_json(path_to_profile, options)
48
-
49
- Dir.mktmpdir do |workdir|
50
- puts "Signing #{options["profile"]} with key #{options["keyname"]}"
51
- profile_md = artifact.read_profile_metadata(path_to_profile)
52
- artifact_filename = "#{profile_md["name"]}-#{profile_md["version"]}.#{SIGNED_PROFILE_SUFFIX}"
53
- tarfile = artifact.profile_compress(path_to_profile, profile_md, workdir)
54
- content = IO.binread(tarfile)
55
- signing_key = KEY_ALG.new File.read "#{options["keyname"]}.pem.key"
56
- sha = ARTIFACT_DIGEST.new
57
- signature = signing_key.sign sha, content
58
- # convert the signature to Base64
59
- signature_base64 = Base64.encode64(signature)
60
- tar_content = IO.binread(tarfile)
61
- File.open(artifact_filename, "wb") do |f|
62
- f.puts(INSPEC_PROFILE_VERSION_1)
63
- f.puts(options["keyname"])
64
- f.puts(ARTIFACT_DIGEST_NAME)
65
- f.puts(signature_base64)
66
- f.puts("") # newline separates artifact header with body
67
- f.write(tar_content)
68
- end
69
- puts "Successfully generated #{artifact_filename}"
70
- end
71
-
72
- # Cleanup
73
- File.delete("#{path_to_profile}/inspec.json")
74
- end
75
-
76
- def self.profile_verify(options)
77
- artifact = new
78
- file_to_verifiy = options["infile"]
79
- puts "Verifying #{file_to_verifiy}"
80
- artifact.verify(file_to_verifiy) do ||
81
- puts "Artifact is valid"
82
- end
83
- end
84
-
85
- def self.profile_install(options)
86
- artifact = new
87
- puts "Installing profile"
88
- file_to_verifiy = options["infile"]
89
- dest_dir = options["destdir"]
90
- artifact.verify(file_to_verifiy) do |content|
91
- Dir.mktmpdir do |workdir|
92
- tmpfile = Pathname.new(workdir).join("artifact_to_install.tar.gz")
93
- File.write(tmpfile, content)
94
- puts "Installing to #{dest_dir}"
95
- `tar xzf #{tmpfile} -C #{dest_dir}`
96
- end
97
- end
98
- end
99
-
100
- def read_profile_metadata(path_to_profile)
101
- begin
102
- p = Pathname.new(path_to_profile)
103
- p = p.join("inspec.yml")
104
- unless p.exist?
105
- raise "#{path_to_profile} doesn't appear to be a valid #{PRODUCT_NAME} profile"
106
- end
107
-
108
- yaml = YAML.load_file(p.to_s)
109
- yaml = yaml.to_hash
110
-
111
- unless yaml.key? "name"
112
- raise "Profile is invalid, name is not defined"
113
- end
114
-
115
- unless yaml.key? "version"
116
- raise "Profile is invalid, version is not defined"
117
- end
118
- rescue => e
119
- # rewrap it and pass it up to the CLI
120
- raise "Error reading #{PRODUCT_NAME} profile metadata: #{e}"
121
- end
122
-
123
- yaml
124
- end
125
-
126
- def profile_compress(path_to_profile, profile_md, workdir)
127
- profile_name = profile_md["name"]
128
- profile_version = profile_md["version"]
129
- outfile_name = "#{workdir}/#{profile_name}-#{profile_version}.tar.gz"
130
- `tar czf #{outfile_name} -C #{path_to_profile} .`
131
- outfile_name
132
- end
133
-
134
- def valid_header?(file_alg, file_version, file_keyname)
135
- public_keyfile = "#{file_keyname}.pem.pub"
136
- puts "Looking for #{public_keyfile} to verify artifact"
137
- unless File.exist? public_keyfile
138
- raise "Can't find #{public_keyfile}"
139
- end
140
-
141
- raise "Invalid artifact digest algorithm detected" unless VALID_PROFILE_DIGESTS.member?(file_alg)
142
- raise "Invalid artifact version detected" unless VALID_PROFILE_VERSIONS.member?(file_version)
143
- end
144
-
145
- def verify(file_to_verifiy, &content_block)
146
- f = File.open(file_to_verifiy, "r")
147
- file_version = f.readline.strip!
148
- file_keyname = f.readline.strip!
149
- file_alg = f.readline.strip!
150
-
151
- file_sig = ""
152
- # the signature is multi-line
153
- while (line = f.readline) != "\n"
154
- file_sig += line
155
- end
156
- file_sig.strip!
157
- f.close
158
-
159
- valid_header?(file_alg, file_version, file_keyname)
160
-
161
- public_keyfile = "#{file_keyname}.pem.pub"
162
- verification_key = KEY_ALG.new File.read public_keyfile
163
-
164
- f = File.open(file_to_verifiy, "r")
165
- while f.readline != "\n" do end
166
- content = f.read
167
-
168
- signature = Base64.decode64(file_sig)
169
- digest = ARTIFACT_DIGEST.new
170
- if verification_key.verify digest, signature, content
171
- content_block.yield(content)
172
- else
173
- raise "Artifact is invalid"
174
- end
175
- end
176
-
177
- def self.write_inspec_json(root_path, opts)
178
- profile = Inspec::Profile.for_path(root_path, opts)
179
- Inspec::Utils::JsonProfileSummary.produce_json(
180
- info: profile.info,
181
- write_path: "#{root_path}/inspec.json",
182
- suppress_output: true
183
- )
184
- end
185
- end
186
- end
187
- end
@@ -1,12 +0,0 @@
1
- module InspecPlugins
2
- module Artifact
3
- class Plugin < Inspec.plugin(2)
4
- plugin_name :'inspec-artifact'
5
-
6
- cli_command :artifact do
7
- require_relative "inspec-artifact/cli"
8
- InspecPlugins::Artifact::CLI
9
- end
10
- end
11
- end
12
- end