inspec 1.40.0 → 1.41.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +30 -9
  3. data/docs/matchers.md +18 -0
  4. data/docs/plugin_kitchen_inspec.md +18 -24
  5. data/docs/profiles.md +39 -2
  6. data/docs/resources/aide_conf.md.erb +18 -28
  7. data/docs/resources/apache_conf.md.erb +19 -33
  8. data/docs/resources/apt.md.erb +22 -36
  9. data/docs/resources/audit_policy.md.erb +9 -24
  10. data/docs/resources/auditd.md.erb +9 -24
  11. data/docs/resources/auditd_conf.md.erb +20 -34
  12. data/docs/resources/auditd_rules.md.erb +8 -24
  13. data/docs/resources/bash.md.erb +4 -26
  14. data/docs/resources/bond.md.erb +25 -40
  15. data/docs/resources/bridge.md.erb +5 -25
  16. data/docs/resources/bsd_service.md.erb +5 -25
  17. data/docs/resources/command.md.erb +35 -50
  18. data/docs/resources/crontab.md.erb +9 -23
  19. data/docs/resources/csv.md.erb +12 -27
  20. data/docs/resources/dh_params.md +1 -0
  21. data/docs/resources/directory.md.erb +5 -25
  22. data/docs/resources/docker.md.erb +60 -57
  23. data/docs/resources/docker_container.md.erb +23 -19
  24. data/docs/resources/docker_image.md.erb +20 -16
  25. data/docs/resources/etc_fstab.md.erb +5 -2
  26. data/docs/resources/etc_group.md.erb +29 -45
  27. data/docs/resources/etc_hosts.md.erb +6 -0
  28. data/docs/resources/etc_hosts_allow.md.erb +6 -2
  29. data/docs/resources/etc_hosts_deny.md.erb +6 -2
  30. data/docs/resources/file.md.erb +198 -212
  31. data/docs/resources/firewalld.md.erb +7 -1
  32. data/docs/resources/gem.md.erb +21 -35
  33. data/docs/resources/group.md.erb +16 -30
  34. data/docs/resources/grub_conf.md.erb +9 -24
  35. data/docs/resources/host.md.erb +32 -49
  36. data/docs/resources/http.md.erb +38 -44
  37. data/docs/resources/iis_app.md.erb +25 -35
  38. data/docs/resources/iis_site.md.erb +26 -40
  39. data/docs/resources/inetd_conf.md.erb +27 -42
  40. data/docs/resources/ini.md.erb +9 -23
  41. data/docs/resources/interface.md.erb +5 -25
  42. data/docs/resources/iptables.md.erb +15 -29
  43. data/docs/resources/json.md.erb +12 -27
  44. data/docs/resources/kernel_module.md.erb +47 -61
  45. data/docs/resources/kernel_parameter.md.erb +15 -29
  46. data/docs/resources/key_rsa.md.erb +3 -0
  47. data/docs/resources/launchd_service.md.erb +5 -25
  48. data/docs/resources/limits_conf.md.erb +15 -29
  49. data/docs/resources/login_def.md.erb +15 -30
  50. data/docs/resources/mount.md.erb +18 -33
  51. data/docs/resources/mssql_session.md.erb +9 -12
  52. data/docs/resources/mysql_conf.md.erb +17 -32
  53. data/docs/resources/mysql_session.md.erb +15 -29
  54. data/docs/resources/nginx.md.erb +6 -0
  55. data/docs/resources/nginx_conf.md.erb +25 -20
  56. data/docs/resources/npm.md.erb +19 -35
  57. data/docs/resources/ntp_conf.md.erb +20 -37
  58. data/docs/resources/oneget.md.erb +15 -30
  59. data/docs/resources/oracledb_session.md.erb +9 -11
  60. data/docs/resources/os.md.erb +29 -43
  61. data/docs/resources/os_env.md.erb +29 -44
  62. data/docs/resources/package.md.erb +33 -42
  63. data/docs/resources/parse_config.md.erb +5 -25
  64. data/docs/resources/parse_config_file.md.erb +31 -43
  65. data/docs/resources/passwd.md.erb +24 -39
  66. data/docs/resources/pip.md.erb +20 -35
  67. data/docs/resources/port.md.erb +43 -57
  68. data/docs/resources/postgres_conf.md.erb +17 -31
  69. data/docs/resources/postgres_hba_conf.md.erb +26 -38
  70. data/docs/resources/postgres_ident_conf.md.erb +25 -37
  71. data/docs/resources/postgres_session.md.erb +15 -29
  72. data/docs/resources/powershell.md.erb +27 -42
  73. data/docs/resources/processes.md.erb +17 -33
  74. data/docs/resources/rabbitmq_config.md.erb +9 -24
  75. data/docs/resources/registry_key.md.erb +27 -42
  76. data/docs/resources/runit_service.md.erb +5 -25
  77. data/docs/resources/security_policy.md.erb +12 -27
  78. data/docs/resources/service.md.erb +27 -42
  79. data/docs/resources/shadow.md.erb +20 -35
  80. data/docs/resources/ssh_config.md.erb +19 -34
  81. data/docs/resources/sshd_config.md.erb +19 -34
  82. data/docs/resources/ssl.md.erb +39 -54
  83. data/docs/resources/sys_info.md.erb +12 -26
  84. data/docs/resources/systemd_service.md.erb +5 -25
  85. data/docs/resources/sysv_service.md.erb +5 -25
  86. data/docs/resources/upstart_service.md.erb +5 -25
  87. data/docs/resources/user.md.erb +29 -44
  88. data/docs/resources/users.md.erb +12 -26
  89. data/docs/resources/vbscript.md.erb +9 -24
  90. data/docs/resources/virtualization.md.erb +8 -23
  91. data/docs/resources/windows_feature.md.erb +15 -30
  92. data/docs/resources/windows_hotfix.md.erb +15 -9
  93. data/docs/resources/windows_task.md.erb +12 -26
  94. data/docs/resources/wmi.md.erb +9 -24
  95. data/docs/resources/x509_certificate.md.erb +4 -0
  96. data/docs/resources/xinetd_conf.md.erb +65 -80
  97. data/docs/resources/xml.md.erb +12 -26
  98. data/docs/resources/yaml.md.erb +12 -27
  99. data/docs/resources/yum.md.erb +37 -51
  100. data/docs/resources/zfs_dataset.md.erb +15 -26
  101. data/docs/resources/zfs_pool.md.erb +9 -20
  102. data/lib/inspec/backend.rb +8 -0
  103. data/lib/inspec/profile.rb +9 -1
  104. data/lib/inspec/shell.rb +13 -13
  105. data/lib/inspec/version.rb +1 -1
  106. data/lib/matchers/matchers.rb +2 -0
  107. data/lib/resources/etc_hosts.rb +1 -1
  108. data/lib/resources/host.rb +4 -1
  109. data/lib/resources/http.rb +173 -23
  110. data/lib/resources/processes.rb +106 -20
  111. data/lib/resources/ssh_conf.rb +1 -1
  112. data/lib/resources/ssl.rb +4 -3
  113. data/lib/utils/object_traversal.rb +35 -10
  114. metadata +2 -2
