atc0005 / todo

A collection of TODO items not specific to any one project
MIT License
0 stars 0 forks source link

Update RPM `postinstall.sh` script to use `restorecon` in place of `chcon` #63

Closed atc0005 closed 1 year ago

atc0005 commented 1 year ago

Overview

The existing logic used by the postinstall.sh scripts in the stable, dev packages is based on explicitly setting a very specific set of SELinux details. Those details were gathered by observation on a few test systems and may not apply to all systems where the RPM packages are installed. Currently those details are set explicitly using the chcon utility.

Instead, we should probably allow the SELinux values to be inherited from the parent directory where the plugins are installed by using the restorecon utility.

TODO

The changes I'm looking to make across projects currently generating packages:

Intended changes ```diff diff --git a/packages/dev/scripts/rpm/postinstall.sh b/packages/dev/scripts/rpm/postinstall.sh index 7d9a69e..3a87f53 100644 --- a/packages/dev/scripts/rpm/postinstall.sh +++ b/packages/dev/scripts/rpm/postinstall.sh @@ -32,12 +32,7 @@ if [ -f "${plugin_path}/${plugin_name}" ]; then else # SELinux is enabled. Set context. echo -e "\nApplying SELinux contexts on ${plugin_path}/${plugin_name} ..." - chcon \ - --verbose \ - -t nagios_unconfined_plugin_exec_t \ - -u system_u \ - -r object_r \ - ${plugin_path}/${plugin_name} + restorecon -v ${plugin_path}/${plugin_name} if [ $? -eq 0 ]; then echo "Successfully applied SELinux contexts on ${plugin_path}/${plugin_name}" diff --git a/packages/stable/scripts/rpm/postinstall.sh b/packages/stable/scripts/rpm/postinstall.sh index 9c2515f..607485f 100644 --- a/packages/stable/scripts/rpm/postinstall.sh +++ b/packages/stable/scripts/rpm/postinstall.sh @@ -32,12 +32,7 @@ if [ -f "${plugin_path}/${plugin_name}" ]; then else # SELinux is enabled. Set context. echo -e "\nApplying SELinux contexts on ${plugin_path}/${plugin_name} ..." - chcon \ - --verbose \ - -t nagios_unconfined_plugin_exec_t \ - -u system_u \ - -r object_r \ - ${plugin_path}/${plugin_name} + restorecon -v ${plugin_path}/${plugin_name} if [ $? -eq 0 ]; then echo "Successfully applied SELinux contexts on ${plugin_path}/${plugin_name}" ```

References

Examples of prior/related work from the atc0005/check-cert project:

Example of intended changes:

Additional reading: