-
Notifications
You must be signed in to change notification settings - Fork 14
Inventory SELinux modules #144
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
nickanderson
merged 1 commit into
cfengine:master
from
nickanderson:inventory-selinux-modules/master
May 21, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| This module inventories the SELinux Modules that are installed. | ||
|
|
||
| * Inventory | ||
| - SELinux Modules Enabled :: SELinux Modules that are installed and not disabled. | ||
| - SELinux Modules Disabled :: SELinux Modules that are installed and disabled. | ||
|
|
||
| [[https://raw.githubusercontent.com/cfengine/modules/master/security/inventory-selinux-modules/inventory-selinux-modules.png]] | ||
|
|
||
| * Configuration | ||
| ** Variables | ||
| - =inventory_selinux:semodule_list_modules.hours_cached= :: Number of hours to cache the output from ~semodule --list-modules=full~. | ||
|
|
||
| * Requirements | ||
|
|
||
| The ~semodule~ command is required for inventory to be reported. | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| body file control | ||
| { | ||
| namespace => "inventory_selinux"; | ||
| } | ||
|
|
||
| bundle agent semodule_list_modules | ||
| { | ||
| classes: | ||
| "_$(this.namespace)_$(this.bundle)_supported_platform" | ||
| if => isexecutable( "$(path[semodule])"); | ||
|
|
||
| vars: | ||
| "path[semodule]" | ||
| string => ifelse( isexecutable("/sbin/semodule"), "/sbin/semodule", | ||
| isexecutable("/usr/sbin/semodule"), "/usr/sbin/semodule", | ||
| "" ), | ||
| meta => { "paths.cf" }; | ||
|
|
||
| _inventory_selinux_semodule_list_modules_supported_platform:: | ||
| "hours_cached" | ||
| string => "1", | ||
| if => not( isvariable( hours_cached )); | ||
|
|
||
| "cache_file" | ||
| string => "$(sys.statedir)/$(this.namespace)_$(this.bundle).txt"; | ||
|
|
||
| "cache_file_age" | ||
| string => filestat( $(cache_file), mtime ), | ||
| if => fileexists( "$(cache_file)" ); | ||
|
|
||
| # Example $(cache_file) content | ||
| # 400 cfengine-enterprise pp | ||
| # 200 container pp | ||
| # 100 wine pp disabled | ||
| # 100 wireshark pp | ||
|
|
||
|
|
||
| "d" data => data_readstringarrayidx( "$(cache_file)", | ||
| "", | ||
| "\s+", | ||
| inf, | ||
| inf), | ||
| if => fileexists( $(cache_file) ); | ||
|
|
||
| "i" slist => getindices( "d" ); | ||
|
|
||
| # Inventory enabled and disabled selinux modules | ||
| "enabled[$(i)]" | ||
| string => "$(d[$(i)][1])", | ||
| if => strcmp( "$(d[$(i)][3])", "" ), | ||
| meta => { "inventory", "attribute_name=SELinux Modules Enabled" }; | ||
|
|
||
| "disabled[$(i)]" | ||
| string => "$(d[$(i)][1])", | ||
| if => strcmp( "$(d[$(i)][3])", "disabled" ), | ||
| meta => { "inventory", "attribute_name=SELinux Modules Disabled" }; | ||
|
|
||
| files: | ||
| _inventory_selinux_semodule_list_modules_supported_platform:: | ||
| # Delete the cache file if it's older than hours_cached | ||
| "$(cache_file)" | ||
| delete => default:tidy, | ||
| if => isgreaterthan( | ||
| format( "%d", eval( "$(sys.systime)-$(cache_file_age)" )), # now minus mtime of cache file | ||
| format( "%d", eval( "$(hours_cached)*60*60" ))); # cache minutes | ||
| commands: | ||
| _inventory_selinux_semodule_list_modules_supported_platform:: | ||
| "/sbin/semodule" | ||
| arglist => { "--list-modules=full", | ||
| ">", "$(cache_file)" }, | ||
| contain => default:in_shell, # Required for redirection | ||
| if => not( fileexists( $(cache_file) )); | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.