2015-10-19 16:05:10 +00:00
=====================================================
2015-10-19 20:34:33 +00:00
InSpec Resources Reference
2015-10-19 16:05:10 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
The following InSpec audit resources are available:
2015-10-19 16:05:10 +00:00
2015-10-26 10:10:09 +00:00
* `` apache_conf ``
2015-10-19 16:05:10 +00:00
* `` apt ``
2015-10-26 10:10:09 +00:00
* `` audit_policy ``
* `` auditd_conf ``
* `` auditd_rules ``
2015-10-19 16:05:10 +00:00
* `` bond ``
* `` bridge ``
2015-10-26 10:10:09 +00:00
* `` csv ``
2015-10-19 16:05:10 +00:00
* `` command ``
* `` directory ``
2015-10-26 10:10:09 +00:00
* `` etc_group ``
2015-10-19 16:05:10 +00:00
* `` file ``
* `` gem ``
* `` group ``
2015-10-26 10:10:09 +00:00
* `` group_policy ``
2015-10-19 16:05:10 +00:00
* `` host ``
2015-10-26 10:10:09 +00:00
* `` inetd_conf ``
2015-10-19 16:05:10 +00:00
* `` interface ``
2015-10-22 05:33:09 +00:00
* `` iptables ``
2015-10-19 16:05:10 +00:00
* `` kernel_module ``
* `` kernel_parameter ``
2015-10-26 10:10:09 +00:00
* `` limits_conf ``
* `` login_defs ``
* `` mysql_conf ``
* `` mysql_session ``
2015-10-19 20:10:31 +00:00
* `` npm ``
2015-10-26 10:10:09 +00:00
* `` ntp_conf ``
2015-10-19 20:10:31 +00:00
* `` oneget ``
* `` os ``
* `` os_env ``
* `` package ``
2015-10-26 10:10:09 +00:00
* `` parse_config ``
* `` parse_config_file ``
* `` passwd ``
2015-10-19 20:10:31 +00:00
* `` pip ``
* `` port ``
2015-10-26 10:10:09 +00:00
* `` postgres_conf ``
* `` postgres_session ``
2015-10-22 05:33:09 +00:00
* `` processes `` << process?
2015-10-19 20:10:31 +00:00
* `` registry_key ``
* `` script ``
2015-10-19 16:05:10 +00:00
* `` security_policy ``
2015-10-26 10:10:09 +00:00
* `` service ``
2015-10-19 16:05:10 +00:00
* `` ssh_config ``
* `` sshd_config ``
2015-10-26 10:10:09 +00:00
* `` user ``
* `` windows_feature ``
2015-10-19 20:10:31 +00:00
* `` yaml ``
2015-10-26 10:10:09 +00:00
* `` yum ``
2015-10-19 16:05:10 +00:00
2015-10-26 23:29:57 +00:00
See below for more information about each InSpec audit resource, its related matchers, and examples of how to use it in a recipe.
2015-10-19 16:05:10 +00:00
2015-10-22 04:13:17 +00:00
2015-10-26 09:41:10 +00:00
apache_conf
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` apache_conf `` InSpec audit resource to test the configuration settings for |apache|. This file is typically located under `` /etc/apache2 `` on the |debian| and |ubuntu| platforms and under `` /etc/httpd `` on the |fedora|, |centos|, |redhat enterprise linux|, and |archlinux| platforms. The configuration settings may vary significantly from platform to platform.
2015-10-20 04:48:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` apache_conf `` InSpec audit resource block declares configuration settings that should be tested:
2015-10-20 04:48:10 +00:00
.. code-block :: ruby
describe apache_conf('path') do
its('setting_name') { should eq 'value' }
end
where
* `` 'setting_name' `` is a configuration setting defined in the |apache| configuration file
* `` ('path') `` is the non-default path to the |apache| configuration file
* `` { should eq 'value' } `` is the value that is expected
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource matches any service that is listed in the |apache| configuration file:
2015-10-20 04:48:10 +00:00
.. code-block :: ruby
its('PidFile') { should_not eq '/var/run/httpd.pid' }
or:
.. code-block :: ruby
its('Timeout') { should eq 300 }
For example:
.. code-block :: ruby
describe apache_conf do
its('MaxClients') { should eq 100 }
its('Listen') { should eq '443'}
end
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource in a test.
2015-10-20 04:48:10 +00:00
2015-10-26 09:41:10 +00:00
**Test for blocking .htaccess files on CentOS**
2015-10-20 04:48:10 +00:00
.. code-block :: ruby
describe apache_conf do
its('AllowOverride') { should eq 'None' }
end
2015-10-26 09:41:10 +00:00
**Test ports for SSL**
2015-10-20 04:48:10 +00:00
.. code-block :: ruby
2015-10-26 09:41:10 +00:00
2015-10-20 04:48:10 +00:00
describe apache_conf do
its('Listen') { should eq '443'}
end
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
apt
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` apt `` InSpec audit resource to verify |apt| repositories on the |debian| and |ubuntu| platforms, and also |ppa| repositories on the |ubuntu| platform.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Stable**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
An `` apt `` InSpec audit resource block tests the contents of |apt| and |ppa| repositories:
2015-10-19 20:29:26 +00:00
.. code-block :: ruby
2015-10-20 01:25:25 +00:00
describe apt('path') do
it { should exist }
it { should be_enabled }
end
2015-10-19 20:29:26 +00:00
where
2015-10-20 01:25:25 +00:00
* `` apt('path') `` must specify an |apt| or |ppa| repository
* `` ('path') `` may be an `` http:// `` address, a `` ppa: `` address, or a short `` repo-name/ppa `` address
2015-10-26 23:29:57 +00:00
* `` exist `` and `` be_enabled `` are a valid matchers for this InSpec audit resource
2015-10-19 20:29:26 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
be_enabled
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_enabled `` matcher tests if a package exists in the repository:
2015-10-19 20:29:26 +00:00
.. code-block :: ruby
2015-10-20 01:25:25 +00:00
it { should be_enabled }
2015-10-19 20:29:26 +00:00
2015-10-26 09:41:10 +00:00
exist
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` exist `` matcher tests if a package exists on the system:
2015-10-19 16:05:10 +00:00
2015-10-19 20:29:26 +00:00
.. code-block :: ruby
2015-10-20 01:25:25 +00:00
it { should exist }
2015-10-19 20:29:26 +00:00
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource in a test.
2015-10-19 20:29:26 +00:00
2015-10-26 09:41:10 +00:00
**Test if Ubuntu is updated to the latest stable Juju package**
2015-10-19 20:29:26 +00:00
.. code-block :: ruby
2015-10-20 01:25:25 +00:00
describe apt('http://ppa.launchpad.net/juju/stable/ubuntu') do
it { should exist }
it { should be_enabled }
end
2015-10-19 20:29:26 +00:00
2015-10-26 09:41:10 +00:00
**Test if Nginx is updated to the latest stable package**
2015-10-19 20:29:26 +00:00
.. code-block :: ruby
2015-10-20 01:25:25 +00:00
describe apt('ppa:nginx/stable') do
it { should exist }
it { should be_enabled }
end
2015-10-19 20:29:26 +00:00
2015-10-20 01:25:25 +00:00
**Verify that a repository exists and is enabled**
2015-10-19 20:29:26 +00:00
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
2015-10-19 20:29:26 +00:00
2015-10-20 01:25:25 +00:00
describe apt('ppa:nginx/stable') do
it { should exist }
it { should be_enabled }
end
2015-10-19 20:29:26 +00:00
2015-10-20 01:25:25 +00:00
**Verify that a repository is not present**
2015-10-19 20:29:26 +00:00
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
describe apt('ubuntu-wine/ppa') do
it { should_not exist }
it { should_not be_enabled }
end
2015-10-19 16:05:10 +00:00
2015-10-20 21:04:07 +00:00
2015-10-26 09:41:10 +00:00
audit_policy
2015-10-19 16:05:10 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` audit_policy `` InSpec audit resource to test auditing policies on the |windows| platform. An auditing policy is a category of security-related events to be audited. Auditing is disabled by default and may be enabled for categories like account management, logon events, policy changes, process tracking, privilege use, system events, or object access. For each auditing category property that is enabled, the auditing level may be set to `` No Auditing `` , `` Not Specified `` , `` Success `` , `` Success and Failure `` , or `` Failure `` .
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-22 17:10:13 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` audit_policy `` InSpec audit resource block declares a parameter that belongs to an audit policy category or subcategory:
2015-10-22 17:10:13 +00:00
.. code-block :: ruby
describe audit_policy do
its('parameter') { should eq 'value' }
end
where
2015-10-26 09:41:10 +00:00
* `` 'parameter' `` must specify a parameter
2015-10-22 17:10:13 +00:00
* `` 'value' `` must be one of `` No Auditing `` , `` Not Specified `` , `` Success `` , `` Success and Failure `` , or `` Failure ``
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource does not have any matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Examples
2015-10-22 17:10:13 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-22 17:10:13 +00:00
**Test that a parameter is set to "No Auditing"**
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-22 17:10:13 +00:00
describe audit_policy do
its('Other Account Logon Events') { should_not eq 'No Auditing' }
end
**Test that a parameter is set to "Success"**
.. code-block :: ruby
describe audit_policy do
its('User Account Management') { should_not eq 'No Auditing' }
end
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
auditd_conf
2015-10-19 16:05:10 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` auditd_conf `` InSpec audit resource to test the configuration settings for the audit daemon. This file is typically located under `` /etc/audit/auditd.conf' `` on |unix| and |linux| platforms.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` auditd_conf `` InSpec audit resource block declares configuration settings that should be tested:
2015-10-20 04:48:54 +00:00
.. code-block :: ruby
2015-10-22 05:49:59 +00:00
describe auditd_conf('path') do
its('keyword') { should eq 'value' }
2015-10-20 04:48:54 +00:00
end
2015-10-22 05:49:59 +00:00
where
* `` 'keyword' `` is a configuration setting defined in the `` auditd.conf `` configuration file
* `` ('path') `` is the non-default path to the `` auditd.conf `` configuration file
* `` { should eq 'value' } `` is the value that is expected
2015-10-26 09:41:10 +00:00
Matchers
2015-10-22 05:49:59 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource matches any keyword that is listed in the `` auditd.conf `` configuration file:
2015-10-22 05:49:59 +00:00
.. code-block :: ruby
its('log_format') { should eq 'raw' }
2015-10-26 09:41:10 +00:00
Examples
2015-10-22 05:49:59 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-22 05:49:59 +00:00
2015-10-26 09:41:10 +00:00
**Test the auditd.conf file**
2015-10-20 04:48:54 +00:00
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-22 05:49:59 +00:00
describe auditd_conf do
its('log_file') { should eq '/full/path/to/file' }
its('log_format') { should eq 'raw' }
its('flush') { should eq 'none' }
its('freq') { should eq '1' }
its('num_logs') { should eq '0' }
its('max_log_file') { should eq '6' }
its('max_log_file_action') { should eq 'email' }
its('space_left') { should eq '2' }
2015-10-20 04:48:54 +00:00
its('action_mail_acct') { should eq 'root' }
2015-10-22 05:49:59 +00:00
its('space_left_action') { should eq 'email' }
its('admin_space_left') { should eq '1' }
its('admin_space_left_action') { should eq 'halt' }
its('disk_full_action') { should eq 'halt' }
its('disk_error_action') { should eq 'halt' }
2015-10-20 04:48:54 +00:00
end
2015-10-19 16:05:10 +00:00
2015-10-22 06:11:46 +00:00
2015-10-26 09:41:10 +00:00
auditd_rules
2015-10-19 16:05:10 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` auditd_rules `` InSpec audit resource to test the rules for logging that exist on the system. The `` audit.rules `` file is typically located under `` /etc/audit/ `` and contains the list of rules that define what is captured in log files.
2015-10-22 06:11:46 +00:00
2015-10-26 09:41:10 +00:00
Syntax
2015-10-22 06:11:46 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` auditd_rules `` InSpec audit resource block declares one (or more) rules to be tested, and then what that rule should do:
2015-10-22 06:11:46 +00:00
.. code-block :: ruby
2015-10-26 09:41:10 +00:00
2015-10-22 06:11:46 +00:00
describe auditd_rules do
its('LIST_RULES') { should eq [
'exit,always syscall=rmdir,unlink',
'exit,always auid=1001 (0x3e9) syscall=open',
'exit,always watch=/etc/group perm=wa',
'exit,always watch=/etc/passwd perm=wa',
'exit,always watch=/etc/shadow perm=wa',
'exit,always watch=/etc/sudoers perm=wa',
'exit,always watch=/etc/secret_directory perm=r',
] }
end
or:
.. code-block :: ruby
audit = command('/sbin/auditctl -l').stdout
options = {
assignment_re: /^\s*([^:]* ?)\s*:\s* (.*?)\s* $/,
multiple_values: true
}
2015-10-26 09:41:10 +00:00
2015-10-22 06:11:46 +00:00
describe auditd_rules(audit, options) do
its('rule') { should eq 1 }
end
where each test
* Must declare one (or more) rules to be tested
* May run a command to `` stdout `` , and then run the test against that output
* May use options to define how configuration data is to be parsed
2015-10-26 09:41:10 +00:00
Options
2015-10-22 06:11:46 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource supports the following options for parsing configuration data. Use them in an `` options `` block stated outside of (and immediately before) the actual test:
2015-10-22 06:11:46 +00:00
.. code-block :: ruby
2015-10-19 16:05:10 +00:00
2015-10-22 06:11:46 +00:00
options = {
assignment_re: /^\s*([^:]* ?)\s*:\s* (.*?)\s* $/,
multiple_values: true
}
describe auditd_rules(options) do
its('rule') { should eq 1 }
end
2015-10-26 09:41:10 +00:00
assignment_re
2015-10-22 06:11:46 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
IDENTICAL TO parse_config << INCLUDE THEM IN BOTH SPOTS WHEN PUBLISHED
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
multiple_values
2015-10-22 06:11:46 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
IDENTICAL TO parse_config << INCLUDE THEM IN BOTH SPOTS WHEN PUBLISHED
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-20 16:52:34 +00:00
2015-10-22 06:11:46 +00:00
**Test if a rule contains a matching element that is identified by a regular expression.**
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-22 06:11:46 +00:00
describe audit_daemon_rules do
its("LIST_RULES") {
should contain_match(/^exit,always arch=.*
key=time-change
syscall=adjtimex,settimeofday/)
}
end
2015-10-20 16:52:34 +00:00
2015-10-19 16:05:10 +00:00
2015-10-22 04:14:48 +00:00
2015-10-26 09:41:10 +00:00
bond
2015-10-19 16:05:10 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` bond `` InSpec audit resource to test a logical, bonded network interface (i.e. "two or more network interfaces aggregated into a single, logical network interface"). On |unix| and |linux| platforms, any value in the `` /proc/net/bonding `` directory may be tested.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Stable**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-22 04:14:48 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` bond `` InSpec audit resource block declares a bonded network interface, and then specifies the properties of that bonded network interface to be tested:
2015-10-22 04:14:48 +00:00
.. code-block :: ruby
describe bond('name') do
it { should exist }
end
where
* `` 'name' `` is the name of the bonded network interface
2015-10-26 23:29:57 +00:00
* `` { should exist } `` is a valid matcher for this InSpec audit resource
2015-10-22 04:14:48 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-22 04:14:48 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-22 04:14:48 +00:00
2015-10-26 09:41:10 +00:00
content
2015-10-22 04:14:48 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The `` content `` matcher tests if contents in the file that defines the bonded network interface match the value specified in the test. The values of the `` content `` matcher are arbitrary:
.. code-block :: ruby
2015-10-23 21:24:00 +00:00
its('content') { should match('value') }
2015-10-22 04:14:48 +00:00
2015-10-26 09:41:10 +00:00
exist
2015-10-22 04:14:48 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The `` exist `` matcher tests if the bonded network interface is available:
.. code-block :: ruby
it { should exist }
2015-10-26 09:41:10 +00:00
have_interface
2015-10-22 04:14:48 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The `` have_interface `` matcher tests if the bonded network interface has one (or more) secondary interfaces:
.. code-block :: ruby
it { should have_interface }
2015-10-26 09:41:10 +00:00
interfaces
2015-10-22 04:14:48 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The `` interfaces `` matcher tests if the named secondary interfaces are available:
.. code-block :: ruby
its('interfaces') { should eq ['eth0', 'eth1', ...] }
2015-10-26 09:41:10 +00:00
params
2015-10-22 04:14:48 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The `` params `` matcher tests arbitrary parameters for the bonded network interface:
.. code-block :: ruby
its('params') { should eq 'value' }
2015-10-26 09:41:10 +00:00
Examples
2015-10-22 04:14:48 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-22 04:14:48 +00:00
2015-10-26 09:41:10 +00:00
**Test if eth0 is a secondary interface for bond0**
2015-10-22 04:14:48 +00:00
.. code-block :: ruby
describe bond('bond0') do
it { should exist }
it { should have_interface 'eth0' }
end
2015-10-26 09:41:10 +00:00
**Test parameters for bond0**
2015-10-22 04:14:48 +00:00
.. code-block :: ruby
describe bond('bond0') do
its('Bonding Mode') { should eq 'IEEE 802.3ad Dynamic link aggregation' }
its('Transmit Hash Policy') { should eq 'layer3+4 (1)' }
its('MII Status') { should eq 'up' }
its('MII Polling Interval (ms)') { should eq '100' }
its('Up Delay (ms)') { should eq '0' }
its('Down Delay (ms)') { should eq '0' }
end
2015-10-19 16:05:10 +00:00
2015-10-22 04:13:17 +00:00
2015-10-26 09:41:10 +00:00
bridge
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` bridge `` InSpec audit resource to test basic network bridge properties, such as name, if an interface is defined, and the associations for any defined interface.
2015-10-19 16:05:10 +00:00
* On |unix| and |linux| platforms, any value in the `` /sys/class/net/{interface}/bridge `` directory may be tested
* On the |windows| platform, the `` Get-NetAdapter `` cmdlet is associated with the `` Get-NetAdapterBinding `` cmdlet and returns the `` ComponentID ms_bridge `` value as a |json| object
.. not sure the previous two bullet items are actually true, but keeping there for reference for now, just in case
2015-10-27 16:47:27 +00:00
**Stability: Stable**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` bridge `` InSpec audit resource block declares xxxxx:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe bridge('br0') do
it { should exist }
it { should have_interface 'eth0' }
end
2015-10-26 09:41:10 +00:00
..
2015-10-19 16:05:10 +00:00
.. where
2015-10-26 09:41:10 +00:00
..
2015-10-19 16:05:10 +00:00
.. * ``xxxxx`` must specify xxxxx
.. * xxxxx
2015-10-26 23:29:57 +00:00
.. * ``xxxxx`` is a valid matcher for this InSpec audit resource
2015-10-26 09:41:10 +00:00
..
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
exist
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` exist `` matcher tests if the network bridge is available:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
it { should exist }
2015-10-26 09:41:10 +00:00
have_interface
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` have_interface `` matcher tests if the named interface is defined for the network bridge:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
it { should have_interface 'eth0' }
2015-10-26 09:41:10 +00:00
interfaces
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` interfaces `` matcher tests if the named interface is present:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('interfaces') { should eq foo }
its('interfaces') { should eq bar }
its('interfaces') { should include foo, bar }
2015-10-19 16:05:10 +00:00
.. wild guessing ^^^
2015-10-26 09:41:10 +00:00
..
2015-10-19 16:05:10 +00:00
.. Examples
2015-10-20 21:16:47 +00:00
.. -----------------------------------------------------
2015-10-26 23:29:57 +00:00
.. The following examples show how to use this InSpec audit resource.
2015-10-26 09:41:10 +00:00
..
.. **xxxxx**
..
2015-10-19 16:05:10 +00:00
.. xxxxx
2015-10-26 09:41:10 +00:00
..
.. **xxxxx**
..
2015-10-19 16:05:10 +00:00
.. xxxxx
2015-10-26 09:41:10 +00:00
..
2015-10-19 16:05:10 +00:00
2015-10-22 17:39:52 +00:00
2015-10-26 09:41:10 +00:00
command
2015-10-19 16:05:10 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` command `` InSpec audit resource to test an arbitrary command that is run on the system.
2015-10-22 17:39:52 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Stable**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-22 17:39:52 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` command `` InSpec audit resource block declares a command to be run, one (or more) expected outputs, and the location to which that output is sent:
2015-10-22 17:39:52 +00:00
.. code-block :: ruby
describe command('command') do
it { should exist }
its('matcher') { should eq 'output' }
end
or:
.. code-block :: ruby
describe command('command').exist? do
its('matcher') { should eq 'output' }
end
where
* `` 'command' `` must specify a command to be run
* `` .exist? `` is the `` exist `` matcher
* `` 'matcher' `` is one of `` exit_status `` , `` stderr `` , or `` stdout ``
* `` 'output' `` tests the output of the command run on the system versus the output value stated in the test
2015-10-26 09:41:10 +00:00
Matchers
2015-10-22 17:39:52 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-22 17:39:52 +00:00
2015-10-26 09:41:10 +00:00
exist
2015-10-22 17:39:52 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The `` exist `` matcher tests if a command may be run on the system:
.. code-block :: ruby
it { should exist }
2015-10-26 09:41:10 +00:00
exit_status
2015-10-22 17:39:52 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The `` exit_status `` matcher tests the exit status for the command:
.. code-block :: ruby
its('exit_status') { should eq 123 }
2015-10-26 09:41:10 +00:00
stderr
2015-10-22 17:39:52 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The `` stderr `` matcher tests results of the command as returned in standard error (stderr):
.. code-block :: ruby
its('stderr') { should eq 'error\n' }
2015-10-26 09:41:10 +00:00
stdout
2015-10-22 17:39:52 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The `` stdout `` matcher tests results of the command as returned in standard output (stdout):
.. code-block :: ruby
its('stdout') { should eq '/^1$/' }
2015-10-26 09:41:10 +00:00
Examples
2015-10-22 17:39:52 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-22 17:39:52 +00:00
2015-10-26 09:41:10 +00:00
**Test for PostgreSQL database running a RC, development, or beta release**
2015-10-22 17:39:52 +00:00
.. code-block :: ruby
describe command('sudo -i psql -V') do
its('stdout') { should_not eq '/RC/' }
its('stdout') { should_not eq '/DEVEL/' }
its('stdout') { should_not eq '/BETA/' }
end
2015-10-26 09:41:10 +00:00
**Test for multiple instances of Nginx**
2015-10-22 17:39:52 +00:00
.. code-block :: ruby
describe command('ps aux | egrep "nginx: master" | egrep -v "grep" | wc -l') do
its('stdout') (should eq '/^1$/' )
end
2015-10-26 09:41:10 +00:00
**Test standard output (stdout)**
2015-10-22 17:39:52 +00:00
.. code-block :: ruby
describe command('echo hello') do
its('stdout') { should eq 'hello\n' }
its('stderr') { should eq '' }
its('exit_status') { should eq 0 }
end
2015-10-26 09:41:10 +00:00
**Test standard error (stderr)**
2015-10-22 17:39:52 +00:00
.. code-block :: ruby
describe command('>&2 echo error') do
its('stdout') { should eq '' }
its('stderr') { should eq 'error\n' }
its('exit_status') { should eq 0 }
end
2015-10-26 09:41:10 +00:00
**Test an exit status code**
2015-10-22 17:39:52 +00:00
.. code-block :: ruby
describe command('exit 123') do
its('stdout') { should eq '' }
its('stderr') { should eq '' }
its('exit_status') { should eq 123 }
end
2015-10-26 09:41:10 +00:00
**Test if the command shell exists**
2015-10-22 17:39:52 +00:00
.. code-block :: ruby
describe command('/bin/sh').exist? do
it { should eq true }
end
2015-10-26 09:41:10 +00:00
**Test for a command that should not exist**
2015-10-22 17:39:52 +00:00
.. code-block :: ruby
describe command('this is not existing').exist? do
it { should eq false }
end
2015-10-26 09:41:10 +00:00
**Test for one peer and one indent**
2015-10-22 17:39:52 +00:00
.. code-block :: ruby
describe command('sudo -i cat #{hba_config_file} | egrep 'peer|ident' | wc -l') do
its('stdout') { should eq '(/^[2|1]/)' }
end
describe command('sudo -i cat #{hba_config_file} | egrep 'trust|password|crypt' | wc -l') do
its('stdout') { should eq '(/^0/)' }
end
2015-10-19 16:05:10 +00:00
2015-10-22 04:13:17 +00:00
2015-10-26 09:41:10 +00:00
csv
2015-10-19 16:05:10 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` csv `` InSpec audit resource to test configuration data in a |csv| file.
2015-10-20 22:02:57 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 22:02:57 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` csv `` InSpec audit resource block declares the configuration data to be tested:
2015-10-20 22:02:57 +00:00
.. code-block :: ruby
describe csv('file') do
its('name') { should eq 'foo' }
end
where
* `` 'file' `` is the path to a |csv| file
* `` name `` is a configuration setting in a |csv| file
* `` should eq 'foo' `` tests a value of `` name `` as read from a |csv| file versus the value declared in the test
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 22:02:57 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-20 22:02:57 +00:00
2015-10-26 09:41:10 +00:00
name
2015-10-20 22:02:57 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` name `` matcher tests the value of `` name `` as read from a |csv| file versus the value declared in the test:
2015-10-20 22:02:57 +00:00
.. code-block :: ruby
its('name') { should eq 'foo' }
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 22:02:57 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-20 22:02:57 +00:00
**Test a CSV file**
.. code-block :: ruby
describe csv('some_file.csv') do
its('setting') { should eq 1 }
end
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
directory
2015-10-19 16:05:10 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` directory `` InSpec audit resource to test if the file type is a directory. This is equivalent to using the `` file `` InSpec audit resource and the `` be_directory `` matcher, but provides a simpler and more direct way to test directories. All of the matchers available to the `` file `` resource that may be used with testing directories may be used with this resource.
2015-10-22 02:52:52 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-22 02:52:52 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` directory `` InSpec audit resource block declares the location of the directory to be tested, and then one (or more) matchers:
2015-10-22 02:52:52 +00:00
.. code-block :: ruby
describe directory('path') do
it { should MATCHER 'value' }
end
2015-10-26 09:41:10 +00:00
Matchers
2015-10-22 02:52:52 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource may use any of the matchers available to the `` file `` resource that are useful for testing a directory.
2015-10-22 02:52:52 +00:00
2015-10-26 09:41:10 +00:00
..
2015-10-22 02:52:52 +00:00
.. Examples
.. -----------------------------------------------------
2015-10-26 23:29:57 +00:00
.. The following examples show how to use this InSpec audit resource.
2015-10-26 09:41:10 +00:00
..
.. **xxxxx**
..
2015-10-22 02:52:52 +00:00
.. xxxxx
2015-10-26 09:41:10 +00:00
..
.. **xxxxx**
..
2015-10-22 02:52:52 +00:00
.. xxxxx
2015-10-26 09:41:10 +00:00
..
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
etc_group
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` etc_group `` InSpec audit resource to test groups that are defined on on |linux| and |unix| platforms. The `` /etc/group `` file stores details about each group---group name, password, group identifier, along with a comma-separate list of users that belong to the group.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 23:51:48 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` etc_group `` InSpec audit resource block declares a collection of properties to be tested:
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-20 23:51:48 +00:00
describe etc_group('path') do
its('matcher') { should eq 'some_value' }
end
2015-10-20 16:52:34 +00:00
2015-10-20 23:51:48 +00:00
or:
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-20 23:51:48 +00:00
describe etc_group.where(item: 'value', item: 'value') do
its('gids') { should_not contain_duplicates }
its('groups') { should include 'user_name' }
its('users') { should include 'user_name' }
end
where
2015-10-20 16:52:34 +00:00
2015-10-20 23:51:48 +00:00
* `` ('path') `` is the non-default path to the `` inetd.conf `` file
* `` .where() `` may specify a specific item and value, to which the matchers are compared
2015-10-26 23:29:57 +00:00
* `` 'gids' `` , `` 'groups' `` , and `` 'users' `` are valid matchers for this InSpec audit resource
2015-10-20 16:52:34 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-20 16:52:34 +00:00
2015-10-26 09:41:10 +00:00
gids
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` gids `` matcher tests if the named group identifier is present or if it contains duplicates:
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-20 23:51:48 +00:00
its('gids') { should_not contain_duplicates }
2015-10-20 16:52:34 +00:00
2015-10-26 09:41:10 +00:00
groups
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` groups `` matcher tests all groups for the named user:
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-20 23:51:48 +00:00
its('groups') { should include 'my_user' }
2015-10-20 16:52:34 +00:00
2015-10-26 09:41:10 +00:00
users
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` users `` matcher tests all groups for the named user:
2015-10-20 16:52:34 +00:00
2015-10-20 23:51:48 +00:00
.. code-block :: ruby
its('users') { should include 'my_user' }
2015-10-26 09:41:10 +00:00
where
2015-10-20 23:51:48 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` where `` matcher allows the test to be focused to one (or more) specific items:
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-20 23:51:48 +00:00
etc_group.where(item: 'value', item: 'value')
2015-10-20 16:52:34 +00:00
2015-10-20 23:51:48 +00:00
where `` item `` may be one (or more) of:
2015-10-20 16:52:34 +00:00
2015-10-20 23:51:48 +00:00
* `` name: 'name' ``
* `` group_name: 'group_name' ``
* `` password: 'password' ``
* `` gid: 'gid' ``
* `` group_id: 'gid' ``
* `` users: 'user_name' ``
* `` members: 'member_name' ``
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 23:51:48 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-20 16:52:34 +00:00
2015-10-26 09:41:10 +00:00
**Test group identifiers (GIDs) for duplicates**
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-19 16:05:10 +00:00
2015-10-20 23:51:48 +00:00
describe etc_group do
its('gids') { should_not contain_duplicates }
end
2015-10-20 16:52:34 +00:00
2015-10-26 09:41:10 +00:00
**Test all groups to see if a specific user belongs to one (or more) groups**
2015-10-20 16:52:34 +00:00
2015-10-20 23:51:48 +00:00
.. code-block :: ruby
describe etc_group do
its('groups') { should include 'my_user' }
end
2015-10-20 16:52:34 +00:00
2015-10-26 09:41:10 +00:00
**Test all groups for a specific user name**
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-20 23:51:48 +00:00
describe etc_group.where(name: 'my_user') do
its('users') { should include 'my_user' }
end
2015-10-26 09:41:10 +00:00
**Filter a list of groups for a specific user**
2015-10-20 23:51:48 +00:00
.. code-block :: ruby
describe etc_group.where(name: 'my_user') do
its('users') { should include 'my_user' }
end
2015-10-26 09:41:10 +00:00
file
2015-10-19 16:05:10 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` file `` InSpec audit resource to test all system file types, including files, directories, symbolic links, named pipes, sockets, character devices, block devices, and doors.
2015-10-22 02:29:50 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Stable**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-22 02:29:50 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` file `` InSpec audit resource block declares the location of the file type to be tested, what type that file should be (if required), and then one (or more) matchers:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
describe file('path') do
it { should MATCHER 'value' }
end
where
* `` ('path') `` is the name of the file and/or the path to the file
2015-10-26 23:29:57 +00:00
* `` MATCHER `` is a valid matcher for this InSpec audit resource
2015-10-22 02:29:50 +00:00
* `` 'value' `` is the value to be tested
2015-10-26 09:41:10 +00:00
Matchers
2015-10-22 02:29:50 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-22 02:29:50 +00:00
2015-10-26 09:41:10 +00:00
be_block_device
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_block_device `` matcher tests if the file exists as a block device, such as `` /dev/disk0 `` or `` /dev/disk0s9 `` :
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should be_block_device }
2015-10-26 09:41:10 +00:00
be_character_device
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_character_device `` matcher tests if the file exists as a character device (that corresponds to a block device), such as `` /dev/rdisk0 `` or `` /dev/rdisk0s9 `` :
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should be_character_device }
2015-10-26 09:41:10 +00:00
be_directory
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_directory `` matcher tests if the file exists as a directory, such as `` /etc/passwd `` , `` /etc/shadow `` , or `` /var/log/httpd `` :
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should be_directory }
2015-10-26 09:41:10 +00:00
be_file
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_file `` matcher tests if the file exists as a file. This can be useful with configuration files like `` /etc/passwd `` where there typically is not an associated file extension---`` passwd.txt `` :
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should be_file }
2015-10-26 09:41:10 +00:00
be_executable
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_executable `` matcher tests if the file exists as a xxxxx:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should be_executable }
.. assuming this carries forward, below -- re: the by owner, group, user examples
The `` be_executable `` matcher may also test if the file is executable by a specific owner, group, or user. For example, a group:
.. code-block :: ruby
it { should be_executable.by('group') }
an owner:
.. code-block :: ruby
it { should be_executable.by('owner') }
a user:
.. code-block :: ruby
it { should be_executable.by_user('user') }
2015-10-26 09:41:10 +00:00
be_grouped_into
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_grouped_into `` matcher tests if the file exists as part of the named group:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should be_grouped_into 'group' }
2015-10-26 09:41:10 +00:00
be_immutable
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_immutable `` matcher tests if the file is immutable, i.e. "cannot be changed":
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should be_immutable }
2015-10-26 09:41:10 +00:00
be_linked_to
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_linked_to `` matcher tests if the file is linked to the named target:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should be_linked_to '/etc/target-file' }
2015-10-26 09:41:10 +00:00
be_mounted
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_mounted `` matcher tests if the file is accessible from the file system:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should be_mounted }
2015-10-26 09:41:10 +00:00
be_owned_by
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_owned_by `` matcher tests if the file is owned by the named user, such as `` root `` :
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should be_owned_by 'root' }
2015-10-26 09:41:10 +00:00
be_pipe
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_pipe `` matcher tests if the file exists as first-in, first-out special file (`` .fifo `` ) that is typically used to define a named pipe, such as `` /var/log/nginx/access.log.fifo `` :
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should be_pipe }
2015-10-26 09:41:10 +00:00
be_readable
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_readable `` matcher tests if the file is readable:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should be_readable }
.. assuming this carries forward, below -- re: the by owner, group, user examples
The `` be_readable `` matcher may also test if the file is readable by a specific owner, group, or user. For example, a group:
.. code-block :: ruby
it { should be_readable.by('group') }
an owner:
.. code-block :: ruby
it { should be_readable.by('owner') }
a user:
.. code-block :: ruby
it { should be_readable.by_user('user') }
2015-10-26 09:41:10 +00:00
be_socket
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_socket `` matcher tests if the file exists as socket (`` .sock `` ), such as `` /var/run/php-fpm.sock `` :
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should be_socket }
2015-10-26 09:41:10 +00:00
be_symlink
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_symlink `` matcher tests if the file exists as a symbolic, or soft link that contains an absolute or relative path reference to another file:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should be_symlink }
2015-10-26 09:41:10 +00:00
be_version
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_version `` matcher tests the version of the file:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should be_version '1.2.3' }
2015-10-26 09:41:10 +00:00
be_writable
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_writable `` matcher tests if the file is writable:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should be_writable }
.. assuming this carries forward, below -- re: the by owner, group, user examples
The `` be_writable `` matcher may also test if the file is writable by a specific owner, group, or user. For example, a group:
.. code-block :: ruby
it { should be_writable.by('group') }
an owner:
.. code-block :: ruby
it { should be_writable.by('owner') }
a user:
.. code-block :: ruby
it { should be_writable.by_user('user') }
2015-10-26 09:41:10 +00:00
content
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` content `` matcher tests if contents in the file match the value specified in the test. The values of the `` content `` matcher are arbitrary and depend on the file type being tested and also the type of information that is expected to be in that file:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
its('content') { should contain 'value' }
The following complete example tests the `` pg_hba.conf `` file in |postgresql| for |md5| requirements. The tests look at all `` host `` and `` local `` settings in that file, and then compare the |md5| checksums against the values in the test:
.. code-block :: bash
describe file(hba_config_file) do
its('content') { should eq '/local\s.*?all\s.* ?all\s.*?md5/' }
its('content') { should eq '%r{/host\s.*?all\s.* ?all\s.*?127.0.0.1\/32\s.* ?md5/}' }
its('content') { should eq '%r{/host\s.*?all\s.* ?all\s.*?::1\/128\s.* ?md5/}' }
end
2015-10-26 09:41:10 +00:00
exist
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` exist `` matcher tests if the named file exists:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should exist }
2015-10-26 09:41:10 +00:00
file_version
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` file_version `` matcher tests if the file's version matches the specified value. The difference between a file's "file version" and "product version" is that the file version is the version number of the file itself, whereas the product version is the version number associated with the application from which that file originates:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
its('file_version') { should eq '1.2.3' }
2015-10-26 09:41:10 +00:00
group
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` group `` matcher tests if the group to which a file belongs matches the specified value:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
its('group') { should eq 'admins' }
2015-10-26 09:41:10 +00:00
have_mode
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` have_mode `` matcher tests if a file has a mode assigned to it:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
it { should have_mode }
2015-10-26 09:41:10 +00:00
link_path
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` link_path `` matcher tests if the file exists at the specified path:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
its('link_path') { should eq '/some/path/to/file' }
2015-10-26 09:41:10 +00:00
link_target
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` link_target `` matcher tests if a file that is linked to this file exists at the specified path:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
its('link_target') { should eq '/some/path/to/file' }
2015-10-26 09:41:10 +00:00
md5sum
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` md5sum `` matcher tests if the |md5| checksum for a file matches the specified value:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
its('md5sum') { should eq '3329x3hf9130gjs9jlasf2305mx91s4j' }
2015-10-26 09:41:10 +00:00
mode
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` mode `` matcher tests if the mode assigned to the file matches the specified value:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
its('mode') { should eq 0644 }
2015-10-26 09:41:10 +00:00
mtime
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` mtime `` matcher tests if the file modification time for the file matches the specified value:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
its('mtime') { should eq 'October 31 2015 12:10:45' }
or:
.. code-block :: bash
describe file('/').mtime.to_i do
it { should <= Time.now.to_i }
it { should >= Time.now.to_i - 1000}
end
2015-10-26 09:41:10 +00:00
owner
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` owner `` matcher tests if the owner of the file matches the specified value:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
its('owner') { should eq 'root' }
2015-10-26 09:41:10 +00:00
product_version
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` product_version `` matcher tests if the file's product version matches the specified value. The difference between a file's "file version" and "product version" is that the file version is the version number of the file itself, whereas the product version is the version number associated with the application from which that file originates:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
its('product_version') { should eq 2.3.4 }
2015-10-26 09:41:10 +00:00
selinux_label
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` selinux_label `` matcher tests if the |selinux| label for a file matches the specified value:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
its('product_version') { should eq 'system_u:system_r:httpd_t:s0' }
2015-10-26 09:41:10 +00:00
sha256sum
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` sha256sum `` matcher tests if the |sha256| checksum for a file matches the specified value:
2015-10-22 02:29:50 +00:00
.. code-block :: ruby
its('sha256sum') { should eq 'b837ch38lh19bb8eaopl8jvxwd2e4g58jn9lkho1w3ed9jbkeicalplaad9k0pjn' }
2015-10-26 09:41:10 +00:00
size
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The `` size `` matcher tests if a file's size matches, is greater than, or is less than the specified value. For example, equal:
.. code-block :: ruby
its('size') { should eq 32375 }
Greater than:
.. code-block :: ruby
its('size') { should > 64 }
Less than:
.. code-block :: ruby
its('size') { should < 10240 }
2015-10-26 09:41:10 +00:00
type
2015-10-22 02:29:50 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The `` type `` matcher tests if the first letter of the file's mode string contains one of the following characters:
* `` - `` or `` f `` (the file is a file); use `` 'file `` to test for this file type
* `` d `` (the file is a directory); use `` 'directory `` to test for this file type
* `` l `` (the file is a symbolic link); use `` 'link `` to test for this file type
* `` p `` (the file is a named pipe); use `` 'pipe `` to test for this file type
* `` s `` (the file is a socket); use `` 'socket `` to test for this file type
* `` c `` (the file is a character device); use `` 'character `` to test for this file type
* `` b `` (the file is a block device); use `` 'block `` to test for this file type
* `` D `` (the file is a door); use `` 'door `` to test for this file type
For example:
.. code-block :: ruby
its('type') { should eq 'file' }
or:
.. code-block :: ruby
its('type') { should eq 'socket' }
2015-10-26 09:41:10 +00:00
Examples
2015-10-22 02:29:50 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-22 02:29:50 +00:00
2015-10-26 09:41:10 +00:00
**Test the contents of a file for MD5 requirements**
2015-10-22 02:29:50 +00:00
.. code-block :: bash
describe file(hba_config_file) do
its('content') { should eq '/local\s.*?all\s.* ?all\s.*?md5/' }
its('content') { should eq '%r{/host\s.*?all\s.* ?all\s.*?127.0.0.1\/32\s.* ?md5/}' }
its('content') { should eq '%r{/host\s.*?all\s.* ?all\s.*?::1\/128\s.* ?md5/}' }
end
2015-10-26 09:41:10 +00:00
**Test if a file exists**
2015-10-22 02:29:50 +00:00
.. code-block :: bash
describe file('/tmp') do
it { should exist }
end
2015-10-26 09:41:10 +00:00
**Test that a file does not exist**
2015-10-22 02:29:50 +00:00
.. code-block :: bash
describe file('/tmpest') do
it { should_not exist }
end
2015-10-26 09:41:10 +00:00
**Test if a file is a directory**
2015-10-22 02:29:50 +00:00
.. code-block :: bash
describe file('/tmp') do
its('type') { should eq :directory }
it { should be_directory }
end
2015-10-26 09:41:10 +00:00
**Test if a file is a file and not a directory**
2015-10-22 02:29:50 +00:00
.. code-block :: bash
describe file('/proc/version') do
its('type') { should eq 'file' }
it { should be_file }
it { should_not be_directory }
end
2015-10-26 09:41:10 +00:00
**Test if a file is a symbolic link**
2015-10-22 02:29:50 +00:00
.. code-block :: bash
describe file('/dev/stdout') do
its('type') { should eq 'symlink' }
it { should be_symlink }
it { should_not be_file }
it { should_not be_directory }
end
2015-10-26 09:41:10 +00:00
**Test if a file is a character device**
2015-10-22 02:29:50 +00:00
.. code-block :: bash
describe file('/dev/zero') do
its('type') { should eq 'character' }
it { should be_character_device }
it { should_not be_file }
it { should_not be_directory }
end
2015-10-26 09:41:10 +00:00
**Test if a file is a block device**
2015-10-22 02:29:50 +00:00
.. code-block :: bash
describe file('/dev/zero') do
its('type') { should eq 'block' }
it { should be_character_device }
it { should_not be_file }
it { should_not be_directory }
end
2015-10-26 09:41:10 +00:00
**Test the mode for a file**
2015-10-22 02:29:50 +00:00
.. code-block :: bash
describe file('/dev') do
its('mode') { should eq 00755 }
end
2015-10-26 09:41:10 +00:00
**Test the owner of a file**
2015-10-22 02:29:50 +00:00
.. code-block :: bash
describe file('/root') do
its('owner') { should eq 'root' }
end
2015-10-26 09:41:10 +00:00
**Test if a file is owned by the root user**
2015-10-22 02:29:50 +00:00
.. code-block :: bash
describe file('/dev') do
it { should be_owned_by 'root' }
end
2015-10-26 09:41:10 +00:00
**Test the mtime for a file**
2015-10-22 02:29:50 +00:00
.. code-block :: bash
describe file('/').mtime.to_i do
it { should <= Time.now.to_i }
it { should >= Time.now.to_i - 1000}
end
2015-10-26 09:41:10 +00:00
**Test that a file's size is between 64 and 10240**
2015-10-22 02:29:50 +00:00
.. code-block :: bash
describe file('/') do
its('size') { should be > 64 }
its('size') { should be < 10240 }
end
2015-10-26 09:41:10 +00:00
**Test that a file's size is zero**
2015-10-22 02:29:50 +00:00
.. code-block :: bash
describe file('/proc/cpuinfo') do
its('size') { should be 0 }
end
2015-10-26 09:41:10 +00:00
**Test that a file is not mounted**
2015-10-22 02:29:50 +00:00
.. code-block :: bash
describe file('/proc/cpuinfo') do
it { should_not be_mounted }
end
2015-10-26 09:41:10 +00:00
**Test an MD5 checksum**
2015-10-22 02:29:50 +00:00
.. code-block :: bash
require 'digest'
cpuinfo = file('/proc/cpuinfo').content
2015-10-26 09:41:10 +00:00
2015-10-22 02:29:50 +00:00
md5sum = Digest::MD5.hexdigest(cpuinfo)
2015-10-26 09:41:10 +00:00
2015-10-22 02:29:50 +00:00
describe file('/proc/cpuinfo') do
its('md5sum') { should eq md5sum }
end
2015-10-26 09:41:10 +00:00
**Test an SHA-256 checksum**
2015-10-22 02:29:50 +00:00
.. code-block :: bash
require 'digest'
cpuinfo = file('/proc/cpuinfo').content
2015-10-26 09:41:10 +00:00
2015-10-22 02:29:50 +00:00
sha256sum = Digest::SHA256.hexdigest(cpuinfo)
2015-10-26 09:41:10 +00:00
2015-10-22 02:29:50 +00:00
describe file('/proc/cpuinfo') do
its('sha256sum') { should eq sha256sum }
end
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
gem
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` gem `` InSpec audit resource to test if a global |gem| package is installed.
2015-10-20 01:25:25 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` gem `` InSpec audit resource block declares a package and (optionally) a package version:
2015-10-19 20:59:05 +00:00
.. code-block :: ruby
2015-10-20 01:25:25 +00:00
describe gem('gem_package_name') do
it { should be_installed }
end
2015-10-19 20:59:05 +00:00
where
2015-10-20 01:25:25 +00:00
* `` ('gem_package_name') `` must specify a |gem| package, such as `` 'rubocop' ``
2015-10-26 23:29:57 +00:00
* `` be_installed `` is a valid matcher for this InSpec audit resource
2015-10-19 20:59:05 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
be_installed
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_installed `` matcher tests if the named |gem| package is installed:
2015-10-19 20:59:05 +00:00
.. code-block :: ruby
it { should be_installed }
2015-10-26 09:41:10 +00:00
version
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` version `` matcher tests if the named package version is on the system:
2015-10-19 16:05:10 +00:00
2015-10-19 20:59:05 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('version') { should eq '0.33.0' }
2015-10-19 20:59:05 +00:00
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 20:59:05 +00:00
2015-10-20 01:25:25 +00:00
**Verify that a gem package is installed, with a specific version**
2015-10-19 20:59:05 +00:00
.. code-block :: ruby
2015-10-20 01:25:25 +00:00
describe gem('rubocop') do
it { should be_installed }
2015-10-20 21:04:07 +00:00
its('version') { should eq '0.33.0' }
2015-10-20 01:25:25 +00:00
end
2015-10-19 16:05:10 +00:00
2015-10-19 20:59:05 +00:00
**Verify that a gem package is not installed**
.. code-block :: ruby
2015-10-20 01:25:25 +00:00
describe gem('rubocop') do
it { should_not be_installed }
end
2015-10-19 20:59:05 +00:00
2015-10-26 09:41:10 +00:00
group
2015-10-19 16:05:10 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` group `` InSpec audit resource to test groups on the system.
2015-10-21 00:20:47 +00:00
2015-10-26 09:41:10 +00:00
Syntax
2015-10-21 00:20:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` group `` InSpec audit resource block declares a group, and then the details to be tested, such as if the group is a local group, the group identifier, or if the group exists:
2015-10-21 00:20:47 +00:00
.. code-block :: ruby
describe group('group_name') do
it { should exist }
its('gid') { should eq 0 }
end
where
* `` 'group_name' `` must specify the name of a group on the system
2015-10-26 23:29:57 +00:00
* `` exist `` and `` 'gid' `` are valid matchers for this InSpec audit resource
2015-10-21 00:20:47 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-21 00:20:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-21 00:20:47 +00:00
2015-10-26 09:41:10 +00:00
be_local
2015-10-21 00:20:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_local `` matcher tests if the group is a local group:
2015-10-21 00:20:47 +00:00
.. code-block :: ruby
it { should be_local }
2015-10-26 09:41:10 +00:00
exist
2015-10-21 00:20:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` exist `` matcher tests if the named user exists:
2015-10-21 00:20:47 +00:00
.. code-block :: ruby
it { should exist }
2015-10-26 09:41:10 +00:00
gid
2015-10-21 00:20:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` gid `` matcher tests the named group identifier:
2015-10-21 00:20:47 +00:00
.. code-block :: ruby
its('gid') { should eq 1234 }
2015-10-26 09:41:10 +00:00
Examples
2015-10-21 00:20:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-21 00:20:47 +00:00
2015-10-26 09:41:10 +00:00
**Test the group identifier for the root group**
2015-10-21 00:20:47 +00:00
.. code-block :: ruby
describe group('root') do
it { should exist }
its('gid') { should eq 0 }
end
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
group_policy
2015-10-19 16:05:10 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` group_policy `` InSpec audit resource to test group policy on the |windows| platform. This resource uses the `` Get-Item `` cmdlet to return all of the policy keys and related values.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-21 00:36:10 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` group_policy `` InSpec audit resource block declares the path to the policy:
2015-10-21 00:36:10 +00:00
.. code-block :: ruby
describe group_policy('Path\to\Policy') do
its('setting') { should eq 'value' }
end
where
2015-10-21 00:39:48 +00:00
* `` 'Path\to\Policy' `` must specify a group policy, such as `` 'Local Policies\Audit Policy' `` or `` 'Local Policies\Security Options' ``
2015-10-21 00:36:10 +00:00
* `` 'setting' `` is the group policy setting to be tested
* `` 'value' `` is compared to the value on the group policy
2015-10-26 09:41:10 +00:00
Matchers
2015-10-21 00:36:10 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
setting
2015-10-21 00:36:10 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` setting `` matcher tests specific, named settings in the group policy:
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-21 00:36:10 +00:00
its('setting') { should eq 'value' }
Use a `` setting `` matcher for each setting to be tested.
2015-10-26 09:41:10 +00:00
Examples
2015-10-21 00:36:10 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-21 00:36:10 +00:00
2015-10-26 09:41:10 +00:00
**Test if users are logged off after the logon time expires**
2015-10-21 00:36:10 +00:00
.. code-block :: ruby
describe group_policy('Local Policies\Security Options') do
its('Automatically log off users when the logon time expires') { should eq 'Enabled' }
end
2015-10-20 16:52:34 +00:00
2015-10-26 09:41:10 +00:00
host
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` host `` InSpec audit resource to test the name used to refer to a specific host and its availability, including the Internet protocols and ports over which that host name should be available.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Stable**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` host `` InSpec audit resource block declares a host name, and then (depending on what is to be tested) a port and/or a protocol:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe host('example.com', port: 80, proto: 'udp') do
it { should be_reachable }
end
where
* `` host() `` must specify a host name and may specify a port number and/or a protocol
* `` 'example.com' `` is the host name
* `` port: `` is the port number
* `` proto: 'name' `` is the Internet protocol: |icmp| (`` proto: 'icmp' `` ), |tcp| (`` proto: 'tcp' `` ), or |udp| (`` proto: 'udp' `` )
2015-10-26 23:29:57 +00:00
* `` be_reachable `` is a valid matcher for this InSpec audit resource
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
be_reachable
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_reachable `` matcher tests if the host name is available:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
it { should be_reachable }
2015-10-26 09:41:10 +00:00
be_resolvable
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_resolvable `` matcher tests for host name resolution, i.e. "resolvable to an IP address":
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
it { should be_resolvable }
2015-10-26 09:41:10 +00:00
ipaddress
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-22 04:13:17 +00:00
The `` ipaddress `` matcher tests if a host name is resolvable to a specific IP address:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('ipaddress') { should include '93.184.216.34' }
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
**Verify host name s reachable over a specific protocol and port number**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe host('example.com', port: 53, proto: 'udp') do
it { should be_reachable }
end
2015-10-26 09:41:10 +00:00
**Verify that a specific IP address can be resolved**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe host('example.com', port: 80, proto: 'tcp') do
it { should be_resolvable }
2015-10-20 21:04:07 +00:00
its('ipaddress') { should include '192.168.1.1' }
2015-10-19 16:05:10 +00:00
end
2015-10-20 01:25:25 +00:00
2015-10-20 21:04:07 +00:00
2015-10-22 04:13:17 +00:00
2015-10-26 09:41:10 +00:00
inetd_conf
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` inetd_conf `` InSpec audit resource to test if a service is enabled in the `` inetd.conf `` file on |linux| and |unix| platforms. |inetd|---the Internet service daemon---listens on dedicated ports, and then loads the appropriate program based on a request. The `` inetd.conf `` file is typically located at `` /etc/inetd.conf `` and contains a list of Internet services associated to the ports on which that service will listen. Only enabled services may handle a request; only services that are required by the system should be enabled.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` inetd_conf `` InSpec audit resource block declares the list of services that should be disabled in the `` inetd.conf `` file:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-26 15:21:51 +00:00
describe inetd_conf('path') do
2015-10-20 21:04:07 +00:00
its('service_name') { should eq 'value' }
2015-10-19 16:05:10 +00:00
end
where
* `` 'service_name' `` is a service listed in the `` inetd.conf `` file
* `` ('path') `` is the non-default path to the `` inetd.conf `` file
* `` should eq 'value' `` is the value that is expected
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource matches any service that is listed in the `` inetd.conf `` file:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('shell') { should eq nil }
2015-10-19 16:05:10 +00:00
or:
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('netstat') { should eq nil }
2015-10-19 16:05:10 +00:00
or:
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('systat') { should eq nil }
2015-10-19 16:05:10 +00:00
For example:
.. code-block :: ruby
describe inetd_conf do
2015-10-20 21:04:07 +00:00
its('shell') { should eq nil }
its('login') { should eq nil }
its('exec') { should eq nil }
2015-10-19 16:05:10 +00:00
end
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
**Verify that FTP is disabled**
2015-10-19 16:05:10 +00:00
The contents if the `` inetd.conf `` file contain the following:
.. code-block :: text
#ftp stream tcp nowait root /usr/sbin/tcpd in.ftpd -l -a
#telnet stream tcp nowait root /usr/sbin/tcpd in.telnetd
and the following test is defined:
.. code-block :: ruby
2015-10-26 15:21:51 +00:00
describe inetd_conf do
2015-10-20 21:04:07 +00:00
its('ftp') { should eq nil }
its('telnet') { should eq nil }
2015-10-19 16:05:10 +00:00
end
Because both the `` ftp `` and `` telnet `` Internet services are commented out (`` # `` ), both services are disabled. Consequently, both tests will return `` true `` . However, if the `` inetd.conf `` file is set as follows:
.. code-block :: text
ftp stream tcp nowait root /usr/sbin/tcpd in.ftpd -l -a
#telnet stream tcp nowait root /usr/sbin/tcpd in.telnetd
then the same test will return `` false `` for `` ftp `` and the entire test will fail.
2015-10-26 09:41:10 +00:00
**Test if telnet is installed**
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
describe package('telnetd') do
it { should_not be_installed }
end
2015-10-26 09:41:10 +00:00
2015-10-20 01:25:25 +00:00
describe inetd_conf do
its('telnet') { should eq nil }
end
2015-10-22 19:00:05 +00:00
2015-10-26 09:41:10 +00:00
interface
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` interface `` InSpec audit resource to test basic network adapter properties, such as name, status, state, address, and link speed (in MB/sec).
2015-10-19 16:05:10 +00:00
* On |unix| and |linux| platforms, any value in the `` /sys/class/net/#{iface} `` directory may be tested.
* On the |windows| platform, the `` Get-NetAdapter `` cmdlet returns the following values: `` Property Name `` , `` InterfaceDescription `` , `` Status `` , `` State `` , `` MacAddress `` , `` LinkSpeed `` , `` ReceiveLinkSpeed `` , `` TransmitLinkSpeed `` , and `` Virtual `` , returned as a |json| object.
.. not sure the previous two bullet items are actually true, but keeping there for reference for now, just in case
2015-10-27 16:47:27 +00:00
**Stability: Stable**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` interface `` InSpec audit resource block declares network interface properties to be tested:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe interface do
it { should be_up }
2015-10-20 21:04:07 +00:00
its('speed') { should eq 1000 }
2015-10-19 16:05:10 +00:00
its('name') { should eq eth0 }
end
2015-10-26 09:41:10 +00:00
..
2015-10-19 16:05:10 +00:00
.. where
2015-10-26 09:41:10 +00:00
..
2015-10-19 16:05:10 +00:00
.. * ``xxxxx`` must specify xxxxx
.. * xxxxx
2015-10-26 23:29:57 +00:00
.. * ``xxxxx`` is a valid matcher for this InSpec audit resource
2015-10-26 09:41:10 +00:00
..
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
be_up
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_up `` matcher tests if the network interface is available:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
it { should be_up }
2015-10-26 09:41:10 +00:00
name
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` name `` matcher tests if the named network interface exists:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('name') { should eq eth0 }
2015-10-26 09:41:10 +00:00
speed
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` speed `` matcher tests the speed of the network interface, in MB/sec:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('speed') { should eq 1000 }
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
..
2015-10-19 16:05:10 +00:00
.. Examples
2015-10-20 21:16:47 +00:00
.. -----------------------------------------------------
2015-10-26 23:29:57 +00:00
.. The following examples show how to use this InSpec audit resource.
2015-10-26 09:41:10 +00:00
..
.. **xxxxx**
..
2015-10-19 16:05:10 +00:00
.. xxxxx
2015-10-26 09:41:10 +00:00
..
.. **xxxxx**
..
2015-10-19 16:05:10 +00:00
.. xxxxx
2015-10-26 09:41:10 +00:00
..
2015-10-20 21:04:07 +00:00
2015-10-22 19:00:05 +00:00
2015-10-26 09:41:10 +00:00
iptables
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` iptables `` InSpec audit resource to test rules that are defined in `` iptables `` , which maintains tables of IP packet filtering rules. There may be more than one table. Each table contains one (or more) chains (both built-in and custom). A chain is a list of rules that match packets. When the rule matches, the rule defines what target to assign to the packet.
2015-10-22 19:00:05 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-22 19:00:05 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` iptables `` InSpec audit resource block declares tests for rules in IP tables:
2015-10-22 19:00:05 +00:00
.. code-block :: ruby
describe iptables(rule:'name', table:'name', chain: 'name') do
it { should have_rule('RULE') }
end
where
* `` iptables() `` may specify any combination of `` rule `` , `` table `` , or `` chain ``
* `` rule:'name' `` is the name of a rule that matches a set of packets
* `` table:'name' `` is the packet matching table against which the test is run
* `` chain: 'name' `` is the name of a user-defined chain or one of `` ACCEPT `` , `` DROP `` , `` QUEUE `` , or `` RETURN ``
* `` have_rule('RULE') `` tests that rule in the iptables file
2015-10-26 09:41:10 +00:00
Matchers
2015-10-22 19:00:05 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-20 21:04:07 +00:00
2015-10-26 09:41:10 +00:00
have_rule
2015-10-22 19:00:05 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
The `` have_rule `` matcher tests the named rule against the information in the `` iptables `` file:
.. code-block :: ruby
it { should have_rule('RULE') }
2015-10-26 09:41:10 +00:00
Examples
2015-10-22 19:00:05 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-22 19:00:05 +00:00
2015-10-26 09:41:10 +00:00
**Test if the IP table allows a packet through**
2015-10-20 21:04:07 +00:00
2015-10-22 19:00:05 +00:00
.. code-block :: ruby
describe iptables do
it { should have_rule('-P INPUT ACCEPT') }
end
2015-10-26 09:41:10 +00:00
**Test if the IP table allows a packet through, for a specific table and chain**
2015-10-22 19:00:05 +00:00
.. code-block :: ruby
describe iptables(table:'mangle', chain: 'input') do
it { should have_rule('-P INPUT ACCEPT') }
end
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
json
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` json `` InSpec audit resource to test data in a |json| file.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` json `` InSpec audit resource block declares the data to be tested:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe json do
its('name') { should eq 'foo' }
end
where
* `` name `` is a configuration setting in a |json| file
* `` should eq 'foo' `` tests a value of `` name `` as read from a |json| file versus the value declared in the test
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
name
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` name `` matcher tests the value of `` name `` as read from a |json| file versus the value declared in the test:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('name') { should eq 'foo' }
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
**Test a cookbook version in a policyfile.lock.json file**
.. code-block :: ruby
describe json('policyfile.lock.json') do
its('cookbook_locks.omnibus.version') { should eq('2.2.0') }
end
2015-10-22 04:13:17 +00:00
2015-10-26 09:41:10 +00:00
kernel_module
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` kernel_module `` InSpec audit resource to test kernel modules on |linux| platforms. These parameters are located under `` /lib/modules `` . Any submodule may be tested using this resource.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Stable**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` kernel_module `` InSpec audit resource block declares a module name, and then tests if that module is a loadable kernel module:
2015-10-19 16:05:10 +00:00
2015-10-20 21:04:07 +00:00
.. code-block :: ruby
2015-10-19 16:05:10 +00:00
2015-10-20 21:04:07 +00:00
describe kernel_module('module_name') do
it { should be_loaded }
end
2015-10-19 16:05:10 +00:00
2015-10-20 21:04:07 +00:00
where
2015-10-19 16:05:10 +00:00
2015-10-20 21:04:07 +00:00
* `` 'module_name' `` must specify a kernel module, such as `` 'bridge' ``
* `` { should be_loaded } `` tests if the module is a loadable kernel module
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
be_loaded
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_loaded `` matcher tests if the module is a loadable kernel module:
2015-10-19 16:05:10 +00:00
2015-10-20 21:04:07 +00:00
.. code-block :: ruby
2015-10-19 16:05:10 +00:00
2015-10-20 21:04:07 +00:00
it { should be_loaded }
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
**Test if a module is loaded**
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
describe kernel_module('bridge') do
it { should be_loaded }
end
2015-10-20 16:52:34 +00:00
2015-10-20 21:04:07 +00:00
2015-10-26 09:41:10 +00:00
kernel_parameter
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` kernel_parameter `` InSpec audit resource to test kernel parameters on |linux| platforms. These parameters are located under `` /proc/sys/net `` . Any subdirectory may be tested using this resource.
2015-10-20 21:04:07 +00:00
.. https://www.kernel.org/doc/Documentation/kernel-parameters.txt
2015-10-27 16:47:27 +00:00
**Stability: Stable**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` kernel_parameter `` InSpec audit resource block declares a parameter and then a value to be tested:
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
describe kernel_parameter('path.to.parameter') do
its('value') { should eq 0 }
end
where
* `` 'path.to.parameter' `` must specify a kernel parameter, such as `` 'net.ipv4.conf.all.forwarding' ``
* `` { should eq 0 } `` states the value to be tested
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-20 21:04:07 +00:00
2015-10-26 09:41:10 +00:00
value
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` value `` matcher tests the value assigned to the named IP address versus the value declared in the test:
2015-10-20 21:04:07 +00:00
.. code-block :: ruby
its('value') { should eq 0 }
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-20 21:04:07 +00:00
2015-10-26 09:41:10 +00:00
**Test if global forwarding is enabled for an IPv4 address**
2015-10-20 21:04:07 +00:00
.. code-block :: ruby
describe kernel_parameter('net.ipv4.conf.all.forwarding') do
its(:value) { should eq 1 }
end
2015-10-26 09:41:10 +00:00
**Test if global forwarding is disabled for an IPv6 address**
2015-10-20 21:04:07 +00:00
.. code-block :: ruby
describe kernel_parameter('net.ipv6.conf.all.forwarding') do
its(:value) { should eq 0 }
end
2015-10-26 09:41:10 +00:00
**Test if an IPv6 address accepts redirects**
2015-10-20 21:04:07 +00:00
.. code-block :: ruby
describe kernel_parameter('net.ipv6.conf.interface.accept_redirects') do
its(:value) { should eq 'true' }
end
2015-10-26 09:41:10 +00:00
limits_conf
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` limits_conf `` InSpec audit resource to test configuration settings in the `` /etc/security/limits.conf `` file. The `` limits.conf `` defines limits for processes (by user and/or group names) and helps ensure that the system on which those processes are running remains stable. Each process may be assigned a hard or soft limit.
2015-10-20 21:04:07 +00:00
* Soft limits are maintained by the shell and defines the number of file handles (or open files) available to the user or group after login
* Hard limits are maintained by the kernel and defines the maximum number of allowed file handles
Entries in the `` limits.conf `` file are similar to:
.. code-block :: bash
grantmc soft nofile 4096
grantmc hard nofile 63536
2015-10-26 09:41:10 +00:00
2015-10-20 21:04:07 +00:00
^^^^^^^^^ ^^^^ ^^^^^^ ^^^^^
domain type item value
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` limits_conf `` InSpec audit resource block declares a domain to be tested, along with associated type, item, and value:
2015-10-20 21:04:07 +00:00
.. code-block :: ruby
describe limits_conf('path') do
its('domain') { should include ['type', 'item', 'value'] }
its('domain') { should eq ['type', 'item', 'value'] }
end
where
* `` ('path') `` is the non-default path to the `` inetd.conf `` file
* `` 'domain' `` is a user or group name, such as `` grantmc ``
* `` 'type' `` is either `` hard `` or `` soft ``
* `` 'item' `` is the item for which limits are defined, such as `` core `` , `` nofile `` , `` stack `` , `` nproc `` , `` priority `` , or `` maxlogins ``
* `` 'value' `` is the value associated with the `` item ``
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-20 21:04:07 +00:00
2015-10-26 09:41:10 +00:00
domain
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` domain `` matcher tests the domain in the `` limits.conf `` file, along with associated type, item, and value:
2015-10-20 21:04:07 +00:00
.. code-block :: ruby
its('domain') { should include ['type', 'item', 'value'] }
For example:
.. code-block :: ruby
its('grantmc') { should include ['hard', 'nofile', '63536'] }
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-20 21:04:07 +00:00
2015-10-26 09:41:10 +00:00
**Test * and ftp limits**
2015-10-20 21:04:07 +00:00
describe limits_conf('path') do
its('*') { should include ['soft', 'core', '0'], ['hard', 'rss', '10000'] }
its('ftp') { should eq ['hard', 'nproc', '0'] }
end
2015-10-20 16:52:34 +00:00
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
login_defs
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` login_defs `` InSpec audit resource to test configuration settings in the `` /etc/login.defs `` file. The `` logins.defs `` file defines site-specific configuration for the shadow password suite on |linux| and |unix| platforms, such as password expiration ranges, minimum/maximum values for automatic selection of user and group identifiers, or the method with which passwords are encrypted.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` login_defs `` InSpec audit resource block declares the `` login.defs `` configuration data to be tested:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe login_defs do
its('name') { should include('foo') }
end
where
* `` name `` is a configuration setting in `` login.defs ``
* `` { should include('foo') } `` tests the value of `` name `` as read from `` login.defs `` versus the value declared in the test
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
name
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` name `` matcher tests the value of `` name `` as read from `` login.defs `` versus the value declared in the test:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('name') { should eq 'foo' }
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
**Test password expiration settings**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe login_defs do
its('PASS_MAX_DAYS') { should eq '180' }
its('PASS_MIN_DAYS') { should eq '1' }
its('PASS_MIN_LEN') { should eq '15' }
its('PASS_WARN_AGE') { should eq '30' }
end
2015-10-26 09:41:10 +00:00
**Test the encryption method**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe login_defs do
its('ENCRYPT_METHOD') { should eq 'SHA512' }
end
2015-10-20 21:04:07 +00:00
**Test xxxxx** <<< what does this test?
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe login_def do
its('UMASK') { should eq '077' }
2015-10-27 16:47:55 +00:00
its('PASS_MAX_DAYS') { should eq '90' }
2015-10-19 16:05:10 +00:00
end
2015-10-26 09:41:10 +00:00
mysql_conf
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` mysql_conf `` InSpec audit resource to test the contents of the configuration file for |mysql|, typically located at `` /etc/mysql/<version>/my.cnf `` .
2015-10-20 21:04:07 +00:00
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` mysql_conf `` InSpec audit resource block declares one (or more) settings in the `` my.cnf `` file, and then compares the setting in the configuration file to the value stated in the test:
2015-10-19 16:05:10 +00:00
2015-10-20 21:04:07 +00:00
.. code-block :: ruby
2015-10-19 16:05:10 +00:00
2015-10-20 21:04:07 +00:00
describe mysql_conf('path') do
its('setting') { should eq 'value' }
end
2015-10-19 16:05:10 +00:00
2015-10-20 21:04:07 +00:00
where
2015-10-20 16:52:34 +00:00
2015-10-20 21:04:07 +00:00
* `` 'setting' `` specifies a setting in the `` my.cnf `` file
* `` ('path') `` is the non-default path to the `` my.cnf `` file
* `` should eq 'value' `` is the value that is expected
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-20 21:04:07 +00:00
2015-10-26 09:41:10 +00:00
setting
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` setting `` matcher tests specific, named settings in the `` my.cnf `` file:
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('setting') { should eq 'value' }
2015-10-20 16:52:34 +00:00
2015-10-20 21:04:07 +00:00
Use a `` setting `` matcher for each setting to be tested.
2015-10-20 16:52:34 +00:00
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-20 21:04:07 +00:00
2015-10-26 09:41:10 +00:00
**Test the maximum number of allowed connections**
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
describe mysql_conf do
its('max_connections') { should eq '505' }
its('max_user_connections') { should eq '500' }
end
2015-10-26 09:41:10 +00:00
**Test slow query logging**
2015-10-20 16:52:34 +00:00
2015-10-20 21:04:07 +00:00
.. code-block :: ruby
2015-10-20 16:52:34 +00:00
2015-10-20 21:04:07 +00:00
describe mysql_conf do
its('slow_query_log_file') { should eq 'hostname_slow.log' }
its('slow_query_log') { should eq '0' }
its('log_queries_not_using_indexes') { should eq '1' }
its('long_query_time') { should eq '0.5' }
its('min_examined_row_limit') { should eq '100' }
end
2015-10-20 16:52:34 +00:00
2015-10-26 09:41:10 +00:00
**Test the port and socket on which MySQL listens**
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
describe mysql_conf do
its('port') { should eq '3306' }
its('socket') { should eq '/var/run/mysqld/mysql.sock' }
end
2015-10-20 16:52:34 +00:00
2015-10-26 09:41:10 +00:00
**Test connection and thread variables**
2015-10-20 16:52:34 +00:00
2015-10-20 21:04:07 +00:00
.. code-block :: ruby
2015-10-19 16:05:10 +00:00
2015-10-20 21:04:07 +00:00
describe mysql_conf do
its('port') { should eq '3306' }
its('socket') { should eq '/var/run/mysqld/mysql.sock' }
its('max_allowed_packet') { should eq '12M' }
its('default_storage_engine') { should eq 'InnoDB' }
its('character_set_server') { should eq 'utf8' }
its('collation_server') { should eq 'utf8_general_ci' }
its('max_connections') { should eq '505' }
its('max_user_connections') { should eq '500' }
its('thread_cache_size') { should eq '505' }
end
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
**Test the safe-user-create parameter**
2015-10-19 16:05:10 +00:00
2015-10-20 21:04:07 +00:00
.. code-block :: ruby
describe mysql_conf.params('mysqld') do
its('safe-user-create') { should eq('1') }
end
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
mysql_session
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` mysql_session `` InSpec audit resource to test SQL commands run against a |mysql| database.
2015-10-20 21:04:07 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` mysql_session `` InSpec audit resource block declares the username and password to use for the session, and then the command to be run:
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
sql = mysql_session('username', 'password')
sql.describe('QUERY') do
its('output') { should eq('') }
end
where
2015-10-20 16:52:34 +00:00
2015-10-20 21:04:07 +00:00
* `` sql = mysql_session `` declares a username and password with permission to run the query
* `` describe('QUERY') `` contains the query to be run
* `` its('output') { should eq('') } `` compares the results of the query against the expected result in the test
2015-10-20 16:52:34 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-20 16:52:34 +00:00
2015-10-26 09:41:10 +00:00
output
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` output `` matcher tests the results of the query:
2015-10-20 16:52:34 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('output') { should eq(/^0/) }
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-20 21:04:07 +00:00
**Test for matching databases**
.. code-block :: ruby
sql = mysql_session('my_user','password')
sql.describe('show databases like \'test\';') do
its(:stdout) { should_not match(/test/) }
end
2015-10-20 16:52:34 +00:00
2015-10-26 09:41:10 +00:00
npm
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` npm `` InSpec audit resource to test if a global |npm| package is installed. |npm| is the `the package manager for Javascript packages <https://docs.npmjs.com> `__ , such as |bower| and |statsd|.
2015-10-20 01:25:25 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` npm `` InSpec audit resource block declares a package and (optionally) a package version:
2015-10-19 21:14:20 +00:00
.. code-block :: ruby
2015-10-20 01:25:25 +00:00
describe gem('npm_package_name') do
it { should be_installed }
end
2015-10-19 21:14:20 +00:00
where
2015-10-20 01:25:25 +00:00
* `` ('npm_package_name') `` must specify a |npm| package, such as `` 'bower' `` or `` 'statsd' ``
2015-10-26 23:29:57 +00:00
* `` be_installed `` is a valid matcher for this InSpec audit resource
2015-10-19 21:14:20 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
be_installed
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_installed `` matcher tests if the named |gem| package and package version (if specified) is installed:
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
it { should be_installed }
2015-10-26 09:41:10 +00:00
version
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` version `` matcher tests if the named package version is on the system:
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('version') { should eq '1.2.3' }
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-20 01:25:25 +00:00
**Verify that bower is installed, with a specific version**
.. code-block :: ruby
describe npm('bower') do
it { should be_installed }
2015-10-20 21:04:07 +00:00
its('version') { should eq '1.4.1' }
2015-10-20 01:25:25 +00:00
end
**Verify that statsd is not installed**
.. code-block :: ruby
describe npm('statsd') do
it { should_not be_installed }
end
2015-10-26 09:41:10 +00:00
ntp_conf
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
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 `` .
2015-10-19 21:14:20 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` ntp_conf `` InSpec audit resource block declares the synchronization settings that should be tested:
2015-10-19 21:14:20 +00:00
.. code-block :: ruby
2015-10-20 01:25:25 +00:00
describe ntp_conf('path') do
2015-10-20 21:04:07 +00:00
its('setting_name') { should eq 'value' }
2015-10-20 01:25:25 +00:00
end
where
* `` 'setting_name' `` is a synchronization setting defined in the `` ntp.conf `` file
* `` ('path') `` is the non-default path to the `` ntp.conf `` file
* `` { should eq 'value' } `` is the value that is expected
2015-10-19 21:14:20 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource matches any service that is listed in the `` ntp.conf `` file:
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
its('server') { should_not eq nil }
or:
2015-10-19 21:14:20 +00:00
.. code-block :: ruby
2015-10-20 01:25:25 +00:00
its('restrict') { should include '-4 default kod notrap nomodify nopeer noquery'}
For example:
.. code-block :: ruby
describe ntp_conf do
its('server') { should_not eq nil }
its('restrict') { should include '-4 default kod notrap nomodify nopeer noquery'}
end
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
**Test for clock drift against named servers**
2015-10-20 04:50:25 +00:00
.. code-block :: ruby
describe ntp_conf do
its('driftfile') { should eq '/var/lib/ntp/ntp.drift' }
its('server') { should eq [
0.ubuntu.pool.ntp.org,
1.ubuntu.pool.ntp.org,
2.ubuntu.pool.ntp.org
] }
end
2015-10-19 21:14:20 +00:00
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
oneget
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
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.
2015-10-20 01:25:25 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` oneget `` InSpec audit resource block declares a package and (optionally) a package version:
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
2015-10-19 21:14:20 +00:00
2015-10-20 01:25:25 +00:00
describe oneget('name') do
it { should be_installed }
end
where
* `` ('name') `` must specify the name of a package, such as `` 'VLC' ``
2015-10-26 23:29:57 +00:00
* `` be_installed `` is a valid matcher for this InSpec audit resource
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 21:14:20 +00:00
2015-10-26 09:41:10 +00:00
be_installed
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_installed `` matcher tests if the named package is installed on the system:
2015-10-19 21:14:20 +00:00
.. code-block :: ruby
2015-10-20 01:25:25 +00:00
it { should be_installed }
2015-10-19 21:14:20 +00:00
2015-10-26 09:41:10 +00:00
version
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` version `` matcher tests if the named package version is on the system:
2015-10-19 21:14:20 +00:00
.. code-block :: ruby
2015-10-19 16:05:10 +00:00
2015-10-20 21:04:07 +00:00
its('version') { should eq '1.2.3' }
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
**Test if VLC is installed**
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
2015-10-19 16:05:10 +00:00
2015-10-20 01:25:25 +00:00
describe package('VLC') do
it { should be_installed }
end
2015-10-26 09:41:10 +00:00
os
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` os `` InSpec audit resource to test the platform on which the system is running.
2015-10-19 21:14:20 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Stable**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` os `` InSpec audit resource block declares the platform to be tested:
2015-10-19 16:05:10 +00:00
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
2015-10-19 16:05:10 +00:00
2015-10-20 01:25:25 +00:00
describe os do
it { should eq 'platform' }
end
2015-10-19 16:05:10 +00:00
2015-10-20 01:25:25 +00:00
where
2015-10-19 16:05:10 +00:00
2015-10-20 01:25:25 +00:00
* `` 'platform' `` is one of `` bsd `` , `` debian `` , `` linux `` , `` redhat `` , `` solaris `` , `` suse `` , `` unix `` , or `` windows ``
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource does not have any matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
**Test for RedHat**
2015-10-19 16:05:10 +00:00
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
2015-10-19 16:05:10 +00:00
2015-10-20 01:25:25 +00:00
describe os do
it { should eq 'redhat' }
end
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
**Test for Ubuntu**
2015-10-19 16:05:10 +00:00
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
2015-10-19 16:05:10 +00:00
2015-10-20 01:25:25 +00:00
describe os do
it { should eq 'debian' }
end
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
**Test for Microsoft Windows**
2015-10-19 16:05:10 +00:00
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
2015-10-19 16:05:10 +00:00
2015-10-20 01:25:25 +00:00
describe os do
it { should eq 'windows' }
end
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
os_env
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` os_env `` InSpec audit resource to test the environment variables for the platform on which the system is running.
2015-10-20 01:25:25 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` os_env `` InSpec audit resource block declares xxxxx:
2015-10-19 20:44:20 +00:00
.. code-block :: ruby
2015-10-20 01:25:25 +00:00
describe os_env('VARIABLE') do
its('matcher') { should eq 1 }
end
2015-10-19 20:44:20 +00:00
where
2015-10-20 01:25:25 +00:00
* `` ('VARIABLE') `` must specify an environment variable, such as `` PATH ``
2015-10-26 23:29:57 +00:00
* `` matcher `` is a valid matcher for this InSpec audit resource
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
exit_status
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` exit_status `` matcher tests the exit status of the platform environment:
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('exit_status') { should eq 0 }
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
split
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` split `` matcher tests the delimiter between environment variables:
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('split') { should include ('') }
2015-10-20 01:25:25 +00:00
or:
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('split') { should_not include ('.') }
2015-10-20 01:25:25 +00:00
Use `` -1 `` to test for cases where there is a trailing colon (`` : `` ), such as `` dir1::dir2: `` :
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('split') { should include ('-1') }
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
stderr
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` stderr `` matcher tests environment variables after they are output to stderr:
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('stderr') { should include('PWD=/root') }
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
**Test the PATH environment variable**
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
describe os_env('PATH') do |dirs|
2015-10-20 21:04:07 +00:00
its('split') { should_not include('') }
its('split') { should_not include('.') }
2015-10-20 01:25:25 +00:00
end
2015-10-19 20:44:20 +00:00
2015-10-26 09:41:10 +00:00
package
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` package `` InSpec audit resource to test if the named package and/or package version is installed on the system.
2015-10-19 20:44:20 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Stable**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` package `` InSpec audit resource block declares a package and (optionally) a package version:
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
describe package('name') do
it { should be_installed }
end
where
* `` ('name') `` must specify the name of a package, such as `` 'nginx' ``
2015-10-26 23:29:57 +00:00
* `` be_installed `` is a valid matcher for this InSpec audit resource
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
be_installed
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_installed `` matcher tests if the named package is installed on the system:
2015-10-19 20:44:20 +00:00
.. code-block :: ruby
it { should be_installed }
2015-10-26 09:41:10 +00:00
version
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` version `` matcher tests if the named package version is on the system:
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('version) { should eq '1.2.3' }
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
**Test if nginx version 1.9.5 is installed**
2015-10-19 20:44:20 +00:00
.. code-block :: ruby
2015-10-20 01:25:25 +00:00
describe package('nginx') do
it { should be_installed }
2015-10-20 21:04:07 +00:00
its('version') { should eq 1.9.5 }
2015-10-20 01:25:25 +00:00
end
2015-10-19 20:44:20 +00:00
2015-10-26 09:41:10 +00:00
**Test that a package is not installed**
2015-10-19 20:44:20 +00:00
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
describe package('some_package') do
it { should_not be_installed }
end
2015-10-19 20:44:20 +00:00
2015-10-26 09:41:10 +00:00
**Test if telnet is installed**
2015-10-19 20:44:20 +00:00
.. code-block :: ruby
2015-10-20 01:25:25 +00:00
describe package('telnetd') do
it { should_not be_installed }
end
2015-10-26 09:41:10 +00:00
2015-10-20 01:25:25 +00:00
describe inetd_conf do
its('telnet') { should eq nil }
end
2015-10-19 16:05:10 +00:00
2015-10-20 01:25:25 +00:00
**Test if ClamAV (an antivirus engine) is installed and running**
2015-10-19 20:44:20 +00:00
.. code-block :: ruby
2015-10-20 01:25:25 +00:00
describe package('clamav') do
it { should be_installed }
its('version') { should eq '0.98.7' }
end
2015-10-26 09:41:10 +00:00
2015-10-20 01:25:25 +00:00
describe service('clamd') do
it { should_not be_enabled }
it { should_not be_installed }
it { should_not be_running }
end
2015-10-19 20:44:20 +00:00
2015-10-26 09:41:10 +00:00
parse_config
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` parse_config `` InSpec audit resource to test arbitrary configuration files, such as testing the results of a regular expression, ensuring that settings are commented out, testing for multiple values, and so on.
2015-10-19 20:44:20 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` parse_config `` InSpec audit resource block declares the location of the configuration file to be tested, and then which settings in that file are to be tested. Because this InSpec audit resource relies on arbitrary configuration files, the test itself is often arbitrary and relies on custom |ruby| code:
2015-10-19 16:05:10 +00:00
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
2015-10-19 16:05:10 +00:00
2015-10-20 01:25:25 +00:00
output = command('some-command').stdout
2015-10-26 09:41:10 +00:00
2015-10-20 01:25:25 +00:00
describe parse_config(output, { data_config_option: value } ) do
its('setting') { should eq 1 }
end
2015-10-19 16:05:10 +00:00
2015-10-20 01:25:25 +00:00
or:
2015-10-19 16:05:10 +00:00
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
audit = command('/sbin/auditctl -l').stdout
options = {
assignment_re: /^\s*([^:]* ?)\s*:\s* (.*?)\s* $/,
multiple_values: true
}
2015-10-26 09:41:10 +00:00
2015-10-20 01:25:25 +00:00
describe parse_config(audit, options) do
its('setting') { should eq 1 }
end
where each test
* Must declare the location of the configuration file to be tested
* Must declare one (or more) settings to be tested
* May run a command to `` stdout `` , and then run the test against that output
* May use options to define how configuration data is to be parsed
2015-10-26 09:41:10 +00:00
Options
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource supports the following options for parsing configuration data. Use them in an `` options `` block stated outside of (and immediately before) the actual test:
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
options = {
assignment_re: /^\s*([^:]* ?)\s*:\s* (.*?)\s* $/,
multiple_values: true
}
describe parse_config(options) do
its('setting') { should eq 1 }
end
2015-10-26 09:41:10 +00:00
assignment_re
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
Use `` assignment_re `` to test a key value using a regular expression:
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
'key = value'
may be tested using the following regular expression, which determines assignment from key to value:
.. code-block :: ruby
assignment_re: /^\s*([^=]* ?)\s*=\s* (.*?)\s* $/
2015-10-26 09:41:10 +00:00
comment_char
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
Use `` comment_char `` to test for comments in a configuration file:
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
comment_char: '#'
2015-10-26 09:41:10 +00:00
key_vals
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
Use `` key_vals `` to test how many values a key contains:
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
key = a b c
contains three values. To test that value to ensure it only contains one, use:
.. code-block :: ruby
key_vals: 1
2015-10-26 09:41:10 +00:00
multiple_values
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
Use `` multiple_values `` to test for the presence of multiple key values:
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
'key = a' and 'key = b'
params['key'] = ['a', 'b']
or:
.. code-block :: ruby
'key = a' and 'key = b'
params['key'] = 'b'
To test if multiple values are present, use:
.. code-block :: ruby
multiple_values: false
The preceding test will fail with the first example and will pass with the second.
2015-10-26 09:41:10 +00:00
standalone_comments
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
Use `` standalone_comments `` to test for comments in a configuration file and to ensure they are not integrated into the same lines as code:
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
'key = value # comment'
params['key'] = 'value'
or:
.. code-block :: ruby
'key = value # comment'
params['key'] = 'value # comment'
To test if comments are standalone, use:
.. code-block :: ruby
standalone_comments: true
The preceding test will fail with the second example and will pass with the first.
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
**Test the expiration time for new account passwords**
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
output = command('useradd -D').stdout
2015-10-26 09:41:10 +00:00
2015-10-20 01:25:25 +00:00
describe parse_config(output) do
2015-10-27 16:47:55 +00:00
its('INACTIVE') { should eq '35' }
2015-10-20 01:25:25 +00:00
end
2015-10-26 09:41:10 +00:00
**Test that bob is a user**
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
describe parse_config(data, { multiple_values: true }) do
its('users') { should include 'bob'}
end
2015-10-26 09:41:10 +00:00
parse_config_file
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` parse_config_file `` InSpec audit resource to test arbitrary configuration files.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` parse_config_file `` InSpec audit resource block declares the location of the configuration file to be tested, and then which settings in that file are to be tested. Because this InSpec audit resource relies on arbitrary configuration files, the test itself is often arbitrary and relies on custom |ruby| code:
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
output = command('some-command').stdout
2015-10-26 09:41:10 +00:00
2015-10-20 01:25:25 +00:00
describe parse_config_file(output, { data_config_option: value } ) do
its('setting') { should eq 1 }
end
or:
.. code-block :: ruby
audit = command('/sbin/auditctl -l').stdout
options = {
assignment_re: /^\s*([^:]* ?)\s*:\s* (.*?)\s* $/,
multiple_values: true
}
2015-10-26 09:41:10 +00:00
2015-10-20 01:25:25 +00:00
describe parse_config_file(audit, options) do
its('setting') { should eq 1 }
end
where each test
* Must declare the location of the configuration file to be tested
* Must declare one (or more) settings to be tested
* May run a command to `` stdout `` , and then run the test against that output
* May use options to define how configuration data is to be parsed
.. or is this one more like this?
.. code-block :: ruby
audit = command('/sbin/auditctl -l').stdout
options = {
assignment_re: /^\s*([^:]* ?)\s*:\s* (.*?)\s* $/,
multiple_values: true
}
2015-10-26 09:41:10 +00:00
2015-10-20 01:25:25 +00:00
describe parse_config_file(audit, options) do
its('setting') { should eq 1 }
end
where each test
* Must declare the location of the configuration file to be tested
* Must declare one (or more) settings to be tested
* May run a command to `` stdout `` , and then run the test against that output
* May use options to define how configuration data is to be parsed
2015-10-26 09:41:10 +00:00
Options
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource supports the following options for parsing configuration data. Use them in an `` options `` block stated outside of (and immediately before) the actual test:
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
describe parse_config_file(/path/to/config/file) do
its('setting') { should eq 1 }
end
InSpec == inspec (command-line)
2015-10-26 09:41:10 +00:00
assignment_re
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-20 01:25:25 +00:00
IDENTICAL TO parse_config << INCLUDE THEM IN BOTH SPOTS WHEN PUBLISHED
2015-10-26 09:41:10 +00:00
comment_char
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-20 01:25:25 +00:00
IDENTICAL TO parse_config << INCLUDE THEM IN BOTH SPOTS WHEN PUBLISHED
2015-10-26 09:41:10 +00:00
key_vals
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-20 01:25:25 +00:00
IDENTICAL TO parse_config << INCLUDE THEM IN BOTH SPOTS WHEN PUBLISHED
2015-10-26 09:41:10 +00:00
multiple_values
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-20 01:25:25 +00:00
IDENTICAL TO parse_config << INCLUDE THEM IN BOTH SPOTS WHEN PUBLISHED
2015-10-26 09:41:10 +00:00
standalone_comments
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-20 01:25:25 +00:00
IDENTICAL TO parse_config << INCLUDE THEM IN BOTH SPOTS WHEN PUBLISHED
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
**Test a configuration setting**
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
describe parse_config_file('/path/to/file.conf') do
its('PARAM_X') { should eq 'Y' }
end
2015-10-26 09:41:10 +00:00
**Use options, and then test a configuration setting**
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
describe parse_config_file('/path/to/file.conf', { multiple_values: true }) do
its('PARAM_X') { should include 'Y' }
end
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
passwd
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` passwd `` InSpec audit resource to test the contents of `` /etc/passwd `` , which contains the following information for users that may log into the system and/or as users that own running processes. The format for `` /etc/passwd `` includes:
2015-10-19 16:05:10 +00:00
* A username
* The password for that user
* The user identifier (UID) assigned to that user
* The group identifier (GID) assigned to that user
* Additional information about that user
* That user's home directory
* That user's default command shell
2015-10-22 04:13:17 +00:00
defined as a colon-delimited row in the file, one row per user:
2015-10-19 16:05:10 +00:00
.. code-block :: bash
root:x:1234:5678:additional_info:/home/dir/:/bin/bash
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` passwd `` InSpec audit resource block declares one (or more) users and associated user information to be tested:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe passwd do
2015-10-20 21:04:07 +00:00
its('matcher') { should eq 0 }
2015-10-19 16:05:10 +00:00
end
where
2015-10-26 23:29:57 +00:00
* `` count `` , `` gids `` , `` passwords `` , `` uid `` , `` uids `` , `` username `` , `` usernames `` , and `` users `` are valid matchers for this InSpec audit resource
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
count
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` count `` matcher tests the number of times the named user appears in `` /etc/passwd `` :
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('count') { should eq 1 }
2015-10-19 16:05:10 +00:00
gids -- ?????
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` gids `` matcher tests if xxxxx:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('gids') { should eq 1234 }
2015-10-19 16:05:10 +00:00
passwords -- ?????
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` passwords `` matcher tests if xxxxx:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('passwords') { should eq xxxxx }
2015-10-19 16:05:10 +00:00
uid -- ?????
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` uid `` matcher tests if xxxxx:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('uid') { should eq xxxxx }
2015-10-19 16:05:10 +00:00
uids -- ?????
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` uids `` matcher tests if xxxxx:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('uids') { should eq 1 }
2015-10-19 16:05:10 +00:00
username -- ?????
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` username `` matcher tests if xxxxx:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('username') { should eq 'root' }
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
usernames
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` usernames `` matcher tests if the usernames in the test match the usernames in `` /etc/passwd `` :
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('usernames') { should eq ['root', 'www-data'] }
2015-10-19 16:05:10 +00:00
users -- ?????
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` users `` matcher tests if xxxxx:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('users') { should eq 'root' }
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
**xxxxx**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe passwd do
2015-10-20 21:04:07 +00:00
its('usernames') { should eq 'root' }
its('uids') { should eq 1 }
2015-10-19 16:05:10 +00:00
end
2015-10-26 09:41:10 +00:00
**xxxxx**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe passwd.uid(0) do
2015-10-20 21:04:07 +00:00
its('username') { should eq 'root' }
its('count') { should eq 1 }
2015-10-19 16:05:10 +00:00
end
2015-10-26 09:41:10 +00:00
pip
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` pip `` InSpec audit resource to test packages that are installed using the |pip| installer.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` pip `` InSpec audit resource block declares a package and (optionally) a package version:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe pip('Jinja2') do
it { should be_installed }
end
where
* `` 'Jinja2' `` is the name of the package
* `` be_installed `` tests to see if the `` Jinja2 `` package is installed
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
be_installed
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_installed `` matcher tests if the named package is installed on the system:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
it { should be_installed }
2015-10-26 09:41:10 +00:00
version
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` version `` matcher tests if the named package version is on the system:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('version') { should eq '1.2.3' }
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
**Test if Jinja2 is installed on the system**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe pip('Jinja2') do
it { should be_installed }
end
2015-10-26 09:41:10 +00:00
**Test if Jinja2 2.8 is installed on the system**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe pip('Jinja2') do
it { should be_installed }
2015-10-20 21:04:07 +00:00
its('version') { should eq '2.8' }
2015-10-19 16:05:10 +00:00
end
2015-10-26 09:41:10 +00:00
port
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` port `` InSpec audit resource to test basic port properties, such as port, process, if it's listening.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Stable**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` port `` InSpec audit resource block declares a port, and then depending on what needs to be tested, a process, protocol, process identifier, and its state (is it listening?):
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe port(514) do
it { should be_listening }
2015-10-20 21:04:07 +00:00
its('process') {should eq 'syslog'}
2015-10-19 16:05:10 +00:00
end
where the `` syslog `` process is tested to see if it's listening on port 514.
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
be_listening
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_listening `` matcher tests if the port is listening for traffic:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
it { should be_listening }
2015-10-26 09:41:10 +00:00
be_listening.with()
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-19 16:05:10 +00:00
The `` be_listening `` matcher can also test if the port is listening for traffic over a specific protocol or on local binding address. Use `` .with() `` to specify a protocol or local binding address. For example, a protocol:
.. code-block :: ruby
it { should be_listening.with('tcp') }
A local binding address:
it { should be_listening.with('127.0.0.1:631') }
A protocol and a local binding address:
it { should be_listening.with('tcp', '127.0.0.1:631') }
2015-10-26 09:41:10 +00:00
pid
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` pid `` matcher tests the process identifier (PID):
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('pid') { should eq '27808' }
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
process
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` process `` matcher tests if the named process is running on the system:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('process') { should eq 'syslog' }
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
protocol
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` protocol `` matcher tests the Internet protocol: |icmp| (`` 'icmp' `` ), |tcp| (`` 'tcp' `` or `` 'tcp6' `` ), or |udp| (`` 'udp' `` or `` 'udp6' `` ):
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('protocol') { should eq 'tcp' }
2015-10-19 16:05:10 +00:00
or for the |ipv6| protocol:
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('protocol') { should eq 'tcp6' }
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
**Test port 80, listening with the TCP protocol**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe port(80) do
it { should be_listening }
its('protocol') {should eq 'tcp'}
end
2015-10-26 09:41:10 +00:00
**Test port 80, listening with TCP version IPv6 protocol**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe port(80) do
it { should be_listening }
its('protocol') {should eq 'tcp6'}
end
2015-10-26 09:41:10 +00:00
**Test ports for SSL, then verify ciphers**
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
describe port(80) do
it { should_not be_listening }
end
2015-10-26 09:41:10 +00:00
2015-10-20 01:25:25 +00:00
describe port(443) do
it { should be_listening }
its('protocol') {should eq 'tcp'}
end
2015-10-26 09:41:10 +00:00
2015-10-20 01:25:25 +00:00
describe sshd_conf do
its('Ciphers') { should eq('chacha20-poly1305@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr') }
end
2015-10-26 09:41:10 +00:00
postgres_conf
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` postgres_conf `` InSpec audit resource to test the contents of the configuration file for |postgresql|, typically located at `` /etc/postgresql/<version>/main/postgresql.conf `` or `` /var/lib/postgres/data/postgresql.conf `` , depending on the platform.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` postgres_conf `` InSpec audit resource block declares one (or more) settings in the `` postgresql.conf `` file, and then compares the setting in the configuration file to the value stated in the test:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe postgres_conf('path') do
its('setting') { should eq 'value' }
end
where
* `` 'setting' `` specifies a setting in the `` postgresql.conf `` file
* `` ('path') `` is the non-default path to the `` postgresql.conf `` file
* `` should eq 'value' `` is the value that is expected
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
setting
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` setting `` matcher tests specific, named settings in the `` postgresql.conf `` file:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('setting') { should eq 'value' }
Use a `` setting `` matcher for each setting to be tested.
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
**Test the maximum number of allowed client connections**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe postgres_conf do
its('max_connections') { should eq '5' }
end
2015-10-26 09:41:10 +00:00
**Test system logging**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe postgres_conf do
its('logging_collector') { should eq 'on' }
its('log_connections') { should eq 'on' }
its('log_disconnections') { should eq 'on' }
its('log_duration') { should eq 'on' }
its('log_hostname') { should eq 'on' }
its('log_line_prefix') { should eq '%t %u %d %h' }
end
2015-10-26 09:41:10 +00:00
**Test the port on which PostgreSQL listens**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe postgres_conf do
its('port') { should eq '5432' }
end
2015-10-26 09:41:10 +00:00
**Test the Unix socket settings**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe postgres_conf do
its('unix_socket_directories') { should eq '.s.PGSQL.5432' }
its('unix_socket_group') { should eq nil }
its('unix_socket_permissions') { should eq '0770' }
end
where `` unix_socket_group `` is set to the |postgresql| default setting (the group to which the server user belongs).
2015-10-26 09:41:10 +00:00
postgres_session
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` postgres_session `` InSpec audit resource to test SQL commands run against a |postgresql| database.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` postgres_session `` InSpec audit resource block declares the username and password to use for the session, and then the command to be run:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
sql = postgres_session('username', 'password')
2015-10-26 16:21:37 +00:00
describe sql.query('SELECT * FROM pg_shadow WHERE passwd IS NULL;') do
2015-10-19 16:05:10 +00:00
its('output') { should eq('') }
end
where
* `` sql = postgres_session `` declares a username and password with permission to run the query
2015-10-26 16:23:43 +00:00
* `` sql.query('') `` contains the query to be run
2015-10-19 16:05:10 +00:00
* `` its('output') { should eq('') } `` compares the results of the query against the expected result in the test
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
output
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` output `` matcher tests the results of the query:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
2015-10-20 21:04:07 +00:00
its('output') { should eq(/^0/) }
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
**Test the PostgreSQL shadow password**
.. code-block :: ruby
sql = postgres_session('my_user', 'password')
2015-10-26 16:21:37 +00:00
describe sql.query('SELECT * FROM pg_shadow WHERE passwd IS NULL;') do
2015-10-20 21:04:07 +00:00
its('output') { should eq('') }
2015-10-19 16:05:10 +00:00
end
2015-10-26 09:41:10 +00:00
**Test for risky database entries**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
sql = postgres_session('my_user', 'password')
2015-10-26 16:21:37 +00:00
describe sql.query('SELECT count (*)
2015-10-19 16:05:10 +00:00
FROM pg_language
WHERE lanpltrusted = 'f'
AND lanname!='internal'
AND lanname!='c';') do
2015-10-20 21:04:07 +00:00
its('output') { should eq(/^0/) }
2015-10-19 16:05:10 +00:00
end
2015-10-26 09:41:10 +00:00
processes
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` processes `` InSpec audit resource to test properties for programs that are running on the system.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` processes `` InSpec audit resource block declares the name of the process to be tested, and then declares one (or more) property/value pairs:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe processes('process_name') do
its('property_name') { should eq 'property_value' }
end
where
* `` processes('process_name') `` must specify the name of a process that is running on the system
* Multiple properties may be tested; for each property to be tested, use an `` its('property_name') `` statement
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
property_name
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` property_name `` matcher tests the named property for the specified value:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('property_name') { should eq 'property_value' }
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
**Test if the list length for the mysqld process is 1**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe processes('mysqld') do
its('list.length') { should eq '1' }
end
2015-10-26 09:41:10 +00:00
**Test if the init process is owned by the root user**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe processes('init') do
its('user') { should eq 'root' }
end
2015-10-26 09:41:10 +00:00
**Test if a high-priority process is running**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe processes('some_process') do
its('state') { should eq 'R<' }
end
2015-10-26 09:41:10 +00:00
registry_key
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` registry_key `` InSpec audit resource to test key values in the |windows| registry.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Stable**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` registry_key `` InSpec audit resource block declares the item in the |windows| registry, the path to a setting under that item, and then one (or more) name/value pairs to be tested:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe registry_key('registry_item', 'path\to\key') do
its('name') { should eq 'value' }
end
where
* `` 'registry_item' `` is a key in the |windows| registry
* `` 'path\to\key' `` is the path in the |windows| registry
* `` ('name') `` and `` 'value' `` represent the name of the key and the value assigned to that key
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
name
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` name `` matcher tests the value for the specified registry setting:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('name') { should eq 'value' }
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
**Test the start time for the Schedule service**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe registry_key('Task Scheduler','HKEY_LOCAL_MACHINE\...\Schedule') do
its('Start') { should eq 2 }
end
where `` 'HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\Schedule' `` is the full path to the setting.
2015-10-26 09:41:10 +00:00
script
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` script `` InSpec audit resource to test a |powershell| script on the |windows| platform.
2015-10-19 16:05:10 +00:00
.. this one is a bit of a wild guess.
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` script `` InSpec audit resource block declares xxxxx:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe script do
its('script_name') { should include 'total_wild_guess' }
end
2015-10-26 09:41:10 +00:00
..
2015-10-19 16:05:10 +00:00
.. where
2015-10-26 09:41:10 +00:00
..
2015-10-19 16:05:10 +00:00
.. * ``xxxxx`` must specify xxxxx
.. * xxxxx
2015-10-26 23:29:57 +00:00
.. * ``xxxxx`` is a valid matcher for this InSpec audit resource
2015-10-26 09:41:10 +00:00
..
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
script_name
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` script_name `` matcher tests the named script against the value specified by the test:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('script_name') { should include 'total_wild_guess' }
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
.. stoopid test below; probably need a better one
2015-10-26 09:41:10 +00:00
**Test that user Grantmc belongs to the Active Directory object**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe script do
its('ADObject') { should include 'Get-ADPermission -Identity Grantmc' }
end
2015-10-20 21:04:07 +00:00
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
security_policy
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` security_policy `` InSpec audit resource to test security policies on the |windows| platform.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` security_policy `` InSpec audit resource block declares the name of a security policy and the value to be tested:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe security_policy do
its('policy_name') { should eq 'value' }
end
where
* `` 'policy_name' `` must specify a security policy
* `` { should eq 'value' } `` tests the value of `` policy_name `` against the value declared in the test
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
policy_name
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` policy_name `` matcher must be the name of a security policy:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('SeNetworkLogonRight') { should eq '*S-1-5-11' }
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
**Verify that only the Administrators group has remote access**
.. code-block :: ruby
describe security_policy do
its('SeRemoteInteractiveLogonRight') { should eq '*S-1-5-32-544' }
end
2015-10-26 09:41:10 +00:00
service
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` service `` InSpec audit resource to test if the named service is installed, running and/or enabled.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Stable**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` service `` InSpec audit resource block declares the name of a service and then one (or more) matchers to test the state of the service:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe service('service_name') do
it { should be_installed }
it { should be_enabled }
it { should be_running }
end
2015-10-19 21:15:11 +00:00
where
2015-10-20 01:25:25 +00:00
* `` ('service_name') `` must specify a service name
2015-10-26 23:29:57 +00:00
* `` be_installed `` , `` be_enabled `` , and `` be_running `` are valid matchers for this InSpec audit resource
2015-10-19 21:15:11 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
be_enabled
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_enabled `` matcher tests if the named service is enabled:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
it { should be_enabled }
2015-10-26 09:41:10 +00:00
be_installed
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_installed `` matcher tests if the named service is installed:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
it { should be_installed }
2015-10-26 09:41:10 +00:00
be_running
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_running `` matcher tests if the named service is running:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
it { should be_running }
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
**Test if the postgresql service is both running and enabled**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe service('postgresql') do
it { should be_enabled }
it { should be_running }
end
2015-10-26 09:41:10 +00:00
**Test if the mysql service is both running and enabled**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe service('mysqld') do
it { should be_enabled }
it { should be_running }
end
2015-10-20 01:25:25 +00:00
**Test if ClamAV (an antivirus engine) is installed and running**
2015-10-19 21:15:11 +00:00
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
describe package('clamav') do
it { should be_installed }
its('version') { should eq '0.98.7' }
end
2015-10-26 09:41:10 +00:00
2015-10-20 01:25:25 +00:00
describe service('clamd') do
it { should_not be_enabled }
it { should_not be_installed }
it { should_not be_running }
end
2015-10-19 21:15:11 +00:00
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
ssh_config
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` ssh_config `` InSpec audit resource to test |openssh| |ssh| client configuration data located at `` etc/ssh/ssh_config `` on |linux| and |unix| platforms.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` ssh_config `` InSpec audit resource block declares the client |openssh| configuration data to be tested:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe ssh_config('path') do
its('name') { should include('foo') }
end
where
* `` name `` is a configuration setting in `` ssh_config ``
* `` ('path') `` is the non-default `` /path/to/ssh_config ``
2015-10-26 09:41:10 +00:00
* `` { should include('foo') } `` tests the value of `` name `` as read from `` ssh_config `` versus the value declared in the test
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
name
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` name `` matcher tests the value of `` name `` as read from `` ssh_config `` versus the value declared in the test:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('name') { should eq 'foo' }
or:
.. code-block :: ruby
2015-10-20 01:25:25 +00:00
it's('name') { should include('bar') }
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
**Test SSH configuration settings**
.. code-block :: ruby
describe ssh_config do
its('cipher') { should eq '3des' }
its('port') { should '22' }
its('hostname') { should include('example.com') }
end
**Test which variables from the local environment are sent to the server**
.. code-block :: ruby
return unless command('ssh').exist?
2015-10-26 09:41:10 +00:00
2015-10-19 16:05:10 +00:00
describe ssh_config do
its('SendEnv') { should include('GORDON_CLIENT') }
end
**Test owner and group permissions**
.. code-block :: ruby
describe ssh_config do
its('owner') { should eq 'root' }
its('mode') { should eq 644 }
end
2015-10-20 21:04:07 +00:00
**Test SSH configuration**
.. code-block :: ruby
describe ssh_config do
its('Host') { should eq '*' }
its('Tunnel') { should eq nil }
its('SendEnv') { should eq 'LANG LC_*' }
its('HashKnownHosts') { should eq 'yes' }
end
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
sshd_config
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` sshd_config `` InSpec audit resource to test configuration data for the |openssh| daemon located at `` etc/ssh/sshd_config `` on |linux| and |unix| platforms. sshd---the |openssh| daemon---listens on dedicated ports, starts a daemon for each incoming connection, and then handles encryption, authentication, key exchanges, command executation, and data exchanges.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` sshd_config `` InSpec audit resource block declares the client |openssh| configuration data to be tested:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe sshd_config('path') do
its('name') { should include('foo') }
end
where
* `` name `` is a configuration setting in `` sshd_config ``
* `` ('path') `` is the non-default `` /path/to/sshd_config ``
2015-10-26 09:41:10 +00:00
* `` { should include('foo') } `` tests the value of `` name `` as read from `` sshd_config `` versus the value declared in the test
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
name
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` name `` matcher tests the value of `` name `` as read from `` sshd_config `` versus the value declared in the test:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('name') { should eq 'foo' }
or:
.. code-block :: ruby
it's('name') {should include('bar') }
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
**Test which variables may be sent to the server**
.. code-block :: ruby
return unless command('sshd').exist?
2015-10-26 09:41:10 +00:00
2015-10-19 16:05:10 +00:00
describe sshd_config do
its('AcceptEnv') { should include('GORDON_SERVER') }
end
**Test for IPv6-only addresses**
.. code-block :: ruby
return unless command('sshd').exist?
2015-10-26 09:41:10 +00:00
2015-10-19 16:05:10 +00:00
describe sshd_config do
its('AddressFamily') { should eq 'inet6' }
end
**Test protocols**
.. code-block :: ruby
describe sshd_config do
its('Protocol') { should eq '2' }
end
2015-10-26 09:41:10 +00:00
**Test ports for SSL, then verify ciphers**
2015-10-20 01:25:25 +00:00
.. code-block :: ruby
describe port(80) do
it { should_not be_listening }
end
2015-10-26 09:41:10 +00:00
2015-10-20 01:25:25 +00:00
describe port(443) do
it { should be_listening }
its('protocol') {should eq 'tcp'}
end
2015-10-26 09:41:10 +00:00
2015-10-20 01:25:25 +00:00
describe sshd_conf do
its('Ciphers') { should eq('chacha20-poly1305@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr') }
end
2015-10-20 21:04:07 +00:00
**Test SSH protocols**
.. code-block :: ruby
describe sshd_config do
its('Port') { should eq '22' }
its('UsePAM') { should eq 'yes' }
its('ListenAddress') { should eq nil }
its('HostKey') { should eq [
'/etc/ssh/ssh_host_rsa_key',
'/etc/ssh/ssh_host_dsa_key',
'/etc/ssh/ssh_host_ecdsa_key',
] }
end
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
user
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` user `` InSpec audit resource to test user profiles, including the groups to which they belong, the frequency of required password changes, the directory paths to home and shell.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Stable**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` user `` InSpec audit resource block declares a user name, and then one (or more) matchers:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe user('root') do
it { should exist }
its('uid') { should eq 1234 }
its('gid') { should eq 1234 }
its('group') { should eq 'root' }
its('groups') { should eq ['root', 'other']}
its('home') { should eq '/root' }
its('shell') { should eq '/bin/bash' }
its('mindays') { should eq 0 }
its('maxdays') { should eq 90 }
its('warndays') { should eq 8 }
end
where
* `` ('root') `` is the user to be tested
* `` it { should exist } `` tests if the user exists
2015-10-26 23:29:57 +00:00
* `` gid `` , `` group `` , `` groups `` , `` home `` , `` maxdays `` , `` mindays `` , `` shell `` , `` uid `` , and `` warndays `` are valid matchers for this InSpec audit resource
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
exist
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` exist `` matcher tests if the named user exists:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
it { should exist }
2015-10-26 09:41:10 +00:00
gid
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` gid `` matcher tests the group identifier:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('gid') { should eq 1234 } }
where `` 1234 `` represents the user identifier.
2015-10-26 09:41:10 +00:00
group
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` group `` matcher tests the group to which the user belongs:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('group') { should eq 'root' }
where `` root `` represents the group.
2015-10-26 09:41:10 +00:00
groups
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` groups `` matcher tests two (or more) groups to which the user belongs:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('groups') { should eq ['root', 'other']}
2015-10-26 09:41:10 +00:00
home
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` home `` matcher tests the home directory path for the user:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('home') { should eq '/root' }
2015-10-26 09:41:10 +00:00
maxdays
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` maxdays `` matcher tests the maximum number of days between password changes:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('maxdays') { should eq 99 }
where `` 99 `` represents the maximum number of days.
2015-10-26 09:41:10 +00:00
mindays
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` mindays `` matcher tests the minimum number of days between password changes:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('mindays') { should eq 0 }
where `` 0 `` represents the maximum number of days.
2015-10-26 09:41:10 +00:00
shell
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` shell `` matcher tests the path to the default shell for the user:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('shell') { should eq '/bin/bash' }
2015-10-26 09:41:10 +00:00
uid
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` uid `` matcher tests the user identifier:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('uid') { should eq 1234 } }
where `` 1234 `` represents the user identifier.
2015-10-26 09:41:10 +00:00
warndays
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` warndays `` matcher tests the number of days a user is warned before a password must be changed:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('warndays') { should eq 5 }
where `` 5 `` represents the number of days a user is warned.
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
2015-10-20 01:25:25 +00:00
**Verify available users for the MySQL server**
.. code-block :: ruby
describe user('root') do
it { should exist }
it { should belong_to_group 'root' }
its('uid') { should eq 0 }
its('groups') { should eq ['root'] }
end
2015-10-26 09:41:10 +00:00
2015-10-20 01:25:25 +00:00
describe user('mysql') do
it { should_not exist }
end
2015-10-19 16:05:10 +00:00
2015-10-22 04:13:17 +00:00
**Test users on multiple platforms**
The |nginx| user is typically `` www-data `` , but on |centos| it's `` nginx `` . The following example shows how to test for the |nginx| user with a single test, but accounting for all platforms:
.. code-block :: ruby
web_user = 'www-data'
web_user = 'nginx' if os[:family] == 'centos'
2015-10-26 09:41:10 +00:00
2015-10-22 04:13:17 +00:00
describe user(web_user) do
it { should exist }
end
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
windows_feature
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` windows_feature `` InSpec audit resource to test features on |windows|. The `` Get-WindowsFeature `` cmdlet returns the following values: `` Property Name `` , `` DisplayName `` , `` Description `` , `` Installed `` , and `` InstallState `` , returned as a |json| object similar to:
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-19 16:05:10 +00:00
.. code-block :: javascript
{
"Name": "XPS-Viewer",
"DisplayName": "XPS Viewer",
"Description": "The XPS Viewer reads, sets permissions, and digitally signs XPS documents.",
"Installed": false,
"InstallState": 0
}
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` windows_feature `` InSpec audit resource block declares the name of the |windows| feature, tests if that feature is installed, and then returns information about that feature:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe windows_feature('feature_name') do
it { should be_installed }
end
where
* `` ('feature_name') `` must specify a |windows| feature name, such as `` DHCP Server `` or `` IIS-Webserver ``
2015-10-26 23:29:57 +00:00
* `` be_installed `` is a valid matcher for this InSpec audit resource
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
be_installed
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_installed `` matcher tests if the named |windows| feature is installed:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
it { should be_installed }
If the feature is installed, the `` Get-WindowsFeature `` cmdlet is run and the name, display name, description, and install state is returned as a |json| object.
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
2015-10-20 21:04:07 +00:00
**Test the DHCP Server feature**
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe windows_feature('DHCP Server') do
it{ should be_installed }
end
2015-10-26 09:41:10 +00:00
yaml
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` yaml `` InSpec audit resource to test configuration data in a |yaml| file.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` yaml `` InSpec audit resource block declares the configuration data to be tested:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe yaml do
its('name') { should eq 'foo' }
end
where
* `` name `` is a configuration setting in a |yaml| file
* `` should eq 'foo' `` tests a value of `` name `` as read from a |yaml| file versus the value declared in the test
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
name
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` name `` matcher tests the value of `` name `` as read from a |yaml| file versus the value declared in the test:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
its('name') { should eq 'foo' }
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
**Test a kitchen.yml file driver**
.. code-block :: ruby
describe yaml('.kitchen.yaml') do
its('driver.name') { should eq('vagrant') }
end
2015-10-20 01:25:25 +00:00
2015-10-26 09:41:10 +00:00
yum
2015-10-20 21:16:47 +00:00
=====================================================
2015-10-26 23:29:57 +00:00
Use the `` yum `` InSpec audit resource to test packages in the |yum| repository.
2015-10-19 16:05:10 +00:00
2015-10-27 16:47:27 +00:00
**Stability: Experimental**
2015-10-26 09:41:10 +00:00
Syntax
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
A `` yum `` InSpec audit resource block declares a package repo, tests if the package repository is present, and if it that package repository is a valid package source (i.e. "is enabled"):
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe yum.repo('name') do
it { should exist }
it { should be_enabled }
end
where
* `` repo('name') `` is the (optional) name of a package repo, using either a full identifier (`` 'updates/7/x86_64' `` ) or a short identifier (`` 'updates' `` )
2015-10-26 09:41:10 +00:00
Matchers
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
This InSpec audit resource has the following matchers.
2015-10-19 16:05:10 +00:00
2015-10-26 09:41:10 +00:00
be_enabled
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` be_enabled `` matcher tests if the package repository is a valid package source:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
it { should be_enabled }
2015-10-26 09:41:10 +00:00
exist
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` exist `` matcher tests if the package repository exists:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
it { should exist }
2015-10-26 09:41:10 +00:00
repo('name')
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-22 04:13:17 +00:00
The `` repo('name') `` matcher names a specific package repository:
2015-10-19 16:05:10 +00:00
.. code-block :: ruby
describe yum.repo('epel') do
...
end
2015-10-26 09:41:10 +00:00
repos
2015-10-20 21:16:47 +00:00
+++++++++++++++++++++++++++++++++++++++++++++++++++++
2015-10-19 16:05:10 +00:00
The `` repos `` matcher tests if a named repo, using either a full identifier (`` 'updates/7/x86_64' `` ) or a short identifier (`` 'updates' `` ), is included in the |yum| repo:
.. code-block :: ruby
its('repos') { should include 'some_repo' }
2015-10-26 09:41:10 +00:00
Examples
2015-10-20 21:16:47 +00:00
-----------------------------------------------------
2015-10-26 23:29:57 +00:00
The following examples show how to use this InSpec audit resource.
2015-10-19 16:05:10 +00:00
**Test if the yum repo exists**
.. code-block :: ruby
describe yum do
its('repos') { should exist }
end
**Test if the 'base/7/x86_64' repo exists and is enabled**
.. code-block :: ruby
describe yum do
its('repos') { should include 'base/7/x86_64' }
its('epel') { should exist }
its('epel') { should be_enabled }
end
**Test if a specific yum repo exists**
.. code-block :: ruby
describe yum.repo('epel') do
it { should exist }
it { should be_enabled }
end