inspec 1.0.0 → 1.35.1
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +933 -101
- data/Gemfile +8 -17
- data/MAINTAINERS.md +2 -1
- data/MAINTAINERS.toml +9 -4
- data/README.md +49 -28
- data/Rakefile +54 -39
- data/bin/inspec +1 -1
- data/docs/dsl_inspec.md +17 -4
- data/docs/dsl_resource.md +1 -1
- data/docs/habitat.md +192 -0
- data/docs/inspec_and_friends.md +4 -2
- data/docs/matchers.md +11 -0
- data/docs/migration.md +293 -0
- data/docs/profiles.md +124 -76
- data/docs/resources/aide_conf.md.erb +81 -0
- data/docs/resources/apache_conf.md.erb +10 -10
- data/docs/resources/apt.md.erb +13 -13
- data/docs/resources/audit_policy.md.erb +10 -10
- data/docs/resources/auditd_conf.md.erb +10 -10
- data/docs/resources/auditd_rules.md.erb +11 -11
- data/docs/resources/bash.md.erb +12 -12
- data/docs/resources/bond.md.erb +15 -15
- data/docs/resources/bridge.md.erb +11 -11
- data/docs/resources/bsd_service.md.erb +11 -11
- data/docs/resources/command.md.erb +23 -23
- data/docs/resources/crontab.md.erb +84 -0
- data/docs/resources/csv.md.erb +10 -10
- data/docs/resources/dh_params.md +191 -0
- data/docs/resources/directory.md.erb +8 -8
- data/docs/resources/docker.md.erb +160 -0
- data/docs/resources/docker_container.md.erb +89 -0
- data/docs/resources/docker_image.md.erb +86 -0
- data/docs/resources/etc_group.md.erb +16 -16
- data/docs/resources/etc_hosts.md.erb +62 -0
- data/docs/resources/file.md.erb +80 -58
- data/docs/resources/gem.md.erb +32 -13
- data/docs/resources/group.md.erb +12 -12
- data/docs/resources/grub_conf.md.erb +11 -11
- data/docs/resources/host.md.erb +27 -18
- data/docs/resources/http.md.erb +104 -0
- data/docs/resources/iis_app.md.erb +126 -0
- data/docs/resources/iis_site.md.erb +17 -17
- data/docs/resources/inetd_conf.md.erb +10 -10
- data/docs/resources/ini.md.erb +9 -9
- data/docs/resources/interface.md.erb +13 -13
- data/docs/resources/iptables.md.erb +21 -14
- data/docs/resources/json.md.erb +11 -11
- data/docs/resources/kernel_module.md.erb +73 -12
- data/docs/resources/kernel_parameter.md.erb +12 -12
- data/docs/resources/key_rsa.md.erb +70 -0
- data/docs/resources/launchd_service.md.erb +11 -11
- data/docs/resources/limits_conf.md.erb +10 -10
- data/docs/resources/login_def.md.erb +12 -12
- data/docs/resources/mount.md.erb +14 -14
- data/docs/resources/mssql_session.md.erb +62 -0
- data/docs/resources/mysql_conf.md.erb +14 -14
- data/docs/resources/mysql_session.md.erb +22 -10
- data/docs/resources/npm.md.erb +13 -13
- data/docs/resources/ntp_conf.md.erb +9 -9
- data/docs/resources/oneget.md.erb +11 -11
- data/docs/resources/oracledb_session.md.erb +53 -0
- data/docs/resources/os.md.erb +17 -17
- data/docs/resources/os_env.md.erb +12 -12
- data/docs/resources/package.md.erb +29 -16
- data/docs/resources/parse_config.md.erb +18 -18
- data/docs/resources/parse_config_file.md.erb +29 -23
- data/docs/resources/{etc_passwd.md.erb → passwd.md.erb} +17 -17
- data/docs/resources/pip.md.erb +15 -15
- data/docs/resources/port.md.erb +23 -23
- data/docs/resources/postgres_conf.md.erb +15 -13
- data/docs/resources/postgres_hba_conf.md.erb +104 -0
- data/docs/resources/postgres_ident_conf.md.erb +87 -0
- data/docs/resources/postgres_session.md.erb +28 -21
- data/docs/resources/powershell.md.erb +14 -14
- data/docs/resources/processes.md.erb +123 -0
- data/docs/resources/rabbitmq_config.md.erb +55 -0
- data/docs/resources/registry_key.md.erb +44 -21
- data/docs/resources/runit_service.md.erb +11 -11
- data/docs/resources/security_policy.md.erb +10 -10
- data/docs/resources/service.md.erb +18 -18
- data/docs/resources/{etc_shadow.md.erb → shadow.md.erb} +19 -19
- data/docs/resources/ssh_config.md.erb +13 -13
- data/docs/resources/sshd_config.md.erb +15 -15
- data/docs/resources/ssl.md.erb +13 -13
- data/docs/resources/sys_info.md.erb +10 -10
- data/docs/resources/systemd_service.md.erb +11 -11
- data/docs/resources/sysv_service.md.erb +11 -11
- data/docs/resources/upstart_service.md.erb +11 -11
- data/docs/resources/user.md.erb +20 -20
- data/docs/resources/users.md.erb +19 -19
- data/docs/resources/vbscript.md.erb +13 -13
- data/docs/resources/virtualization.md.erb +71 -0
- data/docs/resources/windows_feature.md.erb +10 -10
- data/docs/resources/windows_task.md.erb +103 -0
- data/docs/resources/wmi.md.erb +10 -10
- data/docs/resources/x509_certificate.md.erb +146 -0
- data/docs/resources/xinetd_conf.md.erb +17 -17
- data/docs/resources/xml.md.erb +75 -0
- data/docs/resources/yaml.md.erb +25 -11
- data/docs/resources/yum.md.erb +24 -16
- data/docs/resources/zfs_dataset.md.erb +63 -0
- data/docs/resources/zfs_pool.md.erb +57 -0
- data/docs/ruby_usage.md +50 -0
- data/docs/shared/matcher_cmp.md.erb +4 -6
- data/examples/inheritance/README.md +49 -3
- data/examples/inheritance/controls/example.rb +4 -1
- data/examples/inheritance/inspec.yml +3 -1
- data/examples/meta-profile/README.md +29 -3
- data/examples/meta-profile/controls/example.rb +10 -5
- data/examples/meta-profile/inspec.yml +4 -8
- data/examples/profile/README.md +1 -1
- data/examples/profile/controls/example.rb +0 -1
- data/examples/profile/controls/gordon.rb +0 -1
- data/examples/profile/inspec.yml +1 -1
- data/examples/profile-attribute/inspec.yml +1 -1
- data/examples/profile-sensitive/README.md +29 -0
- data/examples/profile-sensitive/controls/sensitive-failures.rb +9 -0
- data/examples/profile-sensitive/controls/sensitive.rb +9 -0
- data/examples/profile-sensitive/inspec.yml +8 -0
- data/inspec.gemspec +10 -2
- data/lib/bundles/inspec-artifact/README.md +1 -0
- data/lib/bundles/inspec-artifact/cli.rb +284 -0
- data/lib/bundles/inspec-artifact.rb +7 -0
- data/lib/bundles/inspec-compliance/README.md +44 -15
- data/lib/bundles/inspec-compliance/api.rb +135 -29
- data/lib/bundles/inspec-compliance/cli.rb +128 -21
- data/lib/bundles/inspec-compliance/configuration.rb +8 -0
- data/lib/bundles/inspec-compliance/http.rb +26 -19
- data/lib/bundles/inspec-compliance/target.rb +50 -25
- data/lib/bundles/inspec-habitat/cli.rb +31 -0
- data/lib/bundles/inspec-habitat/log.rb +10 -0
- data/lib/bundles/inspec-habitat/profile.rb +372 -0
- data/lib/bundles/inspec-habitat.rb +12 -0
- data/lib/bundles/inspec-init/templates/profile/controls/example.rb +0 -1
- data/lib/bundles/inspec-init/templates/profile/inspec.yml +1 -1
- data/lib/bundles/inspec-supermarket/api.rb +7 -5
- data/lib/bundles/inspec-supermarket/cli.rb +2 -2
- data/lib/fetchers/git.rb +4 -2
- data/lib/fetchers/local.rb +4 -1
- data/lib/fetchers/url.rb +64 -10
- data/lib/inspec/archive/tar.rb +1 -1
- data/lib/inspec/backend.rb +26 -3
- data/lib/inspec/base_cli.rb +44 -7
- data/lib/inspec/cached_fetcher.rb +2 -2
- data/lib/inspec/cli.rb +34 -12
- data/lib/inspec/completions/fish.sh.erb +34 -0
- data/lib/inspec/control_eval_context.rb +0 -2
- data/lib/inspec/dependencies/cache.rb +0 -1
- data/lib/inspec/dependencies/dependency_set.rb +2 -2
- data/lib/inspec/dependencies/lockfile.rb +13 -6
- data/lib/inspec/dependencies/requirement.rb +6 -6
- data/lib/inspec/dependencies/resolver.rb +4 -4
- data/lib/inspec/dsl.rb +3 -5
- data/lib/inspec/env_printer.rb +9 -1
- data/lib/inspec/exceptions.rb +8 -0
- data/lib/inspec/fetcher.rb +1 -1
- data/lib/inspec/file_provider.rb +47 -11
- data/lib/inspec/library_eval_context.rb +1 -1
- data/lib/inspec/metadata.rb +62 -18
- data/lib/inspec/method_source.rb +24 -0
- data/lib/inspec/objects/attribute.rb +21 -0
- data/lib/inspec/objects/control.rb +21 -3
- data/lib/inspec/objects/each_loop.rb +2 -1
- data/lib/inspec/objects/list.rb +1 -1
- data/lib/inspec/objects/or_test.rb +17 -2
- data/lib/inspec/objects/tag.rb +27 -0
- data/lib/inspec/objects/test.rb +9 -8
- data/lib/inspec/objects.rb +1 -0
- data/lib/inspec/plugins/fetcher.rb +4 -5
- data/lib/inspec/plugins/resource.rb +1 -2
- data/lib/inspec/plugins/source_reader.rb +3 -3
- data/lib/inspec/plugins.rb +1 -1
- data/lib/inspec/polyfill.rb +0 -1
- data/lib/inspec/profile.rb +92 -23
- data/lib/inspec/profile_context.rb +1 -1
- data/lib/inspec/profile_vendor.rb +66 -0
- data/lib/inspec/resource.rb +29 -3
- data/lib/inspec/rspec_json_formatter.rb +672 -285
- data/lib/inspec/rule.rb +12 -16
- data/lib/inspec/runner.rb +26 -15
- data/lib/inspec/runner_rspec.rb +1 -0
- data/lib/inspec/runtime_profile.rb +26 -0
- data/lib/inspec/schema.rb +185 -0
- data/lib/inspec/secrets/yaml.rb +8 -1
- data/lib/inspec/secrets.rb +1 -1
- data/lib/inspec/shell.rb +92 -22
- data/lib/inspec/source_reader.rb +1 -1
- data/lib/inspec/version.rb +1 -1
- data/lib/inspec.rb +1 -1
- data/lib/matchers/matchers.rb +67 -17
- data/lib/resources/aide_conf.rb +162 -0
- data/lib/resources/apache.rb +0 -1
- data/lib/resources/apache_conf.rb +3 -3
- data/lib/resources/apt.rb +2 -1
- data/lib/resources/audit_policy.rb +0 -1
- data/lib/resources/auditd_conf.rb +1 -2
- data/lib/resources/auditd_rules.rb +5 -5
- data/lib/resources/bond.rb +1 -1
- data/lib/resources/bridge.rb +1 -1
- data/lib/resources/command.rb +5 -3
- data/lib/resources/crontab.rb +102 -0
- data/lib/resources/csv.rb +18 -1
- data/lib/resources/dh_params.rb +84 -0
- data/lib/resources/directory.rb +7 -3
- data/lib/resources/docker.rb +198 -0
- data/lib/resources/docker_container.rb +114 -0
- data/lib/resources/docker_image.rb +96 -0
- data/lib/resources/etc_group.rb +2 -3
- data/lib/resources/etc_hosts.rb +81 -0
- data/lib/resources/file.rb +88 -30
- data/lib/resources/gem.rb +26 -6
- data/lib/resources/groups.rb +4 -5
- data/lib/resources/grub_conf.rb +3 -4
- data/lib/resources/host.rb +175 -35
- data/lib/resources/http.rb +73 -0
- data/lib/resources/iis_app.rb +103 -0
- data/lib/resources/iis_site.rb +23 -0
- data/lib/resources/inetd_conf.rb +9 -4
- data/lib/resources/interface.rb +4 -3
- data/lib/resources/json.rb +37 -14
- data/lib/resources/kernel_module.rb +77 -10
- data/lib/resources/kernel_parameter.rb +0 -1
- data/lib/resources/key_rsa.rb +67 -0
- data/lib/resources/limits_conf.rb +3 -4
- data/lib/resources/login_def.rb +2 -3
- data/lib/resources/mount.rb +34 -4
- data/lib/resources/mssql_session.rb +81 -12
- data/lib/resources/mysql.rb +0 -1
- data/lib/resources/mysql_conf.rb +1 -2
- data/lib/resources/mysql_session.rb +18 -7
- data/lib/resources/nginx_conf.rb +95 -0
- data/lib/resources/ntp_conf.rb +2 -3
- data/lib/resources/oracledb_session.rb +138 -0
- data/lib/resources/os_env.rb +7 -5
- data/lib/resources/package.rb +70 -13
- data/lib/resources/packages.rb +111 -0
- data/lib/resources/parse_config.rb +3 -4
- data/lib/resources/passwd.rb +4 -5
- data/lib/resources/pip.rb +29 -21
- data/lib/resources/port.rb +133 -14
- data/lib/resources/postgres.rb +53 -43
- data/lib/resources/postgres_conf.rb +40 -13
- data/lib/resources/postgres_hba_conf.rb +101 -0
- data/lib/resources/postgres_ident_conf.rb +79 -0
- data/lib/resources/postgres_session.rb +28 -20
- data/lib/resources/powershell.rb +2 -2
- data/lib/resources/processes.rb +61 -26
- data/lib/resources/rabbitmq_conf.rb +53 -0
- data/lib/resources/registry_key.rb +34 -11
- data/lib/resources/security_policy.rb +2 -2
- data/lib/resources/service.rb +17 -7
- data/lib/resources/ssh_conf.rb +17 -6
- data/lib/resources/ssl.rb +3 -4
- data/lib/resources/sys_info.rb +1 -1
- data/lib/resources/toml.rb +26 -0
- data/lib/resources/users.rb +41 -41
- data/lib/resources/virtualization.rb +252 -0
- data/lib/resources/windows_task.rb +106 -0
- data/lib/resources/x509_certificate.rb +143 -0
- data/lib/resources/xinetd.rb +18 -2
- data/lib/resources/xml.rb +27 -0
- data/lib/resources/yaml.rb +10 -2
- data/lib/resources/yum.rb +25 -7
- data/lib/resources/zfs_dataset.rb +60 -0
- data/lib/resources/zfs_pool.rb +49 -0
- data/lib/source_readers/flat.rb +2 -1
- data/lib/source_readers/inspec.rb +30 -11
- data/lib/utils/command_wrapper.rb +3 -3
- data/lib/utils/database_helpers.rb +77 -0
- data/lib/utils/erlang_parser.rb +192 -0
- data/lib/utils/filter.rb +2 -1
- data/lib/utils/filter_array.rb +0 -1
- data/lib/utils/find_files.rb +1 -2
- data/lib/utils/latest_version.rb +21 -0
- data/lib/utils/nginx_parser.rb +76 -0
- data/lib/utils/object_traversal.rb +5 -4
- data/lib/utils/parser.rb +23 -4
- data/lib/utils/plugin_registry.rb +3 -3
- data/lib/utils/simpleconfig.rb +25 -8
- data/lib/utils/spdx.rb +13 -0
- data/lib/utils/spdx.txt +344 -0
- metadata +168 -22
- data/docs/cli.md +0 -342
- data/docs/resources/process.md.erb +0 -73
- /data/docs/{plugin_kitchen_inspec.html.md → plugin_kitchen_inspec.md} +0 -0
data/docs/matchers.md
CHANGED
|
@@ -8,6 +8,7 @@ Inspec uses matchers to help compare resource values to expectations.
|
|
|
8
8
|
The following matchers are available:
|
|
9
9
|
|
|
10
10
|
* `be`
|
|
11
|
+
* `be_in`
|
|
11
12
|
* `cmp`
|
|
12
13
|
* `eq`
|
|
13
14
|
* `include`
|
|
@@ -125,6 +126,16 @@ describe passwd do
|
|
|
125
126
|
end
|
|
126
127
|
```
|
|
127
128
|
|
|
129
|
+
## be_in
|
|
130
|
+
|
|
131
|
+
Verifies that an item is included in a list.
|
|
132
|
+
|
|
133
|
+
```ruby
|
|
134
|
+
describe resource do
|
|
135
|
+
its('item') { should be_in LIST }
|
|
136
|
+
end
|
|
137
|
+
```
|
|
138
|
+
|
|
128
139
|
## match
|
|
129
140
|
|
|
130
141
|
Check if a string matches a regular expression.
|
data/docs/migration.md
ADDED
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: InSpec Migration Guide
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Migrate from Serverspec to InSpec
|
|
6
|
+
|
|
7
|
+
## How is InSpec different from Serverspec
|
|
8
|
+
|
|
9
|
+
We've written a complete blog post about that topic: [The Road to InSpec](https://blog.chef.io/2015/11/04/the-road-to-inspec/)
|
|
10
|
+
|
|
11
|
+
## Is InSpec suitable for infrastructure testing?
|
|
12
|
+
|
|
13
|
+
InSpec is a framework that allows you to run infrastructure testing as well as compliance testing. The compliance features are always optional and provide customers a way to use InSpec for both use-cases. To ensure we build the best infrastructure testing, we migrate our cookbooks [chef-cookbooks](https://github.com/chef-cookbooks) to InSpec.
|
|
14
|
+
|
|
15
|
+
## Which Serverspec resources are available in InSpec?
|
|
16
|
+
|
|
17
|
+
The following resources are available in InSpec:
|
|
18
|
+
|
|
19
|
+
| Serverspec | InSpec |
|
|
20
|
+
|:------------------------------------------------------------------------------------------:|:------------------------------------------------------------------------------------:|
|
|
21
|
+
| [`bond`](http://serverspec.org/resource_types.html#bond) | [`bond`](https://www.inspec.io/docs/reference/resources/bond/) |
|
|
22
|
+
| [`bridge`](http://serverspec.org/resource_types.html#bridge) | [`bridge`](https://www.inspec.io/docs/reference/resources/bridge/) |
|
|
23
|
+
| [`command`](http://serverspec.org/resource_types.html#command) | [`command`](https://www.inspec.io/docs/reference/resources/command/) |
|
|
24
|
+
| [`cron`](http://serverspec.org/resource_types.html#cron) | [`crontab`](https://www.inspec.io/docs/reference/resources/crontab/) |
|
|
25
|
+
| [`docker_container`](http://serverspec.org/resource_types.html#docker_container) | [`docker_container`](https://www.inspec.io/docs/reference/resources/docker_container/) |
|
|
26
|
+
| [`docker_image`](http://serverspec.org/resource_types.html#docker_image) | [`docker_image`](https://www.inspec.io/docs/reference/resources/docker_image/) |
|
|
27
|
+
| [`file`](http://serverspec.org/resource_types.html#file) | [`file`](https://www.inspec.io/docs/reference/resources/file/) |
|
|
28
|
+
| [`group`](http://serverspec.org/resource_types.html#group) | [`group`](https://www.inspec.io/docs/reference/resources/group/) |
|
|
29
|
+
| [`host`](http://serverspec.org/resource_types.html#host) | [`host`](https://www.inspec.io/docs/reference/resources/host/) |
|
|
30
|
+
| [`interface`](http://serverspec.org/resource_types.html#interface) | [`interface`](https://www.inspec.io/docs/reference/resources/interface/) |
|
|
31
|
+
| [`iis_website`](http://serverspec.org/resource_types.html#iis_website) | [`iis_website`](https://www.inspec.io/docs/reference/resources/iis_website/) |
|
|
32
|
+
| [`iis_app_pool`](http://serverspec.org/resource_types.html#iis_app_pool) | [`iis_website`](https://www.inspec.io/docs/reference/resources/iis_website/) |
|
|
33
|
+
| [`iptables`](http://serverspec.org/resource_types.html#iptables) | [`iptables`](https://www.inspec.io/docs/reference/resources/iptables/) |
|
|
34
|
+
| [`kernel_module`](http://serverspec.org/resource_types.html#kernel_module) | [`kernel_module`](https://www.inspec.io/docs/reference/resources/kernel_module/) |
|
|
35
|
+
| [`linux_kernel_parameter`](http://serverspec.org/resource_types.html#linux_kernel_parameter) | [`kernel_parameter`](https://www.inspec.io/docs/reference/resources/kernel_parameter/) |
|
|
36
|
+
| [`mysql_config`](http://serverspec.org/resource_types.html#mysql_config) | [`mysql_conf`](https://www.inspec.io/docs/reference/resources/mysql_conf/) |
|
|
37
|
+
| [`package`](http://serverspec.org/resource_types.html#package) | [`package`](https://www.inspec.io/docs/reference/resources/package/) |
|
|
38
|
+
| [`port`](http://serverspec.org/resource_types.html#port) | [`port`](https://www.inspec.io/docs/reference/resources/port/) |
|
|
39
|
+
| [`ppa`](http://serverspec.org/resource_types.html#ppa) | [`apt`](https://www.inspec.io/docs/reference/resources/apt/) |
|
|
40
|
+
| [`process`](http://serverspec.org/resource_types.html#process) | [`processes`](https://www.inspec.io/docs/reference/resources/processes/) |
|
|
41
|
+
| [`service`](http://serverspec.org/resource_types.html#service) | [`service`](https://www.inspec.io/docs/reference/resources/service/) |
|
|
42
|
+
| [`user`](http://serverspec.org/resource_types.html#user) | [`user`](https://www.inspec.io/docs/reference/resources/user/) |
|
|
43
|
+
| [`windows_feature`](http://serverspec.org/resource_types.html#windows_feature) | [`windows_feature`](https://www.inspec.io/docs/reference/resources/windows_feature/) |
|
|
44
|
+
| [`windows_registry_key`](http://serverspec.org/resource_types.html#windows_registry_key) | [`registry_key`](https://www.inspec.io/docs/reference/resources/registry_key/) |
|
|
45
|
+
| [`x509_certificate`](http://serverspec.org/resource_types.html#x509_certificate) | [`x509_certificate`](https://www.inspec.io/docs/reference/resources/x509_certificate/) |
|
|
46
|
+
| [`yumrepo`](http://serverspec.org/resource_types.html#yumrepo) | [`yum`](https://www.inspec.io/docs/reference/resources/yum/) |
|
|
47
|
+
| [`zfs`](http://serverspec.org/resource_types.html#zfs) | [`zfs_pool`](https://www.inspec.io/docs/reference/resources/zfs_pool/) |
|
|
48
|
+
|
|
49
|
+
Some Serverspec resources are not available yet. We will implement those resources based on user feedback. If you need a resource that is not available in InSpec, please open an [Github issue](https://github.com/chef/inspec/issues). The list of resources that are not available in InSpec:
|
|
50
|
+
|
|
51
|
+
* [`cgroup`](http://serverspec.org/resource_types.html#cgroup)
|
|
52
|
+
* [`default_gateway`](http://serverspec.org/resource_types.html#default_gateway)
|
|
53
|
+
* [`ip6tables`](http://serverspec.org/resource_types.html#ip6tables)
|
|
54
|
+
* [`ipfilter`](http://serverspec.org/resource_types.html#ipfilter)
|
|
55
|
+
* [`ipnat`](http://serverspec.org/resource_types.html#ipnat)
|
|
56
|
+
* [`linux_audit_system`](http://serverspec.org/resource_types.html#linux_audit_system)
|
|
57
|
+
* [`lxc`](http://serverspec.org/resource_types.html#lxc)
|
|
58
|
+
* [`mail_alias`](http://serverspec.org/resource_types.html#mail_alias)
|
|
59
|
+
* [`php_config`](http://serverspec.org/resource_types.html#php_config)
|
|
60
|
+
* [`routing_table`](http://serverspec.org/resource_types.html#routing_table)
|
|
61
|
+
* [`selinux`](http://serverspec.org/resource_types.html#selinux)
|
|
62
|
+
* [`selinux_module`](http://serverspec.org/resource_types.html#selinux_module)
|
|
63
|
+
* [`x509_private_key`](http://serverspec.org/resource_types.html#x509_private_key)
|
|
64
|
+
|
|
65
|
+
In addition InSpec provides additional [resources](https://www.inspec.io/docs/reference/resources/) that are not available in Serverspec:
|
|
66
|
+
|
|
67
|
+
* [`apache_conf`](https://www.inspec.io/docs/reference/resources/apache_conf/)
|
|
68
|
+
* [`apt`](https://www.inspec.io/docs/reference/resources/apt/)
|
|
69
|
+
* [`audit_policy`](https://www.inspec.io/docs/reference/resources/audit_policy/)
|
|
70
|
+
* [`auditd_conf`](https://www.inspec.io/docs/reference/resources/auditd_conf/)
|
|
71
|
+
* [`bash`](https://www.inspec.io/docs/reference/resources/bash/)
|
|
72
|
+
* [`csv`](https://www.inspec.io/docs/reference/resources/csv/)
|
|
73
|
+
* [`etc_shadow`](https://www.inspec.io/docs/reference/resources/etc_shadow/)
|
|
74
|
+
* [`gem`](https://www.inspec.io/docs/reference/resources/gem/)
|
|
75
|
+
* [`grub_conf`](https://www.inspec.io/docs/reference/resources/grub_conf/)
|
|
76
|
+
* [`inetd_conf`](https://www.inspec.io/docs/reference/resources/inetd_conf/)
|
|
77
|
+
* [`ini`](https://www.inspec.io/docs/reference/resources/ini/)
|
|
78
|
+
* [`json`](https://www.inspec.io/docs/reference/resources/json/)
|
|
79
|
+
* [`npm`](https://www.inspec.io/docs/reference/resources/npm/)
|
|
80
|
+
* [`ntp_conf`](https://www.inspec.io/docs/reference/resources/ntp_conf/)
|
|
81
|
+
* [`oneget`](https://www.inspec.io/docs/reference/resources/oneget/)
|
|
82
|
+
* [`pip`](https://www.inspec.io/docs/reference/resources/pip/)
|
|
83
|
+
* [`powershell`](https://www.inspec.io/docs/reference/resources/powershell/)
|
|
84
|
+
* [`security_policy`](https://www.inspec.io/docs/reference/resources/security_policy/)
|
|
85
|
+
* [`ssh_config`](https://www.inspec.io/docs/reference/resources/ssh_config/)
|
|
86
|
+
* [`sshd_config`](https://www.inspec.io/docs/reference/resources/sshd_config/)
|
|
87
|
+
* [`sys_info`](https://www.inspec.io/docs/reference/resources/sys_info/)
|
|
88
|
+
|
|
89
|
+
## How do I migrate my Serverspec tests to InSpec
|
|
90
|
+
|
|
91
|
+
For most cases, the migration to InSpec is pretty straight forward. First, replace the current verifier in `kitchen.yml` configuration with:
|
|
92
|
+
|
|
93
|
+
```
|
|
94
|
+
verifier:
|
|
95
|
+
name: inspec
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Second, rename the directory `test/integration/default/serverspec` to
|
|
99
|
+
`test/integration/default/inspec`
|
|
100
|
+
|
|
101
|
+
Third, remove the Serverspec-specific code from the test files.
|
|
102
|
+
|
|
103
|
+
```
|
|
104
|
+
require 'serverspec'
|
|
105
|
+
|
|
106
|
+
# Required by serverspec
|
|
107
|
+
set :backend, :exec
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
InSpec is now configured with Test-Kitchen:
|
|
111
|
+
|
|
112
|
+
```
|
|
113
|
+
kitchen verify package-install-centos-72
|
|
114
|
+
-----> Starting Kitchen (v1.14.2)
|
|
115
|
+
-----> Verifying <package-install-centos-72>...
|
|
116
|
+
Detected alternative framework tests for `inspec`
|
|
117
|
+
Loaded
|
|
118
|
+
|
|
119
|
+
Target: ssh://vagrant@127.0.0.1:2200
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
PHP has
|
|
123
|
+
✔ php
|
|
124
|
+
✔ the pear.php.net channel
|
|
125
|
+
✔ the pecl.php.net channel
|
|
126
|
+
|
|
127
|
+
Test Summary: 3 successful, 0 failures, 0 skipped
|
|
128
|
+
Finished verifying <package-install-centos-72> (0m0.40s).
|
|
129
|
+
-----> Kitchen is finished. (0m3.31s)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
Some real-world migrations are available:
|
|
133
|
+
|
|
134
|
+
* [docker](https://github.com/chef-cookbooks/docker)
|
|
135
|
+
* [nginx](https://github.com/chef-cookbooks/chef_nginx/pull/5/files)
|
|
136
|
+
* [mysql](https://github.com/chef-cookbooks/mysql/pull/430/files)
|
|
137
|
+
* [php](https://github.com/chef-cookbooks/php/pull/189/files)
|
|
138
|
+
|
|
139
|
+
Some general recommendations:
|
|
140
|
+
|
|
141
|
+
* use test-kitchen 1.14+
|
|
142
|
+
* in case of errors, increase the log level `kitchen verify package-install-centos-72 -l debug`
|
|
143
|
+
|
|
144
|
+
## Do I still need the backend configuration?
|
|
145
|
+
|
|
146
|
+
InSpec does not attach backend information to test files. All tests are defined independently of any backend. Therefore a Serverspec test file:
|
|
147
|
+
|
|
148
|
+
```
|
|
149
|
+
require 'serverspec'
|
|
150
|
+
|
|
151
|
+
# Required by serverspec
|
|
152
|
+
set :backend, :exec
|
|
153
|
+
|
|
154
|
+
describe 'PHP' do
|
|
155
|
+
it 'has php' do
|
|
156
|
+
expect(command('php -v').exit_status).to eq(0)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
it 'has the pear.php.net channel' do
|
|
160
|
+
expect(command('pear list-channels').stdout).to include('pear.php.net')
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
it 'has the pecl.php.net channel' do
|
|
164
|
+
expect(command('pear list-channels').stdout).to include('pecl.php.net')
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
will become the following InSpec test file:
|
|
170
|
+
|
|
171
|
+
```
|
|
172
|
+
describe 'PHP' do
|
|
173
|
+
it 'has php' do
|
|
174
|
+
expect(command('php -v').exit_status).to eq(0)
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
it 'has the pear.php.net channel' do
|
|
178
|
+
expect(command('pear list-channels').stdout).to include('pear.php.net')
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
it 'has the pecl.php.net channel' do
|
|
182
|
+
expect(command('pear list-channels').stdout).to include('pecl.php.net')
|
|
183
|
+
end
|
|
184
|
+
end
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
As you can see, the InSpec test files just focuses on tests and tries to avoid all clutter.
|
|
188
|
+
|
|
189
|
+
## Nested describe blocks
|
|
190
|
+
|
|
191
|
+
Serverspec and RSpec allow you to define nested describe blocks. We did a survey and found out that most users use nested describe blocks only to improve their output report. We believe the code structure should not change to improve the output of a report. Nevertheless we understand that nested describe blocks help you to structure test code. A sample code block looks like:
|
|
192
|
+
|
|
193
|
+
```
|
|
194
|
+
describe 'chef-server-directories' do
|
|
195
|
+
describe file('/etc/opscode') do
|
|
196
|
+
it { should be_directory }
|
|
197
|
+
it { should be_owned_by 'root' }
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
describe file('/etc/opscode-analytics') do
|
|
201
|
+
it { should be_directory }
|
|
202
|
+
it { should be_owned_by 'opscode' }
|
|
203
|
+
it { should be_grouped_into 'opscode' }
|
|
204
|
+
end
|
|
205
|
+
|
|
206
|
+
describe file('/var/log/opscode') do
|
|
207
|
+
it { should be_directory }
|
|
208
|
+
it { should be_owned_by 'opscode' }
|
|
209
|
+
it { should be_grouped_into 'opscode' }
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
describe file('/var/opt/opscode') do
|
|
213
|
+
it { should be_directory }
|
|
214
|
+
it { should be_owned_by 'root' }
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
In InSpec you would split up groups into files.
|
|
220
|
+
|
|
221
|
+
```
|
|
222
|
+
tests
|
|
223
|
+
├── server-directories.rb
|
|
224
|
+
├── other-tests.rb
|
|
225
|
+
└── further-tests.rb
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
Each file can have a top-level description of its content:
|
|
229
|
+
|
|
230
|
+
```
|
|
231
|
+
title "Chef Server Directories"
|
|
232
|
+
|
|
233
|
+
describe file('/etc/opscode') do
|
|
234
|
+
it { should be_directory }
|
|
235
|
+
it { should be_owned_by 'root' }
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
describe file('/etc/opscode-analytics') do
|
|
239
|
+
it { should be_directory }
|
|
240
|
+
it { should be_owned_by 'opscode' }
|
|
241
|
+
it { should be_grouped_into 'opscode' }
|
|
242
|
+
end
|
|
243
|
+
|
|
244
|
+
describe file('/var/log/opscode') do
|
|
245
|
+
it { should be_directory }
|
|
246
|
+
it { should be_owned_by 'opscode' }
|
|
247
|
+
it { should be_grouped_into 'opscode' }
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
describe file('/var/opt/opscode') do
|
|
251
|
+
it { should be_directory }
|
|
252
|
+
it { should be_owned_by 'root' }
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
## Are you supporting the `expect` syntax?
|
|
258
|
+
|
|
259
|
+
Of course. We still prefer the `should` syntax for UX reasons. We did surveys with various types of customers like devops engineers, auditors, managers. All participants who prefered the `expect` syntax have been Ruby experts. All non-Ruby developers found it easier to understand the `should` syntax.
|
|
260
|
+
|
|
261
|
+
### `should` syntax with InSpec
|
|
262
|
+
|
|
263
|
+
```
|
|
264
|
+
describe command('php -v') do
|
|
265
|
+
its('exit_status') { should eq 0 }
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
describe command('pear list-channels') do
|
|
269
|
+
its('stdout') { should include('pear.php.net')}
|
|
270
|
+
end
|
|
271
|
+
|
|
272
|
+
describe command('pear list-channels') do
|
|
273
|
+
its('stdout') { should include('pecl.php.net')}
|
|
274
|
+
end
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### `expect` syntax with InSpec
|
|
278
|
+
|
|
279
|
+
```
|
|
280
|
+
describe 'PHP' do
|
|
281
|
+
it 'has php' do
|
|
282
|
+
expect(command('php -v').exit_status).to eq(0)
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
it 'has the pear.php.net channel' do
|
|
286
|
+
expect(command('pear list-channels').stdout).to include('pear.php.net')
|
|
287
|
+
end
|
|
288
|
+
|
|
289
|
+
it 'has the pecl.php.net channel' do
|
|
290
|
+
expect(command('pear list-channels').stdout).to include('pecl.php.net')
|
|
291
|
+
end
|
|
292
|
+
end
|
|
293
|
+
```
|
data/docs/profiles.md
CHANGED
|
@@ -17,6 +17,8 @@ A profile should have the following structure::
|
|
|
17
17
|
│ └── control_etc.rb
|
|
18
18
|
├── libraries
|
|
19
19
|
│ └── extension.rb
|
|
20
|
+
|── files
|
|
21
|
+
│ └── extras.conf
|
|
20
22
|
└── inspec.yml
|
|
21
23
|
|
|
22
24
|
where:
|
|
@@ -24,6 +26,7 @@ where:
|
|
|
24
26
|
* `inspec.yml` includes the profile description (required)
|
|
25
27
|
* `controls` is the directory in which all tests are located (required)
|
|
26
28
|
* `libraries` is the directory in which all InSpec resource extensions are located (optional)
|
|
29
|
+
* `files` is the directory with additional files that a profile can access (optional)
|
|
27
30
|
* `README.md` should be used to explain the profile, its scope, and usage
|
|
28
31
|
|
|
29
32
|
See a complete example profile in the InSpec open source repository: https://github.com/chef/inspec/tree/master/examples/profile
|
|
@@ -98,24 +101,31 @@ and to target all of these examples in a single `inspec.yml` file:
|
|
|
98
101
|
name: ssh
|
|
99
102
|
supports:
|
|
100
103
|
- os-name: debian
|
|
101
|
-
supports:
|
|
102
104
|
- os-name: ubuntu
|
|
103
105
|
release: 14.04
|
|
104
|
-
supports:
|
|
105
106
|
- os-family: redhat
|
|
106
|
-
supports:
|
|
107
107
|
- platform: aws
|
|
108
108
|
|
|
109
109
|
|
|
110
110
|
# Profile Dependencies
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
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.
|
|
113
113
|
|
|
114
|
-
##
|
|
114
|
+
## Defining the Dependencies
|
|
115
115
|
|
|
116
|
-
|
|
116
|
+
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:
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
depends:
|
|
119
|
+
- name: linux-baseline
|
|
120
|
+
url: https://github.com/dev-sec/linux-baseline/archive/master.tar.gz
|
|
121
|
+
- name: ssh-baseline
|
|
122
|
+
url: https://github.com/dev-sec/ssh-baseline/archive/master.tar.gz
|
|
123
|
+
|
|
124
|
+
InSpec supports a number of dependency sources.
|
|
125
|
+
|
|
126
|
+
### path
|
|
127
|
+
|
|
128
|
+
The `path` setting defines a profile that is located on disk. This setting is typically used during development of profiles and when debugging profiles.
|
|
119
129
|
|
|
120
130
|
depends:
|
|
121
131
|
- name: my-profile
|
|
@@ -123,19 +133,19 @@ For example:
|
|
|
123
133
|
- name: another
|
|
124
134
|
path: ../relative/path
|
|
125
135
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
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, tar.gz format). If the download fails, the profile is inaccessible, or not in the correct format, an error is returned.
|
|
136
|
+
### url
|
|
129
137
|
|
|
130
|
-
|
|
138
|
+
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).
|
|
131
139
|
|
|
132
140
|
depends:
|
|
133
141
|
- name: my-profile
|
|
134
142
|
url: https://my.domain/path/to/profile.tgz
|
|
143
|
+
- name: profile-via-git
|
|
144
|
+
url: https://github.com/myusername/myprofile-repo/archive/master.tar.gz
|
|
135
145
|
|
|
136
|
-
|
|
146
|
+
### git
|
|
137
147
|
|
|
138
|
-
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
|
|
148
|
+
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.
|
|
139
149
|
|
|
140
150
|
For example:
|
|
141
151
|
|
|
@@ -147,105 +157,98 @@ For example:
|
|
|
147
157
|
commit: pinned_commit
|
|
148
158
|
version: semver_via_tags
|
|
149
159
|
|
|
150
|
-
|
|
160
|
+
### supermarket
|
|
151
161
|
|
|
152
|
-
A `supermarket` setting specifies a profile that is located in a cookbook hosted on Chef Supermarket
|
|
162
|
+
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.
|
|
153
163
|
|
|
154
164
|
For example:
|
|
155
165
|
|
|
156
166
|
depends:
|
|
157
167
|
- name: supermarket-profile
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
commit: pinned_commit
|
|
162
|
-
version: semver_via_tags
|
|
168
|
+
supermarket: supermarket-username/supermarket-profile
|
|
169
|
+
|
|
170
|
+
Available Supermarket profiles can be listed with `inspec supermarket profiles`.
|
|
163
171
|
|
|
164
|
-
|
|
172
|
+
### compliance
|
|
165
173
|
|
|
166
|
-
A `
|
|
174
|
+
A `compliance` setting specifies a profile that is located on the Chef Automate or Chef Compliance server.
|
|
167
175
|
|
|
168
176
|
For example:
|
|
169
177
|
|
|
170
178
|
depends:
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
branch: desired_branch
|
|
174
|
-
tag: desired_version
|
|
175
|
-
commit: pinned_commit
|
|
176
|
-
version: semver_via_tags
|
|
179
|
+
- name: linux
|
|
180
|
+
compliance: base/linux
|
|
177
181
|
|
|
178
|
-
##
|
|
182
|
+
## Vendoring Dependencies
|
|
179
183
|
|
|
180
|
-
|
|
184
|
+
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.
|
|
181
185
|
|
|
182
|
-
|
|
186
|
+
If you add or update dependencies in `inspec.yml`, dependencies may be re-vendored and the lockfile updated with `inspec vendor --overwrite`
|
|
183
187
|
|
|
184
|
-
|
|
185
|
-
- name: linux
|
|
186
|
-
compliance: base/linux
|
|
188
|
+
## Using Controls from an Included Profile
|
|
187
189
|
|
|
190
|
+
Once defined in the `inspec.yml`, controls from the included profiles can be used! Let’s look at some examples.
|
|
188
191
|
|
|
189
|
-
|
|
192
|
+
### Including All Controls from a Profile
|
|
190
193
|
|
|
191
|
-
|
|
194
|
+
With the `include_controls` command in a profile, all controls from the named profile will be executed every time the including profile is executed.
|
|
192
195
|
|
|
193
|
-
|
|
194
|
-
- name: ssh-hardening
|
|
195
|
-
supermarket: hardening/ssh-hardening
|
|
196
|
-
- name: os-hardening
|
|
197
|
-
url: https://github.com/dev-sec/tests-os-hardening/archive/master.zip
|
|
198
|
-
- name: ssl-benchmark
|
|
199
|
-
git: https://github.com/dev-sec/ssl-benchmark.git
|
|
200
|
-
- name: windows-patch-benchmark
|
|
201
|
-
git: https://github.com/chris-rock/windows-patch-benchmark.git
|
|
202
|
-
- name: linux
|
|
203
|
-
compliance: base/linux
|
|
196
|
+

|
|
204
197
|
|
|
205
|
-
|
|
198
|
+
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:
|
|
206
199
|
|
|
207
|
-
|
|
200
|
+
* myapp-1
|
|
201
|
+
* myapp-2
|
|
202
|
+
* myapp-3
|
|
203
|
+
* baseline-1
|
|
204
|
+
* baseline-2
|
|
208
205
|
|
|
209
|
-
|
|
206
|
+
This is a great reminder that having a good naming convention for your controls is helpful to avoid confusion when
|
|
207
|
+
including controls from other profiles!
|
|
210
208
|
|
|
211
|
-
|
|
209
|
+
### Skipping a Control from a Profile
|
|
212
210
|
|
|
213
|
-
|
|
211
|
+
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.
|
|
214
212
|
|
|
215
|
-
|
|
213
|
+

|
|
216
214
|
|
|
217
|
-
|
|
218
|
-
impact 1.0
|
|
219
|
-
...
|
|
215
|
+
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.
|
|
220
216
|
|
|
221
|
-
|
|
217
|
+
### Modifying a Control
|
|
222
218
|
|
|
223
|
-
|
|
219
|
+
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?
|
|
224
220
|
|
|
225
|
-
|
|
221
|
+
When a control is included, it can also be modified!
|
|
226
222
|
|
|
227
|
-
|
|
228
|
-
skip_control "cis-fs-2.2"
|
|
223
|
+

|
|
229
224
|
|
|
230
|
-
|
|
225
|
+
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`.
|
|
231
226
|
|
|
232
|
-
|
|
227
|
+
### Selectively Including Controls from a Profile
|
|
233
228
|
|
|
234
|
-
|
|
229
|
+
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.
|
|
235
230
|
|
|
236
|
-
|
|
231
|
+

|
|
237
232
|
|
|
238
|
-
|
|
233
|
+
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:
|
|
239
234
|
|
|
240
|
-
|
|
241
|
-
|
|
235
|
+
* myapp-1
|
|
236
|
+
* myapp-2
|
|
237
|
+
* myapp-3
|
|
238
|
+
* baseline-2
|
|
239
|
+
* baseline-4
|
|
242
240
|
|
|
243
|
-
|
|
241
|
+
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.
|
|
242
|
+
|
|
243
|
+
And, just the way its possible to modify controls when using `include_controls`, controls can be modified as well.
|
|
244
|
+
|
|
245
|
+

|
|
244
246
|
|
|
247
|
+
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.
|
|
245
248
|
|
|
246
|
-
##
|
|
249
|
+
## Using Resources from an Included Profile
|
|
247
250
|
|
|
248
|
-
By default, all of the resources from a listed dependency are available
|
|
251
|
+
By default, all of the custom resources from a listed dependency are available
|
|
249
252
|
for use in your profile. If two of your dependencies provide a resource with
|
|
250
253
|
the same name, you can use the `require_resource` DSL function to
|
|
251
254
|
disambiguate the two:
|
|
@@ -262,15 +265,24 @@ Attributes may be used in profiles to define secrets, such as user names and pas
|
|
|
262
265
|
|
|
263
266
|
For example, a control:
|
|
264
267
|
|
|
268
|
+
# define these attributes on the top-level of your file and re-use them across all tests!
|
|
265
269
|
val_user = attribute('user', default: 'alice', description: 'An identification for the user')
|
|
266
270
|
val_password = attribute('password', description: 'A value for the password')
|
|
267
271
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
272
|
+
control 'system-users' do
|
|
273
|
+
impact 0.8
|
|
274
|
+
desc '
|
|
275
|
+
This test assures that the user "Bob" has a user installed on the system, along with a
|
|
276
|
+
specified password.
|
|
277
|
+
'
|
|
278
|
+
|
|
279
|
+
describe val_user do
|
|
280
|
+
it { should eq 'bob' }
|
|
281
|
+
end
|
|
271
282
|
|
|
272
|
-
|
|
273
|
-
|
|
283
|
+
describe val_password do
|
|
284
|
+
it { should eq 'secret' }
|
|
285
|
+
end
|
|
274
286
|
end
|
|
275
287
|
|
|
276
288
|
And a Yaml file named `profile-attribute.yml`:
|
|
@@ -283,3 +295,39 @@ The following command runs the tests and applies the secrets specified in `profi
|
|
|
283
295
|
$ inspec exec examples/profile-attribute --attrs examples/profile-attribute.yml
|
|
284
296
|
|
|
285
297
|
See the full example in the InSpec open source repository: https://github.com/chef/inspec/tree/master/examples/profile-attribute
|
|
298
|
+
|
|
299
|
+
# Profile files
|
|
300
|
+
|
|
301
|
+
An InSpec profile may contain additional files that can be accessed during tests. This covers use-cases where e.g. a list of ports is provided to be tested.
|
|
302
|
+
|
|
303
|
+
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(...)`.
|
|
304
|
+
|
|
305
|
+
Here is an example for reading and testing a list of ports. The folder structure is:
|
|
306
|
+
|
|
307
|
+
examples/profile
|
|
308
|
+
├── controls
|
|
309
|
+
│ ├── example.rb
|
|
310
|
+
|── files
|
|
311
|
+
│ └── services.yml
|
|
312
|
+
└── inspec.yml
|
|
313
|
+
|
|
314
|
+
With `services.yml` containing:
|
|
315
|
+
|
|
316
|
+
- service_name: httpd-alpha
|
|
317
|
+
port: 80
|
|
318
|
+
- service_name: httpd-beta
|
|
319
|
+
port: 8080
|
|
320
|
+
|
|
321
|
+
The tests in `example.rb` can now access this file:
|
|
322
|
+
|
|
323
|
+
my_services = yaml(content: inspec.profile.file('services.yml')).params
|
|
324
|
+
|
|
325
|
+
my_services.each do |s|
|
|
326
|
+
describe service(s['name']) do
|
|
327
|
+
it { should be_running }
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
describe port(s['port']) do
|
|
331
|
+
it { should be_listening }
|
|
332
|
+
end
|
|
333
|
+
end
|