inspec 1.31.0 → 1.45.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 (194) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/CHANGELOG.md +2599 -1
  4. data/Gemfile +0 -1
  5. data/README.md +24 -34
  6. data/Rakefile +0 -31
  7. data/docs/dsl_inspec.md +10 -0
  8. data/docs/matchers.md +29 -0
  9. data/docs/plugin_kitchen_inspec.md +18 -24
  10. data/docs/profiles.md +101 -81
  11. data/docs/resources/aide_conf.md.erb +71 -0
  12. data/docs/resources/apache_conf.md.erb +19 -33
  13. data/docs/resources/apt.md.erb +22 -36
  14. data/docs/resources/audit_policy.md.erb +9 -24
  15. data/docs/resources/auditd.md.erb +78 -0
  16. data/docs/resources/auditd_conf.md.erb +20 -34
  17. data/docs/resources/auditd_rules.md.erb +8 -24
  18. data/docs/resources/bash.md.erb +4 -26
  19. data/docs/resources/bond.md.erb +25 -40
  20. data/docs/resources/bridge.md.erb +5 -25
  21. data/docs/resources/bsd_service.md.erb +5 -25
  22. data/docs/resources/command.md.erb +35 -50
  23. data/docs/resources/cpan.md.erb +62 -0
  24. data/docs/resources/cran.md.erb +54 -0
  25. data/docs/resources/crontab.md.erb +9 -23
  26. data/docs/resources/csv.md.erb +12 -27
  27. data/docs/resources/dh_params.md +1 -0
  28. data/docs/resources/directory.md.erb +5 -25
  29. data/docs/resources/docker.md.erb +61 -58
  30. data/docs/resources/docker_container.md.erb +23 -19
  31. data/docs/resources/docker_image.md.erb +20 -16
  32. data/docs/resources/elasticsearch.md.erb +245 -0
  33. data/docs/resources/etc_fstab.md.erb +120 -0
  34. data/docs/resources/etc_group.md.erb +29 -45
  35. data/docs/resources/etc_hosts.md.erb +68 -0
  36. data/docs/resources/etc_hosts_allow.md.erb +68 -0
  37. data/docs/resources/etc_hosts_deny.md.erb +68 -0
  38. data/docs/resources/file.md.erb +227 -216
  39. data/docs/resources/firewalld.md.erb +104 -0
  40. data/docs/resources/gem.md.erb +21 -35
  41. data/docs/resources/group.md.erb +16 -30
  42. data/docs/resources/grub_conf.md.erb +9 -24
  43. data/docs/resources/host.md.erb +32 -49
  44. data/docs/resources/http.md.erb +38 -44
  45. data/docs/resources/iis_app.md.erb +25 -35
  46. data/docs/resources/iis_site.md.erb +26 -40
  47. data/docs/resources/inetd_conf.md.erb +27 -42
  48. data/docs/resources/ini.md.erb +9 -23
  49. data/docs/resources/interface.md.erb +5 -25
  50. data/docs/resources/iptables.md.erb +15 -29
  51. data/docs/resources/json.md.erb +12 -27
  52. data/docs/resources/kernel_module.md.erb +47 -61
  53. data/docs/resources/kernel_parameter.md.erb +15 -29
  54. data/docs/resources/key_rsa.md.erb +3 -0
  55. data/docs/resources/launchd_service.md.erb +5 -25
  56. data/docs/resources/limits_conf.md.erb +15 -29
  57. data/docs/resources/login_def.md.erb +15 -30
  58. data/docs/resources/mount.md.erb +18 -33
  59. data/docs/resources/mssql_session.md.erb +9 -12
  60. data/docs/resources/mysql_conf.md.erb +28 -32
  61. data/docs/resources/mysql_session.md.erb +15 -29
  62. data/docs/resources/nginx.md.erb +78 -0
  63. data/docs/resources/nginx_conf.md.erb +127 -0
  64. data/docs/resources/npm.md.erb +19 -35
  65. data/docs/resources/ntp_conf.md.erb +20 -37
  66. data/docs/resources/oneget.md.erb +15 -30
  67. data/docs/resources/oracledb_session.md.erb +9 -11
  68. data/docs/resources/os.md.erb +29 -43
  69. data/docs/resources/os_env.md.erb +23 -44
  70. data/docs/resources/package.md.erb +34 -36
  71. data/docs/resources/parse_config.md.erb +5 -25
  72. data/docs/resources/parse_config_file.md.erb +31 -43
  73. data/docs/resources/{etc_passwd.md.erb → passwd.md.erb} +24 -39
  74. data/docs/resources/pip.md.erb +20 -35
  75. data/docs/resources/port.md.erb +43 -57
  76. data/docs/resources/postgres_conf.md.erb +17 -31
  77. data/docs/resources/postgres_hba_conf.md.erb +26 -38
  78. data/docs/resources/postgres_ident_conf.md.erb +25 -37
  79. data/docs/resources/postgres_session.md.erb +15 -29
  80. data/docs/resources/powershell.md.erb +27 -42
  81. data/docs/resources/processes.md.erb +17 -33
  82. data/docs/resources/rabbitmq_config.md.erb +9 -24
  83. data/docs/resources/registry_key.md.erb +27 -42
  84. data/docs/resources/runit_service.md.erb +5 -25
  85. data/docs/resources/security_policy.md.erb +12 -27
  86. data/docs/resources/service.md.erb +27 -42
  87. data/docs/resources/{etc_shadow.md.erb → shadow.md.erb} +41 -47
  88. data/docs/resources/ssh_config.md.erb +19 -34
  89. data/docs/resources/sshd_config.md.erb +19 -34
  90. data/docs/resources/ssl.md.erb +39 -54
  91. data/docs/resources/sys_info.md.erb +12 -26
  92. data/docs/resources/systemd_service.md.erb +5 -25
  93. data/docs/resources/sysv_service.md.erb +5 -25
  94. data/docs/resources/upstart_service.md.erb +5 -25
  95. data/docs/resources/user.md.erb +29 -44
  96. data/docs/resources/users.md.erb +12 -26
  97. data/docs/resources/vbscript.md.erb +9 -24
  98. data/docs/resources/virtualization.md.erb +8 -23
  99. data/docs/resources/windows_feature.md.erb +15 -30
  100. data/docs/resources/windows_hotfix.md.erb +50 -0
  101. data/docs/resources/windows_task.md.erb +12 -26
  102. data/docs/resources/wmi.md.erb +9 -24
  103. data/docs/resources/x509_certificate.md.erb +4 -0
  104. data/docs/resources/xinetd_conf.md.erb +65 -80
  105. data/docs/resources/xml.md.erb +61 -0
  106. data/docs/resources/yaml.md.erb +12 -27
  107. data/docs/resources/yum.md.erb +37 -51
  108. data/docs/resources/zfs_dataset.md.erb +15 -26
  109. data/docs/resources/zfs_pool.md.erb +9 -20
  110. data/docs/ruby_usage.md +0 -1
  111. data/examples/meta-profile/README.md +1 -1
  112. data/examples/profile-sensitive/README.md +29 -0
  113. data/examples/profile-sensitive/controls/sensitive-failures.rb +9 -0
  114. data/examples/profile-sensitive/controls/sensitive.rb +9 -0
  115. data/examples/profile-sensitive/inspec.yml +8 -0
  116. data/inspec.gemspec +3 -3
  117. data/lib/bundles/inspec-artifact/cli.rb +5 -5
  118. data/lib/bundles/inspec-compliance/README.md +24 -22
  119. data/lib/bundles/inspec-compliance/api/login.rb +152 -0
  120. data/lib/bundles/inspec-compliance/api.rb +46 -16
  121. data/lib/bundles/inspec-compliance/cli.rb +58 -165
  122. data/lib/bundles/inspec-compliance/target.rb +2 -3
  123. data/lib/bundles/inspec-habitat/cli.rb +7 -2
  124. data/lib/bundles/inspec-habitat/profile.rb +44 -20
  125. data/lib/bundles/inspec-init/templates/profile/README.md +1 -1
  126. data/lib/bundles/inspec-init/templates/profile/controls/example.rb +1 -1
  127. data/lib/bundles/inspec-supermarket/api.rb +1 -1
  128. data/lib/inspec/backend.rb +8 -0
  129. data/lib/inspec/cli.rb +1 -1
  130. data/lib/inspec/control_eval_context.rb +16 -6
  131. data/lib/inspec/dependencies/requirement.rb +22 -8
  132. data/lib/inspec/dependencies/resolver.rb +1 -1
  133. data/lib/inspec/exceptions.rb +4 -0
  134. data/lib/inspec/file_provider.rb +38 -9
  135. data/lib/inspec/metadata.rb +17 -3
  136. data/lib/inspec/objects/attribute.rb +16 -7
  137. data/lib/inspec/objects/control.rb +10 -2
  138. data/lib/inspec/plugins/resource.rb +34 -5
  139. data/lib/inspec/profile.rb +10 -1
  140. data/lib/inspec/profile_context.rb +3 -1
  141. data/lib/inspec/resource.rb +17 -5
  142. data/lib/inspec/rspec_json_formatter.rb +48 -14
  143. data/lib/inspec/rule.rb +4 -0
  144. data/lib/inspec/runner.rb +72 -30
  145. data/lib/inspec/shell.rb +24 -19
  146. data/lib/inspec/version.rb +1 -1
  147. data/lib/matchers/matchers.rb +40 -0
  148. data/lib/resources/aide_conf.rb +162 -0
  149. data/lib/resources/auditd.rb +231 -0
  150. data/lib/resources/auditd_rules.rb +3 -1
  151. data/lib/resources/command.rb +1 -1
  152. data/lib/resources/cpan.rb +60 -0
  153. data/lib/resources/cran.rb +66 -0
  154. data/lib/resources/docker.rb +8 -1
  155. data/lib/resources/docker_container.rb +19 -2
  156. data/lib/resources/elasticsearch.rb +172 -0
  157. data/lib/resources/etc_fstab.rb +102 -0
  158. data/lib/resources/etc_group.rb +1 -1
  159. data/lib/resources/etc_hosts.rb +81 -0
  160. data/lib/resources/etc_hosts_allow_deny.rb +122 -0
  161. data/lib/resources/file.rb +87 -10
  162. data/lib/resources/firewalld.rb +144 -0
  163. data/lib/resources/groups.rb +0 -1
  164. data/lib/resources/host.rb +30 -15
  165. data/lib/resources/http.rb +178 -22
  166. data/lib/resources/mssql_session.rb +3 -3
  167. data/lib/resources/mysql_conf.rb +10 -0
  168. data/lib/resources/mysql_session.rb +1 -1
  169. data/lib/resources/nginx.rb +97 -0
  170. data/lib/resources/nginx_conf.rb +134 -1
  171. data/lib/resources/oracledb_session.rb +9 -8
  172. data/lib/resources/os_env.rb +7 -4
  173. data/lib/resources/package.rb +14 -2
  174. data/lib/resources/packages.rb +1 -1
  175. data/lib/resources/pip.rb +28 -20
  176. data/lib/resources/port.rb +251 -3
  177. data/lib/resources/postgres.rb +1 -1
  178. data/lib/resources/postgres_session.rb +1 -1
  179. data/lib/resources/processes.rb +106 -20
  180. data/lib/resources/registry_key.rb +11 -2
  181. data/lib/resources/service.rb +5 -24
  182. data/lib/resources/ssh_conf.rb +1 -1
  183. data/lib/resources/ssl.rb +4 -3
  184. data/lib/resources/toml.rb +2 -2
  185. data/lib/resources/windows_hotfix.rb +35 -0
  186. data/lib/resources/xinetd.rb +4 -6
  187. data/lib/resources/xml.rb +27 -0
  188. data/lib/source_readers/inspec.rb +3 -3
  189. data/lib/utils/find_files.rb +2 -1
  190. data/lib/utils/nginx_parser.rb +10 -1
  191. data/lib/utils/object_traversal.rb +35 -10
  192. data/lib/utils/parser.rb +21 -3
  193. metadata +48 -18
  194. data/docs/cli.md +0 -392
