inspec-core 4.3.2 → 4.6.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (285) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +37 -21
  3. data/etc/deprecations.json +10 -0
  4. data/etc/plugin_filters.json +8 -0
  5. data/lib/bundles/inspec-compliance/api.rb +1 -1
  6. data/lib/bundles/inspec-compliance/configuration.rb +1 -1
  7. data/lib/bundles/inspec-compliance/http.rb +1 -1
  8. data/lib/bundles/inspec-compliance/support.rb +1 -1
  9. data/lib/bundles/inspec-compliance/target.rb +1 -1
  10. data/lib/bundles/inspec-supermarket.rb +3 -7
  11. data/lib/bundles/inspec-supermarket/api.rb +10 -13
  12. data/lib/bundles/inspec-supermarket/cli.rb +12 -15
  13. data/lib/bundles/inspec-supermarket/target.rb +7 -11
  14. data/lib/fetchers/git.rb +14 -15
  15. data/lib/fetchers/local.rb +6 -10
  16. data/lib/fetchers/mock.rb +3 -5
  17. data/lib/fetchers/url.rb +42 -44
  18. data/lib/inspec.rb +23 -24
  19. data/lib/inspec/archive/tar.rb +2 -6
  20. data/lib/inspec/archive/zip.rb +3 -7
  21. data/lib/inspec/backend.rb +8 -9
  22. data/lib/inspec/base_cli.rb +64 -65
  23. data/lib/inspec/cached_fetcher.rb +2 -3
  24. data/lib/inspec/cli.rb +136 -97
  25. data/lib/inspec/config.rb +71 -61
  26. data/lib/inspec/control_eval_context.rb +22 -18
  27. data/lib/inspec/dependencies/cache.rb +2 -3
  28. data/lib/inspec/dependencies/dependency_set.rb +2 -3
  29. data/lib/inspec/dependencies/lockfile.rb +8 -9
  30. data/lib/inspec/dependencies/requirement.rb +7 -8
  31. data/lib/inspec/dependencies/resolver.rb +5 -7
  32. data/lib/inspec/describe.rb +2 -6
  33. data/lib/inspec/dist.rb +20 -0
  34. data/lib/inspec/dsl.rb +4 -7
  35. data/lib/inspec/dsl_shared.rb +1 -2
  36. data/lib/inspec/env_printer.rb +11 -12
  37. data/lib/inspec/errors.rb +0 -4
  38. data/lib/inspec/exceptions.rb +0 -1
  39. data/lib/inspec/expect.rb +5 -8
  40. data/lib/inspec/fetcher.rb +7 -10
  41. data/lib/inspec/file_provider.rb +24 -24
  42. data/lib/inspec/formatters.rb +3 -3
  43. data/lib/inspec/formatters/base.rb +8 -8
  44. data/lib/inspec/globals.rb +2 -2
  45. data/lib/inspec/impact.rb +5 -7
  46. data/lib/inspec/input_registry.rb +84 -33
  47. data/lib/inspec/library_eval_context.rb +3 -6
  48. data/lib/inspec/log.rb +1 -5
  49. data/lib/inspec/metadata.rb +17 -16
  50. data/lib/inspec/method_source.rb +5 -9
  51. data/lib/inspec/objects.rb +10 -12
  52. data/lib/inspec/objects/control.rb +7 -9
  53. data/lib/inspec/objects/describe.rb +9 -11
  54. data/lib/inspec/objects/each_loop.rb +1 -3
  55. data/lib/inspec/objects/input.rb +24 -26
  56. data/lib/inspec/objects/list.rb +4 -6
  57. data/lib/inspec/objects/or_test.rb +2 -4
  58. data/lib/inspec/objects/ruby_helper.rb +3 -5
  59. data/lib/inspec/objects/tag.rb +0 -2
  60. data/lib/inspec/objects/test.rb +9 -11
  61. data/lib/inspec/objects/value.rb +3 -5
  62. data/lib/inspec/plugin/v1.rb +2 -2
  63. data/lib/inspec/plugin/v1/plugin_types/cli.rb +1 -5
  64. data/lib/inspec/plugin/v1/plugin_types/fetcher.rb +2 -5
  65. data/lib/inspec/plugin/v1/plugin_types/resource.rb +4 -6
  66. data/lib/inspec/plugin/v1/plugin_types/secret.rb +1 -5
  67. data/lib/inspec/plugin/v1/plugin_types/source_reader.rb +1 -5
  68. data/lib/inspec/plugin/v1/plugins.rb +15 -19
  69. data/lib/inspec/plugin/v1/registry.rb +0 -4
  70. data/lib/inspec/plugin/v2.rb +8 -8
  71. data/lib/inspec/plugin/v2/activator.rb +1 -1
  72. data/lib/inspec/plugin/v2/config_file.rb +6 -6
  73. data/lib/inspec/plugin/v2/filter.rb +13 -13
  74. data/lib/inspec/plugin/v2/installer.rb +36 -24
  75. data/lib/inspec/plugin/v2/loader.rb +28 -28
  76. data/lib/inspec/plugin/v2/plugin_base.rb +15 -2
  77. data/lib/inspec/plugin/v2/plugin_types/cli.rb +5 -5
  78. data/lib/inspec/plugin/v2/plugin_types/input.rb +34 -0
  79. data/lib/inspec/plugin/v2/plugin_types/mock.rb +1 -1
  80. data/lib/inspec/plugin/v2/registry.rb +7 -7
  81. data/lib/inspec/polyfill.rb +0 -3
  82. data/lib/inspec/profile.rb +55 -63
  83. data/lib/inspec/profile_context.rb +27 -30
  84. data/lib/inspec/profile_vendor.rb +6 -9
  85. data/lib/inspec/reporters.rb +24 -24
  86. data/lib/inspec/reporters/automate.rb +17 -19
  87. data/lib/inspec/reporters/base.rb +1 -1
  88. data/lib/inspec/reporters/cli.rb +88 -91
  89. data/lib/inspec/reporters/json.rb +2 -4
  90. data/lib/inspec/reporters/json_automate.rb +1 -3
  91. data/lib/inspec/reporters/json_min.rb +1 -3
  92. data/lib/inspec/reporters/junit.rb +26 -28
  93. data/lib/inspec/reporters/yaml.rb +1 -3
  94. data/lib/inspec/require_loader.rb +0 -4
  95. data/lib/inspec/resource.rb +4 -125
  96. data/lib/inspec/resources.rb +121 -0
  97. data/lib/{resources → inspec/resources}/aide_conf.rb +24 -25
  98. data/lib/{resources → inspec/resources}/apache.rb +13 -14
  99. data/lib/{resources → inspec/resources}/apache_conf.rb +16 -17
  100. data/lib/{resources → inspec/resources}/apt.rb +17 -17
  101. data/lib/{resources → inspec/resources}/audit_policy.rb +7 -6
  102. data/lib/{resources → inspec/resources}/auditd.rb +62 -64
  103. data/lib/{resources → inspec/resources}/auditd_conf.rb +7 -8
  104. data/lib/{resources → inspec/resources}/bash.rb +6 -8
  105. data/lib/{resources → inspec/resources}/bond.rb +15 -14
  106. data/lib/{resources → inspec/resources}/bridge.rb +8 -8
  107. data/lib/{resources → inspec/resources}/chocolatey_package.rb +10 -8
  108. data/lib/{resources → inspec/resources}/command.rb +11 -10
  109. data/lib/{resources → inspec/resources}/cpan.rb +12 -12
  110. data/lib/{resources → inspec/resources}/cran.rb +9 -9
  111. data/lib/{resources → inspec/resources}/crontab.rb +47 -48
  112. data/lib/{resources → inspec/resources}/csv.rb +5 -5
  113. data/lib/{resources → inspec/resources}/dh_params.rb +5 -7
  114. data/lib/{resources → inspec/resources}/directory.rb +5 -7
  115. data/lib/{resources → inspec/resources}/docker.rb +63 -63
  116. data/lib/{resources → inspec/resources}/docker_container.rb +6 -6
  117. data/lib/{resources → inspec/resources}/docker_image.rb +9 -9
  118. data/lib/{resources → inspec/resources}/docker_object.rb +8 -13
  119. data/lib/{resources → inspec/resources}/docker_plugin.rb +6 -6
  120. data/lib/{resources → inspec/resources}/docker_service.rb +7 -7
  121. data/lib/{resources → inspec/resources}/elasticsearch.rb +40 -42
  122. data/lib/{resources → inspec/resources}/etc_fstab.rb +23 -24
  123. data/lib/{resources → inspec/resources}/etc_group.rb +26 -27
  124. data/lib/{resources → inspec/resources}/etc_hosts.rb +11 -13
  125. data/lib/{resources → inspec/resources}/etc_hosts_allow_deny.rb +25 -27
  126. data/lib/{resources → inspec/resources}/file.rb +80 -79
  127. data/lib/{resources → inspec/resources}/filesystem.rb +20 -15
  128. data/lib/{resources → inspec/resources}/firewalld.rb +26 -26
  129. data/lib/{resources → inspec/resources}/gem.rb +12 -12
  130. data/lib/{resources → inspec/resources}/groups.rb +28 -27
  131. data/lib/{resources → inspec/resources}/grub_conf.rb +46 -48
  132. data/lib/{resources → inspec/resources}/host.rb +31 -29
  133. data/lib/{resources → inspec/resources}/http.rb +24 -24
  134. data/lib/{resources → inspec/resources}/iis_app.rb +6 -7
  135. data/lib/{resources → inspec/resources}/iis_app_pool.rb +21 -19
  136. data/lib/{resources → inspec/resources}/iis_site.rb +17 -15
  137. data/lib/{resources → inspec/resources}/inetd_conf.rb +9 -10
  138. data/lib/{resources → inspec/resources}/ini.rb +7 -8
  139. data/lib/{resources → inspec/resources}/interface.rb +30 -30
  140. data/lib/{resources → inspec/resources}/iptables.rb +8 -8
  141. data/lib/{resources → inspec/resources}/json.rb +8 -10
  142. data/lib/{resources → inspec/resources}/kernel_module.rb +15 -15
  143. data/lib/{resources → inspec/resources}/kernel_parameter.rb +8 -8
  144. data/lib/{resources → inspec/resources}/key_rsa.rb +8 -10
  145. data/lib/{resources → inspec/resources}/ksh.rb +6 -8
  146. data/lib/{resources → inspec/resources}/limits_conf.rb +8 -9
  147. data/lib/{resources/login_def.rb → inspec/resources/login_defs.rb} +9 -10
  148. data/lib/{resources → inspec/resources}/mount.rb +6 -8
  149. data/lib/{resources → inspec/resources}/mssql_session.rb +16 -18
  150. data/lib/inspec/resources/mysql.rb +81 -0
  151. data/lib/{resources → inspec/resources}/mysql_conf.rb +13 -14
  152. data/lib/{resources → inspec/resources}/mysql_session.rb +16 -16
  153. data/lib/{resources → inspec/resources}/nginx.rb +16 -17
  154. data/lib/{resources → inspec/resources}/nginx_conf.rb +26 -27
  155. data/lib/{resources → inspec/resources}/npm.rb +9 -10
  156. data/lib/{resources → inspec/resources}/ntp_conf.rb +9 -10
  157. data/lib/{resources → inspec/resources}/oneget.rb +8 -8
  158. data/lib/{resources → inspec/resources}/oracledb_session.rb +33 -34
  159. data/lib/{resources → inspec/resources}/os.rb +6 -8
  160. data/lib/{resources → inspec/resources}/os_env.rb +11 -12
  161. data/lib/{resources → inspec/resources}/package.rb +66 -65
  162. data/lib/{resources → inspec/resources}/packages.rb +13 -13
  163. data/lib/{resources → inspec/resources}/parse_config.rb +8 -8
  164. data/lib/{resources → inspec/resources}/passwd.rb +18 -19
  165. data/lib/{resources → inspec/resources}/pip.rb +19 -19
  166. data/lib/{resources → inspec/resources}/platform.rb +9 -11
  167. data/lib/{resources → inspec/resources}/port.rb +134 -136
  168. data/lib/{resources → inspec/resources}/postgres.rb +40 -32
  169. data/lib/{resources → inspec/resources}/postgres_conf.rb +17 -17
  170. data/lib/{resources → inspec/resources}/postgres_hba_conf.rb +21 -23
  171. data/lib/{resources → inspec/resources}/postgres_ident_conf.rb +12 -14
  172. data/lib/{resources → inspec/resources}/postgres_session.rb +8 -9
  173. data/lib/{resources → inspec/resources}/powershell.rb +17 -13
  174. data/lib/{resources → inspec/resources}/processes.rb +29 -29
  175. data/lib/{resources/rabbitmq_conf.rb → inspec/resources/rabbitmq_config.rb} +10 -11
  176. data/lib/{resources → inspec/resources}/registry_key.rb +14 -14
  177. data/lib/inspec/resources/script.rb +1 -0
  178. data/lib/{resources → inspec/resources}/security_identifier.rb +11 -10
  179. data/lib/{resources → inspec/resources}/security_policy.rb +59 -58
  180. data/lib/{resources → inspec/resources}/service.rb +74 -75
  181. data/lib/{resources → inspec/resources}/shadow.rb +44 -45
  182. data/lib/{resources/ssh_conf.rb → inspec/resources/ssh_config.rb} +16 -17
  183. data/lib/{resources → inspec/resources}/ssl.rb +28 -29
  184. data/lib/inspec/resources/sys_info.rb +30 -0
  185. data/lib/{resources → inspec/resources}/toml.rb +5 -7
  186. data/lib/{resources → inspec/resources}/users.rb +65 -65
  187. data/lib/{resources → inspec/resources}/vbscript.rb +8 -9
  188. data/lib/{resources → inspec/resources}/virtualization.rb +60 -62
  189. data/lib/{resources → inspec/resources}/windows_feature.rb +9 -9
  190. data/lib/{resources → inspec/resources}/windows_hotfix.rb +5 -5
  191. data/lib/{resources → inspec/resources}/windows_task.rb +16 -15
  192. data/lib/{resources → inspec/resources}/wmi.rb +7 -8
  193. data/lib/{resources → inspec/resources}/x509_certificate.rb +9 -11
  194. data/lib/{resources/xinetd.rb → inspec/resources/xinetd_conf.rb} +27 -29
  195. data/lib/{resources → inspec/resources}/xml.rb +7 -7
  196. data/lib/{resources → inspec/resources}/yaml.rb +5 -6
  197. data/lib/{resources → inspec/resources}/yum.rb +10 -10
  198. data/lib/{resources → inspec/resources}/zfs_dataset.rb +6 -6
  199. data/lib/{resources → inspec/resources}/zfs_pool.rb +4 -4
  200. data/lib/inspec/rspec_extensions.rb +24 -8
  201. data/lib/inspec/rule.rb +14 -15
  202. data/lib/inspec/runner.rb +28 -28
  203. data/lib/inspec/runner_mock.rb +1 -5
  204. data/lib/inspec/runner_rspec.rb +18 -20
  205. data/lib/inspec/runtime_profile.rb +2 -5
  206. data/lib/inspec/schema.rb +142 -143
  207. data/lib/inspec/secrets.rb +3 -7
  208. data/lib/inspec/secrets/yaml.rb +3 -5
  209. data/lib/inspec/shell.rb +11 -15
  210. data/lib/inspec/shell_detector.rb +6 -7
  211. data/lib/inspec/source_reader.rb +4 -8
  212. data/lib/inspec/ui.rb +33 -39
  213. data/lib/inspec/ui_table_helper.rb +12 -0
  214. data/lib/{utils → inspec/utils}/command_wrapper.rb +4 -8
  215. data/lib/{utils → inspec/utils}/convert.rb +0 -4
  216. data/lib/{utils → inspec/utils}/database_helpers.rb +4 -8
  217. data/lib/inspec/utils/deprecation.rb +6 -0
  218. data/lib/{utils → inspec/utils}/deprecation/config_file.rb +19 -19
  219. data/lib/{utils → inspec/utils}/deprecation/deprecator.rb +12 -12
  220. data/lib/{utils → inspec/utils}/deprecation/errors.rb +1 -1
  221. data/lib/{utils → inspec/utils}/deprecation/global_method.rb +2 -2
  222. data/lib/{utils → inspec/utils}/enumerable_delegation.rb +0 -2
  223. data/lib/{utils → inspec/utils}/erlang_parser.rb +61 -65
  224. data/lib/{utils → inspec/utils}/file_reader.rb +1 -2
  225. data/lib/{utils → inspec/utils}/filter.rb +30 -33
  226. data/lib/{utils → inspec/utils}/filter_array.rb +0 -2
  227. data/lib/{utils → inspec/utils}/find_files.rb +9 -12
  228. data/lib/{utils → inspec/utils}/hash.rb +1 -5
  229. data/lib/inspec/utils/json_log.rb +15 -0
  230. data/lib/inspec/utils/latest_version.rb +13 -0
  231. data/lib/{utils → inspec/utils}/modulator.rb +0 -3
  232. data/lib/{utils → inspec/utils}/nginx_parser.rb +31 -35
  233. data/lib/{utils → inspec/utils}/object_traversal.rb +0 -3
  234. data/lib/{utils → inspec/utils}/parser.rb +45 -45
  235. data/lib/{utils → inspec/utils}/pkey_reader.rb +4 -2
  236. data/lib/{utils → inspec/utils}/simpleconfig.rb +8 -10
  237. data/lib/{utils → inspec/utils}/spdx.rb +1 -4
  238. data/lib/{utils → inspec/utils}/spdx.txt +0 -0
  239. data/lib/inspec/utils/telemetry.rb +3 -3
  240. data/lib/inspec/utils/telemetry/collector.rb +30 -9
  241. data/lib/inspec/utils/telemetry/data_series.rb +3 -1
  242. data/lib/inspec/utils/telemetry/global_methods.rb +1 -1
  243. data/lib/inspec/version.rb +1 -1
  244. data/lib/matchers/matchers.rb +22 -25
  245. data/lib/plugins/inspec-artifact/lib/inspec-artifact.rb +1 -1
  246. data/lib/plugins/inspec-artifact/lib/inspec-artifact/base.rb +52 -45
  247. data/lib/plugins/inspec-artifact/lib/inspec-artifact/cli.rb +18 -16
  248. data/lib/plugins/inspec-compliance/lib/inspec-compliance.rb +1 -1
  249. data/lib/plugins/inspec-compliance/lib/inspec-compliance/api.rb +73 -73
  250. data/lib/plugins/inspec-compliance/lib/inspec-compliance/api/login.rb +66 -62
  251. data/lib/plugins/inspec-compliance/lib/inspec-compliance/cli.rb +59 -57
  252. data/lib/plugins/inspec-compliance/lib/inspec-compliance/configuration.rb +11 -11
  253. data/lib/plugins/inspec-compliance/lib/inspec-compliance/http.rb +20 -22
  254. data/lib/plugins/inspec-compliance/lib/inspec-compliance/support.rb +2 -4
  255. data/lib/plugins/inspec-compliance/lib/inspec-compliance/target.rb +30 -27
  256. data/lib/plugins/inspec-habitat/Berksfile +2 -2
  257. data/lib/plugins/inspec-habitat/lib/inspec-habitat.rb +1 -1
  258. data/lib/plugins/inspec-habitat/lib/inspec-habitat/cli.rb +15 -13
  259. data/lib/plugins/inspec-habitat/lib/inspec-habitat/profile.rb +64 -63
  260. data/lib/plugins/inspec-habitat/templates/habitat/hooks/run.erb +3 -3
  261. data/lib/plugins/inspec-habitat/templates/habitat/plan.sh.erb +11 -11
  262. data/lib/plugins/inspec-init/lib/inspec-init.rb +1 -1
  263. data/lib/plugins/inspec-init/lib/inspec-init/cli.rb +6 -8
  264. data/lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb +72 -74
  265. data/lib/plugins/inspec-init/lib/inspec-init/cli_profile.rb +9 -11
  266. data/lib/plugins/inspec-init/lib/inspec-init/renderer.rb +4 -4
  267. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/Gemfile +0 -1
  268. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/inspec-plugin-template.gemspec +0 -2
  269. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template.rb +0 -2
  270. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/cli_command.rb +0 -2
  271. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/plugin.rb +0 -2
  272. data/lib/plugins/inspec-init/templates/plugins/inspec-plugin-template/lib/inspec-plugin-template/version.rb +0 -2
  273. data/lib/plugins/inspec-init/templates/profiles/os/controls/example.rb +6 -7
  274. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli.rb +1 -2
  275. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb +72 -70
  276. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/plugin.rb +1 -1
  277. data/lib/plugins/shared/core_plugin_test_helper.rb +43 -38
  278. data/lib/source_readers/flat.rb +6 -10
  279. data/lib/source_readers/inspec.rb +8 -12
  280. metadata +139 -140
  281. data/lib/resources/mysql.rb +0 -82
  282. data/lib/resources/sys_info.rb +0 -28
  283. data/lib/utils/deprecation.rb +0 -6
  284. data/lib/utils/json_log.rb +0 -18
  285. data/lib/utils/latest_version.rb +0 -22
