inspec 1.0.0 → 1.35.1

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 (286) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +933 -101
  3. data/Gemfile +8 -17
  4. data/MAINTAINERS.md +2 -1
  5. data/MAINTAINERS.toml +9 -4
  6. data/README.md +49 -28
  7. data/Rakefile +54 -39
  8. data/bin/inspec +1 -1
  9. data/docs/dsl_inspec.md +17 -4
  10. data/docs/dsl_resource.md +1 -1
  11. data/docs/habitat.md +192 -0
  12. data/docs/inspec_and_friends.md +4 -2
  13. data/docs/matchers.md +11 -0
  14. data/docs/migration.md +293 -0
  15. data/docs/profiles.md +124 -76
  16. data/docs/resources/aide_conf.md.erb +81 -0
  17. data/docs/resources/apache_conf.md.erb +10 -10
  18. data/docs/resources/apt.md.erb +13 -13
  19. data/docs/resources/audit_policy.md.erb +10 -10
  20. data/docs/resources/auditd_conf.md.erb +10 -10
  21. data/docs/resources/auditd_rules.md.erb +11 -11
  22. data/docs/resources/bash.md.erb +12 -12
  23. data/docs/resources/bond.md.erb +15 -15
  24. data/docs/resources/bridge.md.erb +11 -11
  25. data/docs/resources/bsd_service.md.erb +11 -11
  26. data/docs/resources/command.md.erb +23 -23
  27. data/docs/resources/crontab.md.erb +84 -0
  28. data/docs/resources/csv.md.erb +10 -10
  29. data/docs/resources/dh_params.md +191 -0
  30. data/docs/resources/directory.md.erb +8 -8
  31. data/docs/resources/docker.md.erb +160 -0
  32. data/docs/resources/docker_container.md.erb +89 -0
  33. data/docs/resources/docker_image.md.erb +86 -0
  34. data/docs/resources/etc_group.md.erb +16 -16
  35. data/docs/resources/etc_hosts.md.erb +62 -0
  36. data/docs/resources/file.md.erb +80 -58
  37. data/docs/resources/gem.md.erb +32 -13
  38. data/docs/resources/group.md.erb +12 -12
  39. data/docs/resources/grub_conf.md.erb +11 -11
  40. data/docs/resources/host.md.erb +27 -18
  41. data/docs/resources/http.md.erb +104 -0
  42. data/docs/resources/iis_app.md.erb +126 -0
  43. data/docs/resources/iis_site.md.erb +17 -17
  44. data/docs/resources/inetd_conf.md.erb +10 -10
  45. data/docs/resources/ini.md.erb +9 -9
  46. data/docs/resources/interface.md.erb +13 -13
  47. data/docs/resources/iptables.md.erb +21 -14
  48. data/docs/resources/json.md.erb +11 -11
  49. data/docs/resources/kernel_module.md.erb +73 -12
  50. data/docs/resources/kernel_parameter.md.erb +12 -12
  51. data/docs/resources/key_rsa.md.erb +70 -0
  52. data/docs/resources/launchd_service.md.erb +11 -11
  53. data/docs/resources/limits_conf.md.erb +10 -10
  54. data/docs/resources/login_def.md.erb +12 -12
  55. data/docs/resources/mount.md.erb +14 -14
  56. data/docs/resources/mssql_session.md.erb +62 -0
  57. data/docs/resources/mysql_conf.md.erb +14 -14
  58. data/docs/resources/mysql_session.md.erb +22 -10
  59. data/docs/resources/npm.md.erb +13 -13
  60. data/docs/resources/ntp_conf.md.erb +9 -9
  61. data/docs/resources/oneget.md.erb +11 -11
  62. data/docs/resources/oracledb_session.md.erb +53 -0
  63. data/docs/resources/os.md.erb +17 -17
  64. data/docs/resources/os_env.md.erb +12 -12
  65. data/docs/resources/package.md.erb +29 -16
  66. data/docs/resources/parse_config.md.erb +18 -18
  67. data/docs/resources/parse_config_file.md.erb +29 -23
  68. data/docs/resources/{etc_passwd.md.erb → passwd.md.erb} +17 -17
  69. data/docs/resources/pip.md.erb +15 -15
  70. data/docs/resources/port.md.erb +23 -23
  71. data/docs/resources/postgres_conf.md.erb +15 -13
  72. data/docs/resources/postgres_hba_conf.md.erb +104 -0
  73. data/docs/resources/postgres_ident_conf.md.erb +87 -0
  74. data/docs/resources/postgres_session.md.erb +28 -21
  75. data/docs/resources/powershell.md.erb +14 -14
  76. data/docs/resources/processes.md.erb +123 -0
  77. data/docs/resources/rabbitmq_config.md.erb +55 -0
  78. data/docs/resources/registry_key.md.erb +44 -21
  79. data/docs/resources/runit_service.md.erb +11 -11
  80. data/docs/resources/security_policy.md.erb +10 -10
  81. data/docs/resources/service.md.erb +18 -18
  82. data/docs/resources/{etc_shadow.md.erb → shadow.md.erb} +19 -19
  83. data/docs/resources/ssh_config.md.erb +13 -13
  84. data/docs/resources/sshd_config.md.erb +15 -15
  85. data/docs/resources/ssl.md.erb +13 -13
  86. data/docs/resources/sys_info.md.erb +10 -10
  87. data/docs/resources/systemd_service.md.erb +11 -11
  88. data/docs/resources/sysv_service.md.erb +11 -11
  89. data/docs/resources/upstart_service.md.erb +11 -11
  90. data/docs/resources/user.md.erb +20 -20
  91. data/docs/resources/users.md.erb +19 -19
  92. data/docs/resources/vbscript.md.erb +13 -13
  93. data/docs/resources/virtualization.md.erb +71 -0
  94. data/docs/resources/windows_feature.md.erb +10 -10
  95. data/docs/resources/windows_task.md.erb +103 -0
  96. data/docs/resources/wmi.md.erb +10 -10
  97. data/docs/resources/x509_certificate.md.erb +146 -0
  98. data/docs/resources/xinetd_conf.md.erb +17 -17
  99. data/docs/resources/xml.md.erb +75 -0
  100. data/docs/resources/yaml.md.erb +25 -11
  101. data/docs/resources/yum.md.erb +24 -16
  102. data/docs/resources/zfs_dataset.md.erb +63 -0
  103. data/docs/resources/zfs_pool.md.erb +57 -0
  104. data/docs/ruby_usage.md +50 -0
  105. data/docs/shared/matcher_cmp.md.erb +4 -6
  106. data/examples/inheritance/README.md +49 -3
  107. data/examples/inheritance/controls/example.rb +4 -1
  108. data/examples/inheritance/inspec.yml +3 -1
  109. data/examples/meta-profile/README.md +29 -3
  110. data/examples/meta-profile/controls/example.rb +10 -5
  111. data/examples/meta-profile/inspec.yml +4 -8
  112. data/examples/profile/README.md +1 -1
  113. data/examples/profile/controls/example.rb +0 -1
  114. data/examples/profile/controls/gordon.rb +0 -1
  115. data/examples/profile/inspec.yml +1 -1
  116. data/examples/profile-attribute/inspec.yml +1 -1
  117. data/examples/profile-sensitive/README.md +29 -0
  118. data/examples/profile-sensitive/controls/sensitive-failures.rb +9 -0
  119. data/examples/profile-sensitive/controls/sensitive.rb +9 -0
  120. data/examples/profile-sensitive/inspec.yml +8 -0
  121. data/inspec.gemspec +10 -2
  122. data/lib/bundles/inspec-artifact/README.md +1 -0
  123. data/lib/bundles/inspec-artifact/cli.rb +284 -0
  124. data/lib/bundles/inspec-artifact.rb +7 -0
  125. data/lib/bundles/inspec-compliance/README.md +44 -15
  126. data/lib/bundles/inspec-compliance/api.rb +135 -29
  127. data/lib/bundles/inspec-compliance/cli.rb +128 -21
  128. data/lib/bundles/inspec-compliance/configuration.rb +8 -0
  129. data/lib/bundles/inspec-compliance/http.rb +26 -19
  130. data/lib/bundles/inspec-compliance/target.rb +50 -25
  131. data/lib/bundles/inspec-habitat/cli.rb +31 -0
  132. data/lib/bundles/inspec-habitat/log.rb +10 -0
  133. data/lib/bundles/inspec-habitat/profile.rb +372 -0
  134. data/lib/bundles/inspec-habitat.rb +12 -0
  135. data/lib/bundles/inspec-init/templates/profile/controls/example.rb +0 -1
  136. data/lib/bundles/inspec-init/templates/profile/inspec.yml +1 -1
  137. data/lib/bundles/inspec-supermarket/api.rb +7 -5
  138. data/lib/bundles/inspec-supermarket/cli.rb +2 -2
  139. data/lib/fetchers/git.rb +4 -2
  140. data/lib/fetchers/local.rb +4 -1
  141. data/lib/fetchers/url.rb +64 -10
  142. data/lib/inspec/archive/tar.rb +1 -1
  143. data/lib/inspec/backend.rb +26 -3
  144. data/lib/inspec/base_cli.rb +44 -7
  145. data/lib/inspec/cached_fetcher.rb +2 -2
  146. data/lib/inspec/cli.rb +34 -12
  147. data/lib/inspec/completions/fish.sh.erb +34 -0
  148. data/lib/inspec/control_eval_context.rb +0 -2
  149. data/lib/inspec/dependencies/cache.rb +0 -1
  150. data/lib/inspec/dependencies/dependency_set.rb +2 -2
  151. data/lib/inspec/dependencies/lockfile.rb +13 -6
  152. data/lib/inspec/dependencies/requirement.rb +6 -6
  153. data/lib/inspec/dependencies/resolver.rb +4 -4
  154. data/lib/inspec/dsl.rb +3 -5
  155. data/lib/inspec/env_printer.rb +9 -1
  156. data/lib/inspec/exceptions.rb +8 -0
  157. data/lib/inspec/fetcher.rb +1 -1
  158. data/lib/inspec/file_provider.rb +47 -11
  159. data/lib/inspec/library_eval_context.rb +1 -1
  160. data/lib/inspec/metadata.rb +62 -18
  161. data/lib/inspec/method_source.rb +24 -0
  162. data/lib/inspec/objects/attribute.rb +21 -0
  163. data/lib/inspec/objects/control.rb +21 -3
  164. data/lib/inspec/objects/each_loop.rb +2 -1
  165. data/lib/inspec/objects/list.rb +1 -1
  166. data/lib/inspec/objects/or_test.rb +17 -2
  167. data/lib/inspec/objects/tag.rb +27 -0
  168. data/lib/inspec/objects/test.rb +9 -8
  169. data/lib/inspec/objects.rb +1 -0
  170. data/lib/inspec/plugins/fetcher.rb +4 -5
  171. data/lib/inspec/plugins/resource.rb +1 -2
  172. data/lib/inspec/plugins/source_reader.rb +3 -3
  173. data/lib/inspec/plugins.rb +1 -1
  174. data/lib/inspec/polyfill.rb +0 -1
  175. data/lib/inspec/profile.rb +92 -23
  176. data/lib/inspec/profile_context.rb +1 -1
  177. data/lib/inspec/profile_vendor.rb +66 -0
  178. data/lib/inspec/resource.rb +29 -3
  179. data/lib/inspec/rspec_json_formatter.rb +672 -285
  180. data/lib/inspec/rule.rb +12 -16
  181. data/lib/inspec/runner.rb +26 -15
  182. data/lib/inspec/runner_rspec.rb +1 -0
  183. data/lib/inspec/runtime_profile.rb +26 -0
  184. data/lib/inspec/schema.rb +185 -0
  185. data/lib/inspec/secrets/yaml.rb +8 -1
  186. data/lib/inspec/secrets.rb +1 -1
  187. data/lib/inspec/shell.rb +92 -22
  188. data/lib/inspec/source_reader.rb +1 -1
  189. data/lib/inspec/version.rb +1 -1
  190. data/lib/inspec.rb +1 -1
  191. data/lib/matchers/matchers.rb +67 -17
  192. data/lib/resources/aide_conf.rb +162 -0
  193. data/lib/resources/apache.rb +0 -1
  194. data/lib/resources/apache_conf.rb +3 -3
  195. data/lib/resources/apt.rb +2 -1
  196. data/lib/resources/audit_policy.rb +0 -1
  197. data/lib/resources/auditd_conf.rb +1 -2
  198. data/lib/resources/auditd_rules.rb +5 -5
  199. data/lib/resources/bond.rb +1 -1
  200. data/lib/resources/bridge.rb +1 -1
  201. data/lib/resources/command.rb +5 -3
  202. data/lib/resources/crontab.rb +102 -0
  203. data/lib/resources/csv.rb +18 -1
  204. data/lib/resources/dh_params.rb +84 -0
  205. data/lib/resources/directory.rb +7 -3
  206. data/lib/resources/docker.rb +198 -0
  207. data/lib/resources/docker_container.rb +114 -0
  208. data/lib/resources/docker_image.rb +96 -0
  209. data/lib/resources/etc_group.rb +2 -3
  210. data/lib/resources/etc_hosts.rb +81 -0
  211. data/lib/resources/file.rb +88 -30
  212. data/lib/resources/gem.rb +26 -6
  213. data/lib/resources/groups.rb +4 -5
  214. data/lib/resources/grub_conf.rb +3 -4
  215. data/lib/resources/host.rb +175 -35
  216. data/lib/resources/http.rb +73 -0
  217. data/lib/resources/iis_app.rb +103 -0
  218. data/lib/resources/iis_site.rb +23 -0
  219. data/lib/resources/inetd_conf.rb +9 -4
  220. data/lib/resources/interface.rb +4 -3
  221. data/lib/resources/json.rb +37 -14
  222. data/lib/resources/kernel_module.rb +77 -10
  223. data/lib/resources/kernel_parameter.rb +0 -1
  224. data/lib/resources/key_rsa.rb +67 -0
  225. data/lib/resources/limits_conf.rb +3 -4
  226. data/lib/resources/login_def.rb +2 -3
  227. data/lib/resources/mount.rb +34 -4
  228. data/lib/resources/mssql_session.rb +81 -12
  229. data/lib/resources/mysql.rb +0 -1
  230. data/lib/resources/mysql_conf.rb +1 -2
  231. data/lib/resources/mysql_session.rb +18 -7
  232. data/lib/resources/nginx_conf.rb +95 -0
  233. data/lib/resources/ntp_conf.rb +2 -3
  234. data/lib/resources/oracledb_session.rb +138 -0
  235. data/lib/resources/os_env.rb +7 -5
  236. data/lib/resources/package.rb +70 -13
  237. data/lib/resources/packages.rb +111 -0
  238. data/lib/resources/parse_config.rb +3 -4
  239. data/lib/resources/passwd.rb +4 -5
  240. data/lib/resources/pip.rb +29 -21
  241. data/lib/resources/port.rb +133 -14
  242. data/lib/resources/postgres.rb +53 -43
  243. data/lib/resources/postgres_conf.rb +40 -13
  244. data/lib/resources/postgres_hba_conf.rb +101 -0
  245. data/lib/resources/postgres_ident_conf.rb +79 -0
  246. data/lib/resources/postgres_session.rb +28 -20
  247. data/lib/resources/powershell.rb +2 -2
  248. data/lib/resources/processes.rb +61 -26
  249. data/lib/resources/rabbitmq_conf.rb +53 -0
  250. data/lib/resources/registry_key.rb +34 -11
  251. data/lib/resources/security_policy.rb +2 -2
  252. data/lib/resources/service.rb +17 -7
  253. data/lib/resources/ssh_conf.rb +17 -6
  254. data/lib/resources/ssl.rb +3 -4
  255. data/lib/resources/sys_info.rb +1 -1
  256. data/lib/resources/toml.rb +26 -0
  257. data/lib/resources/users.rb +41 -41
  258. data/lib/resources/virtualization.rb +252 -0
  259. data/lib/resources/windows_task.rb +106 -0
  260. data/lib/resources/x509_certificate.rb +143 -0
  261. data/lib/resources/xinetd.rb +18 -2
  262. data/lib/resources/xml.rb +27 -0
  263. data/lib/resources/yaml.rb +10 -2
  264. data/lib/resources/yum.rb +25 -7
  265. data/lib/resources/zfs_dataset.rb +60 -0
  266. data/lib/resources/zfs_pool.rb +49 -0
  267. data/lib/source_readers/flat.rb +2 -1
  268. data/lib/source_readers/inspec.rb +30 -11
  269. data/lib/utils/command_wrapper.rb +3 -3
  270. data/lib/utils/database_helpers.rb +77 -0
  271. data/lib/utils/erlang_parser.rb +192 -0
  272. data/lib/utils/filter.rb +2 -1
  273. data/lib/utils/filter_array.rb +0 -1
  274. data/lib/utils/find_files.rb +1 -2
  275. data/lib/utils/latest_version.rb +21 -0
  276. data/lib/utils/nginx_parser.rb +76 -0
  277. data/lib/utils/object_traversal.rb +5 -4
  278. data/lib/utils/parser.rb +23 -4
  279. data/lib/utils/plugin_registry.rb +3 -3
  280. data/lib/utils/simpleconfig.rb +25 -8
  281. data/lib/utils/spdx.rb +13 -0
  282. data/lib/utils/spdx.txt +344 -0
  283. metadata +168 -22
  284. data/docs/cli.md +0 -342
  285. data/docs/resources/process.md.erb +0 -73
  286. /data/docs/{plugin_kitchen_inspec.html.md → plugin_kitchen_inspec.md} +0 -0
