From 137a8ce14d9a93a2949e4b1fdfe8e41e44b8f9a3 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Thu, 5 Jun 2025 11:27:53 +0200 Subject: [PATCH] journalctl: politely refuse if non-root usernames are specified for --machine= We currently cannot support that (supporting that would probably require some active component in the machine, or alternatively idmapped mounts or so), hence politely refuse it. See: https://github.com/systemd/systemd/issues/32997#issuecomment-2127700945 --- src/journal/journalctl-util.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/journal/journalctl-util.c b/src/journal/journalctl-util.c index dd6026e9f27..586f702bb4d 100644 --- a/src/journal/journalctl-util.c +++ b/src/journal/journalctl-util.c @@ -5,6 +5,7 @@ #include "alloc-util.h" #include "glob-util.h" +#include "hostname-util.h" #include "id128-util.h" #include "journal-util.h" #include "journalctl.h" @@ -43,9 +44,18 @@ int acquire_journal(sd_journal **ret) { r = sd_journal_open_files_fd(&j, (int[]) { STDIN_FILENO }, 1, arg_journal_additional_open_flags); else if (arg_file) r = sd_journal_open_files(&j, (const char**) arg_file, arg_journal_additional_open_flags); - else if (arg_machine) - r = journal_open_machine(&j, arg_machine, arg_journal_additional_open_flags); - else + else if (arg_machine) { + _cleanup_free_ char *u = NULL, *h = NULL; + + r = split_user_at_host(arg_machine, &u, &h); + if (r < 0) + return log_error_errno(r, "Failed to split machine specification '%s': %m", arg_machine); + + if (!isempty(u) && !streq(u, "root")) + return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Connecting to a machine as non-root is not supported."); + + r = journal_open_machine(&j, h ?: ".host", arg_journal_additional_open_flags); + } else r = sd_journal_open_namespace( &j, arg_namespace, -- 2.47.3