@@ -1,14 +1,13 @@
1
- # encoding: utf-8
2
1
  # copyright: 2015, Vulcano Security GmbH
3
2
 
4
- require 'utils/simpleconfig'
5
- require 'utils/file_reader'
3
+ require "inspec/utils/simpleconfig"
4
+ require "inspec/utils/file_reader"
6
5
 
7
6
  module Inspec::Resources
8
- class SshConf < Inspec.resource(1)
9
- name 'ssh_config'
10
- supports platform: 'unix'
11
- desc 'Use the `ssh_config` InSpec audit resource to test OpenSSH client configuration data located at `/etc/ssh/ssh_config` on Linux and Unix platforms.'
7
+ class SshConfig < Inspec.resource(1)
8
+ name "ssh_config"
9
+ supports platform: "unix"
10
+ desc "Use the `ssh_config` InSpec audit resource to test OpenSSH client configuration data located at `/etc/ssh/ssh_config` on Linux and Unix platforms."
12
11
  example <<~EXAMPLE
13
12
  describe ssh_config do
14
13
  its('cipher') { should contain '3des' }
@@ -20,8 +19,8 @@ module Inspec::Resources
20
19
  include FileReader
21
20
 
22
21
  def initialize(conf_path = nil, type = nil)
23
- @conf_path = conf_path || '/etc/ssh/ssh_config'
24
- typename = (@conf_path.include?('sshd') ? 'Server' : 'Client')
22
+ @conf_path = conf_path || "/etc/ssh/ssh_config"
23
+ typename = (@conf_path.include?("sshd") ? "Server" : "Client")
25
24
  @type = type || "SSH #{typename} configuration #{conf_path}"