@@ -0,0 +1,73 @@
1
+ # encoding: utf-8
2
+ # copyright: 2017, Criteo
3
+ # copyright: 2017, Chef Software Inc
4
+ # author: Guilhem Lettron, Christoph Hartmann
5
+ # license: Apache v2
6
+
7
+ require 'faraday'
8
+ require 'hashie'
9
+
10
+ module Inspec::Resources
11
+ class Http < Inspec.resource(1)
12
+ name 'http'
13
+ desc 'Use the http InSpec audit resource to test http call.'
14
+ example "
15
+ describe http('http://localhost:8080/ping', auth: {user: 'user', pass: 'test'}, params: {format: 'html'}) do
16
+ its('status') { should cmp 200 }
17
+ its('body') { should cmp 'pong' }
18
+ its('headers.Content-Type') { should cmp 'text/html' }
19
+ end
20
+
21
+ describe http('http://example.com/ping').headers do
22
+ its('Content-Length') { should cmp 258 }
23
+ its('Content-Type') { should cmp 'text/html; charset=UTF-8' }
24
+ end
25
+ "
26
+
27
+ def initialize(url, opts = {})
28
+ @url = url
29
+ @method = opts.fetch(:method, 'GET')
30
+ @params = opts.fetch(:params, nil)
31
+ @auth = opts.fetch(:auth, {})
32
+ @headers = opts.fetch(:headers, {})
33
+ @data = opts.fetch(:data, nil)
34
+ @open_timeout = opts.fetch(:open_timeout, 60)
35
+ @read_timeout = opts.fetch(:read_timeout, 60)
36
+ @ssl_verify = opts.fetch(:ssl_verify, true)
37
+ end
38
+
39
+ def status
40
+ response.status
41
+ end
42
+
43
+ def body
44
+ response.body
45
+ end
46
+
47
+ def headers
48
+ Hashie::Mash.new(response.headers.to_h)
49
+ end
50
+
51
+ def to_s
52
+ "http #{@method} on #{@url}"
53
+ end
54
+
55
+ private
56
+
57
+ def response
58
+ return @response if @response
59
+ conn = Faraday.new url: @url, headers: @headers, params: @params, ssl: { verify: @ssl_verify }
60
+
61
+ # set basic authentication
62
+ conn.basic_auth @auth[:user], @auth[:pass] unless @auth.empty?
63
+
64
+ # set default timeout
65
+ conn.options.timeout = @read_timeout # open/read timeout in seconds
66
+ conn.options.open_timeout = @open_timeout # connection open timeout in seconds
67
+
68
+ @response = conn.send(@method.downcase) do |req|
69
+ req.body = @data
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,103 @@
1
+ # encoding: utf-8
2
+ # frozen_string_literal: true
3
+ # check for web applications in IIS
4
+ # Note: this is only supported in windows 2012 and later
5
+ module Inspec::Resources
6
+ class IisApp < Inspec.resource(1)
7
+ name 'iis_app'
8
+ desc 'Tests IIS application configuration on windows. Supported in server 2012+ only'
9
+ example "
10
+ describe iis_app('/myapp', 'Default Web Site') do
11
+ it { should exist }
12
+ it { should have_application_pool('MyAppPool') }
13
+ it { should have_protocols('http') }
14
+ it { should have_site_name('Default Web Site') }
15
+ it { should have_physical_path('C:\\inetpub\\wwwroot\\myapp') }
16
+ it { should have_path('\\My Application') }
17
+ end
18
+ "
19
+
20
+ def initialize(path, site_name)
21
+ @path = path
22
+ @site_name = site_name
23
+ @cache = nil
24
+ @inspec = inspec
25
+
26
+ # verify that this resource is only supported on Windows
27
+ return skip_resource 'The `iis_app` resource is not supported on your OS.' unless inspec.os.windows?
28
+ end
29
+
30
+ def application_pool
31
+ iis_app[:application_pool]
32
+ end
33
+
34
+ def protocols
35
+ iis_app[:protocols]
36
+ end
37
+
38
+ def site_name
39
+ iis_app[:site_name]
40
+ end
41
+
42
+ def path
43
+ iis_app[:path]
44
+ end
45
+
46
+ def physical_path
47
+ iis_app[:physical_path]
48
+ end
49
+
50
+ def exists?
51
+ !iis_app[:path].empty?
52
+ end
53
+
54
+ def has_site_name?(site_name)
55
+ iis_app[:site_name] == site_name
56
+ end
57
+
58
+ def has_application_pool?(application_pool)
59
+ iis_app[:application_pool] == application_pool
60
+ end
61
+
62
+ def has_path?(path)
63
+ iis_app[:path] == path
64
+ end
65
+
66
+ def has_physical_path?(physical_path)
67
+ iis_app[:physical_path] == physical_path
68
+ end
69
+
70
+ def has_protocol?(protocol)
71
+ iis_app[:protocols].include?(protocol)
72
+ end
73
+
74
+ def to_s
75
+ "iis_app '#{@site_name}#{@path}'"
76
+ end
77
+
78
+ private
79
+
80
+ def iis_app
81
+ return @cache unless @cache.nil?
82
+ command = "Import-Module WebAdministration; Get-WebApplication -Name '#{@path}' -Site '#{@site_name}' | Select-Object * | ConvertTo-Json"
83
+ cmd = @inspec.command(command)
84
+
85
+ begin
86
+ app = JSON.parse(cmd.stdout)
87
+ rescue JSON::ParserError => _e
88
+ return {}
89
+ end
90
+
91
+ # map our values to a hash table
92
+ info = {
93
+ site_name: @site_name,
94
+ path: @path,
95
+ application_pool: app['applicationPool'],
96
+ physical_path: app['PhysicalPath'],
97
+ protocols: app['enabledProtocols'],
98
+ }
99
+
100
+ @cache = info unless info.nil?
101
+ end
102
+ end
103
+ end
@@ -121,4 +121,27 @@ module Inspec::Resources
121
121
  info