@@ -6,6 +6,8 @@ title: About the file Resource
6
6
 
7
7
  Use the `file` InSpec audit resource to test all system file types, including files, directories, symbolic links, named pipes, sockets, character devices, block devices, and doors.
8
8
 
9
+ <br>
10
+
9
11
  ## Syntax
10
12
 
11
13
  A `file` resource block declares the location of the file type to be tested, what type that file should be (if required), and then one (or more) matchers:
@@ -20,14 +22,183 @@ where
20
22
  * `MATCHER` is a valid matcher for this resource
21
23
  * `'value'` is the value to be tested
22
24
 
25
+ <br>
23
26
 
24
- ## Matchers
27
+ ## Examples
28
+
29
+ The following examples show how to use this InSpec audit resource.
30
+
31
+ ### Test the contents of a file for MD5 requirements
32
+
33
+ describe file(hba_config_file) do
34
+ its('content') { should match /local\s.*?all\s.*?all\s.*?md5/ }
35
+ its('content') { should match %r{/host\s.*?all\s.*?all\s.*?127.0.0.1\/32\s.*?md5/} }
36
+ its('content') { should match %r{/host\s.*?all\s.*?all\s.*?::1\/128\s.*?md5/} }
37
+ end
38
+
39
+ ### Test if a file exists
40
+
41
+ describe file('/tmp') do
42
+ it { should exist }
43
+ end
44
+
45
+ ### Test that a file does not exist
46
+
47
+ describe file('/tmpest') do
48
+ it { should_not exist }
49
+ end
50
+
51
+ ### Test if a path is a directory
52
+
53
+ describe file('/tmp') do
54
+ its('type') { should eq :directory }
55
+ it { should be_directory }
56
+ end
57
+
58
+ ### Test if a path is a file and not a directory
59
+
60
+ describe file('/proc/version') do
61
+ its('type') { should cmp 'file' }
62
+ it { should be_file }
63
+ it { should_not be_directory }
64
+ end
65
+
66
+ ### Test if a file is a symbolic link
67
+
68
+ describe file('/dev/stdout') do
69
+ its('type') { should cmp 'symlink' }
70
+ it { should be_symlink }
71
+ it { should_not be_file }
72
+ it { should_not be_directory }
73
+ end
74
+
75
+ ### Test if a file is a character device
76
+
77
+ describe file('/dev/zero') do
78
+ its('type') { should cmp 'character' }
79
+ it { should be_character_device }
80
+ it { should_not be_file }
81
+ it { should_not be_directory }
82
+ end
83
+
84
+ ### Test if a file is a block device
85
+
86
+ describe file('/dev/zero') do
87
+ its('type') { should cmp 'block' }
88
+ it { should be_character_device }
89
+ it { should_not be_file }
90
+ it { should_not be_directory }
91
+ end
92
+
93
+ ### Test the mode for a file
94
+
95
+ describe file('/dev') do
96
+ its('mode') { should cmp '00755' }
97
+ end
98
+
99
+ ### Test the owner of a file
100
+
101
+ describe file('/root') do
102
+ its('owner') { should eq 'root' }
103
+ end
104
+
105
+ ### Test if a file is owned by the root user
106
+
107
+ describe file('/dev') do
108
+ it { should be_owned_by 'root' }
109
+ end
110
+
111
+ ### Test the mtime for a file
112
+
113
+ describe file('/') do
114
+ its('mtime') { should <= Time.now.to_i }
115
+ its('mtime') { should >= Time.now.to_i - 1000 }
116
+ end
117
+
118
+ ### Test that a file's size is between 64 and 10240
119
+
120
+ describe file('/') do
121
+ its('size') { should be > 64 }
122
+ its('size') { should be < 10240 }
123
+ end
124
+
125
+ ### Test that a file's size is zero
126
+
127
+ describe file('/proc/cpuinfo') do
128
+ its('size') { should be 0 }
129
+ end
130
+
131
+ ### Test that a file is not mounted
132
+
133
+ describe file('/proc/cpuinfo') do
134
+ it { should_not be_mounted }
135
+ end
136
+
137
+ ### Test an MD5 checksum
138
+
139
+ require 'digest'
140
+ cpuinfo = file('/proc/cpuinfo').content
141
+
142
+ md5sum = Digest::MD5.hexdigest(cpuinfo)
143
+
144
+ describe file('/proc/cpuinfo') do
145
+ its('md5sum') { should eq md5sum }
146
+ end
147
+
148
+ ### Test an SHA-256 checksum
149
+
150
+ require 'digest'
151
+ cpuinfo = file('/proc/cpuinfo').content
152
+
153
+ sha256sum = Digest::SHA256.hexdigest(cpuinfo)
154
+
155
+ describe file('/proc/cpuinfo') do
156
+ its('sha256sum') { should eq sha256sum }
157
+ end
158
+
159
+ ### Verify NTP
160
+
161
+ The following example shows how to use the `file` audit resource to verify if the `ntp.conf` and `leap-seconds` files are present, and then the `command` resource to verify if NTP is installed and running:
162
+
163
+ describe file('/etc/ntp.conf') do
164
+ it { should be_file }
165
+ end
25
166
 