@@ -6,6 +6,8 @@ title: About the docker_image Resource
6
6
 
7
7
  Use the `docker_image` InSpec audit resource to verify a docker image.
8
8
 
9
+ <br>
10
+
9
11
  ## Syntax
10
12
 
11
13
  A `docker_image` resource block declares the image:
@@ -35,10 +37,27 @@ You can also pass in repository and tag as separate values
35
37
  ...
36
38
  end
37
39
 
40
+ <br>
41
+
42
+ ## Examples
43
+
44
+ The following examples show how to use this InSpec `docker_image` resource.
45
+
46
+ ### Test a docker image
47
+
48
+ describe docker_image('alpine:latest') do
49
+ it { should exist }
50
+ its('id') { should eq 'sha256:4a415e...a526' }
51
+ its('image') { should eq 'alpine:latest' }
52
+ its('repo') { should eq 'alpine' }
53
+ its('tag') { should eq 'latest' }
54
+ end
55
+
56
+ <br>
38
57
 
39
58
  ## Matchers
40
59
 
41
- This InSpec audit resource has the following matchers:
60
+ 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/).
42
61
 
43
62
  ### exist
44
63
 
@@ -69,18 +88,3 @@ The `repo` matcher tests the value of the repository name:
69
88
  The `tag` matcher tests the value of image tag:
70
89
 
71
90
  its('tag') { should eq 'latest' }