122
122
  end
123
123
  end
124
+
125
+ # for compatability with serverspec
126
+ # this is deprecated syntax and will be removed in future versions
127
+ class IisSiteServerSpec < IisSite
128
+ name 'iis_website'
129
+ desc 'Tests IIS site configuration on windows. Deprecated, use `iis_site` instead.'
130
+ example "
131
+ describe iis_website('Default Website') do
132
+ it{ should exist }
133
+ it{ should be_running }
134
+ it{ should be_in_app_pool('Default App Pool') }
135
+ end
136
+ "
137
+
138
+ def initialize(site_name)
139
+ super(site_name)
140
+ warn '[DEPRECATION] `iis_website(site_name)` is deprecated. Please use `iis_site(site_name)` instead.'
141
+ end
142
+
143
+ def in_app_pool?(app_pool)
144
+ has_app_pool?(app_pool)
145
+ end
146
+ end
124
147
  end
@@ -2,7 +2,6 @@
2
2
  # copyright: 2015, Vulcano Security GmbH
3
3
  # author: Christoph Hartmann
4
4
  # author: Dominik Richter
5
- # license: All rights reserved
6
5
 
7
6
  require 'utils/simpleconfig'
8
7
 
@@ -22,6 +21,12 @@ module Inspec::Resources
22
21
  @conf_path = path || '/etc/inetd.conf'
