]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core/namespace: hide the correct credentials tree when running in user scope
authorMike Yuan <me@yhndnzj.com>
Sat, 8 Nov 2025 00:59:01 +0000 (01:59 +0100)
committerMike Yuan <me@yhndnzj.com>
Sun, 9 Nov 2025 21:39:42 +0000 (22:39 +0100)
src/core/namespace.c

index 0e12a16592bd707c356c32b48cbdb09c369083d3..07a69c03a6259f1ea214c674be94429a8a9f9a90 100644 (file)
@@ -2811,13 +2811,21 @@ int setup_namespace(const NamespaceParameters *p, char **reterr_path) {
                         return log_oom_debug();
 
                 *me = (MountEntry) {
-                        .path_const = "/run/credentials",
                         .mode = MOUNT_TMPFS,
                         .read_only = true,
                         .options_const = "mode=0755" TMPFS_LIMITS_EMPTY_OR_ALMOST,
                         .flags = MS_NODEV|MS_STRICTATIME|MS_NOSUID|MS_NOEXEC,
                 };
 
+                if (p->runtime_scope == RUNTIME_SCOPE_SYSTEM)
+                        me->path_const = "/run/credentials";
+                else {
+                        r = path_extract_directory(p->creds_path, &me->path_malloc);
+                        if (r < 0)
+                                return log_debug_errno(r, "Failed to extract parent directory from '%s': %m",
+                                                       p->creds_path);
+                }
+
                 me = mount_list_extend(&ml);
                 if (!me)
                         return log_oom_debug();
@@ -2829,9 +2837,11 @@ int setup_namespace(const NamespaceParameters *p, char **reterr_path) {
                         .source_const = p->creds_path,
                         .ignore = true,
                 };
-        } else {
-                /* If our service has no credentials store configured, then make the whole credentials tree
-                 * inaccessible wholesale. */
+        }
+
+        if (!p->creds_path || p->runtime_scope != RUNTIME_SCOPE_SYSTEM) {
+                /* If our service has no credentials store configured, or we're running in user scope, then
+                 * make the system credentials tree inaccessible wholesale. */
 
                 MountEntry *me = mount_list_extend(&ml);
                 if (!me)