72
-
73
-
74
- ## Examples
75
-
76
- The following examples show how to use this InSpec `docker_image` resource.
77
-
78
- ### Test a docker image
79
-
80
- describe docker_image('alpine:latest') do
81
- it { should exist }
82
- its('id') { should eq 'sha256:4a415e...a526' }
83
- its('image') { should eq 'alpine:latest' }
84
- its('repo') { should eq 'alpine' }
85
- its('tag') { should eq 'latest' }
86
- end
@@ -5,13 +5,14 @@ title: About the etc_fstab Resource
5
5
  # etc_fstab
6
6
 
7
7
  Use the `etc_fstab` InSpec audit resource to test information about all partitions and storage devices on a system.
8
+
9
+ <br>
10
+
8
11
  ## Syntax
9
12
 
10
13
  An etc_fstab rule specifies a device name, its mount point, its mount type, the options its mounted with,
11
14
  its dump options, and the order the files system should be checked.
12
15
 
13
- ## Syntax
14
-
15
16
  Use the where clause to match a property to one or more rules in the fstab file.
16
17
 
17
18
  describe etc_fstab.where { device_name == 'value' } do
@@ -91,6 +92,8 @@ where
91
92
  its('file_system_options') { should cmp 0 }
92
93
  end
93
94
 
95
+ <br>
96
+
94
97
  ## Examples
95
98
 
96
99
  The following examples show how to use this InSpec resource.
@@ -6,6 +6,8 @@ title: About the etc_group Resource
6
6
 
7
7
  Use the `etc_group` InSpec audit resource to test groups that are defined on Linux and Unix platforms. The `/etc/group` file stores details about each group---group name, password, group identifier, along with a comma-separate list of users that belong to the group.
8
8
 
9
+ <br>
10
+
9
11
  ## Syntax
10
12
 
11
13
  A `etc_group` resource block declares a collection of properties to be tested:
@@ -28,21 +30,40 @@ where
28
30
  * `.where()` may specify a specific item and value, to which the matchers are compared
29
31
  * `'gids'`, `'groups'`, and `'users'` are valid matchers for this resource
30
32
 
31
- ## Matchers
32
33
 
33
- This InSpec audit resource has the following matchers:
34
+ ## Examples
35
+
36
+ The following examples show how to use this InSpec audit resource.
37
+
38
+ ### Test group identifiers (GIDs) for duplicates
39
+
40
+ describe etc_group do
41
+ its('gids') { should_not contain_duplicates }
42
+ end
43
+
44
+ ### Test all groups to see if a specific user belongs to one (or more) groups
45
+
46
+ describe etc_group do
47
+ its('groups') { should include 'my_group' }
48
+ end
49
+
50
+ ### Test all groups for a specific user name
34
51
 
35
- ### be
52
+ describe etc_group do
53
+ its('users') { should include 'my_user' }
54
+ end
36
55
 
37
- <%= partial "/shared/matcher_be" %>
56
+ ### Filter a list of groups for a specific user
38
57
 
39
- ### cmp
58
+ describe etc_group.where(name: 'my_group') do
59
+ its('users') { should include 'my_user' }
60
+ end
40
61
 
41
- <%= partial "/shared/matcher_cmp" %>
62
+ <br>
42
63
 
43
- ### eq
64
+ ## Matchers
44
65
 
45
- <%= partial "/shared/matcher_eq" %>
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/).
46
67
 
47
68
  ### gids
48
69
 
@@ -56,14 +77,6 @@ The `groups` matcher tests all groups for the named user:
56
77
 
57
78
  its('groups') { should include 'my_group' }
58
79
 
59
- ### include
60
-
61
- <%= partial "/shared/matcher_include" %>
62
-
63
- ### match
64
-
65
- <%= partial "/shared/matcher_match" %>
66
-
67
80
  ### users
68
81
 
69
82
  The `users` matcher tests all groups for the named user:
@@ -85,32 +98,3 @@ where `item` may be one (or more) of:
85
98
  * `group_id: 'gid'`
86
99
  * `users: 'user_name'`
87
100
  * `members: 'member_name'`