26
25
  read_content
27
26
  end
@@ -53,7 +52,7 @@ module Inspec::Resources
53
52
  end
54
53
 
55
54
  def to_s
56
- 'SSH Configuration'
55
+ "SSH Configuration"
57
56
  end
58
57
 
59
58
  private
@@ -70,16 +69,16 @@ module Inspec::Resources
70
69
  conf = SimpleConfig.new(
71
70
  read_content,
72
71
  assignment_regex: /^\s*(\S+?)\s+(.*?)\s*$/,
73
- multiple_values: true,
72
+ multiple_values: true
74
73
  )
75
74
  @params = convert_hash(conf.params)
76
75
  end
77
76
  end
78
77
 
79
- class SshdConf < SshConf
80
- name 'sshd_config'
81
- supports platform: 'unix'
82
- desc 'Use the sshd_config InSpec audit resource to test configuration data for the Open SSH daemon located at /etc/ssh/sshd_config on Linux and UNIX platforms. sshd---the Open SSH daemon---listens on dedicated ports, starts a daemon for each incoming connection, and then handles encryption, authentication, key exchanges, command execution, and data exchanges.'
78
+ class SshdConfig < SshConfig
79
+ name "sshd_config"
80
+ supports platform: "unix"
81
+ desc "Use the sshd_config InSpec audit resource to test configuration data for the Open SSH daemon located at /etc/ssh/sshd_config on Linux and UNIX platforms. sshd---the Open SSH daemon---listens on dedicated ports, starts a daemon for each incoming connection, and then handles encryption, authentication, key exchanges, command execution, and data exchanges."
83
82
  example <<~EXAMPLE