26
- This InSpec audit resource has the following matchers:
167
+ describe file('/etc/ntp.leapseconds') do
168
+ it { should be_file }
169
+ end
170
+
171
+ describe command('pgrep ntp') do
172
+ its('exit_status') { should eq 0 }
173
+ end
174
+
175
+ ### Test parameters of symlinked file
27
176
 
28
- ### be
177
+ If you need to test the parameters of the target file for a symlink, you can use the `link_path` method for the `file` resource.
29
178
 
30
- <%= partial "/shared/matcher_be" %>
179
+ For example, for the following symlink:
180
+
181
+ lrwxrwxrwx. 1 root root 11 03-10 17:56 /dev/virtio-ports/com.redhat.rhevm.vdsm -> ../vport2p1
182
+
183
+ ... you can write controls for both the link and the target.
184
+
185
+ describe file('/dev/virtio-ports/com.redhat.rhevm.vdsm') do
186
+ it { should be_symlink }
187
+ end
188
+
189
+ virito_port_vdsm = file('/dev/virtio-ports/com.redhat.rhevm.vdsm').link_path
190
+ describe file(virito_port_vdsm) do
191
+ it { should exist }
192
+ it { should be_character_device }
193
+ it { should be_owned_by 'ovirtagent' }
194
+ it { should be_grouped_into 'ovirtagent' }
195
+ end
196
+
197
+ <br>
198
+
199
+ ## Matchers
200
+
201
+ This InSpec audit resource has the following matchers. For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
31
202
 
