Просмотр исходного кода

Correct SELinux label on created systemd services

This patch makes sure that services created by Coriolis (like coriolis-writer)
can run on a SELinux enabled worker machine, by correcting the service file's
label, so systemctl can read it.
Daniel Vincze 2 лет назад
Родитель
Сommit
2fb76f8399
1 измененных файлов с 11 добавлено и 1 удалено
  1. 11 1
      coriolis/utils.py

+ 11 - 1
coriolis/utils.py

@@ -25,7 +25,6 @@ import OpenSSL
 from oslo_config import cfg
 from oslo_log import log as logging
 from oslo_serialization import jsonutils
-
 import netifaces
 import paramiko
 # NOTE(gsamfira): I am aware that this is not ideal, but pip
@@ -41,6 +40,7 @@ from coriolis import constants
 from coriolis import exception
 from coriolis import secrets
 
+
 opts = [
     cfg.StrOpt('qemu_img_path',
                default='qemu-img',
@@ -709,6 +709,15 @@ def _write_systemd(ssh, cmdline, svcname, run_as=None, start=True):
                 ssh, "sudo systemctl start %s" % svcname,
                 get_pty=True)
 
+    def _correct_selinux_label():
+        cmd = "sudo /sbin/restorecon -v %s" % serviceFilePath
+        try:
+            exec_ssh_cmd(ssh, cmd, get_pty=True)
+        except exception.CoriolisException:
+            LOG.warn(
+                "Could not relabel service '%s'. SELinux might not be "
+                "installed. Error was: %s", svcname, get_exception_details())
+
     systemd_args = {
         "cmdline": cmdline,
         "username": "root",
@@ -726,6 +735,7 @@ def _write_systemd(ssh, cmdline, svcname, run_as=None, start=True):
         ssh,
         "sudo mv /tmp/%s.service %s" % (name, serviceFilePath),
         get_pty=True)
+    _correct_selinux_label()
     _reload_and_start(start=start)