84
83
  describe sshd_config do
85
84
  its('Protocol') { should eq '2' }
@@ -87,11 +86,11 @@ module Inspec::Resources
87
86
  EXAMPLE
88
87
 
89
88
  def initialize(path = nil)
90
- super(path || '/etc/ssh/sshd_config')
89
+ super(path || "/etc/ssh/sshd_config")
91
90
  end
92
91
 
93
92
  def to_s
94
- 'SSHD Configuration'
93
+ "SSHD Configuration"
95
94
  end
96
95
  end
97
96
  end
@@ -1,16 +1,15 @@
1
- # encoding: utf-8
2
1
  # copyright: 2015, Chef Software Inc.
3
2
 
4
- require 'sslshake'
5
- require 'utils/filter'
6
- require 'uri'
7
- require 'parallel'
3
+ require "sslshake"
4
+ require "inspec/utils/filter"
5
+ require "uri"
6
+ require "parallel"
8
7
 
9
8
  # Custom resource based on the InSpec resource DSL
10
9
  class SSL < Inspec.resource(1)
11
- name 'ssl'
12
- supports platform: 'unix'
13
- supports platform: 'windows'
10
+ name "ssl"
11
+ supports platform: "unix"
12
+ supports platform: "windows"
14
13
 
15
14
  desc "