32
203
  ### be\_block\_device
33
204
 
@@ -61,6 +232,10 @@ an owner:
61
232
 
62
233
  it { should be_executable.by('owner') }
63
234
 
235
+ any user other than the owner or members of the file's group:
236
+
237
+ it { should be_executable.by('others') }
238
+
64
239
  a user:
65
240
 
66
241
  it { should be_executable.by_user('user') }
@@ -121,16 +296,38 @@ an owner:
121
296
 
122
297
  it { should be_readable.by('owner') }
123
298
 
299
+ any user other than the owner or members of the file's group:
300
+
301
+ it { should be_readable.by('others') }
302
+
124
303
  a user:
125
304
 
126
305
  it { should be_readable.by_user('user') }
127
306
 
307
+ ### be_setgid
308
+
309
+ The `be_setgid` matcher tests if the 'setgid' permission is set on the file or directory. On executable files, this causes the process to be started owned by the group that owns the file, rather than the primary group of the invocating user. This can result in escalation of privilege. On Linux, when setgid is set on directories, setgid causes newly created files and directories to be owned by the group that owns the setgid parent directory; additionally, newly created subdirectories will have the setgid bit set. To use this matcher:
310
+
311
+ it { should be_setgid }
312
+
128
313
  ### be_socket
129
314
 
