inspec 0.34.1 → 1.0.0

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 (146) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +323 -6
  3. data/Gemfile +10 -0
  4. data/README.md +1 -1
  5. data/Rakefile +4 -55
  6. data/docs/.gitignore +2 -0
  7. data/docs/README.md +40 -0
  8. data/docs/cli.md +342 -0
  9. data/docs/dsl_inspec.md +245 -0
  10. data/docs/dsl_resource.md +93 -0
  11. data/docs/inspec_and_friends.md +105 -0
  12. data/docs/matchers.md +136 -0
  13. data/docs/plugin_kitchen_inspec.html.md +55 -0
  14. data/docs/profiles.md +285 -0
  15. data/docs/resources/apache_conf.md.erb +75 -0
  16. data/docs/resources/apt.md.erb +84 -0
  17. data/docs/resources/audit_policy.md.erb +61 -0
  18. data/docs/resources/auditd_conf.md.erb +79 -0
  19. data/docs/resources/auditd_rules.md.erb +132 -0
  20. data/docs/resources/bash.md.erb +84 -0
  21. data/docs/resources/bond.md.erb +97 -0
  22. data/docs/resources/bridge.md.erb +67 -0
  23. data/docs/resources/bsd_service.md.erb +76 -0
  24. data/docs/resources/command.md.erb +151 -0
  25. data/docs/resources/csv.md.erb +62 -0
  26. data/docs/resources/directory.md.erb +43 -0
  27. data/docs/resources/etc_group.md.erb +116 -0
  28. data/docs/resources/etc_passwd.md.erb +155 -0
  29. data/docs/resources/etc_shadow.md.erb +149 -0
  30. data/docs/resources/file.md.erb +460 -0
  31. data/docs/resources/gem.md.erb +73 -0
  32. data/docs/resources/group.md.erb +74 -0
  33. data/docs/resources/grub_conf.md.erb +115 -0
  34. data/docs/resources/host.md.erb +85 -0
  35. data/docs/resources/iis_site.md.erb +142 -0
  36. data/docs/resources/inetd_conf.md.erb +99 -0
  37. data/docs/resources/ini.md.erb +69 -0
  38. data/docs/resources/interface.md.erb +66 -0
  39. data/docs/resources/iptables.md.erb +70 -0
  40. data/docs/resources/json.md.erb +76 -0
  41. data/docs/resources/kernel_module.md.erb +60 -0
  42. data/docs/resources/kernel_parameter.md.erb +72 -0
  43. data/docs/resources/launchd_service.md.erb +76 -0
  44. data/docs/resources/limits_conf.md.erb +80 -0
  45. data/docs/resources/login_def.md.erb +77 -0
  46. data/docs/resources/mount.md.erb +83 -0
  47. data/docs/resources/mysql_conf.md.erb +102 -0
  48. data/docs/resources/mysql_session.md.erb +63 -0
  49. data/docs/resources/npm.md.erb +75 -0
  50. data/docs/resources/ntp_conf.md.erb +76 -0
  51. data/docs/resources/oneget.md.erb +67 -0
  52. data/docs/resources/os.md.erb +154 -0
  53. data/docs/resources/os_env.md.erb +98 -0
  54. data/docs/resources/package.md.erb +115 -0
  55. data/docs/resources/parse_config.md.erb +122 -0
  56. data/docs/resources/parse_config_file.md.erb +143 -0
  57. data/docs/resources/pip.md.erb +74 -0
  58. data/docs/resources/port.md.erb +150 -0
  59. data/docs/resources/postgres_conf.md.erb +90 -0
  60. data/docs/resources/postgres_session.md.erb +75 -0
  61. data/docs/resources/powershell.md.erb +116 -0
  62. data/docs/resources/process.md.erb +73 -0
  63. data/docs/resources/registry_key.md.erb +149 -0
  64. data/docs/resources/runit_service.md.erb +76 -0
  65. data/docs/resources/security_policy.md.erb +61 -0
  66. data/docs/resources/service.md.erb +135 -0
  67. data/docs/resources/ssh_config.md.erb +94 -0
  68. data/docs/resources/sshd_config.md.erb +97 -0
  69. data/docs/resources/ssl.md.erb +133 -0
  70. data/docs/resources/sys_info.md.erb +55 -0
  71. data/docs/resources/systemd_service.md.erb +76 -0
  72. data/docs/resources/sysv_service.md.erb +76 -0
  73. data/docs/resources/upstart_service.md.erb +76 -0
  74. data/docs/resources/user.md.erb +154 -0
  75. data/docs/resources/users.md.erb +140 -0
  76. data/docs/resources/vbscript.md.erb +69 -0
  77. data/docs/resources/windows_feature.md.erb +61 -0
  78. data/docs/resources/wmi.md.erb +95 -0
  79. data/docs/resources/xinetd_conf.md.erb +170 -0
  80. data/docs/resources/yaml.md.erb +69 -0
  81. data/docs/resources/yum.md.erb +103 -0
  82. data/docs/ruby_usage.md +154 -0
  83. data/docs/shared/matcher_be.md.erb +1 -0
  84. data/docs/shared/matcher_cmp.md.erb +45 -0
  85. data/docs/shared/matcher_eq.md.erb +3 -0
  86. data/docs/shared/matcher_include.md.erb +1 -0
  87. data/docs/shared/matcher_match.md.erb +1 -0
  88. data/docs/shell.md +150 -0
  89. data/examples/meta-profile/inspec.yml +2 -4
  90. data/inspec.gemspec +1 -1
  91. data/lib/bundles/inspec-compliance/api.rb +28 -18
  92. data/lib/bundles/inspec-compliance/cli.rb +19 -27
  93. data/lib/bundles/inspec-compliance/target.rb +15 -2
  94. data/lib/fetchers/git.rb +4 -0
  95. data/lib/fetchers/local.rb +16 -1
  96. data/lib/fetchers/mock.rb +4 -0
  97. data/lib/fetchers/url.rb +46 -20
  98. data/lib/inspec/base_cli.rb +14 -0
  99. data/lib/inspec/cached_fetcher.rb +67 -0
  100. data/lib/inspec/cli.rb +22 -8
  101. data/lib/inspec/control_eval_context.rb +12 -2
  102. data/lib/inspec/dependencies/{vendor_index.rb → cache.rb} +5 -4
  103. data/lib/inspec/dependencies/dependency_set.rb +8 -14
  104. data/lib/inspec/dependencies/lockfile.rb +5 -13
  105. data/lib/inspec/dependencies/requirement.rb +31 -41
  106. data/lib/inspec/dependencies/resolver.rb +3 -3
  107. data/lib/inspec/dsl.rb +16 -4
  108. data/lib/inspec/errors.rb +1 -0
  109. data/lib/inspec/fetcher.rb +25 -1
  110. data/lib/inspec/objects/each_loop.rb +5 -2
  111. data/lib/inspec/objects/test.rb +8 -2
  112. data/lib/inspec/plugins/fetcher.rb +13 -12
  113. data/lib/inspec/plugins/resource.rb +3 -0
  114. data/lib/inspec/profile.rb +62 -26
  115. data/lib/inspec/profile_context.rb +44 -8
  116. data/lib/inspec/resource.rb +18 -3
  117. data/lib/inspec/rspec_json_formatter.rb +91 -40
  118. data/lib/inspec/rule.rb +45 -2
  119. data/lib/inspec/runner.rb +51 -39
  120. data/lib/inspec/shell.rb +5 -16
  121. data/lib/inspec/version.rb +1 -1
  122. data/lib/resources/apache_conf.rb +1 -1
  123. data/lib/resources/gem.rb +1 -0
  124. data/lib/resources/groups.rb +190 -0
  125. data/lib/resources/oneget.rb +1 -0
  126. data/lib/resources/os.rb +1 -1
  127. data/lib/resources/package.rb +3 -1
  128. data/lib/resources/parse_config.rb +18 -1
  129. data/lib/resources/pip.rb +1 -1
  130. data/lib/resources/security_policy.rb +54 -0
  131. data/lib/resources/ssl.rb +9 -11
  132. data/lib/resources/sys_info.rb +1 -1
  133. data/lib/resources/users.rb +81 -64
  134. metadata +91 -17
  135. data/docs/cli.rst +0 -442
  136. data/docs/dsl_inspec.rst +0 -259
  137. data/docs/dsl_resource.rst +0 -90
  138. data/docs/inspec_and_friends.rst +0 -85
  139. data/docs/matchers.rst +0 -137
  140. data/docs/profiles.rst +0 -169
  141. data/docs/readme.rst +0 -105
  142. data/docs/resources.rst +0 -4836
  143. data/docs/ruby_usage.rst +0 -145
  144. data/docs/shell.rst +0 -130
  145. data/docs/template.rst +0 -51
  146. data/lib/resources/group.rb +0 -137