16
15
  SSL test resource
@@ -33,11 +32,11 @@ class SSL < Inspec.resource(1)
33
32
  EXAMPLE
34
33
 
35
34
  VERSIONS = [
36
- 'ssl2',
37
- 'ssl3',
38
- 'tls1.0',
39
- 'tls1.1',
40
- 'tls1.2',
35
+ "ssl2",
36
+ "ssl3",
37
+ "tls1.0",
38
+ "tls1.1",
39
+ "tls1.2",
41
40
  ].freeze
42
41
 
43
42
  attr_reader :host, :port, :timeout, :retries
@@ -46,10 +45,10 @@ class SSL < Inspec.resource(1)
46
45
  @host = opts[:host]
47
46
  if @host.nil?
48
47
  # Transports like SSH and WinRM will provide a hostname
49
- if inspec.backend.respond_to?('hostname')
48
+ if inspec.backend.respond_to?("hostname")
50
49
  @host = inspec.backend.hostname
51
- elsif inspec.backend.class.to_s == 'Train::Transports::Local::Connection'
52
- @host = 'localhost'
50
+ elsif inspec.backend.class.to_s == "Train::Transports::Local::Connection"
51
+ @host = "localhost"
53
52
  end
54
53
  end
55
54
  @port = opts[:port] || 443
@@ -59,12 +58,12 @@ class SSL < Inspec.resource(1)
59
58
 
60
59
  filter = FilterTable.create
61
60
  filter.register_custom_matcher(:enabled?) do |x|
62
- raise 'Cannot determine host for SSL test. Please specify it or use a different target.' if x.resource.host.nil?
63
- x.handshake.values.any? { |i| i['success'] }
61
+ raise "Cannot determine host for SSL test. Please specify it or use a different target." if x.resource.host.nil?
62
+ x.handshake.values.any? { |i| i["success"] }
64
63
  end
65
- filter.register_column(:ciphers, field: 'cipher')
66
- .register_column(:protocols, field: 'protocol')
67
- .register_custom_property(:handshake) { |x|
64
+ filter.register_column(:ciphers, field: "cipher")
65
+ .register_column(:protocols, field: "protocol")
66
+ .register_custom_property(:handshake) do |x|
68
67
  groups = x.entries.group_by(&:protocol)
69
68
  res = Parallel.map(groups, in_threads: 8) do |proto, e|
70
69
  [proto, SSLShake.hello(x.resource.host, port: x.resource.port,
@@ -72,7 +71,7 @@ class SSL < Inspec.resource(1)
72
71
  timeout: x.resource.timeout, retries: x.resource.retries, servername: x.resource.host)]
73
72
  end
74
73
  Hash[res]
75
- }
74
+ end
76
75
  .install_filter_methods_on_resource(self, :scan_config)
77
76
 
78
77
  def to_s
@@ -83,14 +82,14 @@ class SSL < Inspec.resource(1)
83
82
 
84
83
  def scan_config
85
84
  [
86
- { 'protocol' => 'ssl2', 'ciphers' => SSLShake::SSLv2::CIPHERS.keys },
87
- { 'protocol' => 'ssl3', 'ciphers' => SSLShake::TLS::SSL3_CIPHERS.keys },
88
- { 'protocol' => 'tls1.0', 'ciphers' => SSLShake::TLS::TLS10_CIPHERS.keys },
89
- { 'protocol' => 'tls1.1', 'ciphers' => SSLShake::TLS::TLS10_CIPHERS.keys },
90
- { 'protocol' => 'tls1.2', 'ciphers' => SSLShake::TLS::TLS_CIPHERS.keys },
85
+ { "protocol" => "ssl2", "ciphers" => SSLShake::SSLv2::CIPHERS.keys },
86
+ { "protocol" => "ssl3", "ciphers" => SSLShake::TLS::SSL3_CIPHERS.keys },
87
+ { "protocol" => "tls1.0", "ciphers" => SSLShake::TLS::TLS10_CIPHERS.keys },
88
+ { "protocol" => "tls1.1", "ciphers" => SSLShake::TLS::TLS10_CIPHERS.keys },
89
+ { "protocol" => "tls1.2", "ciphers" => SSLShake::TLS::TLS_CIPHERS.keys },
91
90
  ].map do |line|
92
- line['ciphers'].map do |cipher|
93
- { 'protocol' => line['protocol'], 'cipher' => cipher }
91
+ line["ciphers"].map do |cipher|
92
+ { "protocol" => line["protocol"], "cipher" => cipher }
94
93
  end
95
94
  end.flatten
96
95
  end