130
315
  The `be_socket` matcher tests if the file exists as socket (`.sock`), such as `/var/run/php-fpm.sock`:
131
316
 
132
317
  it { should be_socket }
133
318
 
319
+ ### be_sticky
320
+
321
+ The `be_sticky` matcher tests if the 'sticky bit' permission is set on the directory. On directories, this restricts file deletion to the owner of the file, even if the permission of the parent directory would normally permit deletion by others. This is commonly used on /tmp filesystems. To use this matcher:
322
+
323
+ it { should be_sticky }
324
+
325
+ ### be_setuid
326
+
327
+ The `be_setuid` matcher tests if the 'setuid' permission is set on the file. On executable files, this causes the process to be started owned by the user that owns the file, rather than invocating user. This can result in escalation of privilege. To use this matcher:
328
+
329
+ it { should be_setuid }
330
+
134
331
  ### be_symlink
135
332
 
136
333
  The `be_symlink` matcher tests if the file exists as a symbolic, or soft link that contains an absolute or relative path reference to another file:
@@ -157,13 +354,13 @@ an owner:
157
354
 
158
355
  it { should be_writable.by('owner') }
159
356
 
160
- a user:
357
+ any user other than the owner or members of the file's group:
161
358
 
162
- it { should be_writable.by_user('user') }
359
+ it { should be_writable.by('others') }
163
360
 
164
- ### cmp
361
+ a user:
165
362
 
166
- <%= partial "/shared/matcher_cmp" %>
363
+ it { should be_writable.by_user('user') }
167
364
 
168
365
  ### content
169
366
 