23
22
  end
24
23
 
24
+ # overwrite exec to ensure it works with its
25
+ # TODO: this needs to be fixed in RSpec
26
+ def exec
27
+ read_params['exec']
28
+ end
29
+
25
30
  def method_missing(name)
26
31
  read_params[name.to_s]
27
32
  end
@@ -37,15 +42,15 @@ module Inspec::Resources
37
42
  end
38
43
 
39
44
  content = file.content
40
- if content.empty? && file.size > 0
45
+ if content.empty? && !file.empty?
41
46
  skip_resource "Can't read file \"#{@conf_path}\""
42
47
  return @params = {}
43
48
  end
44
49
  # parse the file
45
50
  conf = SimpleConfig.new(
46
51
  content,
47
- assignment_re: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
48
- key_vals: 6,
52
+ assignment_regex: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
53
+ key_values: 6,
49
54
  multiple_values: false,
50
55
  )
51
56
  @params = conf.params
@@ -1,13 +1,14 @@
1
1
  # encoding: utf-8
2
2
  # author: Christoph Hartmann
3
3
  # author: Dominik Richter
4
+ # author: Aaron Lippold
4
5
 
5
6
  require 'utils/convert'
6
7
 
7
8
  module Inspec::Resources
8
9
  class NetworkInterface < Inspec.resource(1)
