2016-09-22 12:43:57 +00:00
|
|
|
---
|
|
|
|
title: About the kernel_module Resource
|
2018-02-16 00:28:15 +00:00
|
|
|
platform: linux
|
2016-09-22 12:43:57 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# kernel_module
|
|
|
|
|
2017-07-05 09:41:44 +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.
|
|
|
|
|
|
|
|
The `kernel_module` resource can also verify if a kernel module is `blacklisted`
|
|
|
|
or if a module is disabled via a fake install using the `bin_true` or `bin_false`
|
|
|
|
method.
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2017-10-03 21:35:10 +00:00
|
|
|
<br>
|
|
|
|
|
2016-09-27 19:03:23 +00:00
|
|
|
## Syntax
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2017-07-05 09:41:44 +00:00
|
|
|
A `kernel_module` resource block declares a module name, and then tests if that
|
2018-02-28 22:12:37 +00:00
|
|
|
module is a loaded kernel module, if it is enabled, disabled or if it is
|
2017-07-05 09:41:44 +00:00
|
|
|
blacklisted:
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2017-07-05 13:57:47 +00:00
|
|
|
describe kernel_module('module_name') do
|
2016-09-22 12:43:57 +00:00
|
|
|
it { should be_loaded }
|
2017-07-05 09:41:44 +00:00
|
|
|
it { should_not be_disabled }
|
|
|
|
it { should_not be_blacklisted }
|
|
|
|
end
|
2016-09-22 12:43:57 +00:00
|
|
|
|
|
|
|
where
|
|
|
|
|
|
|
|
* `'module_name'` must specify a kernel module, such as `'bridge'`
|
2018-02-28 22:12:37 +00:00
|
|
|
* `{ should be_loaded }` tests if the module is a loaded kernel module
|
2017-07-05 09:41:44 +00:00
|
|
|
* `{ should be_blacklisted }` tests if the module is blacklisted or if the module is disabled via a fake install using /bin/false or /bin/true
|
|
|
|
* `{ should be_disabled }` tests if the module is disabled via a fake install using /bin/false or /bin/true
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2017-10-03 21:35:10 +00:00
|
|
|
<br>
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2017-10-03 21:35:10 +00:00
|
|
|
## Examples
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2017-10-03 21:35:10 +00:00
|
|
|
The following examples show how to use this InSpec audit resource.
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2018-02-28 22:12:37 +00:00
|
|
|
### version
|
|
|
|
|
|
|
|
The `version` property tests if the kernel module on the system has the correct version:
|
|
|
|
|
|
|
|
its('version') { should eq '3.2.2' }
|
|
|
|
|
|
|
|
### Test a kernel module's 'version'
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2017-11-28 23:12:05 +00:00
|
|
|
describe kernel_module('bridge') do
|
|
|
|
it { should be_loaded }
|
2018-02-28 22:12:37 +00:00
|
|
|
its('version') { should cmp >= '2.2.2' }
|
2017-11-28 23:12:05 +00:00
|
|
|
end
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2018-02-28 22:12:37 +00:00
|
|
|
### Test if a kernel module is loaded, not disabled, and not blacklisted
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2017-11-28 23:12:05 +00:00
|
|
|
describe kernel_module('video') do
|
|
|
|
it { should be_loaded }
|
|
|
|
it { should_not be_disabled }
|
|
|
|
it { should_not be_blacklisted }
|
|
|
|
end
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2018-02-28 22:12:37 +00:00
|
|
|
### Check if a kernel module is blacklisted
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2017-11-28 23:12:05 +00:00
|
|
|
describe kernel_module('floppy') do
|
|
|
|
it { should be_blacklisted }
|
|
|
|
end
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2018-02-28 22:12:37 +00:00
|
|
|
### Check if a kernel module is *not* blacklisted and is loaded
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2017-11-28 23:12:05 +00:00
|
|
|
describe kernel_module('video') do
|
|
|
|
it { should_not be_blacklisted }
|
|
|
|
it { should be_loaded }
|
|
|
|
end
|
2017-01-25 20:47:39 +00:00
|
|
|
|
2018-02-28 22:12:37 +00:00
|
|
|
### Check if a kernel module is disabled via 'bin_false'
|
2017-01-25 20:47:39 +00:00
|
|
|
|
2017-11-28 23:12:05 +00:00
|
|
|
describe kernel_module('sstfb') do
|
|
|
|
it { should_not be_loaded }
|
|
|
|
it { should be_disabled }
|
|
|
|
end
|
2017-01-25 20:47:39 +00:00
|
|
|
|
2018-02-28 22:12:37 +00:00
|
|
|
### Check if a kernel module is 'blacklisted'/'disabled' via 'bin_true'
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2017-11-28 23:12:05 +00:00
|
|
|
describe kernel_module('nvidiafb') do
|
|
|
|
it { should_not be_loaded }
|
|
|
|
it { should be_blacklisted }
|
|
|
|
end
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2018-02-28 22:12:37 +00:00
|
|
|
### Check if a kernel module is not loaded
|
2016-09-22 12:43:57 +00:00
|
|
|
|
2017-11-28 23:12:05 +00:00
|
|
|
describe kernel_module('dhcp') do
|
|
|
|
it { should_not be_loaded }
|
|
|
|
end
|
2017-07-05 09:41:44 +00:00
|
|
|
|
2017-10-03 21:35:10 +00:00
|
|
|
<br>
|
2017-07-05 09:41:44 +00:00
|
|
|
|
2017-10-03 21:35:10 +00:00
|
|
|
## Matchers
|
2017-07-05 09:41:44 +00:00
|
|
|
|
2018-02-16 03:07:18 +00:00
|
|
|
For a full list of available matchers, please visit our [matchers page](https://www.inspec.io/docs/reference/matchers/).
|
2017-07-05 09:41:44 +00:00
|
|
|
|
|
|
|
|
2018-02-28 22:12:37 +00:00
|
|
|
### be_blacklisted
|
2017-07-05 09:41:44 +00:00
|
|
|
|
2018-02-28 22:12:37 +00:00
|
|
|
The `be_blacklisted` matcher tests if the kernel module is a blacklisted module:
|
2017-07-05 09:41:44 +00:00
|
|
|
|
2018-02-28 22:12:37 +00:00
|
|
|
it { should be_blacklisted }
|
2017-07-05 09:41:44 +00:00
|
|
|
|
2018-02-28 22:12:37 +00:00
|
|
|
### be_disabled
|
2017-07-05 09:41:44 +00:00
|
|
|
|
2018-02-28 22:12:37 +00:00
|
|
|
The `be_disabled` matcher tests if the kernel module is disabled:
|
|
|
|
|
|
|
|
it { should be_disabled }
|
|
|
|
|
|
|
|
### be_loaded
|
|
|
|
|
|
|
|
The `be_loaded` matcher tests if the kernel module is loaded:
|
|
|
|
|
|
|
|
it { should be_loaded }
|