Semanage command having python issue

I’m trying to make selinux permissive for one of the process (drbd) in Almalinux 8.8 and I’m facing the below python issue while using semanage command,

[root@dnd-st-6-0-0-28-lt-ha1 admin]# semanage permissive -a drbd_t
Traceback (most recent call last):
File “/sbin/semanage”, line 1000, in
do_parser()
File “/sbin/semanage”, line 970, in do_parser
commandParser = createCommandParser()
File “/sbin/semanage”, line 900, in createCommandParser
import seobject
File “/usr/lib/python3.6/site-packages/seobject.py”, line 33, in
import sepolicy
File “/usr/lib/python3.6/site-packages/sepolicy/init.py”, line 7, in
import setools
File “/usr/lib64/python3.6/site-packages/setools/init.py”, line 24, in
version = pkg_resources.get_distribution(“setools”).version
AttributeError: module ‘pkg_resources’ has no attribute ‘get_distribution’

[admin@dnd-st-6-0-0-28-lt-ha1 ~]$ cat /etc/release
AlmaLinux release 8.8 (Sapphire Caracal)
Derived from Red Hat Enterprise Linux 8.8 (Source)
AlmaLinux release 8.8 (Sapphire Caracal)
NAME=“AlmaLinux”
VERSION=“8.8 (Sapphire Caracal)”
ID=“almalinux”
ID_LIKE=“rhel centos fedora”
VERSION_ID=“8.8”
PLATFORM_ID=“platform:el8”
PRETTY_NAME=“AlmaLinux 8.8 (Sapphire Caracal)”
ANSI_COLOR=“0;34”
LOGO=“fedora-logo-icon”
CPE_NAME=“cpe:/o:almalinux:almalinux:8::baseos”
HOME_URL=“https://almalinux.org/

ALMALINUX_MANTISBT_PROJECT="AlmaLinux-8"
ALMALINUX_MANTISBT_PROJECT_VERSION="8.8"
REDHAT_SUPPORT_PRODUCT="AlmaLinux"
REDHAT_SUPPORT_PRODUCT_VERSION="8.8"
AlmaLinux release 8.8 (Sapphire Caracal)
AlmaLinux release 8.8 (Sapphire Caracal)
cpe:/o:almalinux:almalinux:8::baseos

Any help would be appreciated.

Regards,
Srini

On my Alma 8:

[AL8 ~]# dnf --enablerepo=powertools provides */seobject.py
python3-policycoreutils-2.9-24.el8.noarch : SELinux policy core python3 interfaces
Repo        : @System
Matched from:
Filename    : /usr/lib/python3.6/site-packages/seobject.py

[AL8 ~]# dnf --enablerepo=powertools provides *sepolicy/init.py
Error: No Matches found
[AL8 ~]# dnf --enablerepo=powertools provides *setools/init.py
Error: No Matches found
[AL8 ~]# cat /etc/almalinux-release
AlmaLinux release 8.8 (Sapphire Caracal)

I don’t have even the /usr/lib/python3.6/site-packages/sepolicy/init.pyWait! It is
/usr/lib/python3.6/site-packages/sepolicy/__init__.py but your post shows that as bold.
The sepolicy/__init__.py is in python3-policycoreutils too, and the
The setools/__init__.py is in python3-setools.

My /usr/lib/python3.6/site-packages/pkg_resources/__init__.py defines function get_distribution(dist).


[AL8 ~]# semanage permissive --add drbd_t
[AL8 ~]# semanage permissive --list

Builtin Permissive Types 


Customized Permissive Types

drbd_t
[AL8 ~]# semanage permissive --delete drbd_t
libsemanage.semanage_direct_remove_key: Removing last permissive_drbd_t module (no other permissive_drbd_t module exists at another priority).
[AL8 ~]# semanage permissive --list
[AL8 ~]# 

The pkg_resources is in package platform-python-setuptools. Is that ok/up to date?

Thanks jlehtone for the reply. After your reply, I found that platform-python-setuptools is not properly installed.

Thought it is installed, the python files are not found.

[root@test admin]# rpm -ql platform-python-setuptools-39.2.0-7.el8.noarch | grep init.py
/usr/lib/python3.6/site-packages/pkg_resources/init.py
/usr/lib/python3.6/site-packages/pkg_resources/_vendor/init.py
/usr/lib/python3.6/site-packages/pkg_resources/_vendor/packaging/init.py
/usr/lib/python3.6/site-packages/pkg_resources/extern/init.py
/usr/lib/python3.6/site-packages/setuptools/init.py
/usr/lib/python3.6/site-packages/setuptools/_vendor/init.py
/usr/lib/python3.6/site-packages/setuptools/_vendor/packaging/init.py
/usr/lib/python3.6/site-packages/setuptools/command/init.py
/usr/lib/python3.6/site-packages/setuptools/extern/init.py

[root@test admin]# ls -l /usr/lib/python3.6/site-packages/pkg_resources/init.py /usr/lib/python3.6/site-packages/pkg_resources/_vendor/init.py
ls: cannot access ‘/usr/lib/python3.6/site-packages/pkg_resources/init.py’: No such file or directory
ls: cannot access ‘/usr/lib/python3.6/site-packages/pkg_resources/_vendor/init.py’: No such file or directory
[root@test admin]#

Reinstalling platform-python-setuptools-39.2.0-7.el8.noarch solves the problem. I will further look into it.

Thanks for the pointer and help.

1 Like