9
10
  name 'interface'
10
- desc 'Use the interface InSpec audit resource to test basic network adapter properties, such as name, status, state, address, and link speed (in MB/sec).'
11
+ desc 'Use the interface InSpec audit resource to test basic network adapter properties, such as name, status, and link speed (in MB/sec).'
11
12
  example "
12
13
  describe interface('eth0') do
13
14
  it { should exist }
@@ -64,7 +65,7 @@ module Inspec::Resources
64
65
  class LinuxInterface < InterfaceInfo
65
66
  def interface_info(iface)
66
67
  # will return "[mtu]\n1500\n[type]\n1"
67
- cmd = inspec.command("find /sys/class/net/#{iface}/ -type f -maxdepth 1 -exec sh -c 'echo \"[$(basename {})]\"; cat {} || echo -n' \\;")
68
+ cmd = inspec.command("find /sys/class/net/#{iface}/ -maxdepth 1 -type f -exec sh -c 'echo \"[$(basename {})]\"; cat {} || echo -n' \\;")
68
69
  return nil if cmd.exit_status.to_i != 0
69
70
 
70
71
  # parse values, we only recieve values, therefore we threat them as keys
@@ -121,7 +122,7 @@ module Inspec::Resources
121
122
  adapter_collection.push(info) if info[:name].casecmp(iface) == 0
