inspec 0.34.1 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +323 -6
  3. data/Gemfile +10 -0
  4. data/README.md +1 -1
  5. data/Rakefile +4 -55
  6. data/docs/.gitignore +2 -0
  7. data/docs/README.md +40 -0
  8. data/docs/cli.md +342 -0
  9. data/docs/dsl_inspec.md +245 -0
  10. data/docs/dsl_resource.md +93 -0
  11. data/docs/inspec_and_friends.md +105 -0
  12. data/docs/matchers.md +136 -0
  13. data/docs/plugin_kitchen_inspec.html.md +55 -0
  14. data/docs/profiles.md +285 -0
  15. data/docs/resources/apache_conf.md.erb +75 -0
  16. data/docs/resources/apt.md.erb +84 -0
  17. data/docs/resources/audit_policy.md.erb +61 -0
  18. data/docs/resources/auditd_conf.md.erb +79 -0
  19. data/docs/resources/auditd_rules.md.erb +132 -0
  20. data/docs/resources/bash.md.erb +84 -0
  21. data/docs/resources/bond.md.erb +97 -0
  22. data/docs/resources/bridge.md.erb +67 -0
  23. data/docs/resources/bsd_service.md.erb +76 -0
  24. data/docs/resources/command.md.erb +151 -0
  25. data/docs/resources/csv.md.erb +62 -0
  26. data/docs/resources/directory.md.erb +43 -0
  27. data/docs/resources/etc_group.md.erb +116 -0
  28. data/docs/resources/etc_passwd.md.erb +155 -0
  29. data/docs/resources/etc_shadow.md.erb +149 -0
  30. data/docs/resources/file.md.erb +460 -0
  31. data/docs/resources/gem.md.erb +73 -0
  32. data/docs/resources/group.md.erb +74 -0
  33. data/docs/resources/grub_conf.md.erb +115 -0
  34. data/docs/resources/host.md.erb +85 -0
  35. data/docs/resources/iis_site.md.erb +142 -0
  36. data/docs/resources/inetd_conf.md.erb +99 -0
  37. data/docs/resources/ini.md.erb +69 -0
  38. data/docs/resources/interface.md.erb +66 -0
  39. data/docs/resources/iptables.md.erb +70 -0
  40. data/docs/resources/json.md.erb +76 -0
  41. data/docs/resources/kernel_module.md.erb +60 -0
  42. data/docs/resources/kernel_parameter.md.erb +72 -0
  43. data/docs/resources/launchd_service.md.erb +76 -0
  44. data/docs/resources/limits_conf.md.erb +80 -0
  45. data/docs/resources/login_def.md.erb +77 -0
  46. data/docs/resources/mount.md.erb +83 -0
  47. data/docs/resources/mysql_conf.md.erb +102 -0
  48. data/docs/resources/mysql_session.md.erb +63 -0
  49. data/docs/resources/npm.md.erb +75 -0
  50. data/docs/resources/ntp_conf.md.erb +76 -0
  51. data/docs/resources/oneget.md.erb +67 -0
  52. data/docs/resources/os.md.erb +154 -0
  53. data/docs/resources/os_env.md.erb +98 -0
  54. data/docs/resources/package.md.erb +115 -0
  55. data/docs/resources/parse_config.md.erb +122 -0
  56. data/docs/resources/parse_config_file.md.erb +143 -0
  57. data/docs/resources/pip.md.erb +74 -0
  58. data/docs/resources/port.md.erb +150 -0
  59. data/docs/resources/postgres_conf.md.erb +90 -0
  60. data/docs/resources/postgres_session.md.erb +75 -0
  61. data/docs/resources/powershell.md.erb +116 -0
  62. data/docs/resources/process.md.erb +73 -0
  63. data/docs/resources/registry_key.md.erb +149 -0
  64. data/docs/resources/runit_service.md.erb +76 -0
  65. data/docs/resources/security_policy.md.erb +61 -0
  66. data/docs/resources/service.md.erb +135 -0
  67. data/docs/resources/ssh_config.md.erb +94 -0
  68. data/docs/resources/sshd_config.md.erb +97 -0
  69. data/docs/resources/ssl.md.erb +133 -0
  70. data/docs/resources/sys_info.md.erb +55 -0
  71. data/docs/resources/systemd_service.md.erb +76 -0
  72. data/docs/resources/sysv_service.md.erb +76 -0
  73. data/docs/resources/upstart_service.md.erb +76 -0
  74. data/docs/resources/user.md.erb +154 -0
  75. data/docs/resources/users.md.erb +140 -0
  76. data/docs/resources/vbscript.md.erb +69 -0
  77. data/docs/resources/windows_feature.md.erb +61 -0
  78. data/docs/resources/wmi.md.erb +95 -0
  79. data/docs/resources/xinetd_conf.md.erb +170 -0
  80. data/docs/resources/yaml.md.erb +69 -0
  81. data/docs/resources/yum.md.erb +103 -0
  82. data/docs/ruby_usage.md +154 -0
  83. data/docs/shared/matcher_be.md.erb +1 -0
  84. data/docs/shared/matcher_cmp.md.erb +45 -0
  85. data/docs/shared/matcher_eq.md.erb +3 -0
  86. data/docs/shared/matcher_include.md.erb +1 -0
  87. data/docs/shared/matcher_match.md.erb +1 -0
  88. data/docs/shell.md +150 -0
  89. data/examples/meta-profile/inspec.yml +2 -4
  90. data/inspec.gemspec +1 -1
  91. data/lib/bundles/inspec-compliance/api.rb +28 -18
  92. data/lib/bundles/inspec-compliance/cli.rb +19 -27
  93. data/lib/bundles/inspec-compliance/target.rb +15 -2
  94. data/lib/fetchers/git.rb +4 -0
  95. data/lib/fetchers/local.rb +16 -1
  96. data/lib/fetchers/mock.rb +4 -0
  97. data/lib/fetchers/url.rb +46 -20
  98. data/lib/inspec/base_cli.rb +14 -0
  99. data/lib/inspec/cached_fetcher.rb +67 -0
  100. data/lib/inspec/cli.rb +22 -8
  101. data/lib/inspec/control_eval_context.rb +12 -2
  102. data/lib/inspec/dependencies/{vendor_index.rb → cache.rb} +5 -4
  103. data/lib/inspec/dependencies/dependency_set.rb +8 -14
  104. data/lib/inspec/dependencies/lockfile.rb +5 -13
  105. data/lib/inspec/dependencies/requirement.rb +31 -41
  106. data/lib/inspec/dependencies/resolver.rb +3 -3
  107. data/lib/inspec/dsl.rb +16 -4
  108. data/lib/inspec/errors.rb +1 -0
  109. data/lib/inspec/fetcher.rb +25 -1
  110. data/lib/inspec/objects/each_loop.rb +5 -2
  111. data/lib/inspec/objects/test.rb +8 -2
  112. data/lib/inspec/plugins/fetcher.rb +13 -12
  113. data/lib/inspec/plugins/resource.rb +3 -0
  114. data/lib/inspec/profile.rb +62 -26
  115. data/lib/inspec/profile_context.rb +44 -8
  116. data/lib/inspec/resource.rb +18 -3
  117. data/lib/inspec/rspec_json_formatter.rb +91 -40
  118. data/lib/inspec/rule.rb +45 -2
  119. data/lib/inspec/runner.rb +51 -39
  120. data/lib/inspec/shell.rb +5 -16
  121. data/lib/inspec/version.rb +1 -1
  122. data/lib/resources/apache_conf.rb +1 -1
  123. data/lib/resources/gem.rb +1 -0
  124. data/lib/resources/groups.rb +190 -0
  125. data/lib/resources/oneget.rb +1 -0
  126. data/lib/resources/os.rb +1 -1
  127. data/lib/resources/package.rb +3 -1
  128. data/lib/resources/parse_config.rb +18 -1
  129. data/lib/resources/pip.rb +1 -1
  130. data/lib/resources/security_policy.rb +54 -0
  131. data/lib/resources/ssl.rb +9 -11
  132. data/lib/resources/sys_info.rb +1 -1
  133. data/lib/resources/users.rb +81 -64
  134. metadata +91 -17
  135. data/docs/cli.rst +0 -442
  136. data/docs/dsl_inspec.rst +0 -259
  137. data/docs/dsl_resource.rst +0 -90
  138. data/docs/inspec_and_friends.rst +0 -85
  139. data/docs/matchers.rst +0 -137
  140. data/docs/profiles.rst +0 -169
  141. data/docs/readme.rst +0 -105
  142. data/docs/resources.rst +0 -4836
  143. data/docs/ruby_usage.rst +0 -145
  144. data/docs/shell.rst +0 -130
  145. data/docs/template.rst +0 -51
  146. data/lib/resources/group.rb +0 -137
