From 40fa3d7497f0f7fa3f56242395bc0360db25fd21 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Fri, 29 May 2020 14:12:57 +0200 Subject: [PATCH] Ensuring authorized_keys for root on the webserver. --- lib/cr_vmware_tpl/cobbler.py | 9 +++++++++ lib/cr_vmware_tpl/config.py | 33 +++++++++++++++++++++++++++++---- lib/cr_vmware_tpl/handler.py | 3 ++- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/lib/cr_vmware_tpl/cobbler.py b/lib/cr_vmware_tpl/cobbler.py index fd9abfe..efbe9f9 100644 --- a/lib/cr_vmware_tpl/cobbler.py +++ b/lib/cr_vmware_tpl/cobbler.py @@ -349,6 +349,15 @@ class Cobbler(BaseHandler): self.scp_to(local_file, remote_file) + # ------------------------------------------------------------------------- + def ensure_root_authkeys(self): + + bname = 'auth_keys_pp_betrieb' + local_file = self.base_dir / 'keys' / bname + remote_file = self.config.cobbler_ws_docroot / self.config.cobbler_ws_rel_filesdir / bname + + self.ensure_remote_file(local_file, remote_file) + # ------------------------------------------------------------------------- def ensure_profile_ks(self): diff --git a/lib/cr_vmware_tpl/config.py b/lib/cr_vmware_tpl/config.py index 9e20716..12aab8f 100644 --- a/lib/cr_vmware_tpl/config.py +++ b/lib/cr_vmware_tpl/config.py @@ -21,7 +21,7 @@ from fb_tools.config import ConfigError, BaseConfiguration from .xlate import XLATOR -__version__ = '1.4.3' +__version__ = '1.5.0' LOG = logging.getLogger(__name__) _ = XLATOR.gettext @@ -90,6 +90,9 @@ class CrTplConfiguration(BaseConfiguration): 'pixelpark.com', 'pixelpark.de', ] + default_cobbler_ws_base_url = 'http://cobbler.pixelpark.com' + default_cobbler_ws_docroot = Path('/var/www/html') + default_cobbler_ws_rel_filesdir = Path('custom/vmware-template-files') ssh_privkey = 'id_rsa_cr_vmw_tpl' @@ -143,6 +146,9 @@ class CrTplConfiguration(BaseConfiguration): self.cobbler_profile_repos = copy.copy(self.default_cobbler_profile_repos) self.cobbler_nameservers = copy.copy(self.default_cobbler_nameservers) self.cobbler_dns_search = copy.copy(self.default_cobbler_dns_search) + self.cobbler_ws_base_url = self.default_cobbler_ws_base_url + self.cobbler_ws_docroot = self.default_cobbler_ws_docroot + self.cobbler_ws_rel_filesdir = self.default_cobbler_ws_rel_filesdir self.excluded_datastores = [] @@ -466,6 +472,12 @@ class CrTplConfiguration(BaseConfiguration): re_pr_repos_key = re.compile(r'^\s*profile[-_]?repos?\s*$', re.IGNORECASE) re_nameserver_key = re.compile(r'^\s*nameservers?\s*$', re.IGNORECASE) re_dns_search_key = re.compile(r'^\s*dns[-_]?search\s*$', re.IGNORECASE) + re_ws_base_url_key = re.compile( + r'^\s*(?:ws|webserver)[-_]?base[-_]?url\s*$', re.IGNORECASE) + re_ws_docroot_key = re.compile( + r'^\s*(?:ws|webserver)[-_]?docroot\s*$', re.IGNORECASE) + re_ws_rel_filesdir_key = re.compile( + r'^\s*(?:ws|webserver)[-_]?rel(?:ative)?[-_]?filesdir\s*$', re.IGNORECASE) for (key, value) in config.items(section_name): if key.lower() == 'distro' and value.strip() != '': @@ -488,8 +500,8 @@ class CrTplConfiguration(BaseConfiguration): if dpath.is_absolute(): self.cobbler_rootdir = Path(value) else: - msg = _("Path for Cobbler root directory {!r} is not absolute.").format( - str(dpath)) + msg = _("Path for {what} {path!r} is not absolute.").format( + what=_("Cobbler root directory"), path=str(dpath)) LOG.error(msg) continue if key.lower() == 'profile' and value.strip() != '': @@ -505,7 +517,20 @@ class CrTplConfiguration(BaseConfiguration): if re_dns_search_key.match(key) and value.strip() != '': self.cobbler_dns_search = re_split_values.split(value.strip().lower()) continue - + if re_ws_base_url_key.match(key) and value.strip() != '': + self.cobbler_ws_base_url = value.strip().lower() + continue + if re_ws_docroot_key.match(key) and value.strip() != '': + dpath = Path(value.strip()) + if dpath.is_absolute(): + self.cobbler_ws_docroot = dpath + else: + msg = _("Path for {what} {path!r} is not absolute.").format( + what=_("Webserver document root"), path=str(dpath)) + LOG.error(msg) + continue + if re_ws_rel_filesdir_key.match(key) and value.strip() != '': + self.cobbler_ws_rel_filesdir = Path(value.strip()) # ============================================================================= if __name__ == "__main__": diff --git a/lib/cr_vmware_tpl/handler.py b/lib/cr_vmware_tpl/handler.py index 665f5ea..015bdb2 100644 --- a/lib/cr_vmware_tpl/handler.py +++ b/lib/cr_vmware_tpl/handler.py @@ -40,7 +40,7 @@ from .cobbler import CobblerError, Cobbler from .xlate import XLATOR -__version__ = '1.4.5' +__version__ = '1.4.6' LOG = logging.getLogger(__name__) TZ = pytz.timezone('Europe/Berlin') @@ -175,6 +175,7 @@ class CrTplHandler(BaseHandler): self.cobbler.get_cobbler_version() self.check_for_cobbler_distro() self.cobbler.ensure_profile() + self.cobbler.ensure_root_authkeys() return 0 -- 2.39.5