Skip to content

Commit

Permalink
Make library compatible with RHEL-10 and CentOS-10
Browse files Browse the repository at this point in the history
  • Loading branch information
GeorgePantelakis committed Jun 4, 2024
1 parent 7a71631 commit fc5e710
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 19 deletions.
12 changes: 9 additions & 3 deletions SCAutolib/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ def setup_system(self, install_missing: bool, gdm: bool, graphical: bool):
:type graphical: bool
:return:
"""
os_version = _get_os_version()

for d in (LIB_DIR, LIB_BACKUP, LIB_DUMP, LIB_DUMP_USERS, LIB_DUMP_CAS,
LIB_DUMP_CARDS):
d.mkdir(exist_ok=True)
Expand All @@ -158,7 +160,11 @@ def setup_system(self, install_missing: bool, gdm: bool, graphical: bool):
for c in self.lib_conf["cards"]):
packages += ["pcsc-lite-ccid", "pcsc-lite", "virt_cacard",
"vpcd", "softhsm"]
run("dnf -y copr enable jjelen/vsmartcard")
extra_args = ""
if os_version in (OSVersion.RHEL_10, OSVersion.CentOS_10):
# TODO: use better approach later
extra_args = " centos-stream-10-x86_64"
run("dnf -y copr enable jjelen/vsmartcard{0}".format(extra_args))

# Add IPA packages if needed
if any([u["user_type"] != UserType.local
Expand All @@ -175,7 +181,7 @@ def setup_system(self, install_missing: bool, gdm: bool, graphical: bool):
logger.critical(msg)
raise exceptions.SCAutolibException(msg)

os_version = _get_os_version()
print(f"Os version: {os_version}")
if graphical:
if os_version != OSVersion.Fedora:
run(['dnf', 'groupinstall', 'Server with GUI', '-y',
Expand Down Expand Up @@ -533,7 +539,7 @@ def _general_steps_for_ipa():
:return: name of the IPA client package for current Linux
"""
os_version = _get_os_version()
if os_version not in (OSVersion.RHEL_9, OSVersion.CentOS_9):
if os_version in (OSVersion.RHEL_8, OSVersion.CentOS_8):
run("dnf module enable -y idm:DL1")
run("dnf install @idm:DL1 -y")
logger.debug("idm:DL1 module is installed")
Expand Down
12 changes: 7 additions & 5 deletions SCAutolib/enums.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
from enum import Enum, auto


class OSVersion(Enum):
class OSVersion(int, Enum):
"""
Enumeration for Linux versions. Used for more convenient checks.
"""
Fedora = 1
RHEL_9 = 2
RHEL_8 = 3
CentOS_8 = 4
CentOS_9 = 5
RHEL_8 = 2
RHEL_9 = 3
RHEL_10 = 4
CentOS_8 = 5
CentOS_9 = 6
CentOS_10 = 7


class CardType(str, Enum):
Expand Down
9 changes: 8 additions & 1 deletion SCAutolib/models/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,6 @@ class SSSDConf(File):
runtimes.
"""
__instance = None
_template = Path(TEMPLATES_DIR, "sssd.conf")
_conf_file = Path("/etc/sssd/sssd.conf")
_backup_original = None
_backup_default = LIB_BACKUP.joinpath('default-sssd.conf')
Expand All @@ -298,6 +297,14 @@ def __init__(self):
return
self.__initialized = True

with open('/etc/redhat-release', "r") as f:
release = f.read()

if "release 8" in release or "release 9" in release:
self._template = TEMPLATES_DIR.joinpath("sssd.conf-8or9")
else:
self._template = TEMPLATES_DIR.joinpath("sssd.conf-10")

# _default_parser object stores default content of config file
self._default_parser = ConfigParser()
# avoid problems with inserting some 'specific' values
Expand Down
18 changes: 18 additions & 0 deletions SCAutolib/templates/sssd.conf-10
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[sssd]
debug_level = 9
services = nss, pam, ssh, sudo
domains = shadowutils
certificate_verification = no_ocsp

[nss]
debug_level = 9

[pam]
debug_level = 9
pam_cert_auth = True

[domain/shadowutils]
debug_level = 9
id_provider = proxy
proxy_lib_name = files
local_auth_policy = only
File renamed without changes.
25 changes: 15 additions & 10 deletions SCAutolib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,25 +60,30 @@ def _gen_private_key(key_path: Path):

def _get_os_version():
"""
Find Linux version. Available version: RHEL 8, RHEL 9, Fedora.
Find Linux version. Available version: RHEL 8, RHEL 9, RHEL 10, Fedora.
:return: Enum with OS version
"""
with open('/etc/redhat-release', "r") as f:
cnt = f.read()

if "Red Hat Enterprise Linux release 9" in cnt:
return OSVersion.RHEL_9
elif "Red Hat Enterprise Linux release 8" in cnt:
return OSVersion.RHEL_8
elif "Fedora" in cnt:
os_version = None

if "Fedora" in cnt:
return OSVersion.Fedora
elif "CentOS Stream release 8" in cnt:
return OSVersion.CentOS_8
elif "CentOS Stream release 9" in cnt:
return OSVersion.CentOS_9
elif "Red Hat Enterprise Linux" in cnt:
os_version = OSVersion.RHEL_8
elif "CentOS Stream" in cnt:
os_version = OSVersion.CentOS_8
else:
raise SCAutolibException("OS is not detected.")

if "release 9" in cnt:
os_version += 1
elif "release 10" in cnt:
os_version += 2

return os_version


def _install_packages(packages):
"""
Expand Down

0 comments on commit fc5e710

Please sign in to comment.