Skip to contentSkip to conversation

python/sepolicy: Add/remove user even when SELinux is disabled

PATCH Applied Vit Mojzis 2 participants 3 messages May 29, 2023 – Jun 27, 2023 SELinux security module

lore
Share & tools
lore

Vit Mojzis

author
#0 lore raw

PATCH 1/1 python/sepolicy: Add/remove user even when SELinux is disabled

Use "semanage user -a/-d" in spec file generated by "sepolicy generate" even when SELinux is disabled. The command works properly when SELinux is disabled and with this change the user will be present once SELinux is re-enabled.
Also, do not execute the command when the package is updated, only when it is first installed.

---
 python/sepolicy/sepolicy/templates/spec.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
python/sepolicy/sepolicy/templates/spec.py +5 -2
index 16a22081..433c298a 100644
@@ -43,20 +43,23 @@ install -m 644 %{SOURCE3} %{buildroot}/etc/selinux/targeted/contexts/users/DOMAI
 
 %post
 semodule -n -i %{_datadir}/selinux/packages/MODULENAME.pp
+# Add the new user defined in DOMAINNAME_u only when the package is installed (not during updates)
+if [ $1 -eq 1 ]; then
+    /usr/sbin/semanage user -a -R DOMAINNAME_r DOMAINNAME_u
+fi
 if /usr/sbin/selinuxenabled ; then
     /usr/sbin/load_policy
     %relabel_files
-    /usr/sbin/semanage user -a -R DOMAINNAME_r DOMAINNAME_u
 fi;
 exit 0
 
 %postun
 if [ $1 -eq 0 ]; then
+    /usr/sbin/semanage user -d DOMAINNAME_u
     semodule -n -r MODULENAME
     if /usr/sbin/selinuxenabled ; then
        /usr/sbin/load_policy
        %relabel_files
-       /usr/sbin/semanage user -d DOMAINNAME_u
     fi;
 fi;
 exit 0
Signature · 1 line
2.40.0
Acked-by on v1 1/1
#1 lore raw
Quoted 8 lines · Vit Mojzis

Use "semanage user -a/-d" in spec file generated by "sepolicy generate" even when SELinux is disabled. The command works properly when SELinux is disabled and with this change the user will be present once SELinux is re-enabled.
Also, do not execute the command when the package is updated, only when it is first installed.

Quoted 36 lines
---
 python/sepolicy/sepolicy/templates/spec.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
python/sepolicy/sepolicy/templates/spec.py +5 -2
index 16a22081..433c298a 100644
@@ -43,20 +43,23 @@ install -m 644 %{SOURCE3} %{buildroot}/etc/selinux/targeted/contexts/users/DOMAI
 
 %post
 semodule -n -i %{_datadir}/selinux/packages/MODULENAME.pp
+# Add the new user defined in DOMAINNAME_u only when the package is installed (not during updates)
+if [ $1 -eq 1 ]; then
+    /usr/sbin/semanage user -a -R DOMAINNAME_r DOMAINNAME_u
+fi
 if /usr/sbin/selinuxenabled ; then
     /usr/sbin/load_policy
     %relabel_files
-    /usr/sbin/semanage user -a -R DOMAINNAME_r DOMAINNAME_u
 fi;
 exit 0
 
 %postun
 if [ $1 -eq 0 ]; then
+    /usr/sbin/semanage user -d DOMAINNAME_u
     semodule -n -r MODULENAME
     if /usr/sbin/selinuxenabled ; then
        /usr/sbin/load_policy
        %relabel_files
-       /usr/sbin/semanage user -d DOMAINNAME_u
     fi;
 fi;
 exit 0
Signature · 1 line
2.40.0
#2 lore raw
Quoted 9 lines · Petr Lautrbach
Quoted 7 lines · Vit Mojzis

Use "semanage user -a/-d" in spec file generated by "sepolicy generate" even when SELinux is disabled. The command works properly when SELinux is disabled and with this change the user will be present once SELinux is re-enabled.
Also, do not execute the command when the package is updated, only when it is first installed.

Quoted 3 lines
Quoted 1 line

merged, thanks!

Quoted 37 lines
Quoted 37 lines
---
 python/sepolicy/sepolicy/templates/spec.py | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
python/sepolicy/sepolicy/templates/spec.py +5 -2
index 16a22081..433c298a 100644
@@ -43,20 +43,23 @@ install -m 644 %{SOURCE3} %{buildroot}/etc/selinux/targeted/contexts/users/DOMAI
 
 %post
 semodule -n -i %{_datadir}/selinux/packages/MODULENAME.pp
+# Add the new user defined in DOMAINNAME_u only when the package is installed (not during updates)
+if [ $1 -eq 1 ]; then
+    /usr/sbin/semanage user -a -R DOMAINNAME_r DOMAINNAME_u
+fi
 if /usr/sbin/selinuxenabled ; then
     /usr/sbin/load_policy
     %relabel_files
-    /usr/sbin/semanage user -a -R DOMAINNAME_r DOMAINNAME_u
 fi;
 exit 0
 
 %postun
 if [ $1 -eq 0 ]; then
+    /usr/sbin/semanage user -d DOMAINNAME_u
     semodule -n -r MODULENAME
     if /usr/sbin/selinuxenabled ; then
        /usr/sbin/load_policy
        %relabel_files
-       /usr/sbin/semanage user -d DOMAINNAME_u
     fi;
 fi;
 exit 0
Signature · 1 line
2.40.0