inspec 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (247) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +8 -0
  3. data/.rubocop.yml +65 -0
  4. data/.travis.yml +23 -0
  5. data/CHANGELOG.md +38 -0
  6. data/Gemfile +33 -0
  7. data/LICENSE +201 -0
  8. data/MAINTAINERS.md +28 -0
  9. data/MAINTAINERS.toml +42 -0
  10. data/README.md +257 -0
  11. data/Rakefile +47 -0
  12. data/bin/inspec +109 -0
  13. data/docs/ctl_inspec.rst +195 -0
  14. data/docs/dsl_inspec.rst +182 -0
  15. data/docs/readme.rst +100 -0
  16. data/docs/resources.rst +4319 -0
  17. data/docs/template.rst +51 -0
  18. data/examples/test-kitchen/.kitchen.yml +20 -0
  19. data/examples/test-kitchen/Berksfile +3 -0
  20. data/examples/test-kitchen/Gemfile +21 -0
  21. data/examples/test-kitchen/README.md +27 -0
  22. data/examples/test-kitchen/metadata.rb +7 -0
  23. data/examples/test-kitchen/recipes/default.rb +6 -0
  24. data/examples/test-kitchen/recipes/nginx.rb +30 -0
  25. data/examples/test-kitchen/test/integration/default/web_spec.rb +28 -0
  26. data/inspec.gemspec +30 -0
  27. data/lib/inspec.rb +20 -0
  28. data/lib/inspec/backend.rb +42 -0
  29. data/lib/inspec/dsl.rb +151 -0
  30. data/lib/inspec/log.rb +34 -0
  31. data/lib/inspec/metadata.rb +79 -0
  32. data/lib/inspec/plugins.rb +9 -0
  33. data/lib/inspec/plugins/resource.rb +62 -0
  34. data/lib/inspec/profile.rb +138 -0
  35. data/lib/inspec/profile_context.rb +170 -0
  36. data/lib/inspec/resource.rb +76 -0
  37. data/lib/inspec/rspec_json_formatter.rb +27 -0
  38. data/lib/inspec/rule.rb +170 -0
  39. data/lib/inspec/runner.rb +154 -0
  40. data/lib/inspec/shell.rb +66 -0
  41. data/lib/inspec/targets.rb +9 -0
  42. data/lib/inspec/targets/core.rb +27 -0
  43. data/lib/inspec/targets/dir.rb +67 -0
  44. data/lib/inspec/targets/file.rb +29 -0
  45. data/lib/inspec/targets/folder.rb +43 -0
  46. data/lib/inspec/targets/tar.rb +34 -0
  47. data/lib/inspec/targets/url.rb +39 -0
  48. data/lib/inspec/targets/zip.rb +47 -0
  49. data/lib/inspec/version.rb +7 -0
  50. data/lib/matchers/matchers.rb +221 -0
  51. data/lib/resources/apache.rb +29 -0
  52. data/lib/resources/apache_conf.rb +113 -0
  53. data/lib/resources/apt.rb +140 -0
  54. data/lib/resources/audit_policy.rb +63 -0
  55. data/lib/resources/auditd_conf.rb +56 -0
  56. data/lib/resources/auditd_rules.rb +53 -0
  57. data/lib/resources/bond.rb +65 -0
  58. data/lib/resources/bridge.rb +114 -0
  59. data/lib/resources/command.rb +57 -0
  60. data/lib/resources/csv.rb +32 -0
  61. data/lib/resources/directory.rb +15 -0
  62. data/lib/resources/etc_group.rb +150 -0
  63. data/lib/resources/file.rb +110 -0
  64. data/lib/resources/gem.rb +46 -0
  65. data/lib/resources/group.rb +132 -0
  66. data/lib/resources/host.rb +143 -0
  67. data/lib/resources/inetd_conf.rb +56 -0
  68. data/lib/resources/interface.rb +127 -0
  69. data/lib/resources/iptables.rb +65 -0
  70. data/lib/resources/json.rb +64 -0
  71. data/lib/resources/kernel_module.rb +40 -0
  72. data/lib/resources/kernel_parameter.rb +55 -0
  73. data/lib/resources/limits_conf.rb +55 -0
  74. data/lib/resources/login_def.rb +60 -0
  75. data/lib/resources/mysql.rb +81 -0
  76. data/lib/resources/mysql_conf.rb +116 -0
  77. data/lib/resources/mysql_session.rb +52 -0
  78. data/lib/resources/npm.rb +44 -0
  79. data/lib/resources/ntp_conf.rb +58 -0
  80. data/lib/resources/oneget.rb +63 -0
  81. data/lib/resources/os.rb +22 -0
  82. data/lib/resources/os_env.rb +34 -0
  83. data/lib/resources/package.rb +169 -0
  84. data/lib/resources/parse_config.rb +75 -0
  85. data/lib/resources/passwd.rb +93 -0
  86. data/lib/resources/pip.rb +75 -0
  87. data/lib/resources/port.rb +296 -0
  88. data/lib/resources/postgres.rb +37 -0
  89. data/lib/resources/postgres_conf.rb +87 -0
  90. data/lib/resources/postgres_session.rb +59 -0
  91. data/lib/resources/processes.rb +57 -0
  92. data/lib/resources/registry_key.rb +54 -0
  93. data/lib/resources/script.rb +34 -0
  94. data/lib/resources/security_policy.rb +73 -0
  95. data/lib/resources/service.rb +379 -0
  96. data/lib/resources/ssh_conf.rb +75 -0
  97. data/lib/resources/user.rb +374 -0
  98. data/lib/resources/windows_feature.rb +77 -0
  99. data/lib/resources/yaml.rb +23 -0
  100. data/lib/resources/yum.rb +154 -0
  101. data/lib/utils/convert.rb +12 -0
  102. data/lib/utils/detect.rb +15 -0
  103. data/lib/utils/find_files.rb +36 -0
  104. data/lib/utils/hash.rb +13 -0
  105. data/lib/utils/modulator.rb +12 -0
  106. data/lib/utils/parser.rb +61 -0
  107. data/lib/utils/simpleconfig.rb +115 -0
  108. data/tasks/maintainers.rb +213 -0
  109. data/test/docker_run.rb +156 -0
  110. data/test/docker_test.rb +51 -0
  111. data/test/helper.rb +200 -0
  112. data/test/integration/.kitchen.yml +42 -0
  113. data/test/integration/Berksfile +4 -0
  114. data/test/integration/cookbooks/os_prepare/metadata.rb +8 -0
  115. data/test/integration/cookbooks/os_prepare/recipes/apt.rb +20 -0
  116. data/test/integration/cookbooks/os_prepare/recipes/default.rb +9 -0
  117. data/test/integration/cookbooks/os_prepare/recipes/file.rb +21 -0
  118. data/test/integration/cookbooks/os_prepare/recipes/package.rb +26 -0
  119. data/test/integration/default/_debug_spec.rb +1 -0
  120. data/test/integration/default/apt_spec.rb +42 -0
  121. data/test/integration/default/file_spec.rb +109 -0
  122. data/test/integration/default/group_spec.rb +32 -0
  123. data/test/integration/default/kernel_module_spec.rb +17 -0
  124. data/test/integration/default/kernel_parameter_spec.rb +56 -0
  125. data/test/integration/default/package_spec.rb +11 -0
  126. data/test/integration/default/service_spec.rb +28 -0
  127. data/test/integration/default/user_spec.rb +44 -0
  128. data/test/resource/command_test.rb +33 -0
  129. data/test/resource/dsl_test.rb +45 -0
  130. data/test/resource/file_test.rb +130 -0
  131. data/test/resource/ssh_config.rb +9 -0
  132. data/test/resource/sshd_config.rb +9 -0
  133. data/test/test-extra.yaml +11 -0
  134. data/test/test.yaml +11 -0
  135. data/test/unit/mock/cmd/Get-NetAdapter +24 -0
  136. data/test/unit/mock/cmd/GetUserAccount +33 -0
  137. data/test/unit/mock/cmd/GetWin32Group +23 -0
  138. data/test/unit/mock/cmd/PATH +1 -0
  139. data/test/unit/mock/cmd/Resolve-DnsName +26 -0
  140. data/test/unit/mock/cmd/Test-NetConnection +4 -0
  141. data/test/unit/mock/cmd/auditctl +7 -0
  142. data/test/unit/mock/cmd/auditpol +2 -0
  143. data/test/unit/mock/cmd/brew-info-jq +1 -0
  144. data/test/unit/mock/cmd/chage-l-root +7 -0
  145. data/test/unit/mock/cmd/dpkg-s-curl +21 -0
  146. data/test/unit/mock/cmd/dscl +5 -0
  147. data/test/unit/mock/cmd/etc-apt +7 -0
  148. data/test/unit/mock/cmd/find-etc-rc-d-name-S +12 -0
  149. data/test/unit/mock/cmd/find-net-interface +9 -0
  150. data/test/unit/mock/cmd/gem-list-local-a-q-rubocop +1 -0
  151. data/test/unit/mock/cmd/get-net-tcpconnection +24 -0
  152. data/test/unit/mock/cmd/get-netadapter-binding-bridge +4 -0
  153. data/test/unit/mock/cmd/get-package-firefox +30 -0
  154. data/test/unit/mock/cmd/get-package-ruby +18 -0
  155. data/test/unit/mock/cmd/get-service-dhcp +10 -0
  156. data/test/unit/mock/cmd/get-windows-feature +7 -0
  157. data/test/unit/mock/cmd/getent-hosts-example.com +1 -0
  158. data/test/unit/mock/cmd/getent-passwd-root +1 -0
  159. data/test/unit/mock/cmd/id-chartmann +1 -0
  160. data/test/unit/mock/cmd/id-root +1 -0
  161. data/test/unit/mock/cmd/initctl-show-config-ssh +3 -0
  162. data/test/unit/mock/cmd/initctl-status-ssh +1 -0
  163. data/test/unit/mock/cmd/iptables-s +6 -0
  164. data/test/unit/mock/cmd/launchctl-list +3 -0
  165. data/test/unit/mock/cmd/ls-1-etc-init.d +2 -0
  166. data/test/unit/mock/cmd/ls-sys-class-net-br +2 -0
  167. data/test/unit/mock/cmd/lsmod +2 -0
  168. data/test/unit/mock/cmd/lsof-np-itcp +4 -0
  169. data/test/unit/mock/cmd/netstat-tulpen +5 -0
  170. data/test/unit/mock/cmd/npm-ls-g--json-bower +9 -0
  171. data/test/unit/mock/cmd/pacman-qi-curl +21 -0
  172. data/test/unit/mock/cmd/ping-example.com +6 -0
  173. data/test/unit/mock/cmd/pip-show-jinja2 +11 -0
  174. data/test/unit/mock/cmd/ps-aux +3 -0
  175. data/test/unit/mock/cmd/pw-usershow-root-7 +1 -0
  176. data/test/unit/mock/cmd/reg_schedule +1 -0
  177. data/test/unit/mock/cmd/rpm-qia-curl +24 -0
  178. data/test/unit/mock/cmd/sbin_sysctl +1 -0
  179. data/test/unit/mock/cmd/secedit-export +7 -0
  180. data/test/unit/mock/cmd/service-e +2 -0
  181. data/test/unit/mock/cmd/service-sendmail-onestatus +3 -0
  182. data/test/unit/mock/cmd/service-sshd-status +1 -0
  183. data/test/unit/mock/cmd/sockstat +5 -0
  184. data/test/unit/mock/cmd/success +0 -0
  185. data/test/unit/mock/cmd/systemctl-show-all-sshd +6 -0
  186. data/test/unit/mock/cmd/win32_product +8 -0
  187. data/test/unit/mock/cmd/yum-repolist-all +52 -0
  188. data/test/unit/mock/files/auditd.conf +4 -0
  189. data/test/unit/mock/files/bond0 +37 -0
  190. data/test/unit/mock/files/etcgroup +3 -0
  191. data/test/unit/mock/files/example.csv +6 -0
  192. data/test/unit/mock/files/inetd.conf +2 -0
  193. data/test/unit/mock/files/kitchen.yml +7 -0
  194. data/test/unit/mock/files/limits.conf +5 -0
  195. data/test/unit/mock/files/login.defs +5 -0
  196. data/test/unit/mock/files/mysql.conf +8 -0
  197. data/test/unit/mock/files/mysql2.conf +2 -0
  198. data/test/unit/mock/files/ntp.conf +5 -0
  199. data/test/unit/mock/files/passwd +2 -0
  200. data/test/unit/mock/files/policyfile.lock.json +12 -0
  201. data/test/unit/mock/files/ssh_config +5 -0
  202. data/test/unit/mock/files/sshd_config +7 -0
  203. data/test/unit/mock/profiles/empty/metadata.rb +0 -0
  204. data/test/unit/mock/profiles/metadata/metadata.rb +1 -0
  205. data/test/unit/profile_context_test.rb +140 -0
  206. data/test/unit/profile_test.rb +49 -0
  207. data/test/unit/resources/apt_test.rb +46 -0
  208. data/test/unit/resources/audit_policy_test.rb +13 -0
  209. data/test/unit/resources/auditd_conf_test.rb +15 -0
  210. data/test/unit/resources/auditd_rules_test.rb +21 -0
  211. data/test/unit/resources/bond_test.rb +24 -0
  212. data/test/unit/resources/bridge_test.rb +56 -0
  213. data/test/unit/resources/csv_test.rb +35 -0
  214. data/test/unit/resources/etc_group_test.rb +37 -0
  215. data/test/unit/resources/gem_test.rb +20 -0
  216. data/test/unit/resources/group_test.rb +96 -0
  217. data/test/unit/resources/host_test.rb +38 -0
  218. data/test/unit/resources/inetd_conf_test.rb +15 -0
  219. data/test/unit/resources/interface_test.rb +54 -0
  220. data/test/unit/resources/iptables_test.rb +30 -0
  221. data/test/unit/resources/json_test.rb +36 -0
  222. data/test/unit/resources/kernel_module_test.rb +23 -0
  223. data/test/unit/resources/kernel_parameter_test.rb +13 -0
  224. data/test/unit/resources/limits_conf_test.rb +14 -0
  225. data/test/unit/resources/login_def_test.rb +16 -0
  226. data/test/unit/resources/mysql_conf_test.rb +14 -0
  227. data/test/unit/resources/npm_test.rb +20 -0
  228. data/test/unit/resources/ntp_conf_test.rb +16 -0
  229. data/test/unit/resources/oneget_test.rb +45 -0
  230. data/test/unit/resources/os_env_test.rb +13 -0
  231. data/test/unit/resources/package_test.rb +51 -0
  232. data/test/unit/resources/passwd_test.rb +24 -0
  233. data/test/unit/resources/pip_test.rb +15 -0
  234. data/test/unit/resources/port_test.rb +46 -0
  235. data/test/unit/resources/processes_test.rb +32 -0
  236. data/test/unit/resources/registry_key_test.rb +19 -0
  237. data/test/unit/resources/script_test.rb +19 -0
  238. data/test/unit/resources/security_policy_test.rb +16 -0
  239. data/test/unit/resources/service_test.rb +116 -0
  240. data/test/unit/resources/ssh_conf_test.rb +33 -0
  241. data/test/unit/resources/user_test.rb +93 -0
  242. data/test/unit/resources/windows_feature.rb +17 -0
  243. data/test/unit/resources/yaml_test.rb +34 -0
  244. data/test/unit/resources/yum_test.rb +68 -0
  245. data/test/unit/simpleconfig_test.rb +80 -0
  246. data/test/unit/utils/content_parser_test.rb +30 -0
  247. metadata +555 -0
