inspec-core 2.3.10 → 2.3.23

Sign up to get free protection for your applications and to get access to all the features.
Files changed (216) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +34 -13
  3. data/etc/plugin_filters.json +25 -0
  4. data/inspec-core.gemspec +1 -1
  5. data/lib/bundles/inspec-compliance/api.rb +3 -0
  6. data/lib/bundles/inspec-compliance/configuration.rb +3 -0
  7. data/lib/bundles/inspec-compliance/http.rb +3 -0
  8. data/lib/bundles/inspec-compliance/support.rb +3 -0
  9. data/lib/bundles/inspec-compliance/target.rb +3 -0
  10. data/lib/inspec/objects/attribute.rb +3 -0
  11. data/lib/inspec/plugin/v2.rb +3 -0
  12. data/lib/inspec/plugin/v2/filter.rb +62 -0
  13. data/lib/inspec/plugin/v2/installer.rb +21 -1
  14. data/lib/inspec/plugin/v2/loader.rb +4 -0
  15. data/lib/inspec/profile.rb +3 -1
  16. data/lib/inspec/version.rb +1 -1
  17. data/lib/plugins/inspec-plugin-manager-cli/lib/inspec-plugin-manager-cli/cli_command.rb +25 -3
  18. data/lib/plugins/inspec-plugin-manager-cli/test/functional/inspec-plugin_test.rb +65 -11
  19. data/lib/plugins/inspec-plugin-manager-cli/test/unit/cli_args_test.rb +5 -1
  20. data/lib/resources/package.rb +1 -1
  21. metadata +4 -197
  22. data/docs/.gitignore +0 -2
  23. data/docs/README.md +0 -41
  24. data/docs/dev/control-eval.md +0 -62
  25. data/docs/dev/filtertable-internals.md +0 -353
  26. data/docs/dev/filtertable-usage.md +0 -533
  27. data/docs/dev/integration-testing.md +0 -31
  28. data/docs/dev/plugins.md +0 -323
  29. data/docs/dsl_inspec.md +0 -354
  30. data/docs/dsl_resource.md +0 -100
  31. data/docs/glossary.md +0 -381
  32. data/docs/habitat.md +0 -193
  33. data/docs/inspec_and_friends.md +0 -114
  34. data/docs/matchers.md +0 -161
  35. data/docs/migration.md +0 -293
  36. data/docs/platforms.md +0 -119
  37. data/docs/plugin_kitchen_inspec.md +0 -60
  38. data/docs/plugins.md +0 -57
  39. data/docs/profiles.md +0 -576
  40. data/docs/reporters.md +0 -170
  41. data/docs/resources/aide_conf.md.erb +0 -86
  42. data/docs/resources/apache.md.erb +0 -77
  43. data/docs/resources/apache_conf.md.erb +0 -78
  44. data/docs/resources/apt.md.erb +0 -81
  45. data/docs/resources/audit_policy.md.erb +0 -57
  46. data/docs/resources/auditd.md.erb +0 -89
  47. data/docs/resources/auditd_conf.md.erb +0 -78
  48. data/docs/resources/bash.md.erb +0 -85
  49. data/docs/resources/bond.md.erb +0 -100
  50. data/docs/resources/bridge.md.erb +0 -67
  51. data/docs/resources/bsd_service.md.erb +0 -77
  52. data/docs/resources/chocolatey_package.md.erb +0 -68
  53. data/docs/resources/command.md.erb +0 -176
  54. data/docs/resources/cpan.md.erb +0 -89
  55. data/docs/resources/cran.md.erb +0 -74
  56. data/docs/resources/crontab.md.erb +0 -103
  57. data/docs/resources/csv.md.erb +0 -64
  58. data/docs/resources/dh_params.md.erb +0 -221
  59. data/docs/resources/directory.md.erb +0 -40
  60. data/docs/resources/docker.md.erb +0 -240
  61. data/docs/resources/docker_container.md.erb +0 -113
  62. data/docs/resources/docker_image.md.erb +0 -104
  63. data/docs/resources/docker_plugin.md.erb +0 -80
  64. data/docs/resources/docker_service.md.erb +0 -124
  65. data/docs/resources/elasticsearch.md.erb +0 -252
  66. data/docs/resources/etc_fstab.md.erb +0 -135
  67. data/docs/resources/etc_group.md.erb +0 -85
  68. data/docs/resources/etc_hosts.md.erb +0 -88
  69. data/docs/resources/etc_hosts_allow.md.erb +0 -84
  70. data/docs/resources/etc_hosts_deny.md.erb +0 -84
  71. data/docs/resources/file.md.erb +0 -543
  72. data/docs/resources/filesystem.md.erb +0 -51
  73. data/docs/resources/firewalld.md.erb +0 -117
  74. data/docs/resources/gem.md.erb +0 -108
  75. data/docs/resources/group.md.erb +0 -71
  76. data/docs/resources/grub_conf.md.erb +0 -111
  77. data/docs/resources/host.md.erb +0 -96
  78. data/docs/resources/http.md.erb +0 -207
  79. data/docs/resources/iis_app.md.erb +0 -132
  80. data/docs/resources/iis_site.md.erb +0 -145
  81. data/docs/resources/inetd_conf.md.erb +0 -104
  82. data/docs/resources/ini.md.erb +0 -86
  83. data/docs/resources/interface.md.erb +0 -68
  84. data/docs/resources/iptables.md.erb +0 -74
  85. data/docs/resources/json.md.erb +0 -73
  86. data/docs/resources/kernel_module.md.erb +0 -130
  87. data/docs/resources/kernel_parameter.md.erb +0 -63
  88. data/docs/resources/key_rsa.md.erb +0 -95
  89. data/docs/resources/launchd_service.md.erb +0 -67
  90. data/docs/resources/limits_conf.md.erb +0 -85
  91. data/docs/resources/login_defs.md.erb +0 -81
  92. data/docs/resources/mount.md.erb +0 -79
  93. data/docs/resources/mssql_session.md.erb +0 -78
  94. data/docs/resources/mysql_conf.md.erb +0 -109
  95. data/docs/resources/mysql_session.md.erb +0 -84
  96. data/docs/resources/nginx.md.erb +0 -89
  97. data/docs/resources/nginx_conf.md.erb +0 -148
  98. data/docs/resources/npm.md.erb +0 -78
  99. data/docs/resources/ntp_conf.md.erb +0 -70
  100. data/docs/resources/oneget.md.erb +0 -63
  101. data/docs/resources/oracledb_session.md.erb +0 -103
  102. data/docs/resources/os.md.erb +0 -153
  103. data/docs/resources/os_env.md.erb +0 -101
  104. data/docs/resources/package.md.erb +0 -130
  105. data/docs/resources/packages.md.erb +0 -77
  106. data/docs/resources/parse_config.md.erb +0 -113
  107. data/docs/resources/parse_config_file.md.erb +0 -148
  108. data/docs/resources/passwd.md.erb +0 -151
  109. data/docs/resources/pip.md.erb +0 -77
  110. data/docs/resources/port.md.erb +0 -147
  111. data/docs/resources/postgres_conf.md.erb +0 -89
  112. data/docs/resources/postgres_hba_conf.md.erb +0 -103
  113. data/docs/resources/postgres_ident_conf.md.erb +0 -86
  114. data/docs/resources/postgres_session.md.erb +0 -79
  115. data/docs/resources/powershell.md.erb +0 -112
  116. data/docs/resources/processes.md.erb +0 -119
  117. data/docs/resources/rabbitmq_config.md.erb +0 -51
  118. data/docs/resources/registry_key.md.erb +0 -197
  119. data/docs/resources/runit_service.md.erb +0 -67
  120. data/docs/resources/security_policy.md.erb +0 -57
  121. data/docs/resources/service.md.erb +0 -131
  122. data/docs/resources/shadow.md.erb +0 -267
  123. data/docs/resources/ssh_config.md.erb +0 -83
  124. data/docs/resources/sshd_config.md.erb +0 -93
  125. data/docs/resources/ssl.md.erb +0 -129
  126. data/docs/resources/sys_info.md.erb +0 -52
  127. data/docs/resources/systemd_service.md.erb +0 -67
  128. data/docs/resources/sysv_service.md.erb +0 -67
  129. data/docs/resources/upstart_service.md.erb +0 -67
  130. data/docs/resources/user.md.erb +0 -150
  131. data/docs/resources/users.md.erb +0 -137
  132. data/docs/resources/vbscript.md.erb +0 -65
  133. data/docs/resources/virtualization.md.erb +0 -67
  134. data/docs/resources/windows_feature.md.erb +0 -69
  135. data/docs/resources/windows_hotfix.md.erb +0 -63
  136. data/docs/resources/windows_task.md.erb +0 -95
  137. data/docs/resources/wmi.md.erb +0 -91
  138. data/docs/resources/x509_certificate.md.erb +0 -161
  139. data/docs/resources/xinetd_conf.md.erb +0 -166
  140. data/docs/resources/xml.md.erb +0 -95
  141. data/docs/resources/yaml.md.erb +0 -79
  142. data/docs/resources/yum.md.erb +0 -108
  143. data/docs/resources/zfs_dataset.md.erb +0 -63
  144. data/docs/resources/zfs_pool.md.erb +0 -57
  145. data/docs/shared/matcher_be.md.erb +0 -1
  146. data/docs/shared/matcher_cmp.md.erb +0 -43
  147. data/docs/shared/matcher_eq.md.erb +0 -3
  148. data/docs/shared/matcher_include.md.erb +0 -1
  149. data/docs/shared/matcher_match.md.erb +0 -1
  150. data/docs/shell.md +0 -217
  151. data/docs/style.md +0 -178
  152. data/examples/README.md +0 -8
  153. data/examples/custom-resource/README.md +0 -3
  154. data/examples/custom-resource/controls/example.rb +0 -7
  155. data/examples/custom-resource/inspec.yml +0 -8
  156. data/examples/custom-resource/libraries/batsignal.rb +0 -20
  157. data/examples/custom-resource/libraries/gordon.rb +0 -21
  158. data/examples/inheritance/README.md +0 -65
  159. data/examples/inheritance/controls/example.rb +0 -14
  160. data/examples/inheritance/inspec.yml +0 -16
  161. data/examples/kitchen-ansible/.kitchen.yml +0 -25
  162. data/examples/kitchen-ansible/Gemfile +0 -19
  163. data/examples/kitchen-ansible/README.md +0 -53
  164. data/examples/kitchen-ansible/files/nginx.repo +0 -6
  165. data/examples/kitchen-ansible/tasks/main.yml +0 -16
  166. data/examples/kitchen-ansible/test/integration/default/default.yml +0 -5
  167. data/examples/kitchen-ansible/test/integration/default/web_spec.rb +0 -28
  168. data/examples/kitchen-chef/.kitchen.yml +0 -20
  169. data/examples/kitchen-chef/Berksfile +0 -3
  170. data/examples/kitchen-chef/Gemfile +0 -19
  171. data/examples/kitchen-chef/README.md +0 -27
  172. data/examples/kitchen-chef/metadata.rb +0 -7
  173. data/examples/kitchen-chef/recipes/default.rb +0 -6
  174. data/examples/kitchen-chef/recipes/nginx.rb +0 -30
  175. data/examples/kitchen-chef/test/integration/default/web_spec.rb +0 -28
  176. data/examples/kitchen-puppet/.kitchen.yml +0 -23
  177. data/examples/kitchen-puppet/Gemfile +0 -20
  178. data/examples/kitchen-puppet/Puppetfile +0 -25
  179. data/examples/kitchen-puppet/README.md +0 -53
  180. data/examples/kitchen-puppet/manifests/site.pp +0 -33
  181. data/examples/kitchen-puppet/metadata.json +0 -11
  182. data/examples/kitchen-puppet/modules/.gitkeep +0 -0
  183. data/examples/kitchen-puppet/test/integration/default/web_spec.rb +0 -28
  184. data/examples/meta-profile/README.md +0 -37
  185. data/examples/meta-profile/controls/example.rb +0 -13
  186. data/examples/meta-profile/inspec.yml +0 -13
  187. data/examples/plugins/inspec-resource-lister/Gemfile +0 -12
  188. data/examples/plugins/inspec-resource-lister/LICENSE +0 -13
  189. data/examples/plugins/inspec-resource-lister/README.md +0 -62
  190. data/examples/plugins/inspec-resource-lister/Rakefile +0 -40
  191. data/examples/plugins/inspec-resource-lister/inspec-resource-lister.gemspec +0 -45
  192. data/examples/plugins/inspec-resource-lister/lib/inspec-resource-lister.rb +0 -16
  193. data/examples/plugins/inspec-resource-lister/lib/inspec-resource-lister/cli_command.rb +0 -70
  194. data/examples/plugins/inspec-resource-lister/lib/inspec-resource-lister/plugin.rb +0 -55
  195. data/examples/plugins/inspec-resource-lister/lib/inspec-resource-lister/version.rb +0 -10
  196. data/examples/plugins/inspec-resource-lister/test/fixtures/README.md +0 -24
  197. data/examples/plugins/inspec-resource-lister/test/functional/README.md +0 -18
  198. data/examples/plugins/inspec-resource-lister/test/functional/inspec_resource_lister_test.rb +0 -110
  199. data/examples/plugins/inspec-resource-lister/test/helper.rb +0 -26
  200. data/examples/plugins/inspec-resource-lister/test/unit/README.md +0 -17
  201. data/examples/plugins/inspec-resource-lister/test/unit/cli_args_test.rb +0 -64
  202. data/examples/plugins/inspec-resource-lister/test/unit/plugin_def_test.rb +0 -51
  203. data/examples/profile-attribute.yml +0 -2
  204. data/examples/profile-attribute/README.md +0 -14
  205. data/examples/profile-attribute/controls/example.rb +0 -11
  206. data/examples/profile-attribute/inspec.yml +0 -8
  207. data/examples/profile-sensitive/README.md +0 -29
  208. data/examples/profile-sensitive/controls/sensitive-failures.rb +0 -9
  209. data/examples/profile-sensitive/controls/sensitive.rb +0 -9
  210. data/examples/profile-sensitive/inspec.yml +0 -8
  211. data/examples/profile/README.md +0 -48
  212. data/examples/profile/controls/example.rb +0 -24
  213. data/examples/profile/controls/gordon.rb +0 -36
  214. data/examples/profile/controls/meta.rb +0 -36
  215. data/examples/profile/inspec.yml +0 -11
  216. data/examples/profile/libraries/gordon_config.rb +0 -59