122
123
  end
123
124
 
124
- return nil if adapters.size == 0
125
+ return nil if adapters.empty?
125
126
  warn "[Possible Error] detected multiple network interfaces with the name #{iface}" if adapters.size > 1
126
127
  adapters[0]
127
128
  end
@@ -12,6 +12,15 @@ module Inspec::Resources
12
12
  describe json('policyfile.lock.json') do
13
13
  its(['cookbook_locks','omnibus','version']) { should eq('2.2.0') }
14
14
  end
15
+
16
+ describe json({ command: 'retrieve_data.py --json' }) do
17
+ its('state') { should eq('open') }
18
+ end
19
+
20
+ describe json({ content: '{\"item1\": { \"status\": \"available\" } }' }) do
21
+ its(['item1', 'status']) { should cmp 'available' }
22
+ end
23
+
15
24
  "
16
25
 
17
26
  include ObjectTraverser
@@ -19,21 +28,31 @@ module Inspec::Resources
19
28
  # make params readable
20
29
  attr_reader :params
21
30
 
22
- def initialize(path)
23
- @path = path
24
- @file = inspec.file(@path)
25
- @file_content = @file.content
31
+ def initialize(opts)
32
+ @opts = opts
33
+ if opts.is_a?(Hash)
34
+ if opts.key?(:content)
35
+ @file_content = opts[:content]
36
+ elsif opts.key?(:command)
37
+ @command = inspec.command(opts[:command])
38
+ @file_content = @command.stdout
39
+ end
40
+ else
41
+ @path = opts
42
+ @file = inspec.file(@opts)
43
+ @file_content = @file.content
26
44
 
27
- # check if file is available
28
- if !@file.file?
29
- skip_resource "Can't find file \"#{@conf_path}\""
30
- return @params = {}
31
- end
45
+ # check if file is available
46
+ if !@file.file?
47
+ skip_resource "Can't find file \"#{@path}\""
48
+ return @params = {}
49
+ end
32
50
 
33
- # check if file is readable
34
- if @file_content.empty? && @file.size > 0
35
- skip_resource "Can't read file \"#{@conf_path}\""
36
- return @params = {}
51
+ # check if file is readable
52
+ if @file_content.nil? && !@file.empty?
53
+ skip_resource "Can't read file \"#{@path}\""
54
+ return @params = {}
55
+ end
37
56
  end
38
57
 
39
58
  @params = parse(@file_content)
@@ -61,7 +80,11 @@ module Inspec::Resources
61
80
  end
62
81
 
63
82
  def to_s
64
- "Json #{@path}"
83
+ if @opts.is_a?(Hash) && @opts.key?(:content)
84
+ 'Json content'
85
+ else
86
+ "Json #{@path}"
87
+ end
65
88
  end
66
89
  end
67
90
  end
@@ -1,30 +1,54 @@
1
1
  # encoding: utf-8
2
2
  # author: Christoph Hartmann
3
3
  # author: Dominik Richter
4
- # license: All rights reserved
4
+ # author: Aaron Lippold
5
+ # author: Adam Leff
5
6
 
6
7
  module Inspec::Resources
7
8
  class KernelModule < Inspec.resource(1)
8
9
  name 'kernel_module'
9
- desc 'Use the kernel_module InSpec audit resource to test kernel modules on Linux platforms. These parameters are located under /lib/modules. Any submodule may be tested using this resource.'
10
+ desc 'Use the kernel_module InSpec audit resource to test kernel modules on
11
+ Linux platforms. These parameters are located under /lib/modules. Any submodule
12
+ may be tested using this resource.
13
+
14
+ The `kernel_module` resource can also verify if a kernel module is `blacklisted`
15
+ or if a module is disabled via a fake install using the `bin_true` or `bin_false`
16
+ method.'
17
+
10
18
  example "
