From d9c00f655fd1a17db7682e1e7b392709165823eb Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Fri, 23 Sep 2022 13:49:44 -0400 Subject: [PATCH] Eval symlinks on XDG_RUNTIME_DIR Partial Fix for https://github.com/containers/podman/issues/14606 [NO NEW TESTS NEEDED] Signed-off-by: Daniel J Walsh --- cmd/podman/registry/config.go | 5 ++++- libpod/reset.go | 5 ++++- pkg/systemd/dbus.go | 6 +++++- pkg/util/utils_supported.go | 6 ++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cmd/podman/registry/config.go b/cmd/podman/registry/config.go index a118fdc4dd6a..cf6d4baea10e 100644 --- a/cmd/podman/registry/config.go +++ b/cmd/podman/registry/config.go @@ -103,7 +103,10 @@ func setXdgDirs() error { } if _, found := os.LookupEnv("DBUS_SESSION_BUS_ADDRESS"); !found { - sessionAddr := filepath.Join(os.Getenv("XDG_RUNTIME_DIR"), "bus") + sessionAddr, err := filepath.EvalSymlinks(filepath.Join(os.Getenv("XDG_RUNTIME_DIR"), "bus")) + if err != nil { + return err + } if _, err := os.Stat(sessionAddr); err == nil { os.Setenv("DBUS_SESSION_BUS_ADDRESS", "unix:path="+sessionAddr) } diff --git a/libpod/reset.go b/libpod/reset.go index b3ece03bf1ca..066b243fc44e 100644 --- a/libpod/reset.go +++ b/libpod/reset.go @@ -157,7 +157,10 @@ func (r *Runtime) reset(ctx context.Context) error { } } - xdgRuntimeDir := filepath.Clean(os.Getenv("XDG_RUNTIME_DIR")) + xdgRuntimeDir, err := filepath.EvalSymlinks(os.Getenv("XDG_RUNTIME_DIR")) + if err != nil { + return err + } _, prevError := r.store.Shutdown(true) graphRoot := filepath.Clean(r.store.GraphRoot()) if graphRoot == xdgRuntimeDir { diff --git a/pkg/systemd/dbus.go b/pkg/systemd/dbus.go index 6887a466eceb..059d39958aa0 100644 --- a/pkg/systemd/dbus.go +++ b/pkg/systemd/dbus.go @@ -129,7 +129,11 @@ func dbusAuthRootlessConnection(createBus func(opts ...godbus.ConnOption) (*godb func newRootlessConnection() (*dbus.Conn, error) { return dbus.NewConnection(func() (*godbus.Conn, error) { return dbusAuthRootlessConnection(func(opts ...godbus.ConnOption) (*godbus.Conn, error) { - path := filepath.Join(os.Getenv("XDG_RUNTIME_DIR"), "systemd/private") + path := filepath.Join(os.Getenv("XDG_RUNTIME_DIR"), "systemd", "private") + path, err := filepath.EvalSymlinks(path) + if err != nil { + return nil, err + } return godbus.Dial(fmt.Sprintf("unix:path=%s", path)) }) }) diff --git a/pkg/util/utils_supported.go b/pkg/util/utils_supported.go index b3d690158bf6..90a2ecf862e5 100644 --- a/pkg/util/utils_supported.go +++ b/pkg/util/utils_supported.go @@ -27,6 +27,12 @@ func GetRuntimeDir() (string, error) { rootlessRuntimeDirOnce.Do(func() { runtimeDir := os.Getenv("XDG_RUNTIME_DIR") + + if runtimeDir != "" { + rootlessRuntimeDir, rootlessRuntimeDirError = filepath.EvalSymlinks(runtimeDir) + return + } + uid := fmt.Sprintf("%d", rootless.GetRootlessUID()) if runtimeDir == "" { tmpDir := filepath.Join("/run", "user", uid)