@@ -0,0 +1,30 @@
1
+ require "inspec/resources/command"
2
+ require "inspec/resources/powershell"
3
+
4
+ module Inspec::Resources
5
+ # this resource returns additional system informatio
6
+ class System < Inspec.resource(1)
7
+ name "sys_info"
8
+ supports platform: "unix"
9
+ supports platform: "windows"
10
+
11
+ desc "Use the user InSpec system resource to test for operating system properties."
12
+ example <<~EXAMPLE
13
+ describe sys_info do
14
+ its('hostname') { should eq 'example.com' }
15
+ end
16
+ EXAMPLE
17
+
18
+ # returns the hostname of the local system
19
+ def hostname
20
+ os = inspec.os
21
+ if os.linux? || os.darwin?
22
+ inspec.command("hostname").stdout.chomp
23
+ elsif os.windows?
24
+ inspec.powershell("$env:computername").stdout.chomp
25
+ else
26
+ skip_resource "The `sys_info.hostname` resource is not supported on your OS yet."
27
+ end
28
+ end
29
+ end
30
+ end
@@ -1,12 +1,10 @@
1
- # encoding: utf-8
2
- # author: Nolan Davidson
3
-
4
- require 'tomlrb'
1
+ require "tomlrb"
2
+ require "inspec/resources/json"
5
3
 
6
4
  module Inspec::Resources
7
5
  class TomlConfig < JsonConfig
8
- name 'toml'
9
- desc 'Use the toml InSpec resource to test configuration data in a TOML file'
6
+ name "toml"
7
+ desc "Use the toml InSpec resource to test configuration data in a TOML file"
10
8
  example <<~EXAMPLE
11
9
  describe toml('default.toml') do
12
10
  its('key') { should eq('value') }
@@ -26,7 +24,7 @@ module Inspec::Resources
26
24
  # used by JsonConfig to build up a full to_s method
27
25
  # based on whether a file path, content, or command was supplied.
28
26
  def resource_base_name
29
- 'TOML'
27
+ "TOML"
30
28
  end
31
29
  end
32
30
  end
@@ -1,8 +1,8 @@
1
- # encoding: utf-8
2
-
3
- require 'utils/parser'
4
- require 'utils/convert'
5
- require 'utils/filter'
1
+ require "inspec/utils/parser"
2
+ require "inspec/utils/convert"
3
+ require "inspec/utils/filter"
4
+ require "inspec/utils/simpleconfig"
5
+ require "inspec/resources/powershell"
6
6
 
7
7
  module Inspec::Resources
8
8
  # This file contains two resources, the `user` and `users` resource.
@@ -17,15 +17,15 @@ module Inspec::Resources
17
17
  LinuxUser.new(inspec)
18
18
  elsif os.windows?
19
19
  WindowsUser.new(inspec)
20
- elsif ['darwin'].include?(os[:family])
20
+ elsif ["darwin"].include?(os[:family])
21
21
  DarwinUser.new(inspec)
22
- elsif ['freebsd'].include?(os[:family])
22
+ elsif ["freebsd"].include?(os[:family])
23
23
  FreeBSDUser.new(inspec)
24
- elsif ['aix'].include?(os[:family])
24
+ elsif ["aix"].include?(os[:family])
25
25
  AixUser.new(inspec)
26
26
  elsif os.solaris?
27
27
  SolarisUser.new(inspec)
28
- elsif ['hpux'].include?(os[:family])
28
+ elsif ["hpux"].include?(os[:family])
29
29
  HpuxUser.new(inspec)
30
30
  end
31
31
  end
@@ -52,10 +52,10 @@ module Inspec::Resources
52
52
  class Users < Inspec.resource(1)
53
53
  include UserManagementSelector
54
54
 
55
- name 'users'
56
- supports platform: 'unix'
57
- supports platform: 'windows'
58
- desc 'Use the users InSpec audit resource to test local user profiles. Users can be filtered by groups to which they belong, the frequency of required password changes, the directory paths to home and shell.'
55
+ name "users"
56
+ supports platform: "unix"
57
+ supports platform: "windows"
58
+ desc "Use the users InSpec audit resource to test local user profiles. Users can be filtered by groups to which they belong, the frequency of required password changes, the directory paths to home and shell."
59
59
  example <<~EXAMPLE
60
60
  describe users.where { uid == 0 }.entries do
61
61
  it { should eq ['root'] }
@@ -66,7 +66,7 @@ module Inspec::Resources
66
66
  def initialize
67
67
  # select user provider
68
68
  @user_provider = select_user_manager(inspec.os)
69
- return skip_resource 'The `users` resource is not supported on your OS yet.' if @user_provider.nil?
69
+ return skip_resource "The `users` resource is not supported on your OS yet." if @user_provider.nil?
70
70
  end
71
71
 
72
72
  filter = FilterTable.create
@@ -87,7 +87,7 @@ module Inspec::Resources
87
87
  filter.install_filter_methods_on_resource(self, :collect_user_details)
88
88
 
89
89
  def to_s
90
- 'Users'
90
+ "Users"
91
91
  end
92
92
 
93
93
  private
@@ -137,10 +137,10 @@ module Inspec::Resources
137
137
  # end
138
138
  class User < Inspec.resource(1)
139
139
  include UserManagementSelector
140
- name 'user'
141
- supports platform: 'unix'
142
- supports platform: 'windows'
143
- desc 'Use the user InSpec audit resource to test user profiles, including the groups to which they belong, the frequency of required password changes, the directory paths to home and shell.'
140
+ name "user"
141
+ supports platform: "unix"
142
+ supports platform: "windows"
143
+ desc "Use the user InSpec audit resource to test user profiles, including the groups to which they belong, the frequency of required password changes, the directory paths to home and shell."
144
144
  example <<~EXAMPLE
145
145
  describe user('root') do
146
146
  it { should exist }
@@ -152,7 +152,7 @@ module Inspec::Resources
152
152
  @username = username
153
153
  # select user provider
154
154
  @user_provider = select_user_manager(inspec.os)
155
- return skip_resource 'The `user` resource is not supported on your OS yet.' if @user_provider.nil?
155
+ return skip_resource "The `user` resource is not supported on your OS yet." if @user_provider.nil?
156
156
  end