@@ -0,0 +1,75 @@
1
+ ---
2
+ title: About the npm Resource
3
+ ---
4
+
5
+ # npm
6
+
7
+ Use the `npm` InSpec audit resource to test if a global NPM package is installed. NPM is the the package manager for Node.js packages (https://docs.npmjs.com), such as Bower and StatsD.
8
+
9
+
10
+ # Syntax
11
+
12
+ A `npm` resource block declares a package and (optionally) a package version:
13
+
14
+ describe gem('npm_package_name') do
15
+ it { should be_installed }
16
+ end
17
+
18
+ where
19
+
20
+ * `('npm_package_name')` must specify an NPM package, such as `'bower'` or `'statsd'`
21
+ * `be_installed` is a valid matcher for this resource
22
+
23
+
24
+ # Matchers
25
+
26
+ This InSpec audit resource has the following matchers:
27
+
28
+ ## be
29
+
30
+ <%= partial "/shared/matcher_be" %>
31
+
32
+ ## be_installed
33
+
34
+ The `be_installed` matcher tests if the named Gem package and package version (if specified) is installed:
35
+
36
+ it { should be_installed }
37
+
38
+ ## cmp
39
+
40
+ <%= partial "/shared/matcher_cmp" %>
41
+
42
+ ## eq
43
+
44
+ <%= partial "/shared/matcher_eq" %>
45
+
46
+ ## include
47
+
48
+ <%= partial "/shared/matcher_include" %>
49
+
50
+ ## match
51
+
52
+ <%= partial "/shared/matcher_match" %>
53
+
54
+ ## version
55
+
56
+ The `version` matcher tests if the named package version is on the system:
57
+
58
+ its('version') { should eq '1.2.3' }
59
+
60
+ # Examples
61
+
62
+ The following examples show how to use this InSpec audit resource.
63
+
64
+ ## Verify that bower is installed, with a specific version
65
+
66
+ describe npm('bower') do
67
+ it { should be_installed }
68
+ its('version') { should eq '1.4.1' }
69
+ end
70
+
71
+ ## Verify that statsd is not installed
72
+
73
+ describe npm('statsd') do
74
+ it { should_not be_installed }
75
+ end
@@ -0,0 +1,76 @@
1
+ ---
2
+ title: About the ntp_conf Resource
3
+ ---
4
+
5
+ # ntp_conf
6
+
7
+ Use the `ntp_conf` InSpec audit resource to test the synchronization settings defined in the `ntp.conf` file. This file is typically located at `/etc/ntp.conf`.
8
+
9
+
10
+ # Syntax
11
+
12
+ An `ntp_conf` resource block declares the synchronization settings that should be tested:
13
+
14
+ describe ntp_conf('path') do
15
+ its('setting_name') { should eq 'value' }
16
+ end
17
+
18
+ where
19
+
20
+ * `'setting_name'` is a synchronization setting defined in the `ntp.conf` file
21
+ * `('path')` is the non-default path to the `ntp.conf` file
22
+ * `{ should eq 'value' }` is the value that is expected
23
+
24
+
25
+ # Matchers
26
+
27
+ This resource matches any service that is listed in the `ntp.conf` file:
28
+
29
+ its('server') { should_not eq nil }
30
+
31
+ or:
32
+
33
+ its('restrict') { should include '-4 default kod notrap nomodify nopeer noquery'}
34
+
35
+ For example:
36
+
37
+ describe ntp_conf do
38
+ its('server') { should_not eq nil }
39
+ its('restrict') { should include '-4 default kod notrap nomodify nopeer noquery'}
40
+ end
41
+
42
+
43
+ ## be
44
+
45
+ <%= partial "/shared/matcher_be" %>
46
+
47
+ ## cmp
48
+
49
+ <%= partial "/shared/matcher_cmp" %>
50
+
51
+ ## eq
52
+
53
+ <%= partial "/shared/matcher_eq" %>
54
+
55
+ ## include
56
+
57
+ <%= partial "/shared/matcher_include" %>
58
+
59
+ ## match
60
+
61
+ <%= partial "/shared/matcher_match" %>
62
+
63
+ # Examples
64
+
65
+ The following examples show how to use this InSpec audit resource.
66
+
67
+ ## Test for clock drift against named servers
68
+
69
+ describe ntp_conf do
70
+ its('driftfile') { should eq '/var/lib/ntp/ntp.drift' }
71
+ its('server') { should eq [
72
+ 0.ubuntu.pool.ntp.org,
73
+ 1.ubuntu.pool.ntp.org,
74
+ 2.ubuntu.pool.ntp.org
75
+ ] }
76
+ end
@@ -0,0 +1,67 @@
1
+ ---
2
+ title: About the oneget Resource
3
+ ---
4
+
5
+ # oneget
6
+
7
+ Use the `oneget` InSpec audit resource to test if the named package and/or package version is installed on the system. This resource uses Oneget, which is `part of the Windows Management Framework 5.0 and Windows 10 <https://github.com/OneGet/oneget>`__. This resource uses the `Get-Package` cmdlet to return all of the package names in the Oneget repository.
8
+
9
+ # Syntax
10
+
11
+ A `oneget` resource block declares a package and (optionally) a package version:
12
+
13
+ describe oneget('name') do
14
+ it { should be_installed }
15
+ end
16
+
17
+ where
18
+
19
+ * `('name')` must specify the name of a package, such as `'VLC'`
20
+ * `be_installed` is a valid matcher for this resource
21
+
22
+
23
+ # Matchers
24
+
25
+ This InSpec audit resource has the following matchers:
26
+
27
+ ## be
28
+
29
+ <%= partial "/shared/matcher_be" %>
30
+
31
+ ## be_installed
32
+
33
+ The `be_installed` matcher tests if the named package is installed on the system:
34
+
35
+ it { should be_installed }
36
+
37
+ ## cmp
38
+
39
+ <%= partial "/shared/matcher_cmp" %>
40
+
41
+ ## eq
42
+
43
+ <%= partial "/shared/matcher_eq" %>
44
+
45
+ ## include
46
+
47
+ <%= partial "/shared/matcher_include" %>
48
+
49
+ ## match
50
+
51
+ <%= partial "/shared/matcher_match" %>
52
+
53
+ ## version
54
+
55
+ The `version` matcher tests if the named package version is on the system:
56
+
57
+ its('version') { should eq '1.2.3' }
58
+
59
+ # Examples
60
+
61
+ The following examples show how to use this InSpec audit resource.
62
+
63
+ ## Test if VLC is installed
64
+
65
+ describe oneget('VLC') do
66
+ it { should be_installed }
67
+ end
@@ -0,0 +1,154 @@
1
+ ---
2
+ title: About the os Resource
3
+ ---
4
+
5
+ # os
6
+
7
+ Use the `os` InSpec audit resource to test the platform on which the system is running.
8
+
9
+ # Syntax
10
+
11
+ An `os` resource block declares the platform to be tested. The platform may specified via matcher or control block name. For example, using a matcher:
12
+
13
+ describe os[:family] do
14
+ it { should eq 'platform_name' }
15
+ end
16
+
17
+ or using the block name:
18
+
19
+ describe os[:family_name] do
20
+ ...
21
+ end
22
+
23
+ * `'platform_name'` (a string) or `:family_name` (a symbol) is one of `aix`, `bsd`, `darwin`, `debian`, `hpux`, `linux`, `redhat`, `solaris`, `suse`, `unix`, or `windows`
24
+
25
+ # Matchers
26
+
27
+ This InSpec audit resource has the following matchers:
28
+
29
+ ## be
30
+
31
+ <%= partial "/shared/matcher_be" %>
32
+
33
+ ## cmp
34
+
35
+ <%= partial "/shared/matcher_cmp" %>
36
+
37
+ ## eq
38
+
39
+ <%= partial "/shared/matcher_eq" %>
40
+
41
+ ## include
42
+
43
+ <%= partial "/shared/matcher_include" %>
44
+
45
+ ## match
46
+
47
+ <%= partial "/shared/matcher_match" %>
48
+
49
+ # os.family? Helpers
50
+
51
+ The `os` audit resource includes a collection of helpers that enable more granular testing of platforms, platform names, architectures, and releases. Use any of the following platform-specific helpers to test for specific platforms:
52
+
53
+ * `aix?`
54
+ * `bsd?` (including Darwin, FreeBSD, NetBSD, and OpenBSD)
55
+ * `darwin?`
56
+ * `debian?`
57
+ * `hpux?`
58
+ * `linux?` (including Alpine Linux, Amazon Linux, ArchLinux, CoreOS, Exherbo, Fedora, Gentoo, and Slackware)
59
+ * `redhat?`
60
+ * `solaris?` (including Nexenta Core, OmniOS, Open Indiana, Solaris Open, and SmartOS)
61
+ * `suse?`
62
+ * `unix?`
63
+ * `windows?`
64
+
65
+ For example, to test for Darwin use:
66
+
67
+ describe os.bsd? do
68
+ it { should eq true }
69
+ end
70
+
71
+ To test for Windows use:
72
+
73
+ describe os.windows? do
74
+ it { should eq true }
75
+ end
76
+
77
+ and to test for Redhat use:
78
+
79
+ describe os.redhat? do
80
+ it { should eq true }
81
+ end
82
+
83
+ Use the following helpers to test for operating system names, releases, and architectures:
84
+
85
+ describe os.name do
86
+ it { should eq 'foo' }
87
+ end
88
+
89
+ describe os.release do
90
+ it { should eq 'foo' }
91
+ end
92
+
93
+ describe os.arch do
94
+ it { should eq 'foo' }
95
+ end
96
+
97
+ # os[:family] Symbols
98
+
99
+ Use `os[:family]` to enable more granular testing of platforms, platform names, architectures, and releases. Use any of the following platform-specific symbols to test for specific platforms:
100
+
101
+ * `:aix`
102
+ * `:bsd` For platforms that are part of the Berkeley OS family: `:darwin`, `:freebsd`, `:netbsd`, and `:openbsd`.
103
+ * `:debian`
104
+ * `:hpux`
105
+ * `:linux`. For platforms that are part of the Linux family: `:alpine`, `:amazon`, `:arch`, `:coreos`, `:exherbo`, `:fedora`, `:gentoo`, and `:slackware`.
106
+ * `:redhat`
107
+ * `:solaris`. For platforms that are part of the Solaris family: `:nexentacore`, `:omnios`, `:openindiana`, `:opensolaris`, and `:smartos`.
108
+ * `:suse`
109
+ * `:unix`
110
+ * `:windows`
111
+
112
+ For example, both of the following tests should have the same result:
113
+
114
+ if os[:family] == 'debian'
115
+ describe port(69) do
116
+ its('processes') { should include 'in.tftpd' }
117
+ end
118
+ elsif os[:family] == 'rhel'
119
+ describe port(69) do
120
+ its('processes') { should include 'xinetd' }
121
+ end
122
+ end
123
+
124
+ if os[:debian]
125
+ describe port(69) do
126
+ its('processes') { should include 'in.tftpd' }
127
+ end
128
+ elsif os[:rhel]
129
+ describe port(69) do
130
+ its('processes') { should include 'xinetd' }
131
+ end
132
+ end
133
+
134
+ # Examples
135
+
136
+ The following examples show how to use this InSpec audit resource.
137
+
138
+ ## Test for RedHat
139
+
140
+ describe os[:family] do
141
+ it { should eq 'redhat' }
142
+ end
143
+
144
+ ## Test for Ubuntu
145
+
146
+ describe os[:family] do
147
+ it { should eq 'debian' }
148
+ end
149
+
150
+ ## Test for Microsoft Windows
151
+
152
+ describe os[:family] do
153
+ it { should eq 'windows' }
154
+ end
@@ -0,0 +1,98 @@
1
+ ---
2
+ title: About the os_env Resource
3
+ ---
4
+
5
+ # os_env
6
+
7
+ Use the `os_env` InSpec audit resource to test the environment variables for the platform on which the system is running.
8
+
9
+ # Syntax
10
+
11
+ A `os_env` resource block declares an environment variable, and then declares its value:
12
+
13
+ describe os_env('VARIABLE') do
14
+ its('matcher') { should eq 1 }
15
+ end
16
+
17
+ where
18
+
19
+ * `('VARIABLE')` must specify an environment variable, such as `PATH`
20
+ * `matcher` is a valid matcher for this resource
21
+
22
+
23
+ # Matchers
24
+
25
+ This InSpec audit resource has the following matchers:
26
+
27
+ ## be
28
+
29
+ <%= partial "/shared/matcher_be" %>
30
+
31
+ ## cmp
32
+
33
+ <%= partial "/shared/matcher_cmp" %>
34
+
35
+ ## content
36
+
37
+ The `content` matcher return the value of the environment variable:
38
+
39
+ its('content') { should eq '/usr/local/bin:/usr/local/sbin:/usr/sbin:/usr/bin:/sbin' }
40
+
41
+ ## eq
42
+
43
+ <%= partial "/shared/matcher_eq" %>
44
+
45
+ ## include
46
+
47
+ <%= partial "/shared/matcher_include" %>
48
+
49
+ ## match
50
+
51
+ <%= partial "/shared/matcher_match" %>
52
+
53
+ ## split
54
+
55
+ The `split` splits the content with the `:` deliminator:
56
+
57
+ its('split') { should include (':') }
58
+
59
+ or:
60
+
61
+ its('split') { should_not include ('.') }
62
+
63
+ Use `-1` to test for cases where there is a trailing colon (`:`), such as `dir1::dir2:`:
64
+
65
+ its('split') { should include ('-1') }
66
+
67
+ # Examples
68
+
69
+ The following examples show how to use this InSpec audit resource.
70
+
71
+ ## Test the PATH environment variable
72
+
73
+ describe os_env('PATH') do
74
+ its('split') { should_not include('') }
75
+ its('split') { should_not include('.') }
76
+ end
77
+
78
+ ## Test Habitat environment variables
79
+
80
+ Habitat uses the `os_env` resource to test environment variables. The environment variables are first defined in a whitespace array, after which each environment variable is tested:
81
+
82
+ hab_env_vars = %w(HAB_AUTH_TOKEN
83
+ HAB_CACHE_KEY_PATH
84
+ HAB_DEPOT_URL
85
+ HAB_ORG
86
+ HAB_ORIGIN
87
+ HAB_ORIGIN_KEYS
88
+ HAB_RING
89
+ HAB_RING_KEY
90
+ HAB_STUDIOS_HOME
91
+ HAB_STUDIO_ROOT
92
+ HAB_USER)
93
+
94
+ hab_env_vars.each do |e|
95
+ describe os_env(e) do
96
+ its('content') { should eq nil }
97
+ end
98
+ end
@@ -0,0 +1,115 @@
1
+ ---
2
+ title: About the package Resource
3
+ ---
4
+
5
+ # package
6
+
7
+ Use the `package` InSpec audit resource to test if the named package and/or package version is installed on the system.
8
+
9
+
10
+ # Syntax
11
+
12
+ A `package` resource block declares a package and (optionally) a package version:
13
+
14
+ describe package('name') do
15
+ it { should be_installed }
16
+ end
17
+
18
+ where
19
+
20
+ * `('name')` must specify the name of a package, such as `'nginx'`
21
+ * `be_installed` is a valid matcher for this resource
22
+
23
+ # Matchers
24
+
25
+ This InSpec audit resource has the following matchers:
26
+
27
+ ## be
28
+
29
+ <%= partial "/shared/matcher_be" %>
30
+
31
+ ## be_installed
32
+
33
+ The `be_installed` matcher tests if the named package is installed on the system:
34
+
35
+ it { should be_installed }
36
+
37
+ ## cmp
38
+
39
+ <%= partial "/shared/matcher_cmp" %>
40
+
41
+ ## eq
42
+
43
+ <%= partial "/shared/matcher_eq" %>
44
+
45
+ ## include
46
+
47
+ <%= partial "/shared/matcher_include" %>
48
+
49
+ ## match
50
+
51
+ <%= partial "/shared/matcher_match" %>
52
+
53
+ ## version
54
+
55
+ The `version` matcher tests if the named package version is on the system:
56
+
57
+ its('version') { should eq '1.2.3' }
58
+
59
+ # Examples
60
+
61
+ The following examples show how to use this InSpec audit resource.
62
+
63
+ ## Test if nginx version 1.9.5 is installed
64
+
65
+ describe package('nginx') do
66
+ it { should be_installed }
67
+ its('version') { should eq 1.9.5 }
68
+ end
69
+
70
+ ## Test that a package is not installed
71
+
72
+ describe package('some_package') do
73
+ it { should_not be_installed }
74
+ end
75
+
76
+ ## Test if telnet is installed
77
+
78
+ describe package('telnetd') do
79
+ it { should_not be_installed }
80
+ end
81
+
82
+ describe inetd_conf do
83
+ its('telnet') { should eq nil }
84
+ end
85
+
86
+ ## Test if ClamAV (an antivirus engine) is installed and running
87
+
88
+ describe package('clamav') do
89
+ it { should be_installed }
90
+ its('version') { should eq '0.98.7' }
91
+ end
92
+
93
+ describe service('clamd') do
94
+ it { should_not be_enabled }
95
+ it { should_not be_installed }
96
+ it { should_not be_running }
97
+ end
98
+
99
+ ## Verify if Memcached is installed, enabled, and running
100
+
101
+ Memcached is an in-memory key-value store that helps improve the performance of database-driven websites and can be installed, maintained, and tested using the `memcached` cookbook (maintained by Chef). The following example is from the `memcached` cookbook and shows how to use a combination of the `package`, `service`, and `port` InSpec audit resources to test if Memcached is installed, enabled, and running:
102
+
103
+ describe package('memcached') do
104
+ it { should be_installed }
105
+ end
106
+
107
+ describe service('memcached') do
108
+ it { should be_installed }
109
+ it { should be_enabled }
110
+ it { should be_running }
111
+ end
112
+
113
+ describe port(11_211) do
114
+ it { should be_listening }
115
+ end
@@ -0,0 +1,122 @@
1
+ ---
2
+ title: About the parse_config Resource
3
+ ---
4
+
5
+ # parse_config
6
+
7
+ Use the `parse_config` InSpec audit resource to test arbitrary configuration files.
8
+
9
+ # Syntax
10
+
11
+ A `parse_config` resource block declares the location of the configuration setting to be tested, and then what value is to be tested. Because this resource relies on arbitrary configuration files, the test itself is often arbitrary and relies on custom Ruby code:
12
+
13
+ output = command('some-command').stdout
14
+
15
+ describe parse_config(output, { data_config_option: value } ) do
16
+ its('setting') { should eq 1 }
17
+ end
18
+
19
+ or:
20
+
21
+ audit = command('/sbin/auditctl -l').stdout
22
+ options = {
23
+ assignment_re: /^\s*([^:]*?)\s*:\s*(.*?)\s*$/,
24
+ multiple_values: true
25
+ }
26
+
27
+ describe parse_config(audit, options) do
28
+ its('setting') { should eq 1 }
29
+ end
30
+
31
+ where each test
32
+
33
+ * Must declare the location of the configuration file to be tested
34
+ * Must declare one (or more) settings to be tested
35
+ * May run a command to `stdout`, and then run the test against that output
36
+ * May use options to define how configuration data is to be parsed
37
+
38
+ # Matchers
39
+
40
+ This InSpec audit resource has the following matchers:
41
+
42
+ ## assignment_re
43
+
44
+ Use `assignment_re` to test a key value using a regular expression:
45
+
46
+ 'key = value'
47
+
48
+ may be tested using the following regular expression, which determines assignment from key to value:
49
+
50
+ assignment_re: /^\s*([^=]*?)\s*=\s*(.*?)\s*$/
51
+
52
+ ## be
53
+
54
+ <%= partial "/shared/matcher_be" %>
55
+
56
+ ## cmp
57
+
58
+ <%= partial "/shared/matcher_cmp" %>
59
+
60
+ ## comment_char
61
+
62
+ Use `comment_char` to test for comments in a configuration file:
63
+
64
+ comment_char: '#'
65
+
66
+ ## eq
67
+
68
+ <%= partial "/shared/matcher_eq" %>
69
+
70
+ ## include
71
+
72
+ <%= partial "/shared/matcher_include" %>
73
+
74
+ ## key_vals
75
+
76
+ Use `key_vals` to test how many values a key contains:
77
+
78
+ key = a b c
79
+
80
+ contains three values. To test that value to ensure it only contains one, use:
81
+
82
+ key_vals: 1
83
+
84
+ ## match
85
+
86
+ <%= partial "/shared/matcher_match" %>
87
+
88
+ ## multiple_values
89
+
90
+ Use `multiple_values` if the source file uses the same key multiple times. All values will be aggregated in an array:
91
+
92
+ # # file structure:
93
+ # key = a
94
+ # key = b
95
+ # key2 = c
96
+ params['key'] = ['a', 'b']
97
+ params['key2'] = ['c']
98
+
99
+ To use plain key value mapping, use `multiple_values: false`:
100
+
101
+ # # file structure:
102
+ # key = a
103
+ # key = b
104
+ # key2 = c
105
+ params['key'] = 'b'
106
+ params['key2'] = 'c'
107
+
108
+ ## standalone_comments
109
+
110
+ Use `standalone_comments` to parse comments as a line, otherwise inline comments are allowed:
111
+
112
+ 'key = value # comment'
113
+ params['key'] = 'value # comment'
114
+
115
+ Use `standalone_comments: false`, to parse the following:
116
+
117
+ 'key = value # comment'
118
+ params['key'] = 'value'
119
+
120
+ # Examples
121
+
122
+ None.