data/docs/plugins.md DELETED
@@ -1,57 +0,0 @@
1
- ---
2
- title: About InSpec and Train Plugins
3
- ---
4
-
5
- # InSpec and Train Plugins
6
-
7
- ## What are InSpec Plugins?
8
-
9
- InSpec Plugins are optional software components that extend the capabilities of InSpec. For example, [`inspec-iggy`](https://github.com/inspec/inspec-iggy) is a Plugin project that aims to generate InSpec controls from infrastructure-as-code files. Plugins are distributed as RubyGems, and InSpec manages their installation. InSpec Plugins always begin with the prefix 'inspec-'.
10
-
11
- ## What are Train Plugins?
12
-
13
- Train Plugins allow InSpec to speak to new kinds of targets (typically new remote targets or APIs, but you could treat the local system in a new way if you wished to). For example, if you wanted to audit a Kubernetes cluster, you might want a transport that can talk to the supervisor API. You'd develop a Train Plugin for that, and install it using the InSpec command line. Train Plugins always begin with the prefix 'train-'.
14
-
15
- ## What can plugins do?
16
-
17
- Currently, each plugin can offer one or more of these capabilities:
18
-
19
- * define a new command-line-interface (CLI) command suite
20
- * connectivity to new types of hosts or cloud providers (`train` plugins)
21
-
22
- Future work might include new capability types, such as:
23
-
24
- * reporters (output generators)
25
- * DSL extensions at the file, control, or test level
26
- * attribute fetchers to allow reading InSpec attributes from new sources (for example, a remote, encrypted key-value store)
27
-
28
- ## How do I find out which plugins are available?
29
-
30
- The InSpec CLI can tell you which plugins are available:
31
-
32
- ```bash
33
- $ inspec plugin search
34
- ```
35
-
36
- ## How do I install and manage plugins?
37
-
38
- The InSpec command line now offers a new subcommand just for managing plugins.
39
-
40
- You can install a plugin by running:
41
-
42
- ```bash
43
- $ inspec plugin install inspec-some-plugin
44
- $ inspec plugin install train-some-plugin
45
- ```
46
-
47
- For more details on what the `plugin` command can do, see the [online help](https://www.inspec.io/docs/reference/cli/#plugin), or run `inspec plugin help`.
48
-
49
- ## How do I write a plugin?
50
-
51
- ### InSpec Plugins
52
-
53
- For details on how to author an InSpec Plugin, see the [developer documentation](https://github.com/inspec/inspec/blob/master/docs/dev/plugins.md)
54
-
55
- ### Train Plugins
56
-
57
- For details on how to author a Train Plugin, see the [developer documentation](https://github.com/inspec/train/blob/master/docs/dev/plugins.md)
data/docs/profiles.md DELETED
@@ -1,576 +0,0 @@
1
- ---
2
- title: About InSpec Profiles
3
- ---
4
-
5
- # InSpec Profiles
6
-
7
- InSpec supports the creation of complex test and compliance profiles, which organize controls to support dependency management and code reuse. Each profile is a standalone structure with its own distribution and execution flow.
8
-
9
- # Profile Structure
10
-
11
- A profile should have the following structure::
12
-
13
- ```YAML
14
- examples/profile
15
- ├── README.md
16
- ├── controls
17
- │ ├── example.rb
18
- │ └── control_etc.rb
19
- ├── libraries
20
- │ └── extension.rb
21
- |── files
22
- │ └── extras.conf
23
- └── inspec.yml
24
- ```
25
-
26
- where:
27
-
28
- * `inspec.yml` includes the profile description (required)
29
- * `controls` is the directory in which all tests are located (required)
30
- * `libraries` is the directory in which all InSpec resource extensions are located (optional)
31
- * `files` is the directory with additional files that a profile can access (optional)
32
- * `README.md` should be used to explain the profile, its scope, and usage
33
-
34
- See a complete example profile in the InSpec open source repository: [Example InSpec Profile](https://github.com/chef/inspec/tree/master/examples/profile)
35
-
36
- Also check out [Explore InSpec resources](https://learn.chef.io/modules/explore-inspec-resources#/) on Learn Chef Rally to learn more about how profiles are structured with hands-on examples.
37
-
38
- ## inspec.yml
39
-
40
- Each profile must have an `inspec.yml` file that defines the following information:
41
-
42
- * Use `name` to specify a unique name for the profile. Required.
43
- * Use `title` to specify a human-readable name for the profile.
44
- * Use `maintainer` to specify the profile maintainer.
45
- * Use `copyright` to specify the copyright holder.
46
- * Use `copyright_email` to specify support contact information for the profile, typically an email address.
47
- * Use `license` to specify the license for the profile.
48
- * Use `summary` to specify a one line summary for the profile.
49
- * Use `description` to specify a multiple line description of the profile.
50
- * Use `version` to specify the profile version.
51
- * Use `inspec_version` to place SemVer constraints on the version of InSpec that the profile can run under.
52
- * Use `supports` to specify a list of supported platform targets.
53
- * Use `depends` to define a list of profiles on which this profile depends.
54
- * Use `attributes` to define a list of attributes you can use in your controls.
55
-
56
- `name` is required; all other profile settings are optional. For example:
57
-
58
- ```YAML
59
- name: ssh
60
- title: Basic SSH
61
- maintainer: Chef Software, Inc.
62
- copyright: Chef Software, Inc.
63
- copyright_email: support@chef.io
64
- license: Proprietary, All rights reserved
65
- summary: Verify that SSH Server and SSH Client are configured securely
66
- version: 1.0.0
67
- supports:
68
- - os-family: linux
69
- depends:
70
- - name: profile
71
- path: ../path/to/profile
72
- inspec_version: "~> 2.1"
73
- ```
74
-
75
- The `inspec.yml` also supports embedded ERB in the file. For example:
76
-
77
- ```YAML
78
- name: dummy
79
- title: InSpec Profile
80
- maintainer: The Authors
81
- copyright: The Authors
82
- copyright_email: you@example.com
83
- license: Apache-2.0
84
- summary: An InSpec Compliance Profile
85
- version: 0.1.0
86
- depends:
87
- - name: inherit
88
- url: "https://artifactory.com/artifactory/example-repo-local/inspec/0.4.1.tar.gz"
89
- username: <%= ENV['USERNAME'] %>
90
- password: <%= ENV['API_KEY'] %>
91
- ```
92
-
93
- ## Verify Profiles
94
-
95
- Use the `inspec check` command to verify the implementation of a profile:
96
-
97
- ```bash
98
- $ inspec check examples/profile
99
- ```
100
-
101
- # Platform Support
102
-
103
- Use the `supports` setting in the `inspec.yml` file to specify one (or more) platforms for which a profile is targeting. The list of supported platforms may contain the following:
104
-
105
- * Use `platform-family` to restrict to a specific platform family.
106
- * Use `platform-name` to restrict on a specific platform name.
107
- * Use `release` to restrict to a specific platform version (used with platform-name).
108
- * Use `platform` to restrict on either platform-name or platform-family.
109
-
110
- For compatibility we support `os-name` and `os-family`. We recommend all users to change `os-name` to `platform-name` and `os-family` to `platform-family`.
111
-
112
- With InSpec 2.0, we introduced new families to help distinguish the cloud platforms. The new families can restrict the platform family to `os`, `aws`, `azure` or `gcp`.
113
-
114
- For example, to target anything running Debian Linux:
115
-
116
- ```YAML
117
- name: ssh
118
- supports:
119
- - platform-name: debian
120
- ```
121
-
122
- and to target only Ubuntu version 14.04
123
-
124
- ```YAML
125
- name: ssh
126
- supports:
127
- - platform-name: ubuntu
128
- release: 14.04
129
- ```
130
-
131
- and to target the entire RedHat platform (including CentOS and Oracle Linux):
132
-
133
- ```YAML
134
- name: ssh
135
- supports:
136
- - platform-family: redhat
137
- ```
138
-
139
- and to target anything running on Amazon AWS:
140
-
141
- ```YAML
142
- name: ssh
143
- supports:
144
- - platform: aws
145
- ```
146
-
147
- and to target all of these examples in a single `inspec.yml` file:
148
-
149
- ```YAML
150
- name: ssh
151
- supports:
152
- - platform-name: debian
153
- - platform-name: ubuntu
154
- release: 14.04
155
- - platform-family: redhat
156
- - platform: aws
157
- ```
158
-
159
- # Profile Dependencies
160
-
161
- An InSpec profile can bring in the controls and custom resources from another InSpec profile. Additionally, when inheriting the controls of another profile, a profile can skip or even modify those included controls.
162
-
163
- For hands-on examples, check out [Create a custom InSpec profile](https://learn.chef.io/modules/create-a-custom-profile#/) on Learn Chef Rally.
164
-
165
- ## Defining the Dependencies
166
-
167
- Before a profile can use controls from another profile, the to-be-included profile needs to be specified in the including profile’s `inspec.yml` file in the `depends` section. For each profile to be included, a location for the profile from where to be fetched and a name for the profile should be included. For example:
168
-
169
- ```YAML
170
- depends:
171
- - name: linux-baseline
172
- url: https://github.com/dev-sec/linux-baseline/archive/master.tar.gz
173
- - name: ssh-baseline
174
- url: https://github.com/dev-sec/ssh-baseline/archive/master.tar.gz
175
- ```
176
-
177
- InSpec supports a number of dependency sources.
178
-
179
- ### path
180
-
181
- The `path` setting defines a profile that is located on disk. This setting is typically used during development of profiles and when debugging profiles.
182
-
183
- ```YAML
184
- depends:
185
- - name: my-profile
186
- path: /absolute/path
187
- - name: another
188
- path: ../relative/path
189
- ```
190
-
191
- ### url
192
-
193
- The `url` setting specifies a profile that is located at an HTTP- or HTTPS-based URL. The profile must be accessible via a HTTP GET operation and must be a valid profile archive (zip, tar, or tar.gz format).
194
-
195
- ```YAML
196
- depends:
197
- - name: my-profile
198
- url: https://my.domain/path/to/profile.tgz
199
- - name: profile-via-git
200
- url: https://github.com/myusername/myprofile-repo/archive/master.tar.gz
201
- ```
202
-
203
- `url` also supports basic authentication.
204
-
205
- ```YAML
206
- depends:
207
- - name: my-profile
208
- url: https://my.domain/path/to/profile.tgz
209
- username: user
210
- password: password
211
- ```
212
-
213
- ### git
214
-
215
- A `git` setting specifies a profile that is located in a git repository, with optional settings for branch, tag, commit, and version. The source location is translated into a URL upon resolution. This type of dependency supports version constraints via semantic versioning as git tags.
216
-
217
- For example:
218
-
219
- ```YAML
220
- depends:
221
- - name: git-profile
222
- git: http://url/to/repo
223
- branch: desired_branch
224
- tag: desired_version
225
- commit: pinned_commit
226
- version: semver_via_tags
227
- ```
228
-
229
- ### supermarket
230
-
231
- A `supermarket` setting specifies a profile that is located in a cookbook hosted on Chef Supermarket. The source location is translated into a URL upon resolution.
232
-
233
- For example:
234
-
235
- ```YAML
236
- depends:
237
- - name: supermarket-profile
238
- supermarket: supermarket-username/supermarket-profile
239
- ```
240
-
241
- Available Supermarket profiles can be listed with `inspec supermarket profiles`.
242
-
243
- ### compliance
244
-
245
- A `compliance` setting specifies a profile that is located on the Chef Automate or Chef Compliance server.
246
-
247
- For example:
248
-
249
- ```YAML
250
- depends:
251
- - name: linux
252
- compliance: base/linux
253
- ```
254
-
255
- ## Vendoring Dependencies
256
-
257
- When you execute a local profile, the `inspec.yml` file will be read in order to source any profile dependencies. It will then cache the dependencies locally and generate an `inspec.lock` file.
258
-
259
- If you add or update dependencies in `inspec.yml`, dependencies may be re-vendored and the lockfile updated with `inspec vendor --overwrite`
260
-
261
- ## Using Controls from an Included Profile
262
-
263
- Once defined in the `inspec.yml`, controls from the included profiles can be used! Let’s look at some examples.
264
-
265
- ### Including All Controls from a Profile
266
-
267
- With the `include_controls` command in a profile, all controls from the named profile will be executed every time the including profile is executed.
268
-
269
- ![Include Controls](/images/profile_inheritance/include_controls.png)
270
-
271
- In the example above, every time `my-app-profile` is executed, all the controls from `my-baseline` are also executed. Therefore, the following controls would be executed:
272
-
273
- * myapp-1
274
- * myapp-2
275
- * myapp-3
276
- * baseline-1
277
- * baseline-2
278
-
279
- This is a great reminder that having a good naming convention for your controls is helpful to avoid confusion when
280
- including controls from other profiles!
281
-
282
- ### Skipping a Control from a Profile
283
-
284
- What if one of the controls from the included profile does not apply to your environment? Luckily, it is not necessary to maintain a slightly-modified copy of the included profile just to delete a control. The `skip_control` command tells InSpec to not run a particular control.
285
-
286
- ![Include Controls with Skip](/images/profile_inheritance/include_controls_with_skip.png)
287
-
288
-
289
- In the above example, all controls from `my-app-profile` and `my-baseline` profile will be executed every time `my-app-profile` is executed **except** for control `baseline-2` from the `my-baseline` profile.
290
-
291
- ### Modifying a Control
292
-
293
- Let's say a particular control from an included profile should still be run, but the impact isn't appropriate? Perhaps the test should still run, but if it fails, it should be treated as low severity instead of high severity?
294
-
295
- When a control is included, it can also be modified!
296
-
297
- ![Include Controls with Modification](/images/profile_inheritance/include_controls_with_mod.png)
298
-
299
- In the above example, all controls from `my-baseline` are executed along with all the controls from the including profile, `my-app-profile`. However, should control `baseline-1` fail, it will be raised with an impact of `0.5` instead of the originally-intended impact of `1.0`.
300
-
301
- ### Selectively Including Controls from a Profile
302
-
303
- If there are only a handful of controls that should be executed from an included profile, it's not necessarily to skip all the unneeded controls, or worse, copy/paste those controls bit-for-bit into your profile. Instead, use the `require_controls` command.
304
-
305
- ![Require Controls](/images/profile_inheritance/require_controls.png)
306
-
307
- Whenever `my-app-profile` is executed, in addition to its own controls, it will run only the controls specified in the `require_controls` block. In the case, the following controls would be executed:
308
-
309
- * myapp-1
310
- * myapp-2
311
- * myapp-3
312
- * baseline-2
313
- * baseline-4
314
-
315
- Controls `baseline-1`, `baseline-3`, and `baseline-5` would not be run, just as if they were manually skipped. This method of including specific controls ensures only the controls specified are executed; if new controls are added to a later version of `my-baseline`, they would not be run.
316
-
317
- And, just the way its possible to modify controls when using `include_controls`, controls can be modified as well.
318
-
319
- ![Require Controls with Modification](/images/profile_inheritance/require_controls_with_mod.png)
320
-
321
- As with the prior example, only `baseline-2` and `baseline-4` are executed, but if `baseline-2` fails, it will report with an impact of `0.5` instead of the originally-intended `1.0` impact.
322
-
323
- ## Using Resources from an Included Profile
324
-
325
- By default, all of the custom resources from a listed dependency are available
326
- for use in your profile. If two of your dependencies provide a resource with
327
- the same name, you can use the `require_resource` DSL function to
328
- disambiguate the two:
329
-
330
- ```YAML
331
- require_resource(profile: 'my_dep', resource: 'my_res',
332
- as: 'my_res2')
333
- ```
334
-
335
- This will allow you to reference the resource `my_res` from the
336
- profile `my_dep` using the name `my_res2`.
337
-
338
- # Profile Attributes
339
-
340
- Attributes are frequently used to parameterize a profile for use in different environments or targets. It can also be used define secrets, such as user names and passwords, that should not otherwise be stored in plain-text in a cookbook. Attributes may be set for the whole profile in the `inspec.yml`.
341
-
342
- Attributes may contain the following options:
343
-
344
- * Use `default` to set a default value for the attribute.
345
- * Use `type` to restrict an attribute to a specific type (any, string, numeric, array, hash, boolean, regex).
346
- * Use `required` to mandate the attribute has a default value or a value from a attribute YAML file.
347
- * Use `description` to set a brief description for the attribute.
348
-
349
-
350
- You can specify attributes in your `inspec.yml` using the `attributes` setting. For example, to add a `user` attribute for your profile:
351
-
352
- ```YAML
353
- attributes:
354
- - name: user
355
- type: string
356
- default: bob
357
- ```
358
-
359
- Example of adding a array object of servers:
360
-
361
- ```YAML
362
- attributes:
363
- - name: servers
364
- type: array
365
- default:
366
- - server1
367
- - server2
368
- - server3
369
- ```
370
-
371
- To access an attribute you will use the `attribute` keyword. You can use this anywhere in your control code.
372
-
373
- For example:
374
-
375
- ```Ruby
376
- current_user = attribute('user')
377
-
378
- control 'system-users' do
379
- describe attribute('user') do
380
- it { should eq 'bob' }
381
- end
382
-
383
- describe current_user do
384
- it { should eq attribute('user') }
385
- end
386
- end
387
- ```
388
-
389
- For sensitive data it is recomended to use a secrets YAML file located on the local machine to populate the values of attributes. A secrets file will always overwrite a attributes default value. To use the secrets file run `inspec exec` and specify the path to that Yaml file using the `--attrs` attribute.
390
-
391
- For example, a inspec.yml:
392
-
393
- ```YAML
394
- attributes:
395
- - name: username
396
- type: string
397
- required: true
398
- - name: password
399
- type: string
400
- required: true
401
- ```
402
-
403
- The control:
404
-
405
- ```Ruby
406
- control 'system-users' do
407
- impact 0.8
408
- desc '
409
- This test assures that the user "Bob" has a user installed on the system, along with a
410
- specified password.
411
- '
412
-
413
- describe attribute('username') do
414
- it { should eq 'bob' }
415
- end
416
-
417
- describe attribute('password') do
418
- it { should eq 'secret' }
419
- end
420
- end
421
- ```
422
-
423
- And a YAML file named `profile-attribute.yml`:
424
-
425
- ```YAML
426
- username: bob
427
- password: secret
428
- ```
429
-
430
- The following command runs the tests and applies the secrets specified in `profile-attribute.yml`:
431
-
432
- ```bash
433
- $ inspec exec examples/profile-attribute --attrs examples/profile-attribute.yml
434
- ```
435
-
436
- To change your attributes for platform specific cases you can setup multiple `--attrs` files.
437
-
438
- For example, a inspec.yml:
439
-
440
- ```YAML
441
- attributes:
442
- - name: users
443
- type: array
444
- required: true
445
- ```
446
-
447
- A YAML file named `windows.yml`
448
-
449
- ```YAML
450
- users:
451
- - Administrator
452
- - Guest
453
- - Randy
454
- ```
455
-
456
- A YAML file named `linux.yml`
457
-
458
- ```YAML
459
- users:
460
- - root
461
- - shadow
462
- - rmadison
463
- ```
464
-
465
- The control file:
466
-
467
- ```RUBY
468
- control 'system-users' do
469
- impact 0.8
470
- desc 'Confirm the proper users are created on the system'
471
-
472
- describe users do
473
- its('usernames') { should eq attribute('users') }
474
- end
475
- end
476
- ```
477
-
478
- The following command runs the tests and applies the attributes specified:
479
-
480
- ```bash
481
- $ inspec exec examples/profile-attribute --attrs examples/windows.yml
482
- $ inspec exec examples/profile-attribute --attrs examples/linux.yml
483
- ```
484
-
485
- See the full example in the InSpec open source repository: [Example InSpec Profile with Attributes](https://github.com/chef/inspec/tree/master/examples/profile-attribute)
486
-
487
- # Profile files
488
-
489
- An InSpec profile may contain additional files that can be accessed during tests. A profile file enables you to separate the logic of your tests from the data your tests check for, for example, the list of ports you require to be open.
490
-
491
- To access these files, they must be stored in the `files` directory at the root of a profile. They are accessed by their name relative to this folder with `inspec.profile.file(...)`.
492
-
493
- Here is an example for reading and testing a list of ports. The folder structure is:
494
-
495
- ```YAML
496
- examples/profile
497
- ├── controls
498
- │ ├── example.rb
499
- │── files
500
- │ └── services.yml
501
- └── inspec.yml
502
- ```
503
-
504
- With `services.yml` containing:
505
-
506
- ```YAML
507
- - service_name: httpd-alpha
508
- port: 80
509
- - service_name: httpd-beta
510
- port: 8080
511
- ```
512
-
513
- The tests in `example.rb` can now access this file:
514
-
515
- ```Ruby
516
- my_services = yaml(content: inspec.profile.file('services.yml')).params
517
-
518
- my_services.each do |s|
519
- describe service(s['service_name']) do
520
- it { should be_running }
521
- end
522
-
523
- describe port(s['port']) do
524
- it { should be_listening }
525
- end
526
- end
527
- ```
528
-
529
- For a more complete example that uses a profile file, see [Explore InSpec resources](https://learn.chef.io/modules/explore-inspec-resources#/) on Learn Chef Rally.
530
-
531
- # "should" vs. "expect" syntax
532
-
533
- Users familiar with the RSpec testing framework may know that there are two ways to write test statements: `should` and `expect`. The RSpec community decided that `expect` is the preferred syntax. However, InSpec recommends the `should` syntax as it tends to read more easily to those users who are not as technical.
534
-
535
- InSpec will continue to support both methods of writing tests. Consider this `file` test:
536
-
537
- ```Ruby
538
- describe file('/tmp/test.txt') do
539
- it { should be_file }
540
- end
541
- ```
542
-
543
- This can be re-written with `expect` syntax
544
-
545
- ```Ruby
546
- describe file('/tmp/test.txt') do
547
- it 'should be a file' do
548
- expect(subject).to(be_file)
549
- end
550
- end
551
- ```
552
-
553
- The output of both of the above examples looks like this:
554
-
555
- ```text
556
- File /tmp/test.txt
557
- ✔ should be a file
558
- ```
559
-
560
- In addition, you can make use of the `subject` keyword to further control your output if you choose:
561
-
562
- ```Ruby
563
- describe 'test file' do
564
- subject { file('/tmp/test.txt') }
565
- it 'should be a file' do
566
- expect(subject).to(be_file)
567
- end
568
- end
569
- ```
570
-
571
- ... which will render the following output:
572
-
573
- ```text
574
- test file
575
- ✔ should be a file
576
- ```