Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vmupdate: Fix SELinux plugin detection #177

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 26 additions & 20 deletions vmupdate/agent/source/plugins/fix_meminfo_writer_label.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import subprocess
import os


def fix_meminfo_writer_label(os_data, log, **kwargs):
Expand All @@ -9,27 +10,32 @@ def fix_meminfo_writer_label(os_data, log, **kwargs):
"""

if os_data["id"] == "fedora":
meminfo_path = "/usr/sbin/meminfo-writer"
expected_label = "qubes_meminfo_writer_exec_t"
if os.path.exists("/usr/sbin/selinuxenabled"):
meminfo_path = "/usr/sbin/meminfo-writer"
expected_label = "qubes_meminfo_writer_exec_t"

label_changed = False
try:
output = subprocess.check_output(
["ls", "-Z", meminfo_path], universal_newlines=True
)
if expected_label not in output:
subprocess.check_call(["chcon", "-t", expected_label, meminfo_path])
log.info(
f"SELinux label for {meminfo_path} changed to '{expected_label}'"
)
label_changed = True
except subprocess.CalledProcessError as e:
log.error(f"Error processing {meminfo_path}: {e}")

if label_changed:
label_changed = False
try:
subprocess.check_call(["systemctl", "restart", "qubes-meminfo-writer"])
log.info("qubes-meminfo-writer service restarted")
if subprocess.call(["/usr/sbin/selinuxenabled"]) == 0:
output = subprocess.check_output(
["ls", "-Z", meminfo_path], universal_newlines=True
)
if expected_label not in output:
subprocess.check_call(
["chcon", "-t", expected_label, meminfo_path]
)
log.info(
f"SELinux label for {meminfo_path} changed to '{expected_label}'"
)
label_changed = True
except subprocess.CalledProcessError as e:
log.error(f"Error restarting qubes-meminfo-writer service: {e}")
log.error(f"Error processing {meminfo_path}: {e}")

if label_changed:
try:
subprocess.check_call(
["systemctl", "restart", "qubes-meminfo-writer"]
)
log.info("qubes-meminfo-writer service restarted")
except subprocess.CalledProcessError as e:
log.error(f"Error restarting qubes-meminfo-writer service: {e}")