157
157
 
158
158
  def exists?
@@ -213,35 +213,35 @@ module Inspec::Resources
213
213
 
214
214
  # implement 'mindays' method to be compatible with serverspec
215
215
  def minimum_days_between_password_change
216
- Inspec.deprecate(:resource_user_serverspec_compat, 'The user resource `minimum_days_between_password_change` property is deprecated. Please use `mindays`.')
216
+ Inspec.deprecate(:resource_user_serverspec_compat, "The user resource `minimum_days_between_password_change` property is deprecated. Please use `mindays`.")
217
217
  mindays
218
218
  end
219
219
 
220
220
  # implement 'maxdays' method to be compatible with serverspec
221
221
  def maximum_days_between_password_change
222
- Inspec.deprecate(:resource_user_serverspec_compat, 'The user resource `maximum_days_between_password_change` property is deprecated. Please use `maxdays`.')
222
+ Inspec.deprecate(:resource_user_serverspec_compat, "The user resource `maximum_days_between_password_change` property is deprecated. Please use `maxdays`.")
223
223
  maxdays
224
224
  end
225
225
 
226
226
  # implements rspec has matcher, to be compatible with serverspec
227
227
  # @see: https://github.com/rspec/rspec-expectations/blob/master/lib/rspec/matchers/built_in/has.rb
228
228
  def has_uid?(compare_uid)
229
- Inspec.deprecate(:resource_user_serverspec_compat, 'The user resource `has_uid?` matcher is deprecated.')
229
+ Inspec.deprecate(:resource_user_serverspec_compat, "The user resource `has_uid?` matcher is deprecated.")
230
230
  uid == compare_uid
231
231
  end
232
232
 
233
233
  def has_home_directory?(compare_home)
234
- Inspec.deprecate(:resource_user_serverspec_compat, 'The user resource `has_home_directory?` matcher is deprecated. Please use `its(\'home\')`.')
234
+ Inspec.deprecate(:resource_user_serverspec_compat, "The user resource `has_home_directory?` matcher is deprecated. Please use `its('home')`.")
235
235
  home == compare_home
236
236
  end
237
237
 
238
238
  def has_login_shell?(compare_shell)
239
- Inspec.deprecate(:resource_user_serverspec_compat, 'The user resource `has_login_shell?` matcher is deprecated. Please use `its(\'shell\')`.')
239
+ Inspec.deprecate(:resource_user_serverspec_compat, "The user resource `has_login_shell?` matcher is deprecated. Please use `its('shell')`.")
240
240
  shell == compare_shell
241
241
  end
242
242
 
243
243
  def has_authorized_key?(_compare_key)
244
- Inspec.deprecate(:resource_user_serverspec_compat, 'The user resource `has_authorized_key?` matcher is deprecated. There is no currently implemented alternative')
244
+ Inspec.deprecate(:resource_user_serverspec_compat, "The user resource `has_authorized_key?` matcher is deprecated. There is no currently implemented alternative")
245
245
  raise NotImplementedError
246
246
  end
247
247
 
@@ -288,7 +288,7 @@ module Inspec::Resources
288
288
  # groups: '',
289
289
  # }
290
290
  def identity(_username)
291
- raise 'user provider must implement the `identity` method'
291
+ raise "user provider must implement the `identity` method"
292
292
  end
293
293
 
294
294
  # returns optional information about a user, eg shell
@@ -309,7 +309,7 @@ module Inspec::Resources
309
309
 
310
310
  # returns an array with users
311
311
  def list_users
312
- raise 'user provider must implement the `list_users` method'
312
+ raise "user provider must implement the `list_users` method"
313
313
  end
314
314
 
315
315
  # retuns all aspects of the user as one hash
@@ -326,9 +326,9 @@ module Inspec::Resources
326
326
 
327
327
  # returns the full information list for a user
328
328
  def collect_user_details
329
- list_users.map { |username|
329
+ list_users.map do |username|
330
330
  user_details(username.chomp)
331
- }
331
+ end
332
332
  end
333
333
  end
334
334
 
@@ -337,7 +337,7 @@ module Inspec::Resources
337
337
  attr_reader :inspec, :id_cmd, :list_users_cmd
338
338
  def initialize(inspec)
339
339
  @inspec = inspec
340
- @id_cmd ||= 'id'
340
+ @id_cmd ||= "id"
341
341
  @list_users_cmd ||= 'cut -d: -f1 /etc/passwd | grep -v "^#"'
342
342
  super
343
343
  end
@@ -353,10 +353,10 @@ module Inspec::Resources
353
353
  def parse_value(line)
354
354
  SimpleConfig.new(
355
355
  line,
356
- line_separator: ',',
356
+ line_separator: ",",
357
357
  assignment_regex: /^\s*([^\(]*?)\s*\(\s*(.*?)\)*$/,
358
358
  group_re: nil,
359
- multiple_values: false,
359
+ multiple_values: false
360
360
  ).params
361
361
  end
362
362
 
@@ -370,15 +370,15 @@ module Inspec::Resources
370
370
  parse_id_entries(cmd.stdout.chomp),
371
371
  assignment_regex: /^\s*([^=]*?)\s*=\s*(.*?)\s*$/,
372
372
  group_re: nil,
373
- multiple_values: false,
373
+ multiple_values: false
374
374
  ).params
375
375
 
376
376
  {
377
- uid: convert_to_i(parse_value(params['uid']).keys[0]),
378
- username: parse_value(params['uid']).values[0],
379
- gid: convert_to_i(parse_value(params['gid']).keys[0]),
380
- groupname: parse_value(params['gid']).values[0],
381
- groups: parse_value(params['groups']).values,
377
+ uid: convert_to_i(parse_value(params["uid"]).keys[0]),
378
+ username: parse_value(params["uid"]).values[0],
379
+ gid: convert_to_i(parse_value(params["gid"]).keys[0]),
380
+ groupname: parse_value(params["gid"]).values[0],
381
+ groups: parse_value(params["groups"]).values,
382
382
  }
383
383
  end
384
384
 
@@ -386,8 +386,8 @@ module Inspec::Resources
386
386
  def parse_id_entries(raw)
387
387
  data = []