data/README.md ADDED
@@ -0,0 +1,257 @@
1
+ # InSpec
2
+
3
+ ## What is InSpec?
4
+
5
+ InSpec is an open-source testing framework for infrastructure with an easy language for specifying compliance, security, and policy requirements. The project name stands for "infrastructure specification" and can be thought of as an abbreviation of "inspect".
6
+
7
+ You can use InSpec to examine any node in your infrastructure. The InSpec framework runs locally or remotely on the node being inspected. It uses test rules written in the InSpec language as input. Detected security, compliance, or policy issues are flagged in a log.
8
+
9
+ The InSpec project includes many resources that help you write audit rules quickly and easily. Here are some examples.
10
+
11
+ * Disallow insecure protocols - In this example, the package and inetd_conf resources ensure that insecure services and protocols, such as telnet, are not used.
12
+
13
+ ```ruby
14
+ describe package('telnetd') do
15
+   it { should_not be_installed }
16
+ end
17
+
18
+ describe inetd_conf do
19
+   its("telnet") { should eq nil }
20
+ end
21
+ ```
22
+
23
+ * Only accept requests on secure ports - This test ensures, that a web server is only listening on well-secured ports.
24
+
25
+ ```ruby
26
+ describe port(80) do
27
+   it { should_not be_listening }
28
+ end
29
+
30
+ describe port(443) do
31
+   it { should be_listening }
32
+   its('protocol') {should eq 'tcp'}
33
+ end
34
+ ```
35
+
36
+ * Use approved strong ciphers - This test ensures, that only enterprise-compliant ciphers are used for SSH servers.
37
+
38
+ ```ruby
39
+ describe sshd_config do
40
+    its('Ciphers') { should eq('chacha20-poly1305@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr') }
41
+ end
42
+ ```
43
+
44
+ * Test your `kitchen.yml` file, to verify that only Vagrant is configured as the driver.
45
+
46
+ ```ruby
47
+ describe yaml('.kitchen.yml') do
48
+ its('driver.name') { should eq('vagrant') }
49
+ end
50
+ ```
51
+
52
+ ## Test your Server, VM, or workstation.
53
+
54
+ Small example: Write a your checks in `test.rb`:
55
+
56
+ ```ruby
57
+ describe file('/proc/cpuinfo') do
58
+ it { should be_file }
59
+ end
60
+
61
+ describe ssh_config do
62
+ its('Protocol') { should eq('2') }
63
+ end
64
+ ```
65
+
66
+ Run this file locally:
67
+
68
+ ```bash
69
+ inspec exec test.rb
70
+ ```
71
+
72
+ ## Installation
73
+
74
+ Requires Ruby ( >1.9 ).
75
+
76
+ To simply run it without installation, you must install [bundler](http://bundler.io/):
77
+
78
+ ```bash
79
+ bundle install
80
+ bundle exec bin/inspec help
81
+ ```
82
+
83
+ To install it as a gem locally, run:
84
+
85
+ ```bash
86
+ gem build inspec.gemspec
87
+ gem install inspec-*.gem
88
+ ```
89
+
90
+ You should now be able to run:
91
+
92
+ ```bash
93
+ inspec --help
94
+ ```
95
+
96
+ ## Usage
97
+
98
+ ### exec
99
+
100
+ Run tests against different targets:
101
+
102
+ ```bash
103
+ # run test locally
104
+ inspec exec test.rb
105
+
106
+ # run test on remote host on SSH
107
+ inspec exec test.rb -t ssh://user@hostname
108
+
109
+ # run test on remote windows host on WinRM
110
+ inspec exec test.rb -t winrm://Administrator@windowshost --password 'your-password'
111
+
112
+ # run test on docker container
113
+ inspec exec test.rb -t docker://container_id
114
+ ```
115
+
116
+ ### detect
117
+
118
+ Verify your configuration and detect
119
+
120
+ ```bash
121
+ id=$( docker run -dti ubuntu:14.04 /bin/bash )
122
+ inspec detect -t docker://$id
123
+ ```
124
+
125
+ Which will provide you with:
126
+
127
+ ```
128
+ {"family":"ubuntu","release":"14.04","arch":null}
129
+ ```
130
+
131
+ ## Custom resources
132
+
133
+ You can easily create your own resources. Here is a custom resource for an
134
+ application called Gordon and save it in `gordon_config.rb`:
135
+
136
+ ```ruby
137
+ require 'yaml'
138
+
139
+ class GordonConfig < Inspec.resource
140
+ name 'gordon_config'
141
+
142
+ def initialize
143
+ @path = '/etc/gordon/config.yaml'
144
+ @config = inspec.file(@path).content
145
+ @params = YAML.load(@config)
146
+ end
147
+
148
+ def method_missing(name)
149
+ @params[name.to_s]
150
+ end
151
+ end
152
+ ```
153
+
154
+ Include this file in your `test.rb`:
155
+
156
+ ```ruby
157
+ require_relative 'gordon_config'
158
+ ```
159
+
160
+ Now you can start using your new resource:
161
+
162
+ ```ruby
163
+ describe gordon_config do
164
+ its('Version') { should eq('1.0') }
165
+ end
166
+ ```
167
+
168
+ ## Tests
169
+
170
+ We perform `unit`, `resource` and `integration` tests.
171
+
172
+ * `unit` tests ensure the intended behaviour of the implementation
173
+ * `resource` tests run against docker containers
174
+ * `integration` tests run against VMs via test-kitchen and [kitchen-inspec](https://github.com/chef/kitchen-inspec)
175
+
176
+ ### Unit tests
177
+
178
+ Just
179
+ ```bash
180
+ bundle exec rake test
181
+ ```
182
+ as usual.
183
+
184
+ ### Resource tests
185
+
186
+ Make sure the backend execution layer behaves as expected. These tests will take a while, as a lot of different operating systems and configurations are being tested.
187
+
188
+ You will require:
189
+
190
+ * docker
191
+
192
+ Run `resource` tests with
193
+
194
+ ```bash
195
+ bundle exec rake test:resources config=test/test.yaml
196
+ bundle exec rake test:resources config=test/test-extra.yaml
197
+ ```
198
+
199
+ ### Integration tests
200
+
201
+ These tests download various virtual machines, to ensure InSpec is working as expected across different operating systems.
202
+
203
+ You will require:
204
+
205
+ * vagrant with virtualbox
206
+ * test-kitchen
207
+
208
+ Run `integration` tests with
209
+
210
+ ```bash
211
+ cd test/integration
212
+ bundle exec kitchen test -t .
213
+ ```
214
+
215
+ ### Chef Delivery Tests
216
+
217
+ It may be informative to look at what [tests Chef Delivery](https://github.com/chef/inspec/blob/master/.delivery/build-cookbook/recipes/unit.rb) is running for CI.
218
+
219
+ ## Learn More
220
+
221
+ For more information see the InSpec documentation: https://github.com/chef/inspec/tree/master/docs
222
+
223
+ ## Kudos
224
+
225
+ InSpec is inspired by the wonderful [Serverspec](http://serverspec.org) project. Kudos to [mizzy](https://github.com/mizzy) and [all contributors](https://github.com/mizzy/serverspec/graphs/contributors)!
226
+
227
+ ## Contributing
228
+
229
+ 1. Fork it
230
+ 1. Create your feature branch (git checkout -b my-new-feature)
231
+ 1. Commit your changes (git commit -am 'Add some feature')
232
+ 1. Push to the branch (git push origin my-new-feature)
233
+ 1. Create new Pull Request
234
+
235
+ ## License
236
+
237
+ | **Author:** | Dominik Richter (<drichter@chef.io>)
238
+
239
+ | **Author:** | Christoph Hartmann (<chartmann@chef.io>)
240
+
241
+ | **Copyright:** | Copyright (c) 2015 Chef Software Inc.
242
+
243
+ | **Copyright:** | Copyright (c) 2015 Vulcano Security GmbH.
244
+
245
+ | **License:** | Apache License, Version 2.0
246
+
247
+ Licensed under the Apache License, Version 2.0 (the "License");
248
+ you may not use this file except in compliance with the License.
249
+ You may obtain a copy of the License at
250
+
251
+ http://www.apache.org/licenses/LICENSE-2.0
252
+
253
+ Unless required by applicable law or agreed to in writing, software
254
+ distributed under the License is distributed on an "AS IS" BASIS,
255
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
256
+ See the License for the specific language governing permissions and
257
+ limitations under the License.
data/Rakefile ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env rake
2
+ # encoding: utf-8
3
+
4
+ require 'rake/testtask'
5
+ require 'rubocop/rake_task'
6
+ require_relative 'tasks/maintainers'
7
+
8
+ # Rubocop
9
+ desc 'Run Rubocop lint checks'
10
+ task :rubocop do
11
+ RuboCop::RakeTask.new
12
+ end
13
+
14
+ # lint the project
15
+ desc 'Run robocop linter'
16
+ task lint: [:rubocop]
17
+
18
+ # run tests
19
+ task default: [:test, :lint]
20
+
21
+ Rake::TestTask.new do |t|
22
+ t.libs << 'test'
23
+ t.pattern = 'test/unit/**/*_test.rb'
24
+ t.warning = true
25
+ t.verbose = true
26
+ t.ruby_opts = ['--dev'] if defined?(JRUBY_VERSION)
27
+ end
28
+
29
+ namespace :test do
30
+ task :isolated do
31
+ Dir.glob('test/unit/*_test.rb').all? do |file|
32
+ sh(Gem.ruby, '-w', '-Ilib:test', file)
33
+ end or fail 'Failures'
34
+ end
35
+
36
+ task :resources do
37
+ tests = Dir['test/resource/*_test.rb']
38
+ return if tests.empty?
39
+ sh(Gem.ruby, 'test/docker_test.rb', *tests)
40
+ end
41
+
42
+ task :vm do
43
+ concurrency = ENV['CONCURRENCY'] || 4
44
+ path = File.join(File.dirname(__FILE__), 'test', 'integration')
45
+ sh('sh', '-c', "cd #{path} && bundle exec kitchen test -c #{concurrency} -t .")
46
+ end
47
+ end
data/bin/inspec ADDED
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ # Copyright 2015 Dominik Richter. All rights reserved.
4
+ # author: Dominik Richter
5
+ # author: Christoph Hartmann
6
+
7
+ require 'thor'
8
+ require 'json'
9
+ require_relative '../lib/inspec'
10
+
11
+ class InspecCLI < Thor
12
+ def self.target_options
13
+ option :target, aliases: :t, type: :string, default: nil,
14
+ desc: 'Simple targeting option using URIs, e.g. ssh://user:pass@host:port'
15
+ option :backend, aliases: :b, type: :string, default: nil,
16
+ desc: 'Choose a backend: local, ssh, winrm, docker.'
17
+ option :host, type: :string,
18
+ desc: 'Specify a remote host which is tested.'
19
+ option :port, type: :numeric,
20
+ desc: 'Specify the login port for a remote scan.'
21
+ option :user, type: :string, default: nil,
22
+ desc: 'The login user for a remote scan.'
23
+ option :password, type: :string, default: nil,
24
+ desc: 'Login password for a remote scan, if required.'
25
+ option :key_files, type: :array, default: nil,
26
+ desc: 'Login key or certificate file for a remote scan.'
27
+ option :path, type: :string, default: nil,
28
+ desc: 'Login path to use when connecting to the target (WinRM).'
29
+ option :sudo, type: :boolean, default: false,
30
+ desc: 'Run scans with sudo. Only activates on Unix and non-root user.'
31
+ option :sudo_password, type: :string, default: nil,
32
+ desc: 'Specify a sudo password, if it is required.'
33
+ option :sudo_options, type: :string, default: '',
34
+ desc: 'Additional sudo options for a remote scan.'
35
+ option :ssl, type: :boolean, default: false,
36
+ desc: 'Use SSL for transport layer encryption (WinRM).'
37
+ option :self_signed, type: :boolean, default: false,
38
+ desc: 'Allow remote scans with self-signed certificates (WinRM).'
39
+ end
40
+
41
+ desc 'json PATH', 'read all tests in PATH and generate a JSON profile'
42
+ option :id, type: :string,
43
+ desc: 'Attach a profile ID to all test results'
44
+ option :output, aliases: :o, type: :string,
45
+ desc: 'Save the created profile to a path'
46
+ def json(path)
47
+ profile = Inspec::Profile.from_path(path, options)
48
+ dst = options[:output].to_s
49
+ if dst.empty?
50
+ puts JSON.pretty_generate(profile.info)
51
+ else
52
+ if File.exist? dst
53
+ puts "----> updating #{dst}"
54
+ else
55
+ puts "----> creating #{dst}"
56
+ end
57
+ fdst = File.expand_path(dst)
58
+ File.write(fdst, JSON.dump(profile.info))
59
+ end
60
+ end
61
+
62
+ desc 'check PATH', 'verify test structure in PATH'
63
+ def check(path)
64
+ o = options.dup
65
+ o[:logger] = Logger.new(STDOUT)
66
+ profile = Inspec::Profile.from_path(path, o)
67
+ exit 1 unless profile.check
68
+ end
69
+
70
+ desc 'exec PATHS', 'run all test files'
71
+ option :id, type: :string,
72
+ desc: 'Attach a profile ID to all test results'
73
+ target_options
74
+ option :format, type: :string, default: 'progress'
75
+ def exec(*tests)
76
+ runner = Inspec::Runner.new(options)
77
+ runner.add_tests(tests)
78
+ runner.run
79
+ rescue RuntimeError => e
80
+ puts e.message
81
+ end
82
+
83
+ desc 'detect', 'detect the target OS'
84
+ target_options
85
+ def detect
86
+ runner = Inspec::Runner.new(options)
87
+ rel = File.join(File.dirname(__FILE__), *%w{.. lib utils detect.rb})
88
+ detect_util = File.expand_path(rel)
89
+ runner.add_tests([detect_util])
90
+ runner.run
91
+ rescue RuntimeError => e
92
+ puts e.message
93
+ end
94
+
95
+ desc 'shell', 'open an interactive debugging shell'
96
+ target_options
97
+ def shell_func
98
+ runner = Inspec::Runner.new(options)
99
+ Inspec::Shell.new(runner).start
100
+ rescue RuntimeError => e
101
+ puts e.message
102
+ end
103
+
104
+ desc 'version', 'prints the version of this tool'
105
+ def version
106
+ puts Inspec::VERSION
107
+ end
108
+ end
109
+ InspecCLI.start(ARGV)
@@ -0,0 +1,195 @@
1
+ =====================================================
2
+ InSpec CLI
3
+ =====================================================
4
+
5
+ Use the InSpec CLI to run audit tests against targets using locally, SSH, |winrm|, or on |docker| containers.
6
+
7
+ Common Options
8
+ =====================================================
9
+ The following options may be used with any of the InSpec CLI subcommands:
10
+
11
+ ``-b``, ``--backend``
12
+ Specify the backend. Possible values: ``local`` (default), ``ssh``, ``winrm``, or ``docker``.
13
+
14
+ ``--sudo``
15
+ Run scans with sudo. Only activates on Unix and non-root user. Default value: ``false``.
16
+
17
+ ``--host``
18
+ The remote host to be tested.
19
+
20
+ ``--key-files``
21
+ The login key or certificate file required for remote scanning.
22
+
23
+ ``--password``
24
+ The login password for remote scanning.
25
+
26
+ ``--path``
27
+ The login path used to connect to the target for |winrm|.
28
+
29
+ ``--port``
30
+ The port over which remote scanning will occur.
31
+
32
+ ``--self_signed``
33
+ Use to allow remote scanning with self-signed certificates for |winrm| targets. Default value: ``false``.
34
+
35
+ ``--ssl``
36
+ Use to require transport-layer encryption via SSL for |winrm| targets. Default value: ``false``.
37
+
38
+ ``--sudo_options``
39
+ Additional options that may be required by the sudo password for remote scanning. Default value: ``''``.
40
+
41
+ ``--sudo_password``
42
+ The sudo password, if required.
43
+
44
+ ``-t``, ``--target``
45
+ The URI for the target of a remote scan, preceded by the target's backend. For example: ``backend://user:pass@host:port``, where ``backend`` is one of ``docker``, ``local``, ``ssh``, or ``winrm``.
46
+
47
+ ``--user``
48
+ The login user for remote scanning.
49
+
50
+
51
+
52
+ check
53
+ =====================================================
54
+ Use ``inspec check`` to run all tests at the specified path.
55
+
56
+ Syntax
57
+ -----------------------------------------------------
58
+ This subcommand has the following syntax:
59
+
60
+ .. code-block:: bash
61
+
62
+ $ inspec check PATH (options)
63
+
64
+ where:
65
+
66
+ * ``PATH`` is the location against which tests are run
67
+
68
+
69
+
70
+ detect
71
+ =====================================================
72
+ Use ``inspec detect`` to detect the platform for the target.
73
+
74
+ For example, if the configuration on the target is:
75
+
76
+ .. code-block:: bash
77
+
78
+ id=$( docker run -dti ubuntu:14.04 /bin/bash )
79
+
80
+ the following command:
81
+
82
+ .. code-block:: bash
83
+
84
+ $ inspec detect -t docker://$id
85
+
86
+ will return:
87
+
88
+ .. code-block:: javascript
89
+
90
+ {"family":"ubuntu","release":"14.04","arch":null}
91
+
92
+
93
+ exec
94
+ =====================================================
95
+ Use ``inspec exec`` to run all tests at the specified path.
96
+
97
+ Syntax
98
+ -----------------------------------------------------
99
+ This subcommand has the following syntax:
100
+
101
+ .. code-block:: bash
102
+
103
+ $ inspec exec PATHS (options)
104
+
105
+ where:
106
+
107
+ * ``PATHS`` is one (or more) locations against which tests are run
108
+
109
+ Options
110
+ -----------------------------------------------------
111
+ This subcommand has additional options:
112
+
113
+ ``--id``
114
+ Use to attach a profile identifier to all test results.
115
+
116
+ Examples
117
+ -----------------------------------------------------
118
+ The following examples show how to use this subcommand.
119
+
120
+ **Run a test locally**
121
+
122
+ .. code-block:: bash
123
+
124
+ $ inspec exec test.rb
125
+
126
+ **Run a test on a remote host using SSH**
127
+
128
+ .. code-block:: bash
129
+
130
+ $ inspec exec test.rb -t ssh://user@hostname
131
+
132
+ **Run a test on a remote host using WinRM**
133
+
134
+ .. code-block:: bash
135
+
136
+ $ inspec exec test.rb -t winrm://Administrator@windowshost --password 'password'
137
+
138
+ **Run a test against a Docker container**
139
+
140
+ .. code-block:: bash
141
+
142
+ $ inspec exec test.rb -t docker://container_id
143
+
144
+
145
+
146
+ help
147
+ =====================================================
148
+ Use ``inspec help`` to print help for the |ctl inspec| from the command shell.
149
+
150
+
151
+
152
+ json
153
+ =====================================================
154
+ Use ``inspec json`` to read all tests at the specified path, and then generate a |json| profile to standard output (stdout).
155
+
156
+ Syntax
157
+ -----------------------------------------------------
158
+ This subcommand has the following syntax:
159
+
160
+ .. code-block:: bash
161
+
162
+ $ inspec json PATH (options)
163
+
164
+ where:
165
+
166
+ * ``PATH`` is the location against which tests are run
167
+
168
+ Options
169
+ -----------------------------------------------------
170
+ This subcommand has additional options:
171
+
172
+ ``--id``
173
+ Use to attach a profile identifier to all test results.
174
+
175
+ ``-o``, ``--output``
176
+ Use to save the |json| profile to a file instead of printing to stdout.
177
+
178
+
179
+
180
+ shell
181
+ =====================================================
182
+ Use ``inspec shell`` to open an interactive debugging shell.
183
+
184
+
185
+
186
+ version
187
+ =====================================================
188
+ Use ``inspec version`` to print the version of the InSpec CLI.
189
+
190
+
191
+ .. |winrm| replace:: Windows Remote Management
192
+ .. _winrm: https://msdn.microsoft.com/en-us/library/aa384426(v=vs.85).aspx
193
+ .. |docker| replace:: Docker
194
+ .. _docker: https://www.docker.com/
195
+ .. |json| replace:: JSON