88
-
89
-
90
- ## Examples
91
-
92
- The following examples show how to use this InSpec audit resource.
93
-
94
- ### Test group identifiers (GIDs) for duplicates
95
-
96
- describe etc_group do
97
- its('gids') { should_not contain_duplicates }
98
- end
99
-
100
- ### Test all groups to see if a specific user belongs to one (or more) groups
101
-
102
- describe etc_group do
103
- its('groups') { should include 'my_group' }
104
- end
105
-
106
- ### Test all groups for a specific user name
107
-
108
- describe etc_group do
109
- its('users') { should include 'my_user' }
110
- end
111
-
112
- ### Filter a list of groups for a specific user
113
-
114
- describe etc_group.where(name: 'my_group') do
115
- its('users') { should include 'my_user' }
116
- end
@@ -9,6 +9,8 @@ Use the `etc_hosts` InSpec audit resource to test rules set to match IP addresse
9
9
 
10
10
  An etc/hosts rule specifies an IP address and what its hostname is along with optional aliases it can have.
11
11
 
12
+ <br>
13
+
12
14
  ## Syntax
13
15
 
14
16
  Use the where clause to match a property to one or more rules in the hosts file.
@@ -31,10 +33,14 @@ where
31
33
  * `primary_name` is the name associated with the ip address.
32
34
  * `all_host_names` is a list including the primary_name as the first entry followed by any aliase names the host has.
33
35
 
36
+ <br>
37
+
34
38
  ## Supported Properties
35
39
 
36
40
  'ip_address', 'primary_name', 'all_host_names'
37
41
 
42
+ <br>
43
+
38
44
  ## Property Examples and Return Types
39
45
 
40
46
  ### ip_address
@@ -6,13 +6,13 @@ title: About the etc_hosts_allow Resource
6
6
 
7
7
  Use the `etc_hosts_allow` InSpec audit resource to test rules set to accept daemon and client traffic set in /etc/hosts.allow file.
8
8
 
9
+ <br>
10
+
9
11
  ## Syntax
10
12
 
11
13
  An etc/hosts.allow rule specifies one or more daemons mapped to one or more clients,
12
14
  with zero or more options to use to accept traffic when found.
13
15
 
14
- ## Syntax
15
-
16
16
  Use the where clause to match a property to one or more rules in the hosts.allow file.
17
17
 
18
18
  describe etc_hosts_allow.where { daemon == 'value' } do
@@ -33,10 +33,14 @@ where
33
33
  * `client_list` is a list of clients will be allowed to pass traffic in.
34
34
  * `options` is a list of tasks that to be done with the rule when traffic is found.
35
35
 
36
+ <br>
37
+
36
38
  ## Supported Properties
37
39
 
38
40
  'daemon', 'client_list', 'options'
39
41
 
42
+ <br>
43
+
40
44
  ## Property Examples and Return Types
41
45
 
42
46
  ### daemon
@@ -6,13 +6,13 @@ title: About the etc_hosts_deny Resource
6
6
 
7
7
  Use the `etc_hosts_deny` InSpec audit resource to test rules set to reject daemon and client traffic set in /etc/hosts.deny.
8
8
 
9
+ <br>
10
+
9
11
  ## Syntax
10
12
 
11
13
  An etc/hosts.deny rule specifies one or more daemons mapped to one or more clients,
12
14
  with zero or more options to use to reject traffic when found.
13
15
 
14
- ## Syntax
15
-
16
16
  Use the where clause to match a property to one or more rules in the hosts.deny file.
17
17
 
18
18
  describe etc_hosts_deny.where { daemon == 'value' } do
@@ -33,10 +33,14 @@ where
33
33
  * `client_list` is a list of clients will be rejected to pass traffic in.
34
34
  * `options` is a list of tasks that to be done with the rule when traffic is found.
35
35
 
36
+ <br>
37
+
36
38
  ## Supported Properties
37
39
 
38
40
  'daemon', 'client_list', 'options'
39
41
 
42
+ <br>
43
+
40
44
  ## Property Examples and Return Types
41
45
 
42
46
  ### daemon
@@ -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
25
83
 
26
- This InSpec audit resource has the following matchers:
84
+ ### Test if a file is a block device
27
85
 
28
- ### be
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
29
92
 
30
- <%= partial "/shared/matcher_be" %>
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
166
+
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
176
+
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.
178
+
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
 
@@ -137,7 +308,7 @@ a user:
137
308
 
138
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:
139
310
 
140
- it { should be_setgid }
311
+ it { should be_setgid }
141
312
 
142
313
  ### be_socket
143
314
 