388
388
  until (index = raw.index(/\)\s{1}/)).nil?
389
- data.push(raw[0, index+1]) # inclue closing )
390
- raw = raw[index+2, raw.length-index-2]
389
+ data.push(raw[0, index + 1]) # inclue closing )
390
+ raw = raw[index + 2, raw.length - index - 2]
391
391
  end
392
392
  data.push(raw) if !raw.nil?
393
393
  data.join("\n")
@@ -404,8 +404,8 @@ module Inspec::Resources
404
404
  # returns: root:x:0:0:root:/root:/bin/bash
405
405
  passwd = parse_passwd_line(cmd.stdout.chomp)
406
406
  {
407
- home: passwd['home'],
408
- shell: passwd['shell'],
407
+ home: passwd["home"],
408
+ shell: passwd["shell"],
409
409
  }
410
410
  end
411
411
 
@@ -417,13 +417,13 @@ module Inspec::Resources
417
417
  cmd.stdout.chomp,
418
418
  assignment_regex: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
419
419
  group_re: nil,
420
- multiple_values: false,
420
+ multiple_values: false
421
421
  ).params
422
422
 
423
423
  {
424
- mindays: convert_to_i(params['Minimum number of days between password change']),
425
- maxdays: convert_to_i(params['Maximum number of days between password change']),
426
- warndays: convert_to_i(params['Number of days of warning before password expires']),
424
+ mindays: convert_to_i(params["Minimum number of days between password change"]),
425
+ maxdays: convert_to_i(params["Maximum number of days between password change"]),
426
+ warndays: convert_to_i(params["Number of days of warning before password expires"]),
427
427
  }
428
428
  end
429
429
  end
@@ -431,7 +431,7 @@ module Inspec::Resources
431
431
  class SolarisUser < LinuxUser
432
432
  def initialize(inspec)
433
433
  @inspec = inspec
434
- @id_cmd ||= 'id -a'
434
+ @id_cmd ||= "id -a"
435
435
  super
436
436
  end
437
437
  end
@@ -456,24 +456,24 @@ module Inspec::Resources
456
456
  lsuser = inspec.command("lsuser -C -a home shell #{username}")
457
457
  return nil if lsuser.exit_status != 0
458
458
 
459
- user = lsuser.stdout.chomp.split("\n").last.split(':')
459
+ user = lsuser.stdout.chomp.split("\n").last.split(":")
460
460
  {
461
- home: user[1],
461
+ home: user[1],
462
462
  shell: user[2],
463
463
  }
464
464
  end
465
465
 
466
466
  def credentials(username)
467
467
  cmd = inspec.command(
468
- "lssec -c -f /etc/security/user -s #{username} -a minage -a maxage -a pwdwarntime",
468
+ "lssec -c -f /etc/security/user -s #{username} -a minage -a maxage -a pwdwarntime"
469
469
  )
470
470
  return nil if cmd.exit_status != 0
471
471
 
472
- user_sec = cmd.stdout.chomp.split("\n").last.split(':')
472
+ user_sec = cmd.stdout.chomp.split("\n").last.split(":")
473
473
 
474
474
  {
475
- mindays: user_sec[1].to_i * 7,
476
- maxdays: user_sec[2].to_i * 7,
475
+ mindays: user_sec[1].to_i * 7,
476
+ maxdays: user_sec[2].to_i * 7,
477
477
  warndays: user_sec[3].to_i,
478
478
  }
479
479
  end
@@ -483,7 +483,7 @@ module Inspec::Resources
483
483
  def meta_info(username)
484
484
  hpuxuser = inspec.command("logins -x -l #{username}")
485
485
  return nil if hpuxuser.exit_status != 0
486
- user = hpuxuser.stdout.chomp.split(' ')
486
+ user = hpuxuser.stdout.chomp.split(" ")
487
487
  {
488
488
  home: user[4],
489
489
  shell: user[5],
@@ -498,7 +498,7 @@ module Inspec::Resources
498
498
  # @see http://superuser.com/questions/592921/mac-osx-users-vs-dscl-command-to-list-user
499
499
  class DarwinUser < UnixUser
500
500
  def initialize(inspec)
501
- @list_users_cmd ||= 'dscl . list /Users'
501
+ @list_users_cmd ||= "dscl . list /Users"
502
502
  super
503
503
  end
504
504
 
@@ -510,12 +510,12 @@ module Inspec::Resources
510
510
  cmd.stdout.chomp,
511
511
  assignment_regex: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
512
512
  group_re: nil,
513
- multiple_values: false,
513
+ multiple_values: false
514
514
  ).params
515
515
 
516
516
  {
517
- home: params['NFSHomeDirectory'],
518
- shell: params['UserShell'],
517
+ home: params["NFSHomeDirectory"],
518
+ shell: params["UserShell"],
519
519
  }
520
520
  end
521
521
  end
@@ -524,10 +524,10 @@ module Inspec::Resources
524
524
  # @see: https://www.freebsd.org/doc/handbook/users-synopsis.html
525
525
  # @see: https://www.freebsd.org/cgi/man.cgi?pw(8)
526
526
  # It offers the following commands:
527
- # - adduser(8) The recommended command-line application for adding new users.
528
- # - rmuser(8) The recommended command-line application for removing users.
529
- # - chpass(1) A flexible tool for changing user database information.
530
- # - passwd(1) The command-line tool to change user passwords.
527
+ # - adduser(8) The recommended command-line application for adding new users.
528
+ # - rmuser(8) The recommended command-line application for removing users.
529
+ # - chpass(1) A flexible tool for changing user database information.
530
+ # - passwd(1) The command-line tool to change user passwords.
531
531
  class FreeBSDUser < UnixUser
532
532
  include PasswdParser
533
533
 
@@ -537,8 +537,8 @@ module Inspec::Resources
537
537
  # returns: root:*:0:0:Charlie &:/root:/bin/csh
538
538
  passwd = parse_passwd_line(cmd.stdout.chomp)
539
539
  {
540
- home: passwd['home'],
541
- shell: passwd['shell'],
540
+ home: passwd["home"],
541
+ shell: passwd["shell"],
542
542
  }
543
543
  end
544
544
  end