data/docs/cli.md ADDED
@@ -0,0 +1,342 @@
1
+ ---
2
+ title: About the InSpec CLI
3
+ ---
4
+
5
+ # InSpec CLI
6
+
7
+ Use the InSpec CLI to run tests and audits against targets using local, SSH, WinRM, or Docker connections.
8
+
9
+ ## archive
10
+
11
+ Archive a profile to tar.gz (default) or zip
12
+
13
+ ### Syntax
14
+
15
+ This subcommand has the following syntax:
16
+
17
+ ```bash
18
+ $ inspec archive PATH
19
+ ```
20
+
21
+ ### Options
22
+
23
+ This subcommand has additional options:
24
+
25
+ * ``--ignore-errors``, ``--no-ignore-errors``
26
+ Ignore profile warnings.
27
+ * ``-o``, ``--output=OUTPUT``
28
+ Save the archive to a path
29
+ * ``--overwrite``, ``--no-overwrite``
30
+ Overwrite existing archive.
31
+ * ``--profiles-path=PROFILES_PATH``
32
+ Folder which contains referenced profiles.
33
+ * ``--tar``, ``--no-tar``
34
+ Generates a tar.gz archive.
35
+ * ``--zip``, ``--no-zip``
36
+ Generates a zip archive.
37
+
38
+ ## check
39
+
40
+ Verify all tests at the specified path
41
+
42
+ ### Syntax
43
+
44
+ This subcommand has the following syntax:
45
+
46
+ ```bash
47
+ $ inspec check PATH
48
+ ```
49
+
50
+ ### Options
51
+
52
+ This subcommand has additional options:
53
+
54
+ * ``--format=FORMAT``
55
+
56
+ * ``--profiles-path=PROFILES_PATH``
57
+ Folder which contains referenced profiles.
58
+
59
+ ## compliance
60
+
61
+ Chef compliance commands
62
+
63
+ ### Syntax
64
+
65
+ This subcommand has the following syntax:
66
+
67
+ ```bash
68
+ $ inspec compliance SUBCOMMAND ...
69
+ ```
70
+
71
+ ## detect
72
+
73
+ Detect the target os
74
+
75
+ ### Syntax
76
+
77
+ This subcommand has the following syntax:
78
+
79
+ ```bash
80
+ $ inspec detect
81
+ ```
82
+
83
+ ### Options
84
+
85
+ This subcommand has additional options:
86
+
87
+ * ``-b``, ``--backend=BACKEND``
88
+ Choose a backend: local, ssh, winrm, docker.
89
+ * ``--format=FORMAT``
90
+
91
+ * ``--host=HOST``
92
+ Specify a remote host which is tested.
93
+ * ``--json-config=JSON_CONFIG``
94
+ Read configuration from JSON file (`-` reads from stdin).
95
+ * ``-i``, ``--key-files=one two three``
96
+ Login key or certificate file for a remote scan.
97
+ * ``-l``, ``--log-level=LOG_LEVEL``
98
+ Set the log level: info (default), debug, warn, error
99
+ * ``--password=PASSWORD``
100
+ Login password for a remote scan, if required.
101
+ * ``--path=PATH``
102
+ Login path to use when connecting to the target (WinRM).
103
+ * ``-p``, ``--port=N``
104
+ Specify the login port for a remote scan.
105
+ * ``--self-signed``, ``--no-self-signed``
106
+ Allow remote scans with self-signed certificates (WinRM).
107
+ * ``--ssl``, ``--no-ssl``
108
+ Use SSL for transport layer encryption (WinRM).
109
+ * ``--sudo``, ``--no-sudo``
110
+ Run scans with sudo. Only activates on Unix and non-root user.
111
+ * ``--sudo-command=SUDO_COMMAND``
112
+ Alternate command for sudo.
113
+ * ``--sudo-options=SUDO_OPTIONS``
114
+ Additional sudo options for a remote scan.
115
+ * ``--sudo-password=SUDO_PASSWORD``
116
+ Specify a sudo password, if it is required.
117
+ * ``-t``, ``--target=TARGET``
118
+ Simple targeting option using URIs, e.g. ssh://user:pass@host:port
119
+ * ``--user=USER``
120
+ The login user for a remote scan.
121
+
122
+ ## env
123
+
124
+ Output shell-appropriate completion configuration
125
+
126
+ ### Syntax
127
+
128
+ This subcommand has the following syntax:
129
+
130
+ ```bash
131
+ $ inspec env
132
+ ```
133
+
134
+ ## exec
135
+
136
+ Run all test files at the specified path.
137
+
138
+ ### Syntax
139
+
140
+ This subcommand has the following syntax:
141
+
142
+ ```bash
143
+ $ inspec exec PATHS
144
+ ```
145
+
146
+ ### Options
147
+
148
+ This subcommand has additional options:
149
+
150
+ * ``--attrs=one two three``
151
+ Load attributes file (experimental)
152
+ * ``-b``, ``--backend=BACKEND``
153
+ Choose a backend: local, ssh, winrm, docker.
154
+ * ``--cache=CACHE``
155
+ Use the given path for caching dependencies. (default: ~/.inspec/cache)
156
+ * ``--color``, ``--no-color``
157
+ Use colors in output.
158
+ * ``--controls=one two three``
159
+ A list of controls to run. Ignore all other tests.
160
+ * ``--create-lockfile``, ``--no-create-lockfile``
161
+ Write out a lockfile based on this execution (unless one already exists)
162
+ * ``--format=FORMAT``
163
+ Which formatter to use: cli, progress, documentation, json, json-min
164
+ * ``--host=HOST``
165
+ Specify a remote host which is tested.
166
+ * ``--json-config=JSON_CONFIG``
167
+ Read configuration from JSON file (`-` reads from stdin).
168
+ * ``-i``, ``--key-files=one two three``
169
+ Login key or certificate file for a remote scan.
170
+ * ``-l``, ``--log-level=LOG_LEVEL``
171
+ Set the log level: info (default), debug, warn, error
172
+ * ``--password=PASSWORD``
173
+ Login password for a remote scan, if required.
174
+ * ``--path=PATH``
175
+ Login path to use when connecting to the target (WinRM).
176
+ * ``-p``, ``--port=N``
177
+ Specify the login port for a remote scan.
178
+ * ``--profiles-path=PROFILES_PATH``
179
+ Folder which contains referenced profiles.
180
+ * ``--self-signed``, ``--no-self-signed``
181
+ Allow remote scans with self-signed certificates (WinRM).
182
+ * ``--ssl``, ``--no-ssl``
183
+ Use SSL for transport layer encryption (WinRM).
184
+ * ``--sudo``, ``--no-sudo``
185
+ Run scans with sudo. Only activates on Unix and non-root user.
186
+ * ``--sudo-command=SUDO_COMMAND``
187
+ Alternate command for sudo.
188
+ * ``--sudo-options=SUDO_OPTIONS``
189
+ Additional sudo options for a remote scan.
190
+ * ``--sudo-password=SUDO_PASSWORD``
191
+ Specify a sudo password, if it is required.
192
+ * ``-t``, ``--target=TARGET``
193
+ Simple targeting option using URIs, e.g. ssh://user:pass@host:port
194
+ * ``--user=USER``
195
+ The login user for a remote scan.
196
+
197
+ ## help
198
+
199
+ Describe available commands or one specific command
200
+
201
+ ### Syntax
202
+
203
+ This subcommand has the following syntax:
204
+
205
+ ```bash
206
+ $ inspec help [COMMAND]
207
+ ```
208
+
209
+ ## init
210
+
211
+ Scaffolds a new project
212
+
213
+ ### Syntax
214
+
215
+ This subcommand has the following syntax:
216
+
217
+ ```bash
218
+ $ inspec init TEMPLATE ...
219
+ ```
220
+
221
+ ## json
222
+
223
+ Read all tests in path and generate a json summary
224
+
225
+ ### Syntax
226
+
227
+ This subcommand has the following syntax:
228
+
229
+ ```bash
230
+ $ inspec json PATH
231
+ ```
232
+
233
+ ### Options
234
+
235
+ This subcommand has additional options:
236
+
237
+ * ``--controls=one two three``
238
+ A list of controls to include. Ignore all other tests.
239
+ * ``-o``, ``--output=OUTPUT``
240
+ Save the created profile to a path
241
+ * ``--profiles-path=PROFILES_PATH``
242
+ Folder which contains referenced profiles.
243
+
244
+ ## msccm
245
+
246
+ Microsoft systems center configuration manager commands
247
+
248
+ ### Syntax
249
+
250
+ This subcommand has the following syntax:
251
+
252
+ ```bash
253
+ $ inspec msccm SUBCOMMAND ...
254
+ ```
255
+
256
+ ## shell
257
+
258
+ Open an interactive debugging shell
259
+
260
+ ### Syntax
261
+
262
+ This subcommand has the following syntax:
263
+
264
+ ```bash
265
+ $ inspec shell
266
+ ```
267
+
268
+ ### Options
269
+
270
+ This subcommand has additional options:
271
+
272
+ * ``-b``, ``--backend=BACKEND``
273
+ Choose a backend: local, ssh, winrm, docker.
274
+ * ``-c``, ``--command=COMMAND``
275
+ A single command string to run instead of launching the shell
276
+ * ``--host=HOST``
277
+ Specify a remote host which is tested.
278
+ * ``--json-config=JSON_CONFIG``
279
+ Read configuration from JSON file (`-` reads from stdin).
280
+ * ``-i``, ``--key-files=one two three``
281
+ Login key or certificate file for a remote scan.
282
+ * ``-l``, ``--log-level=LOG_LEVEL``
283
+ Set the log level: info (default), debug, warn, error
284
+ * ``--password=PASSWORD``
285
+ Login password for a remote scan, if required.
286
+ * ``--path=PATH``
287
+ Login path to use when connecting to the target (WinRM).
288
+ * ``-p``, ``--port=N``
289
+ Specify the login port for a remote scan.
290
+ * ``--self-signed``, ``--no-self-signed``
291
+ Allow remote scans with self-signed certificates (WinRM).
292
+ * ``--ssl``, ``--no-ssl``
293
+ Use SSL for transport layer encryption (WinRM).
294
+ * ``--sudo``, ``--no-sudo``
295
+ Run scans with sudo. Only activates on Unix and non-root user.
296
+ * ``--sudo-command=SUDO_COMMAND``
297
+ Alternate command for sudo.
298
+ * ``--sudo-options=SUDO_OPTIONS``
299
+ Additional sudo options for a remote scan.
300
+ * ``--sudo-password=SUDO_PASSWORD``
301
+ Specify a sudo password, if it is required.
302
+ * ``-t``, ``--target=TARGET``
303
+ Simple targeting option using URIs, e.g. ssh://user:pass@host:port
304
+ * ``--user=USER``
305
+ The login user for a remote scan.
306
+
307
+ ## supermarket
308
+
309
+ Supermarket commands
310
+
311
+ ### Syntax
312
+
313
+ This subcommand has the following syntax:
314
+
315
+ ```bash
316
+ $ inspec supermarket SUBCOMMAND ...
317
+ ```
318
+
319
+ ## vendor
320
+
321
+ Download all dependencies and generate a lockfile
322
+
323
+ ### Syntax
324
+
325
+ This subcommand has the following syntax:
326
+
327
+ ```bash
328
+ $ inspec vendor
329
+ ```
330
+
331
+ ## version
332
+
333
+ Prints the version of this tool
334
+
335
+ ### Syntax
336
+
337
+ This subcommand has the following syntax:
338
+
339
+ ```bash
340
+ $ inspec version
341
+ ```
342
+
@@ -0,0 +1,245 @@
1
+ ---
2
+ title: InSpec DSL
3
+ ---
4
+
5
+ # InSpec DSL
6
+
7
+ InSpec is a run-time framework and rule language used to specify compliance, security, and policy requirements. It includes a collection of resources that help you write auditing controls quickly and easily. The syntax used by both open source and |chef compliance| auditing is the same. The open source |inspec resource| framework is compatible with |chef compliance|.
8
+
9
+ The InSpec DSL is a Ruby DSL for writing audit controls, which includes audit resources that you can invoke.
10
+
11
+ The following sections describe the syntax and show some simple examples of using the InSpec resources.
12
+
13
+ ## Syntax
14
+
15
+ The following resource tests |ssh| server configuration. For example, a simple control may described as:
16
+
17
+ ```ruby
18
+ describe sshd_config do
19
+ its('Port') { should eq('22') }
20
+ end
21
+ ```
22
+
23
+ In various use cases like implementing IT compliance across different departments, it becomes handy to extend the control with metadata. Each control may define an additional ``impact``, ``title`` or ``desc``. An example looks like:
24
+
25
+ ```ruby
26
+ control 'sshd-8' do
27
+ impact 0.6
28
+ title 'Server: Configure the service port'
29
+ desc '
30
+ Always specify which port the SSH server should listen to.
31
+ Prevent unexpected settings.
32
+ '
33
+ tag 'ssh','sshd','openssh-server'
34
+ tag cce: 'CCE-27072-8'
35
+ ref 'NSA-RH6-STIG - Section 3.5.2.1', url: 'https://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf'
36
+
37
+ describe sshd_config do
38
+ its('Port') { should eq('22') }
39
+ end
40
+ end
41
+ ```
42
+
43
+ where
44
+
45
+ * `'sshd-8'` is the name of the control
46
+ * `impact`, `title`, and `desc` define metadata that fully describes the importance of the control, its purpose, with a succinct and complete description
47
+ * `impact` is an float that measures the importance of the compliance results and must be a value between `0.0` and `1.0`.
48
+ * `tag` is optional meta-information with with key or key-value pairs
49
+ * `ref` is a reference to an external document
50
+ * `describe` is a block that contains at least one test. A `control` block must contain at least one `describe` block, but may contain as many as required
51
+ * `sshd_config` is an InSpec resource. For the full list of InSpec resources, see InSpec resource documentation
52
+ * `its('Port')` is the matcher; `{ should eq('22') }` is the test. A `describe` block must contain at least one matcher, but may contain as many as required
53
+
54
+
55
+ ## Advanced concepts
56
+
57
+ With inspec it is possible to check if at least one of a collection of checks is true. For example: If a setting is configured in two different locations, you may want to test if either configuration A or configuration B have been set. This is accomplished via `describe.one`. It defines a block of tests with at least one valid check.
58
+
59
+ ```ruby
60
+ describe.one do
61
+ describe ConfigurationA do
62
+ its('setting_1') { should eq true }
63
+ end
64
+
65
+ describe ConfigurationB do
66
+ its('setting_2') { should eq true }
67
+ end
68
+ end
69
+ ```
70
+
71
+ ## Examples
72
+
73
+ The following examples show simple compliance tests using a single `control` block.
74
+
75
+ ## Test System Event Log
76
+
77
+ The following test shows how to audit machines running Windows 2012 R2 that pwassword complexity is enabled:
78
+
79
+ ```ruby
80
+ control 'windows-account-102' do
81
+ impact 1.0
82
+ title 'Windows Password Complexity is Enabled'
83
+ desc 'Password must meet complexity requirement'
84
+ describe security_policy do
85
+ its('PasswordComplexity') { should eq 1 }
86
+ end
87
+ end
88
+ ```
89
+
90
+ ## Are PosgtreSQL passwords empty?
91
+
92
+ The following test shows how to audit machines running PostgerSQL to ensure that passwords are not empty.
93
+
94
+ ```ruby
95
+ control 'postgres-7' do
96
+ impact 1.0
97
+ title 'Don't allow empty passwords'
98
+ describe postgres_session('user', 'pass').query("SELECT * FROM pg_shadow WHERE passwd IS NULL;") do
99
+ its('output') { should eq('') }
100
+ end
101
+ end
102
+ ```
103
+
104
+ ## Are MySQL passwords in ENV?
105
+
106
+ The following test shows how to audit machines running MySQL to ensure that passwords are not stored in `ENV`:
107
+
108
+ ```ruby
109
+ control 'mysql-3' do
110
+ impact 1.0
111
+ title 'Do not store your MySQL password in your ENV'
112
+ desc '
113
+ Storing credentials in your ENV may easily expose
114
+ them to an attacker. Prevent this at all costs.
115
+ '
116
+ describe command('env') do
117
+ its('stdout') { should_not match(/^MYSQL_PWD=/) }
118
+ end
119
+ end
120
+ ```
121
+
122
+ ## Is `/etc/ssh` a Directory?
123
+
124
+ The following test shows how to audit machines to ensure that `/etc/ssh` is a directory:
125
+
126
+ ```ruby
127
+ control 'basic-1' do
128
+ impact 1.0
129
+ title '/etc/ssh should be a directory'
130
+ desc '
131
+ In order for OpenSSH to function correctly, its
132
+ configuration path must be a folder.
133
+ '
134
+ describe file('/etc/ssh') do
135
+ it { should be_directory }
136
+ end
137
+ end
138
+ ```
139
+
140
+ ## Is Apache running?
141
+
142
+ The following test shows how to audit machines to ensure that Apache is enabled and running:
143
+
144
+ ```ruby
145
+ control 'apache-1' do
146
+ impact 0.3
147
+ title 'Apache2 should be configured and running'
148
+ describe service(apache.service) do
149
+ it { should be_enabled }
150
+ it { should be_running }
151
+ end
152
+ end
153
+ ```
154
+
155
+ ## Are insecure packages installed ?
156
+
157
+ The following test shows how to audit machines for insecure packages:
158
+
159
+ ```ruby
160
+ control 'cis-os-services-5.1.3' do
161
+ impact 0.7
162
+ title '5.1.3 Ensure rsh client is not installed'
163
+
164
+ describe package('rsh') do
165
+ it { should_not be_installed }
166
+ end
167
+
168
+ describe package('rsh-redone-client') do
169
+ it { should_not be_installed }
170
+ end
171
+ end
172
+ ```
173
+
174
+ ## Test Windows Registry Keys
175
+
176
+ The following test shows how to audit machines to ensure Safe DLL Seach Mode is enabled:
177
+
178
+ ```ruby
179
+ control 'windows-base-101' do
180
+ impact 1.0
181
+ title 'Safe DLL Search Mode is Enabled'
182
+ desc '
183
+ @link: https://msdn.microsoft.com/en-us/library/ms682586(v=vs.85).aspx
184
+ '
185
+ describe registry_key('HKLM\\System\\CurrentControlSet\\Control\\Session Manager') do
186
+ it { should exist }
187
+ it { should_not have_property_value('SafeDllSearchMode', :type_dword, '0') }
188
+ end
189
+ end
190
+ ```
191
+
192
+ ## Exclude specific test
193
+
194
+ This shows how to allow skipping certain tests if conditions are not met, by using `only_if`.
195
+ In this example the test will not be performed if `redis-cli` command does not exist, because for example package on remote host was not installed.
196
+
197
+ ```ruby
198
+ control 'nutcracker-connect-redis-001' do
199
+ impact 1.0
200
+ title 'Check if nutcracker can pass commands to redis'
201
+ desc 'execute redis-cli set key command, to check connectivity of the service'
202
+
203
+ only_if do
204
+ command('redis-cli').exist?
205
+ end
206
+
207
+ describe command('redis-cli SET test_inspec "HELLO"') do
208
+ its(:stdout) { should match(/OK/) }
209
+ end
210
+ end
211
+ ```
212
+
213
+ Mixing this with other conditionals (like checking existence of the files etc.) can help to test different test paths using inspec. This way you can skip certain tests which would 100% fail due to the way servers are prepared, but you know that the same test suites are reused later in different circumstances by different teams.
214
+
215
+ ## Additional metadata for controls
216
+
217
+
218
+ The following example illustrates various ways to add tags and references to `control`
219
+
220
+ ```ruby
221
+ control 'ssh-1' do
222
+ impact 1.0
223
+
224
+ title 'Allow only SSH Protocol 2'
225
+ desc 'Only SSH protocol version 2 connections should be permitted.
226
+ The default setting in /etc/ssh/sshd_config is correct, and can be
227
+ verified by ensuring that the following line appears: Protocol 2'
228
+
229
+ tag 'production','development'
230
+ tag 'ssh','sshd','openssh-server'
231
+
232
+ tag cce: 'CCE-27072-8'
233
+ tag disa: 'RHEL-06-000227'
234
+
235
+ tag remediation: 'stig_rhel6/recipes/sshd-config.rb'
236
+ tag remediation: 'https://supermarket.chef.io/cookbooks/ssh-hardening'
237
+
238
+ ref 'NSA-RH6-STIG - Section 3.5.2.1', url: 'https://www.nsa.gov/ia/_files/os/redhat/rhel5-guide-i731.pdf'
239
+ ref 'http://people.redhat.com/swells/scap-security-guide/RHEL/6/output/ssg-centos6-guide-C2S.html'
240
+
241
+ describe ssh_config do
242
+ its ('Protocol') { should eq '2'}
243
+ end
244
+ end
245
+ ```
@@ -0,0 +1,93 @@
1
+ ---
2
+ title: Resource DSL
3
+ ---
4
+
5
+ # Resource DSL
6
+
7
+ InSpec provides a mechanism for defining custom resources. These become
8
+ available with their respective names and provide easy functionality to
9
+ profiles.
10
+
11
+ ## Resource location
12
+
13
+ Resources may be added to profiles in the libraries folder:
14
+
15
+ ```bash
16
+ $ tree examples/profile
17
+ examples/profile
18
+ ...
19
+ ├── libraries
20
+ │   └── gordon_config.rb
21
+ ```
22
+
23
+ ## Resource structure
24
+
25
+ The smallest possible resource takes this form:
26
+
27
+ ```ruby
28
+ class Tiny < Inspec.resource(1)
29
+ name 'tiny'
30
+ end
31
+ ```
32
+
33
+ Resources are written as a regular Ruby class which inherits from
34
+ Inspec.resource. The number (1) specifies the version this resource
35
+ plugin targets. As InSpec evolves, this interface may change and may
36
+ require a higher version.
37
+
38
+ The following attributes can be configured:
39
+
40
+ * name - Identifier of the resource (required)
41
+ * desc - Description of the resource (optional)
42
+ * example - Example usage of the resource (optional)
43
+
44
+ The following methods are available to the resource:
45
+
46
+ * inspec - Contains a registry of all other resources to interact with the operating system or target in general.
47
+ * skip\_resource - A resource may call this method to indicate, that requirements aren't met. All tests that use this resource will be marked as skipped.
48
+
49
+ The following example shows a full resource using attributes and methods
50
+ to provide simple access to a configuration file:
51
+
52
+ ```ruby
53
+ class GordonConfig < Inspec.resource(1)
54
+ name 'gordon_config'
55
+
56
+ desc '
57
+ Resource description ...
58
+ '
59
+
60
+ example '
61
+ describe gordon_config do
62
+ its("signal") { should eq "on" }
63
+ end
64
+ '
65
+
66
+ # Load the configuration file on initialization
67
+ def initialize(path = nil)
68
+ @path = path || '/etc/gordon.conf'
69
+ @params = SimpleConfig.new( read_content )
70
+ end
71
+
72
+ # Expose all parameters of the configuration file.
73
+ def method_missing(name)
74
+ @params[name]
75
+ end
76
+
77
+ private
78
+
79
+ def read_content
80
+ f = inspec.file(@path)
81
+ # Test if the path exist and that it's a file
82
+ if f.file?
83
+ # Retrieve the file's contents
84
+ f.content
85
+ else
86
+ # If the file doesn't exist, skip all tests that use gordon_config
87
+ skip_resource "Can't read config from #{@path}."
88
+ end
89
+ end
90
+ end
91
+ ```
92
+
93
+ For a full example, see our [example resource](../examples/profile/libraries/gordon_config.rb).