Skip to content

Commit

Permalink
(#issue_318) Added ability for users to switch between '/bin/true' an…
Browse files Browse the repository at this point in the history
…d '/bin/false' when disabling kernel modules via the kmod_blacklist class

Fixes #318
  • Loading branch information
michael-riddle committed Jul 9, 2024
1 parent 4549884 commit 983077e
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
* Mon Jul 09 2024 Mike Riddle <[email protected]> - 4.22.0
- Added ability for users to switch between '/bin/true' and '/bin/false' when disabling kernel modules via the kmod_blacklist class

* Tue Jul 02 2024 Steven Pritchard <[email protected]> - 4.21.0
- Clean up use of legacy facts to better support Puppet 8

Expand Down
11 changes: 11 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,7 @@ The following parameters are available in the `simp::kmod_blacklist` class:

* [`enable_defaults`](#-simp--kmod_blacklist--enable_defaults)
* [`blacklist`](#-simp--kmod_blacklist--blacklist)
* [`produce_error`](#-simp--kmod_blacklist--produce_error)
* [`custom_blacklist`](#-simp--kmod_blacklist--custom_blacklist)
* [`allow_overrides`](#-simp--kmod_blacklist--allow_overrides)
* [`lock_modules`](#-simp--kmod_blacklist--lock_modules)
Expand Down Expand Up @@ -758,6 +759,16 @@ Default value:
]
```

##### <a name="-simp--kmod_blacklist--produce_error"></a>`produce_error`

Data type: `Boolean`

If set to true, any disabled modules will point to '/bin/false', which will
produce an error when anyone attempts to load the module. Default is false,
which will point to '/bin/true', which will not produce any error.

Default value: `false`

##### <a name="-simp--kmod_blacklist--custom_blacklist"></a>`custom_blacklist`

Data type: `Array[String]`
Expand Down
13 changes: 12 additions & 1 deletion manifests/kmod_blacklist.pp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
# @param blacklist
# List of kernel modules to be blacklisted by default
#
# @param produce_error
# If set to true, any disabled modules will point to '/bin/false', which will
# produce an error when anyone attempts to load the module. Default is false,
# which will point to '/bin/true', which will not produce any error.
#
# @param custom_blacklist
# Additional kernel modules to be blacklisted
#
Expand Down Expand Up @@ -50,6 +55,7 @@
'usb-storage'
],
Array[String] $custom_blacklist = [],
Boolean $produce_error = false,
Boolean $allow_overrides = true,
Boolean $lock_modules = false,
Boolean $notify_if_reboot_required = true
Expand Down Expand Up @@ -80,7 +86,12 @@
$_obsolete_disable_file = '/etc/modprobe.d/zz_simp_disable.conf'
}

$_disable_file_content = join($_blacklist.map |$mod| { "install ${mod} /bin/true" }, "\n")
$_produce_error = $produce_error ? {
true => '/bin/false',
false => '/bin/true'
}

$_disable_file_content = join($_blacklist.map |$mod| { "install ${mod} ${_produce_error}" }, "\n")

file { $_disable_file:
ensure => file,
Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "simp-simp",
"version": "4.21.0",
"version": "4.22.0",
"author": "SIMP Team",
"summary": "default profiles for core SIMP installations",
"license": "Apache-2.0",
Expand Down
10 changes: 10 additions & 0 deletions spec/classes/00_classes/kmod_blacklist_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@

end

context 'when producing an error on module load' do
let(:params){{
:produce_error => true
}}

it 'should blacklist all the default kmods and point to /bin/false' do

Check failure on line 191 in spec/classes/00_classes/kmod_blacklist_spec.rb

View workflow job for this annotation

GitHub Actions / Spec (classes 00, Puppet 7.x [SIMP 6.6/PE 2021.7])

simp::kmod_blacklist supported operating systems on almalinux-8-x86_64 when producing an error on module load should blacklist all the default kmods and point to /bin/false Failure/Error: is_expected.to create_file("/etc/modprobe.d/00_simp_disable.conf").with_content(stock_blacklist.map{|x| x = "install #{x} /bin/false" }.join("\n") + "\n") expected that the catalogue would contain File[/etc/modprobe.d/00_simp_disable.conf] with content set to supplied string Diff: - install bluetooth /bin/false\n - install cramfs /bin/false\n - install dccp /bin/false\n - install dccp_ipv4 /bin/false\n - install dccp_ipv6 /bin/false\n - install freevxfs /bin/false\n - install hfs /bin/false\n - install hfsplus /bin/false\n - install ieee1394 /bin/false\n - install jffs2 /bin/false\n - install net-pf-31 /bin/false\n - install rds /bin/false\n - install sctp /bin/false\n - install squashfs /bin/false\n - install tipc /bin/false\n - install udf /bin/false\n - install usb-storage /bin/false\n

Check failure on line 191 in spec/classes/00_classes/kmod_blacklist_spec.rb

View workflow job for this annotation

GitHub Actions / Spec (classes 00, Puppet 8.x)

simp::kmod_blacklist supported operating systems on almalinux-8-x86_64 when producing an error on module load should blacklist all the default kmods and point to /bin/false Failure/Error: is_expected.to create_file("/etc/modprobe.d/00_simp_disable.conf").with_content(stock_blacklist.map{|x| x = "install #{x} /bin/false" }.join("\n") + "\n") expected that the catalogue would contain File[/etc/modprobe.d/00_simp_disable.conf] with content set to supplied string Diff: - install bluetooth /bin/false\n - install cramfs /bin/false\n - install dccp /bin/false\n - install dccp_ipv4 /bin/false\n - install dccp_ipv6 /bin/false\n - install freevxfs /bin/false\n - install hfs /bin/false\n - install hfsplus /bin/false\n - install ieee1394 /bin/false\n - install jffs2 /bin/false\n - install net-pf-31 /bin/false\n - install rds /bin/false\n - install sctp /bin/false\n - install squashfs /bin/false\n - install tipc /bin/false\n - install udf /bin/false\n - install usb-storage /bin/false\n
is_expected.to create_file("/etc/modprobe.d/00_simp_disable.conf").with_content(stock_blacklist.map{|x| x = "install #{x} /bin/false" }.join("\n") + "\n")
end
end

end
end
end
Expand Down

0 comments on commit 983077e

Please sign in to comment.