11
- describe kernel_module('bridge') do
12
- it { should be_loaded }
13
- end
19
+
20
+ describe kernel_module('video') do
21
+ it { should be_loaded }
22
+ it { should_not be_disabled }
23
+ it { should_not be_blacklisted }
24
+ end
25
+
26
+ describe kernel_module('sstfb') do
27
+ it { should_not be_loaded }
28
+ it { should be_disabled }
29
+ end
30
+
31
+ describe kernel_module('floppy') do
32
+ it { should be_blacklisted }
33
+ end
34
+
35
+ describe kernel_module('dhcp') do
36
+ it { should_not be_loaded }
37
+ end
14
38
  "
15
39
 
16
40
  def initialize(modulename = nil)
17
41
  @module = modulename
18
-
19
42
  # this resource is only supported on Linux
20
43
  return skip_resource 'The `kernel_parameter` resource is not supported on your OS.' if !inspec.os.linux?
21
44
  end
22
45
 
23
46
  def loaded?
24
- # default lsmod command
25
- lsmod_cmd = 'lsmod'
26
- # special care for CentOS 5 and sudo
27
- lsmod_cmd = '/sbin/lsmod' if inspec.os[:name] == 'centos' && inspec.os[:release].to_i == 5
47
+ if inspec.os.redhat? || inspec.os.name == 'fedora'
48
+ lsmod_cmd = '/sbin/lsmod'
49
+ else
50
+ lsmod_cmd = 'lsmod'
51
+ end
28
52
 
29
53
  # get list of all modules
30
54
  cmd = inspec.command(lsmod_cmd)
@@ -36,8 +60,51 @@ module Inspec::Resources
36
60
  !found.nil?
37
61
  end
38
62
 