@@ -179,10 +376,6 @@ The following complete example tests the `pg_hba.conf` file in PostgreSQL for MD
179
376
  its('content') { should match(%r{host\s.*?all\s.*?all\s.*?::1\/128\s.*?md5})
180
377
  end
181
378
 
182
- ### eq
183
-
184
- <%= partial "/shared/matcher_eq" %>
185
-
186
379
  ### exist
187
380
 
188
381
  The `exist` matcher tests if the named file exists:
@@ -207,26 +400,13 @@ The `have_mode` matcher tests if a file has a mode assigned to it:
207
400
 
208
401
  it { should have_mode }
209
402
 
210
- ### include
211
-
212
- <%= partial "/shared/matcher_include" %>
213
-
214
403
  ### link_path
215
404
 
216
- The `link_path` matcher tests if the file exists at the specified path:
405
+ The `link_path` matcher tests if the file exists at the specified path. If the file is a symlink,
406
+ InSpec will resolve the symlink and return the ultimate linked file:
217
407
 
218
408
  its('link_path') { should eq '/some/path/to/file' }
219
409
 
220
- ### link_target
221
-
222
- The `link_target` matcher tests if a file that is linked to this file exists at the specified path:
223
-
224
- its('link_target') { should eq '/some/path/to/file' }
225
-
226
- ### match
227
-
228
- <%= partial "/shared/matcher_match" %>
229
-
230
410
  ### md5sum
231
411
 
232
412
  The `md5sum` matcher tests if the MD5 checksum for a file matches the specified value:
@@ -241,15 +421,11 @@ The `mode` matcher tests if the mode assigned to the file matches the specified
241
421
 
242
422
  ### mtime
243
423
 
244
- The `mtime` matcher tests if the file modification time for the file matches the specified value:
424
+ The `mtime` matcher tests if the file modification time for the file matches the specified value. The mtime, where supported, is returned as the number of seconds since the epoch.
245
425
 
246
- its('mtime') { should eq 'October 31 2015 12:10:45' }
247
-
248
- or:
249
-
250
- describe file('/').mtime.to_i do
251
- it { should <= Time.now.to_i }
252
- it { should >= Time.now.to_i - 1000}
426
+ describe file('/') do
427
+ its('mtime') { should <= Time.now.to_i }
428
+ its('mtime') { should >= Time.now.to_i - 1000 }
253
429
  end
254
430
 
255
431
  ### owner
@@ -292,191 +468,26 @@ Less than:
292
468
 
293
469
  ### type
294
470
 
295
- The `type` matcher tests if the first letter of the file's mode string contains one of the following characters:
471
+ The `type` matcher tests for the file type. The available types are:
472
+
473
+ * `file`: the object is a file
474
+ * `directory`: the object is a directory
475
+ * `link`: the object is a symbolic link
476
+ * `pipe`: the object is a named pipe
477
+ * `socket`: the object is a socket
478
+ * `character_device`: the object is a character device
479
+ * `block_device`: the object is a block device
480
+ * `door`: the object is a door device
296
481
 
297
- * `-` or `f` (the file is a file); use `'file` to test for this file type
298
- * `d` (the file is a directory); use `'directory` to test for this file type
299
- * `l` (the file is a symbolic link); use `'link` to test for this file type
300
- * `p` (the file is a named pipe); use `'pipe` to test for this file type
301
- * `s` (the file is a socket); use `'socket` to test for this file type
302
- * `c` (the file is a character device); use `'character` to test for this file type
303
- * `b` (the file is a block device); use `'block` to test for this file type
304
- * `D` (the file is a door); use `'door` to test for this file type
482
+ The `type` method usually returns the type as a Ruby "symbol". We recommend using the `cmp` matcher to match
483
+ either by symbol or string.
305
484
 
306
485
  For example:
307
486
 
308
- its('type') { should eq 'file' }
487
+ its('type') { should eq :file }
488
+ its('type') { should cmp 'file' }
309
489
 
310
490
  or:
311
491
 
312
- its('type') { should eq 'socket' }
313
-
314
- ## Examples
315
-
316
- The following examples show how to use this InSpec audit resource.
317
-
318
- ### Test the contents of a file for MD5 requirements
319
-
320
- describe file(hba_config_file) do
321
- its('content') { should match /local\s.*?all\s.*?all\s.*?md5/ }
322
- its('content') { should match %r{/host\s.*?all\s.*?all\s.*?127.0.0.1\/32\s.*?md5/} }
323
- its('content') { should match %r{/host\s.*?all\s.*?all\s.*?::1\/128\s.*?md5/} }
324
- end
325
-
326
- ### Test if a file exists
327
-
328
- describe file('/tmp') do
329
- it { should exist }
330
- end
331
-
332
- ### Test that a file does not exist
333
-
334
- describe file('/tmpest') do
335
- it { should_not exist }
336
- end
337
-
338
- ### Test if a path is a directory
339
-
340
- describe file('/tmp') do
341
- its('type') { should eq :directory }
342
- it { should be_directory }
343
- end
344
-
345
- ### Test if a path is a file and not a directory
346
-
347
- describe file('/proc/version') do
348
- its('type') { should eq 'file' }
349
- it { should be_file }
350
- it { should_not be_directory }
351
- end
352
-
353
- ### Test if a file is a symbolic link
354
-
355
- describe file('/dev/stdout') do
356
- its('type') { should eq 'symlink' }
357
- it { should be_symlink }
358
- it { should_not be_file }
359
- it { should_not be_directory }
360
- end
361
-
362
- ### Test if a file is a character device
363
-
364
- describe file('/dev/zero') do
365
- its('type') { should eq 'character' }
366
- it { should be_character_device }
367
- it { should_not be_file }
368
- it { should_not be_directory }
369
- end
370
-
371
- ### Test if a file is a block device
372
-
373
- describe file('/dev/zero') do
374
- its('type') { should eq 'block' }
375
- it { should be_character_device }
376
- it { should_not be_file }
377
- it { should_not be_directory }
378
- end
379
-
380
- ### Test the mode for a file
381
-
382
- describe file('/dev') do
383
- its('mode') { should cmp '00755' }
384
- end
385
-
386
- ### Test the owner of a file
387
-
388
- describe file('/root') do
389
- its('owner') { should eq 'root' }
390
- end
391
-
392
- ### Test if a file is owned by the root user
393
-
394
- describe file('/dev') do
395
- it { should be_owned_by 'root' }
396
- end
397
-
398
- ### Test the mtime for a file
399
-
400
- describe file('/').mtime.to_i do
401
- it { should <= Time.now.to_i }
402
- it { should >= Time.now.to_i - 1000}
403
- end
404
-
405
- ### Test that a file's size is between 64 and 10240
406
-
407
- describe file('/') do
408
- its('size') { should be > 64 }
409
- its('size') { should be < 10240 }
410
- end
411
-
412
- ### Test that a file's size is zero
413
-
414
- describe file('/proc/cpuinfo') do
415
- its('size') { should be 0 }
416
- end
417
-
418
- ### Test that a file is not mounted
419
-
420
- describe file('/proc/cpuinfo') do
421
- it { should_not be_mounted }
422
- end
423
-
424
- ### Test an MD5 checksum
425
-
426
- require 'digest'
427
- cpuinfo = file('/proc/cpuinfo').content
428
-
429
- md5sum = Digest::MD5.hexdigest(cpuinfo)
430
-
431
- describe file('/proc/cpuinfo') do
432
- its('md5sum') { should eq md5sum }
433
- end
434
-
435
- ### Test an SHA-256 checksum
436
-
437
- require 'digest'
438
- cpuinfo = file('/proc/cpuinfo').content
439
-
440
- sha256sum = Digest::SHA256.hexdigest(cpuinfo)
441
-
442
- describe file('/proc/cpuinfo') do
443
- its('sha256sum') { should eq sha256sum }
444
- end
445
-
446
- ### Verify NTP
447
-
448
- The following example shows how to use the `file` audit resource to verify if the `ntp.conf` and `leap-seconds` files are present, and then the `command` resource to verify if NTP is installed and running:
449
-
450
- describe file('/etc/ntp.conf') do
451
- it { should be_file }
452
- end
453
-
454
- describe file('/etc/ntp.leapseconds') do
455
- it { should be_file }
456
- end
457
-
458
- describe command('pgrep ntp') do
459
- its('exit_status') { should eq 0 }
460
- end
461
-
462
- ### Test parameters of symlinked file
463
-
464
- If you need to test the parameters of the target file for a symlink, you can use the `link_path` method for the `file` resource.
465
-
466
- For example, for the following symlink:
467
-
468
- lrwxrwxrwx. 1 root root 11 03-10 17:56 /dev/virtio-ports/com.redhat.rhevm.vdsm -> ../vport2p1
469
-
470
- ... you can write controls for both the link and the target.
471
-
472
- describe file('/dev/virtio-ports/com.redhat.rhevm.vdsm') do
473
- it { should be_symlink }
474
- end
475
-
476
- virito_port_vdsm = file('/dev/virtio-ports/com.redhat.rhevm.vdsm').link_path
477
- describe file(virito_port_vdsm) do
478
- it { should exist }
479
- it { should be_character_device }
480
- it { should be_owned_by 'ovirtagent' }
481
- it { should be_grouped_into 'ovirtagent' }
482
- end
492
+ its('type') { should eq :socket }
493
+ its('type') { should cmp 'socket' }
@@ -0,0 +1,104 @@
1
+ ---
2
+ title: About the firewalld Resource
3
+ ---
4
+
5
+ # firewalld
6
+
7
+ Use the `firewalld` InSpec audit resource to test that firewalld is configured to allow and deny access to specific hosts, services and ports on a system.
8
+
9
+ A firewalld has a number of zones that can be configured to allow and deny access to specific hosts, services, and ports.
10
+
11
+ <br>
12
+
13
+ ## Syntax
14
+
15
+ describe firewalld do
16
+ it { should be_running }
17
+ its('default_zone') { should eq 'public' }
18
+ it { should have_service_enabled_in_zone('ssh', 'public') }
19
+ it { should have_rule_enabled('family=ipv4 source address=192.168.0.14 accept', 'public') }
20
+ end
21
+
22
+ Use the where clause to test open interfaces, sources, and services in active zones.
23
+
24
+ describe firewalld.where { zone == 'public' } do
25
+ its('interfaces') { should cmp ['enp0s3', 'eno2'] }
26
+ its('sources') { should cmp ['192.168.1.0/24', '192.168.1.2'] }
27
+ its('services') { should cmp ['ssh', 'icmp'] }
28
+ end
29
+
30
+ <br>
31
+
32
+ ## Supported Properties
33
+
34
+ ### interfaces
35
+
36
+ The `interfaces` property is used in conjunction with the where class to display open interfaces in an active zone.
37
+
38
+ describe firewalld.where { zone == 'public' } do
39
+ its('interfaces') { should cmp ['enp0s3', 'eno2'] }
40
+ end
41
+
42
+ ### sources
43
+
44
+ The `sources` property is used in conjunction with the where class to display open sources in an active zone.
45
+
46
+ describe firewalld.where { zone == 'public' } do
47
+ its('sources') { should cmp ['192.168.1.0/24', '192.168.1.2'] }
48
+ end
49
+
50
+ ### services
51
+
52
+ The `services` property is used in conjunction with the where class to display open services in an active zone.
53
+
54
+ describe firewalld.where { zone == 'public' } do
55
+ its('services') { should cmp ['ssh', 'icmp'] }
56
+ end
57
+
58
+ ### default_zone
59
+
60
+ The `default_zone` property displays the default active zone to be used.
61
+
62
+ its('default_zone') { should eq 'public' }
63
+
64
+ <br>
65
+
66
+ ## Matchers
67
+
68
+ This InSpec audit resource has the following matchers. For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
69
+
70
+ ### `be_installed`
71
+
72
+ The `be_installed` matcher tests if the firewalld service is installed:
73
+
74
+ it { should be_installed }
75
+
76
+ ### `be_running`
77
+
78
+ The `be_running` matcher tests if the firewalld service is running:
79
+
80
+ it { should be_running }
81
+
82
+ ### have_zone
83
+
84
+ `have_zone` returns true or false if the zone is set on firewalld. It does not mean the zone is active.
85
+
86
+ it { should have_zone('public') }
87
+
88
+ ### `have_service_enabled_in_zone`
89
+
90
+ `have_service_enabled_in_zone` returns true or false if the service is allowed in the specified zone.
91
+
92
+ it { should have_service_enabled_in_zone('ssh', 'public') }
93
+
94
+ ### `have_port_enabled_in_zone`
95
+
96
+ `have_port_enabled_in_zone` returns true or false if the port is allowed in the specified zone.
97
+
98
+ it { should have_port_enabled_in_zone('22/tcp', 'public') }
99
+
100
+ ### `have_rule_enabled`
101
+
102
+ `have_rule_enabled` returns true or false if the rich-rule has been specified in the zone.
103
+
104
+ it { should have_rule_enabled('family=ipv4 source address=192.168.0.14 accept', 'public') }
@@ -6,6 +6,8 @@ title: About the gem Resource
6
6
 
7
7
  Use the `gem` InSpec audit resource to test if a global Gem package is installed.
8
8
 
9
+ <br>
10
+
9
11
  ## Syntax
10
12
 
11
13
  A `gem` resource block declares a package and (optionally) a package version:
@@ -20,41 +22,7 @@ where
20
22
  * `('gem_binary')` can specify the path to a non-default gem binary, defaults to `'gem'`
21
23
  * `be_installed` is a valid matcher for this resource
22
24
 
23
- ## Matchers
24
-
25
- This InSpec audit resource has the following matchers:
26
-
27
- ### be
28
-
29
- <%= partial "/shared/matcher_be" %>
30
-
31
- ### be_installed
32
-
33
- The `be_installed` matcher tests if the named Gem package is installed:
34
-
35
- it { should be_installed }
36
-
37
- ### cmp
38
-
39
- <%= partial "/shared/matcher_cmp" %>
40
-
41
- ### eq
42
-
43
- <%= partial "/shared/matcher_eq" %>
44
-
45
- ### include
46
-
47
- <%= partial "/shared/matcher_include" %>
48
-
49
- ### match
50
-
51
- <%= partial "/shared/matcher_match" %>
52
-
53
- ### version
54
-
55
- The `version` matcher tests if the named package version is on the system:
56
-
57
- its('version') { should eq '0.33.0' }
25
+ <br>
58
26
 
59
27
  ## Examples
60
28
 
@@ -90,3 +58,21 @@ The following examples show how to use this InSpec audit resource.
90
58
  describe gem('knife-backup', :chef_server) do
91
59
  it { should be_installed }
92
60
  end
61
+
62
+ <br>
63
+
64
+ ## Matchers
65
+
66
+ This InSpec audit resource has the following matchers. For a full list of available matchers please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
67
+
68
+ ### be_installed
69
+
70
+ The `be_installed` matcher tests if the named Gem package is installed:
71
+
72
+ it { should be_installed }
73
+
74
+ ### version
75
+
76
+ The `version` matcher tests if the named package version is on the system:
77
+
78
+ its('version') { should eq '0.33.0' }