URL: https://github.com/freeipa/freeipa/pull/4904 Author: tiran Title: #4904: Add ipaplatforms for containers Action: opened
PR body: """ ### Allow to override ipaplatform with env var The ipaplatform provider module can now be overriden by setting IPAPLATFORM_OVERRIDE environment variable. ### Add ipaplatform for Fedora and RHEL container Container platforms for Fedora and RHEL simplify FreeIPA container effort. Paths are based on patches from https://github.com/freeipa/freeipa-container ### Write state dir to smb.conf smb.conf now sets state and cache directory, then includes the registry. This also allows us to write the final smb.conf before importing remaining settings into the Samba registry. """ To pull the PR as Git branch: git remote add ghfreeipa https://github.com/freeipa/freeipa git fetch ghfreeipa pull/4904/head:pr4904 git checkout pr4904
From ba7d30927237e83396a2b606e71fafd9c8d67e50 Mon Sep 17 00:00:00 2001 From: Christian Heimes <chei...@redhat.com> Date: Thu, 15 Aug 2019 11:35:42 +0200 Subject: [PATCH 1/3] Allow to override ipaplatform with env var The ipaplatform provider module can now be overriden by setting IPAPLATFORM_OVERRIDE environment variable. --- ipaplatform/osinfo.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/ipaplatform/osinfo.py b/ipaplatform/osinfo.py index bfb2d62564..fa614c7804 100644 --- a/ipaplatform/osinfo.py +++ b/ipaplatform/osinfo.py @@ -12,16 +12,23 @@ - fedora - rhel - ubuntu (like debian) + +The platform ids for ipaplatform providers are based on: + +1) IPAPLATFORM_OVERRIDE env var +2) ipaplatform.override.OVERRIDE value +3) ID field of /etc/os-release (Linux) +4) ID_LIKE fields of /etc/os-release (Linux) """ from __future__ import absolute_import +from collections.abc import Mapping import importlib -import io import re +import os import sys import warnings -import six import ipaplatform try: @@ -30,13 +37,6 @@ OVERRIDE = None -# pylint: disable=no-name-in-module, import-error -if six.PY3: - from collections.abc import Mapping -else: - from collections import Mapping -# pylint: enable=no-name-in-module, import-error - _osrelease_line = re.compile( u"^(?!#)(?P<name>[a-zA-Z0-9_]+)=" u"(?P<quote>[\"\']?)(?P<value>.+)(?P=quote)$" @@ -49,7 +49,7 @@ def _parse_osrelease(filename='/etc/os-release'): https://www.freedesktop.org/software/systemd/man/os-release.html """ release = {} - with io.open(filename, encoding='utf-8') as f: + with open(filename) as f: for line in f: mo = _osrelease_line.match(line) if mo is not None: @@ -186,10 +186,15 @@ def platform_ids(self): """Ordered tuple of detected platforms (including override) """ platforms = [] - if OVERRIDE is not None: + # env var first + env = os.environ.get("IPAPLATFORM_OVERRIDE") + if env: + platforms.append(env) + # override from package definition + if OVERRIDE is not None and OVERRIDE not in platforms: # allow RPM and Debian packages to override platform platforms.append(OVERRIDE) - if OVERRIDE != self.id: + if self.id not in platforms: platforms.append(self.id) platforms.extend(self.id_like) return tuple(platforms) From f309a130b254a7fe340b83382d450347625b3be3 Mon Sep 17 00:00:00 2001 From: Christian Heimes <chei...@redhat.com> Date: Thu, 9 Jul 2020 09:36:36 +0200 Subject: [PATCH 2/3] Add ipaplatform for Fedora and RHEL container Container platforms for Fedora and RHEL simplify FreeIPA container effort. Paths are based on patches from https://github.com/freeipa/freeipa-container Signed-off-by: Christian Heimes <chei...@redhat.com> --- install/share/ipaca_default.ini | 1 - ipaplatform/base/paths.py | 3 ++- ipaplatform/fedora_container/__init__.py | 7 ++++++ ipaplatform/fedora_container/constants.py | 13 ++++++++++ ipaplatform/fedora_container/paths.py | 29 +++++++++++++++++++++++ ipaplatform/fedora_container/services.py | 27 +++++++++++++++++++++ ipaplatform/fedora_container/tasks.py | 13 ++++++++++ ipaplatform/rhel_container/__init__.py | 7 ++++++ ipaplatform/rhel_container/constants.py | 13 ++++++++++ ipaplatform/rhel_container/paths.py | 29 +++++++++++++++++++++++ ipaplatform/rhel_container/services.py | 27 +++++++++++++++++++++ ipaplatform/rhel_container/tasks.py | 13 ++++++++++ ipaplatform/setup.py | 2 ++ ipaserver/install/dogtaginstance.py | 1 + 14 files changed, 183 insertions(+), 2 deletions(-) create mode 100644 ipaplatform/fedora_container/__init__.py create mode 100644 ipaplatform/fedora_container/constants.py create mode 100644 ipaplatform/fedora_container/paths.py create mode 100644 ipaplatform/fedora_container/services.py create mode 100644 ipaplatform/fedora_container/tasks.py create mode 100644 ipaplatform/rhel_container/__init__.py create mode 100644 ipaplatform/rhel_container/constants.py create mode 100644 ipaplatform/rhel_container/paths.py create mode 100644 ipaplatform/rhel_container/services.py create mode 100644 ipaplatform/rhel_container/tasks.py diff --git a/install/share/ipaca_default.ini b/install/share/ipaca_default.ini index a51256116d..e71edaca7d 100644 --- a/install/share/ipaca_default.ini +++ b/install/share/ipaca_default.ini @@ -25,7 +25,6 @@ ipa_ca_pem_file=/etc/ipa/ca.crt # Dogtag defaults pki_instance_name=pki-tomcat -pki_configuration_path=/etc/pki pki_instance_configuration_path=%(pki_configuration_path)s/%(pki_instance_name)s pki_admin_cert_file=%(pki_client_dir)s/ca_admin.cert diff --git a/ipaplatform/base/paths.py b/ipaplatform/base/paths.py index ba4718f301..398b9f72d2 100644 --- a/ipaplatform/base/paths.py +++ b/ipaplatform/base/paths.py @@ -113,6 +113,7 @@ class BasePathNamespace: CA_CERTIFICATES_BUNDLE_PEM = None CA_CERTIFICATES_DIR = None NSS_DB_DIR = "/etc/pki/nssdb" + PKI_CONFIGURATION = "/etc/pki" PKI_TOMCAT = "/etc/pki/pki-tomcat" PKI_TOMCAT_ALIAS_DIR = "/etc/pki/pki-tomcat/alias" PKI_TOMCAT_ALIAS_PWDFILE_TXT = "/etc/pki/pki-tomcat/alias/pwdfile.txt" @@ -323,7 +324,7 @@ class BasePathNamespace: "/var/lib/pki/pki-tomcat/ca/profiles/ca/caSignedLogCert.cfg") KRA_CS_CFG_PATH = "/var/lib/pki/pki-tomcat/conf/kra/CS.cfg" KRACERT_P12 = "/root/kracert.p12" - SAMBA_DIR = "/var/lib/samba/" + SAMBA_DIR = "/var/lib/samba" SSSD_DB = "/var/lib/sss/db" SSSD_MC_GROUP = "/var/lib/sss/mc/group" SSSD_MC_PASSWD = "/var/lib/sss/mc/passwd" diff --git a/ipaplatform/fedora_container/__init__.py b/ipaplatform/fedora_container/__init__.py new file mode 100644 index 0000000000..62f648841f --- /dev/null +++ b/ipaplatform/fedora_container/__init__.py @@ -0,0 +1,7 @@ +# +# Copyright (C) 2020 FreeIPA Contributors see COPYING for license +# +""" +This module contains Fedora Container specific platform files. +""" +NAME = 'fedora_container' diff --git a/ipaplatform/fedora_container/constants.py b/ipaplatform/fedora_container/constants.py new file mode 100644 index 0000000000..21f04c4feb --- /dev/null +++ b/ipaplatform/fedora_container/constants.py @@ -0,0 +1,13 @@ +# +# Copyright (C) 2020 FreeIPA Contributors see COPYING for license +# +"""Fedora container constants +""" +from ipaplatform.fedora.constants import FedoraConstantsNamespace + + +class FedoraContainerConstantsNamespace(FedoraConstantsNamespace): + pass + + +constants = FedoraContainerConstantsNamespace() diff --git a/ipaplatform/fedora_container/paths.py b/ipaplatform/fedora_container/paths.py new file mode 100644 index 0000000000..47e7b59355 --- /dev/null +++ b/ipaplatform/fedora_container/paths.py @@ -0,0 +1,29 @@ +# +# Copyright (C) 2020 FreeIPA Contributors see COPYING for license +# +"""Fedora container paths +""" +import os + +from ipaplatform.fedora.paths import FedoraPathNamespace + + +def data(path): + return os.path.join("/data", path[1:]) + + +class FedoraContainerPathNamespace(FedoraPathNamespace): + KRB5_CONF = data(FedoraPathNamespace.KRB5_CONF) + KRB5_KEYTAB = data(FedoraPathNamespace.KRB5_KEYTAB) + NAMED_KEYTAB = data(FedoraPathNamespace.NAMED_KEYTAB) + NAMED_CUSTOM_CONF = data(FedoraPathNamespace.NAMED_CUSTOM_CONF) + NAMED_CUSTOM_OPTIONS_CONF = data( + FedoraPathNamespace.NAMED_CUSTOM_OPTIONS_CONF + ) + NSSWITCH_CONF = data(FedoraPathNamespace.NSSWITCH_CONF) + PKI_CONFIGURATION = data(FedoraPathNamespace.PKI_CONFIGURATION) + SAMBA_DIR = data(FedoraPathNamespace.SAMBA_DIR) + HTTPD_IPA_WSGI_MODULES_CONF = None + + +paths = FedoraContainerPathNamespace() diff --git a/ipaplatform/fedora_container/services.py b/ipaplatform/fedora_container/services.py new file mode 100644 index 0000000000..46fda2dfcb --- /dev/null +++ b/ipaplatform/fedora_container/services.py @@ -0,0 +1,27 @@ +# +# Copyright (C) 2020 FreeIPA Contributors see COPYING for license +# +"""Fedora container services +""" +from ipaplatform.fedora import services as fedora_services + + +fedora_container_system_units = fedora_services.fedora_system_units.copy() + + +class FedoraContainerService(fedora_services.FedoraService): + system_units = fedora_container_system_units + + +def fedora_container_service_class_factory(name, api=None): + return fedora_services.fedora_service_class_factory(name, api) + + +class FedoraContainerServices(fedora_services.FedoraServices): + def service_class_factory(self, name, api=None): + return fedora_container_service_class_factory(name, api) + + +timedate_services = fedora_services.timedate_services +service = fedora_container_service_class_factory +knownservices = FedoraContainerServices() diff --git a/ipaplatform/fedora_container/tasks.py b/ipaplatform/fedora_container/tasks.py new file mode 100644 index 0000000000..946e581e01 --- /dev/null +++ b/ipaplatform/fedora_container/tasks.py @@ -0,0 +1,13 @@ +# +# Copyright (C) 2020 FreeIPA Contributors see COPYING for license +# +"""Fedora container tasks +""" +from ipaplatform.fedora.tasks import FedoraTaskNamespace + + +class FedoraContainerTaskNamespace(FedoraTaskNamespace): + pass + + +tasks = FedoraContainerTaskNamespace() diff --git a/ipaplatform/rhel_container/__init__.py b/ipaplatform/rhel_container/__init__.py new file mode 100644 index 0000000000..8bd13a42e9 --- /dev/null +++ b/ipaplatform/rhel_container/__init__.py @@ -0,0 +1,7 @@ +# +# Copyright (C) 2020 FreeIPA Contributors see COPYING for license +# +""" +This module contains RHEL Container specific platform files. +""" +NAME = 'rhel_container' diff --git a/ipaplatform/rhel_container/constants.py b/ipaplatform/rhel_container/constants.py new file mode 100644 index 0000000000..7cf5cb3a9e --- /dev/null +++ b/ipaplatform/rhel_container/constants.py @@ -0,0 +1,13 @@ +# +# Copyright (C) 2020 FreeIPA Contributors see COPYING for license +# +"""RHEL container constants +""" +from ipaplatform.rhel.constants import RHELConstantsNamespace + + +class RHELContainerConstantsNamespace(RHELConstantsNamespace): + pass + + +constants = RHELContainerConstantsNamespace() diff --git a/ipaplatform/rhel_container/paths.py b/ipaplatform/rhel_container/paths.py new file mode 100644 index 0000000000..5598daeb5e --- /dev/null +++ b/ipaplatform/rhel_container/paths.py @@ -0,0 +1,29 @@ +# +# Copyright (C) 2020 FreeIPA Contributors see COPYING for license +# +"""RHEL container paths +""" +import os + +from ipaplatform.rhel.paths import RHELPathNamespace + + +def data(path): + return os.path.join("/data", path[1:]) + + +class RHELContainerPathNamespace(RHELPathNamespace): + KRB5_CONF = data(RHELPathNamespace.KRB5_CONF) + KRB5_KEYTAB = data(RHELPathNamespace.KRB5_KEYTAB) + NAMED_KEYTAB = data(RHELPathNamespace.NAMED_KEYTAB) + NAMED_CUSTOM_CONF = data(RHELPathNamespace.NAMED_CUSTOM_CONF) + NAMED_CUSTOM_OPTIONS_CONF = data( + RHELPathNamespace.NAMED_CUSTOM_OPTIONS_CONF + ) + NSSWITCH_CONF = data(RHELPathNamespace.NSSWITCH_CONF) + PKI_CONFIGURATION = data(RHELPathNamespace.PKI_CONFIGURATION) + SAMBA_DIR = data(RHELPathNamespace.SAMBA_DIR) + HTTPD_IPA_WSGI_MODULES_CONF = None + + +paths = RHELContainerPathNamespace() diff --git a/ipaplatform/rhel_container/services.py b/ipaplatform/rhel_container/services.py new file mode 100644 index 0000000000..ed7b12e371 --- /dev/null +++ b/ipaplatform/rhel_container/services.py @@ -0,0 +1,27 @@ +# +# Copyright (C) 2020 FreeIPA Contributors see COPYING for license +# +"""RHEL container services +""" +from ipaplatform.rhel import services as rhel_services + + +rhel_container_system_units = rhel_services.rhel_system_units.copy() + + +class RHELContainerService(rhel_services.RHELService): + system_units = rhel_container_system_units + + +def rhel_container_service_class_factory(name, api=None): + return rhel_services.rhel_service_class_factory(name, api) + + +class RHELContainerServices(rhel_services.RHELServices): + def service_class_factory(self, name, api=None): + return rhel_container_service_class_factory(name, api) + + +timedate_services = rhel_services.timedate_services +service = rhel_container_service_class_factory +knownservices = RHELContainerServices() diff --git a/ipaplatform/rhel_container/tasks.py b/ipaplatform/rhel_container/tasks.py new file mode 100644 index 0000000000..0b7fdcf7c2 --- /dev/null +++ b/ipaplatform/rhel_container/tasks.py @@ -0,0 +1,13 @@ +# +# Copyright (C) 2020 FreeIPA Contributors see COPYING for license +# +"""RHEL container tasks +""" +from ipaplatform.rhel.tasks import RHELTaskNamespace + + +class RHELContainerTaskNamespace(RHELTaskNamespace): + pass + + +tasks = RHELContainerTaskNamespace() diff --git a/ipaplatform/setup.py b/ipaplatform/setup.py index 20bfc69125..0d4bb380fc 100644 --- a/ipaplatform/setup.py +++ b/ipaplatform/setup.py @@ -36,8 +36,10 @@ "ipaplatform.base", "ipaplatform.debian", "ipaplatform.fedora", + "ipaplatform.fedora_container", "ipaplatform.redhat", "ipaplatform.rhel", + "ipaplatform.rhel_container", "ipaplatform.suse" ], install_requires=[ diff --git a/ipaserver/install/dogtaginstance.py b/ipaserver/install/dogtaginstance.py index 7e295665cf..524262ad75 100644 --- a/ipaserver/install/dogtaginstance.py +++ b/ipaserver/install/dogtaginstance.py @@ -824,6 +824,7 @@ def __init__(self, subsystem, fqdn, domain, self.defaults = dict( # pretty much static ipa_ca_pem_file=paths.IPA_CA_CRT, + pki_configuration_path=paths.PKI_CONFIGURATION, # variable ipa_ca_subject=ca_subject, ipa_subject_base=subject_base, From 0b7e04ced4391fe68e7c9c301fe5da9b7b96ef3a Mon Sep 17 00:00:00 2001 From: Christian Heimes <chei...@redhat.com> Date: Thu, 9 Jul 2020 10:56:51 +0200 Subject: [PATCH 3/3] Write state dir to smb.conf smb.conf now sets state and cache directory, then includes the registry. This also allows us to write the final smb.conf before importing remaining settings into the Samba registry. Signed-off-by: Christian Heimes <chei...@redhat.com> --- install/share/smb.conf.registry.template | 35 +++++++++++++++++++ install/share/smb.conf.template | 40 ++++------------------ ipaserver/install/adtrustinstance.py | 43 +++++++++++++----------- 3 files changed, 65 insertions(+), 53 deletions(-) create mode 100644 install/share/smb.conf.registry.template diff --git a/install/share/smb.conf.registry.template b/install/share/smb.conf.registry.template new file mode 100644 index 0000000000..1370b1e144 --- /dev/null +++ b/install/share/smb.conf.registry.template @@ -0,0 +1,35 @@ +[global] +workgroup = $NETBIOS_NAME +netbios name = $HOST_NETBIOS_NAME +realm = $REALM +kerberos method = dedicated keytab +dedicated keytab file = /etc/samba/samba.keytab +create krb5 conf = no +security = user +domain master = yes +domain logons = yes +log level = 1 +max log size = 100000 +log file = /var/log/samba/log.%m +passdb backend = ipasam:ldapi://$LDAPI_SOCKET +disable spoolss = yes +ldapsam:trusted=yes +ldap ssl = off +ldap suffix = $SUFFIX +ldap user suffix = cn=users,cn=accounts +ldap group suffix = cn=groups,cn=accounts +ldap machine suffix = cn=computers,cn=accounts +rpc_server:epmapper = external +rpc_server:lsarpc = external +rpc_server:lsass = external +rpc_server:lsasd = external +rpc_server:samr = external +rpc_server:netlogon = external +rpc_server:tcpip = yes +rpc_daemon:epmd = fork +rpc_daemon:lsasd = fork +idmap config * : backend = tdb +idmap config * : range = 0 - 0 +idmap config $NETBIOS_NAME : backend = sss +idmap config $NETBIOS_NAME : range = $IPA_LOCAL_RANGE +max smbd processes = 1000 diff --git a/install/share/smb.conf.template b/install/share/smb.conf.template index 1370b1e144..0463bc58a8 100644 --- a/install/share/smb.conf.template +++ b/install/share/smb.conf.template @@ -1,35 +1,7 @@ +### Added by IPA Installer ### +# DO NOT EDIT # [global] -workgroup = $NETBIOS_NAME -netbios name = $HOST_NETBIOS_NAME -realm = $REALM -kerberos method = dedicated keytab -dedicated keytab file = /etc/samba/samba.keytab -create krb5 conf = no -security = user -domain master = yes -domain logons = yes -log level = 1 -max log size = 100000 -log file = /var/log/samba/log.%m -passdb backend = ipasam:ldapi://$LDAPI_SOCKET -disable spoolss = yes -ldapsam:trusted=yes -ldap ssl = off -ldap suffix = $SUFFIX -ldap user suffix = cn=users,cn=accounts -ldap group suffix = cn=groups,cn=accounts -ldap machine suffix = cn=computers,cn=accounts -rpc_server:epmapper = external -rpc_server:lsarpc = external -rpc_server:lsass = external -rpc_server:lsasd = external -rpc_server:samr = external -rpc_server:netlogon = external -rpc_server:tcpip = yes -rpc_daemon:epmd = fork -rpc_daemon:lsasd = fork -idmap config * : backend = tdb -idmap config * : range = 0 - 0 -idmap config $NETBIOS_NAME : backend = sss -idmap config $NETBIOS_NAME : range = $IPA_LOCAL_RANGE -max smbd processes = 1000 +debug pid = yes +state directory = $SAMBA_DIR +cache directory = $SAMBA_DIR +include = registry diff --git a/ipaserver/install/adtrustinstance.py b/ipaserver/install/adtrustinstance.py index 7e711a2b8d..c51848d9b3 100644 --- a/ipaserver/install/adtrustinstance.py +++ b/ipaserver/install/adtrustinstance.py @@ -458,12 +458,12 @@ def __create_samba_domain_object(self): api.Backend.ldap2.add_entry(entry) def __write_smb_conf(self): - conf_fd = open(self.smb_conf, "w") - conf_fd.write('### Added by IPA Installer ###\n') - conf_fd.write('[global]\n') - conf_fd.write('debug pid = yes\n') - conf_fd.write('config backend = registry\n') - conf_fd.close() + template = os.path.join( + paths.USR_SHARE_IPA_DIR, "smb.conf.template" + ) + conf = ipautil.template_file(template, self.sub_dict) + with open(self.smb_conf, "w") as f: + f.write(conf) def __add_plugin_conf(self, name, plugin_cn, ldif_file): """ @@ -536,12 +536,14 @@ def __add_s4u2proxy_target(self): self.print_msg(UPGRADE_ERROR % dict(dn=targets_dn)) def __write_smb_registry(self): - # Workaround for: https://fedorahosted.org/freeipa/ticket/5687 - # We make sure that paths.SMB_CONF file exists, hence touch it - with open(paths.SMB_CONF, 'a'): - os.utime(paths.SMB_CONF, None) + """Import IPA specific config into Samba registry - template = os.path.join(paths.USR_SHARE_IPA_DIR, "smb.conf.template") + Configuration is imported after __write_smb_conf() has modified + smb.conf to include registry. + """ + template = os.path.join( + paths.USR_SHARE_IPA_DIR, "smb.conf.registry.template" + ) conf = ipautil.template_file(template, self.sub_dict) with tempfile.NamedTemporaryFile(mode='w') as tmp_conf: tmp_conf.write(conf) @@ -739,13 +741,16 @@ def __enable(self): logger.info("EXTID Service startup entry already exists.") def __setup_sub_dict(self): - self.sub_dict = dict(REALM = self.realm, - SUFFIX = self.suffix, - NETBIOS_NAME = self.netbios_name, - HOST_NETBIOS_NAME = self.host_netbios_name, - SMB_DN = self.smb_dn, - LDAPI_SOCKET = self.ldapi_socket, - FQDN = self.fqdn) + self.sub_dict = dict( + REALM=self.realm, + SUFFIX=self.suffix, + NETBIOS_NAME=self.netbios_name, + HOST_NETBIOS_NAME=self.host_netbios_name, + SMB_DN=self.smb_dn, + LDAPI_SOCKET=self.ldapi_socket, + FQDN=self.fqdn, + SAMBA_DIR=paths.SAMBA_DIR, + ) def setup(self, fqdn, realm_name, netbios_name, reset_netbios_name, rid_base, secondary_rid_base, @@ -820,8 +825,8 @@ def create_instance(self): self.step("creating samba domain object", \ self.__create_samba_domain_object) self.step("retrieve local idmap range", self.__retrieve_local_range) - self.step("creating samba config registry", self.__write_smb_registry) self.step("writing samba config file", self.__write_smb_conf) + self.step("creating samba config registry", self.__write_smb_registry) self.step("adding cifs Kerberos principal", self.request_service_keytab) self.step("adding cifs and host Kerberos principals to the adtrust agents group", \
_______________________________________________ FreeIPA-devel mailing list -- freeipa-devel@lists.fedorahosted.org To unsubscribe send an email to freeipa-devel-le...@lists.fedorahosted.org Fedora Code of Conduct: https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines: https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives: https://lists.fedorahosted.org/archives/list/freeipa-devel@lists.fedorahosted.org