63
+ def disabled?
64
+ !modprobe_output.match(%r{^install\s+#{@module}\s+/(s?)bin/(true|false)}).nil?
65
+ end
66
+
67
+ def blacklisted?
68
+ !modprobe_output.match(/^blacklist\s+#{@module}/).nil? || disabled_via_bin_true? || disabled_via_bin_false?
69
+ end
70
+
71
+ def version
72
+ cmd = inspec.command("#{modinfo_cmd_for_os} -F version #{@module}")
73
+ cmd.exit_status.zero? ? cmd.stdout.delete("\n") : nil
74
+ end
75
+
39
76
  def to_s
40
77
  "Kernel Module #{@module}"
41
78
  end
79
+
80
+ private
81
+
82
+ def modprobe_output
83
+ @modprobe_output ||= inspec.command("#{modprobe_cmd_for_os} --showconfig").stdout
84
+ end
85
+
86
+ def modinfo_cmd_for_os
87
+ if inspec.os.redhat? || inspec.os.name == 'fedora'
88
+ '/sbin/modinfo'
89
+ else
90
+ 'modinfo'
91
+ end
92
+ end
93
+
94
+ def modprobe_cmd_for_os
95
+ if inspec.os.redhat? || inspec.os.name == 'fedora'
96
+ '/sbin/modprobe'
97
+ else
98
+ 'modprobe'
99
+ end
100
+ end
101
+
102
+ def disabled_via_bin_true?
103
+ !modprobe_output.match(%r{^install\s+#{@module}\s+/(s?)bin/true}).nil?
104
+ end
105
+
106
+ def disabled_via_bin_false?
107
+ !modprobe_output.match(%r{^install\s+#{@module}\s+/(s?)bin/false}).nil?
108
+ end
42
109
  end
43
110
  end
@@ -1,6 +1,5 @@
1
1
  # encoding: utf-8
2
2
  # author: Christoph Hartmann
3
- # license: All rights reserved
4
3
 
5
4
  module Inspec::Resources
6
5
  class KernelParameter < Inspec.resource(1)
@@ -0,0 +1,67 @@
1
+ # encoding: utf-8
2
+ # author: Richard Nixon
3
+ # author: Christoph Hartmann
4
+
5
+ require 'openssl'
6
+ require 'hashie/mash'
7
+
8
+ module Inspec::Resources
9
+ class RsaKey < Inspec.resource(1)
10
+ name 'key_rsa'
11
+ desc 'public/private RSA key pair test'
12
+ example "
13
+ describe rsa_key('/etc/pki/www.mywebsite.com.key') do
14
+ its('public_key') { should match /BEGIN RSA PUBLIC KEY/ }
15
+ end
16
+
17
+ describe rsa_key('/etc/pki/www.mywebsite.com.key', 'passphrase') do
18
+ it { should be_private }
19
+ it { should be_public }
20
+ end
21
+ "
22
+
23
+ def initialize(keypath, passphrase = nil)
24
+ @key_path = keypath
25
+ @key_file = inspec.file(@key_path)
26
+ @key = nil
27
+ @passphrase = passphrase
28
+
29
+ return skip_resource "Unable to find key file #{@key_path}" unless @key_file.exist?
30
+
31
+ begin
32
+ @key = OpenSSL::PKey.read(@key_file.content, @passphrase)
33
+ rescue OpenSSL::PKey::RSAError => _
34
+ return skip_resource "Unable to load key file #{@key_path}"
35
+ end
36
+ end
37
+
38
+ def public?
39
+ return if @key.nil?
40
+ @key.public?
41
+ end
42
+
43
+ def public_key
44
+ return if @key.nil?
45
+ @key.public_key.to_s
46
+ end
47
+
48
+ def private?
49
+ return if @key.nil?
50
+ @key.private?
51
+ end
52
+
53
+ def private_key
54
+ return if @key.nil?
55
+ @key.to_s
56
+ end
57
+
58
+ def key_length
59
+ return if @key.nil?
60
+ @key.public_key.n.num_bytes * 8
61
+ end
62
+
63
+ def to_s
64
+ "rsa_key #{@key_path}"
65
+ end
66
+ end
67
+ end
@@ -2,7 +2,6 @@
2
2
  # copyright: 2015, Vulcano Security GmbH
3
3
  # author: Christoph Hartmann
4
4
  # author: Dominik Richter
5
- # license: All rights reserved
6
5
 
7
6
  require 'utils/simpleconfig'
8
7
 
@@ -35,7 +34,7 @@ module Inspec::Resources
35
34
  end
36
35
 
37
36
  content = file.content
38
- if content.empty? && file.size > 0
37
+ if content.empty? && !file.empty?
39
38
  skip_resource "Can't read file \"#{@conf_path}\""
40
39
  return @params = {}
41
40
  end
@@ -43,8 +42,8 @@ module Inspec::Resources
43
42
  # parse the file
44
43
  conf = SimpleConfig.new(
45
44
  content,
46
- assignment_re: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
47
- key_vals: 3,
45
+ assignment_regex: /^\s*(\S+?)\s+(.*?)\s+(.*?)\s+(.*?)\s*$/,
46
+ key_values: 3,
48
47
  multiple_values: true,
49
48
  )
50
49
  @params = conf.params
@@ -2,7 +2,6 @@
2
2
  # copyright: 2015, Vulcano Security GmbH
3
3
  # author: Christoph Hartmann
4
4
  # author: Dominik Richter
5
- # license: All rights reserved
6
5
 
7
6
  require 'utils/simpleconfig'
8
7
 
@@ -47,7 +46,7 @@ module Inspec::Resources
47
46
  end
48
47
 
49
48
  content = file.content
50
- if content.empty? && file.size > 0
49
+ if content.empty? && !file.empty?
51
50
  skip_resource "Can't read file \"#{@conf_path}\""
52
51
  return @params = {}
53
52
  end
@@ -55,7 +54,7 @@ module Inspec::Resources
55
54
  # parse the file
56
55
  conf = SimpleConfig.new(
57
56
  content,
58
- assignment_re: /^\s*(\S+)\s+(\S*)\s*$/,
57
+ assignment_regex: /^\s*(\S+)\s+(\S*)\s*$/,
59
58
  multiple_values: false,
60
59
  )
61
60
  @params = conf.params
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  # author: Christoph Hartmann
3
3
  # author: Dominik Richter
4
+ # author: Joseph Benden
4
5
 
5
6
  require 'utils/simpleconfig'
6
7
 
@@ -18,13 +19,12 @@ module Inspec::Resources
18
19
  its('options') { should include 'nodev' }
19
20
  end
20
21
  "
21
- include MountParser
22
-
23
22
  attr_reader :file
24
23
 
25
24
  def initialize(path)
26
25
  @path = path
27
- return skip_resource 'The `mount` resource is not supported on your OS yet.' if !inspec.os.linux?
26
+ @mount_manager = mount_manager_for_os
27
+ return skip_resource 'The `mount` resource is not supported on your OS yet.' if @mount_manager.nil?
28
28
  @file = inspec.backend.file(@path)
29
29
  end
30
30
 
@@ -49,12 +49,42 @@ module Inspec::Resources
49
49
  line = mounted.stdout.lines.to_a.last if mounted.stdout.lines.count > 1
50
50
 
51
51
  # parse content if we are on linux
52
- @mount_options ||= parse_mount_options(line)
52
+ @mount_options ||= @mount_manager.parse_mount_options(line)
53
53
  @mount_options[name]
54
54
  end
55
55
 
56
56
  def to_s
57
57
  "Mount #{@path}"
58
58
  end
59
+
60
+ private
61
+
62
+ def mount_manager_for_os
63
+ os = inspec.os
64
+ if os.linux?
65
+ LinuxMounts.new(inspec)
66
+ elsif ['freebsd'].include?(os[:family])
67
+ BsdMounts.new(inspec)
68
+ end
69
+ end
70
+ end
71
+
72
+ class MountsInfo
73
+ attr_reader :inspec
74
+ def initialize(inspec)
75
+ @inspec = inspec
76
+ end
77
+
78
+ def parse_mount_options(_mount_line, _compatibility = false)
79
+ raise NotImplementedError
80
+ end
81
+ end
82
+
83
+ class LinuxMounts < MountsInfo
84
+ include LinuxMountParser
85
+ end
86
+
87
+ class BsdMounts < MountsInfo
88
+ include BsdMountParser
59
89
  end
60
90
  end