@@ -149,13 +320,13 @@ The `be_socket` matcher tests if the file exists as socket (`.sock`), such as `/
149
320
 
150
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:
151
322
 
152
- it { should be_sticky }
323
+ it { should be_sticky }
153
324
 
154
325
  ### be_setuid
155
326
 
156
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:
157
328
 
158
- it { should be_setuid }
329
+ it { should be_setuid }
159
330
 
160
331
  ### be_symlink
161
332
 
@@ -191,10 +362,6 @@ a user:
191
362
 
192
363
  it { should be_writable.by_user('user') }
193
364
 
194
- ### cmp
195
-
196
- <%= partial "/shared/matcher_cmp" %>
197
-
198
365
  ### content
199
366
 
200
367
  The `content` matcher tests if contents in the file match the value specified in a regular expression. The values of the `content` matcher are arbitrary and depend on the file type being tested and also the type of information that is expected to be in that file:
@@ -209,10 +376,6 @@ The following complete example tests the `pg_hba.conf` file in PostgreSQL for MD
209
376
  its('content') { should match(%r{host\s.*?all\s.*?all\s.*?::1\/128\s.*?md5})
210
377
  end
211
378
 
212
- ### eq
213
-
214
- <%= partial "/shared/matcher_eq" %>
215
-
216
379
  ### exist
217
380
 
218
381
  The `exist` matcher tests if the named file exists:
@@ -237,10 +400,6 @@ The `have_mode` matcher tests if a file has a mode assigned to it:
237
400
 
238
401
  it { should have_mode }
239
402
 
240
- ### include
241
-
242
- <%= partial "/shared/matcher_include" %>
243
-
244
403
  ### link_path
245
404
 
246
405
  The `link_path` matcher tests if the file exists at the specified path. If the file is a symlink,
@@ -248,10 +407,6 @@ InSpec will resolve the symlink and return the ultimate linked file:
248
407
 
249
408
  its('link_path') { should eq '/some/path/to/file' }
250
409
 
251
- ### match
252
-
253
- <%= partial "/shared/matcher_match" %>
254
-
255
410
  ### md5sum
256
411
 
257
412
  The `md5sum` matcher tests if the MD5 checksum for a file matches the specified value:
@@ -266,15 +421,11 @@ The `mode` matcher tests if the mode assigned to the file matches the specified
266
421
 
267
422
  ### mtime
268
423
 
269
- The `mtime` matcher tests if the file modification time for the file matches the specified value:
270
-
271
- its('mtime') { should eq 'October 31 2015 12:10:45' }
272
-
273
- or:
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.
274
425
 
275
- describe file('/').mtime.to_i do
276
- it { should <= Time.now.to_i }
277
- 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 }
278
429
  end
279
430
 
280
431
  ### owner
@@ -317,191 +468,26 @@ Less than:
317
468
 
318
469
  ### type
319
470
 
320
- 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
321
481
 
322
- * `-` or `f` (the file is a file); use `'file` to test for this file type
323
- * `d` (the file is a directory); use `'directory` to test for this file type
324
- * `l` (the file is a symbolic link); use `'link` to test for this file type
325
- * `p` (the file is a named pipe); use `'pipe` to test for this file type
326
- * `s` (the file is a socket); use `'socket` to test for this file type
327
- * `c` (the file is a character device); use `'character` to test for this file type
328
- * `b` (the file is a block device); use `'block` to test for this file type
329
- * `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.
330
484
 
331
485
  For example:
332
486
 
333
- its('type') { should eq 'file' }
487
+ its('type') { should eq :file }
488
+ its('type') { should cmp 'file' }
334
489
 
335
490
  or:
336
491
 
337
- its('type') { should eq 'socket' }
338
-
339
- ## Examples
340
-
341
- The following examples show how to use this InSpec audit resource.
342
-
343
- ### Test the contents of a file for MD5 requirements
344
-
345
- describe file(hba_config_file) do
346
- its('content') { should match /local\s.*?all\s.*?all\s.*?md5/ }
347
- its('content') { should match %r{/host\s.*?all\s.*?all\s.*?127.0.0.1\/32\s.*?md5/} }
348
- its('content') { should match %r{/host\s.*?all\s.*?all\s.*?::1\/128\s.*?md5/} }
349
- end
350
-
351
- ### Test if a file exists
352
-
353
- describe file('/tmp') do
354
- it { should exist }
355
- end
356
-
357
- ### Test that a file does not exist
358
-
359
- describe file('/tmpest') do
360
- it { should_not exist }
361
- end
362
-
363
- ### Test if a path is a directory
364
-
365
- describe file('/tmp') do
366
- its('type') { should eq :directory }
367
- it { should be_directory }
368
- end
369
-
370
- ### Test if a path is a file and not a directory
371
-
372
- describe file('/proc/version') do
373
- its('type') { should eq 'file' }
374
- it { should be_file }
375
- it { should_not be_directory }
376
- end
377
-
378
- ### Test if a file is a symbolic link
379
-
380
- describe file('/dev/stdout') do
381
- its('type') { should eq 'symlink' }
382
- it { should be_symlink }
383
- it { should_not be_file }
384
- it { should_not be_directory }
385
- end
386
-
387
- ### Test if a file is a character device
388
-
389
- describe file('/dev/zero') do
390
- its('type') { should eq 'character' }
391
- it { should be_character_device }
392
- it { should_not be_file }
393
- it { should_not be_directory }
394
- end
395
-
396
- ### Test if a file is a block device
397
-
398
- describe file('/dev/zero') do
399
- its('type') { should eq 'block' }
400
- it { should be_character_device }
401
- it { should_not be_file }
402
- it { should_not be_directory }
403
- end
404
-
405
- ### Test the mode for a file
406
-
407
- describe file('/dev') do
408
- its('mode') { should cmp '00755' }
409
- end
410
-
411
- ### Test the owner of a file
412
-
413
- describe file('/root') do
414
- its('owner') { should eq 'root' }
415
- end
416
-
417
- ### Test if a file is owned by the root user
418
-
419
- describe file('/dev') do
420
- it { should be_owned_by 'root' }
421
- end
422
-
423
- ### Test the mtime for a file
424
-
425
- describe file('/').mtime.to_i do
426
- it { should <= Time.now.to_i }
427
- it { should >= Time.now.to_i - 1000}
428
- end
429
-
430
- ### Test that a file's size is between 64 and 10240
431
-
432
- describe file('/') do
433
- its('size') { should be > 64 }
434
- its('size') { should be < 10240 }
435
- end
436
-
437
- ### Test that a file's size is zero
438
-
439
- describe file('/proc/cpuinfo') do
440
- its('size') { should be 0 }
441
- end
442
-
443
- ### Test that a file is not mounted
444
-
445
- describe file('/proc/cpuinfo') do
446
- it { should_not be_mounted }
447
- end
448
-
449
- ### Test an MD5 checksum
450
-
451
- require 'digest'
452
- cpuinfo = file('/proc/cpuinfo').content
453
-
454
- md5sum = Digest::MD5.hexdigest(cpuinfo)
455
-
456
- describe file('/proc/cpuinfo') do
457
- its('md5sum') { should eq md5sum }
458
- end
459
-
460
- ### Test an SHA-256 checksum
461
-
462
- require 'digest'
463
- cpuinfo = file('/proc/cpuinfo').content
464
-
465
- sha256sum = Digest::SHA256.hexdigest(cpuinfo)
466
-
467
- describe file('/proc/cpuinfo') do
468
- its('sha256sum') { should eq sha256sum }
469
- end
470
-
471
- ### Verify NTP
472
-
473
- 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:
474
-
475
- describe file('/etc/ntp.conf') do
476
- it { should be_file }
477
- end
478
-
479
- describe file('/etc/ntp.leapseconds') do
480
- it { should be_file }
481
- end
482
-
483
- describe command('pgrep ntp') do
484
- its('exit_status') { should eq 0 }
485
- end
486
-
487
- ### Test parameters of symlinked file
488
-
489
- 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.
490
-
491
- For example, for the following symlink:
492
-
493
- lrwxrwxrwx. 1 root root 11 03-10 17:56 /dev/virtio-ports/com.redhat.rhevm.vdsm -> ../vport2p1
494
-
495
- ... you can write controls for both the link and the target.
496
-
497
- describe file('/dev/virtio-ports/com.redhat.rhevm.vdsm') do
498
- it { should be_symlink }
499
- end
500
-
501
- virito_port_vdsm = file('/dev/virtio-ports/com.redhat.rhevm.vdsm').link_path
502
- describe file(virito_port_vdsm) do
503
- it { should exist }
504
- it { should be_character_device }
505
- it { should be_owned_by 'ovirtagent' }
506
- it { should be_grouped_into 'ovirtagent' }
507
- end
492
+ its('type') { should eq :socket }
493
+ its('type') { should cmp 'socket' }