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

Eval symlinks on XDG_RUNTIME_DIR #15918

Merged
merged 1 commit into from
Oct 31, 2022

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Sep 23, 2022

Partial Fix for #14606

[NO NEW TESTS NEEDED]

Signed-off-by: Daniel J Walsh dwalsh@redhat.com

Does this PR introduce a user-facing change?

None

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 23, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Sep 23, 2022
@@ -359,7 +359,8 @@ static void __attribute__((constructor)) init()

/* Shortcut. If we are able to join the pause pid file, do it now so we don't
need to re-exec. */
xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR");
char path[PATH_MAX];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whitespace here looks a bit wierd

@mheon
Copy link
Member

mheon commented Oct 13, 2022

Code LGTM, I'm good to merge whenever the tests start passing

@rhatdan rhatdan force-pushed the XDG_RUNTIME_DIR branch 2 times, most recently from fcef9f7 to d9c00f6 Compare October 17, 2022 14:08
@rhatdan
Copy link
Member Author

rhatdan commented Oct 19, 2022

@edsantiago Any idea what is breaking the Windows man page generator? I don't see how this PR is causing this error?

@edsantiago
Copy link
Member

The error I see is:

docs: no doc file nor link docs/build/man/podman-.1 for 'podman '

The space looks suspicious but I don't know this code and have no idea what it means. Am looking into it now.

The other weird thing I see is:

lstat podman_tmp_5mgn/podman-run--1/bus: no such file or directory

I think that's related, because the string lstat does not appear on a successful CI run of this step. Continuing to investigate, am posting this in case it triggers a memory in anyone.

@edsantiago
Copy link
Member

Okay..... there's a weird error involving "bus", and your PR adds the string "bus". I think there's a connection. Maybe XDG_WHATEVER is unset on Macs?

@edsantiago
Copy link
Member

I see your new push but I don't think that's going to fix it: XDG_RUNTIME_DIR gets set complicatedly in one of the config.go files. I'm looking right now at

tmpDir := filepath.Join(os.TempDir(), fmt.Sprintf("podman-run-%s", uid))
if err := os.MkdirAll(tmpDir, 0700); err != nil {

...which has the string "podman-run-%s" which closely matches the "podman-run--1" in the lstat error (except, wtf, is "-1" a valid UID in Mac-land???). The other part, podman_tmp_5mgn, is set in Makefile: that's $TMPDIR. So XDG is getting set to a default value in TMPDIR, and something is then failing later. But I can't reproduce it on my end no matter what I use for TMPDIR and XDG. Still looking.

@edsantiago
Copy link
Member

AHA! Reproduced it via hackery:

diff --git a/pkg/util/utils_supported.go b/pkg/util/utils_supported.go
index 90a2ecf86..c5877ea9f 100644
--- a/pkg/util/utils_supported.go
+++ b/pkg/util/utils_supported.go
@@ -34,7 +34,7 @@ func GetRuntimeDir() (string, error) {
                }
 
                uid := fmt.Sprintf("%d", rootless.GetRootlessUID())
-               if runtimeDir == "" {
+               if runtimeDir == "xxxx" {
                        tmpDir := filepath.Join("/run", "user", uid)
                        if err := os.MkdirAll(tmpDir, 0700); err != nil {
                                logrus.Debug(err)

With that, compile, and run:

$ mkdir foo123
$ env -i TMPDIR=foo123 bin/podman-remote help
lstat foo123/podman-run-14904/bus: no such file or directory
$ echo $?
1

@edsantiago
Copy link
Member

This patch (against main, not against your PR) fixes it. Obviously there may be a better solution:

diff --git a/cmd/podman/registry/config.go b/cmd/podman/registry/config.go
index a118fdc4d..0f6028888 100644
--- a/cmd/podman/registry/config.go
+++ b/cmd/podman/registry/config.go
@@ -105,7 +105,12 @@ func setXdgDirs() error {
        if _, found := os.LookupEnv("DBUS_SESSION_BUS_ADDRESS"); !found {
                sessionAddr := filepath.Join(os.Getenv("XDG_RUNTIME_DIR"), "bus")
                if _, err := os.Stat(sessionAddr); err == nil {
-                       os.Setenv("DBUS_SESSION_BUS_ADDRESS", "unix:path="+sessionAddr)
+                       dereferenced, err := filepath.EvalSymlinks(sessionAddr)
+                       if err != nil {
+                               return err
+                       }
+
+                       os.Setenv("DBUS_SESSION_BUS_ADDRESS", "unix:path="+dereferenced)
                }
        }

Comment on lines 106 to 107
runtimeDir := os.Getenv("XDG_RUNTIME_DIR")
if runtimeDir != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't quite the same as mine. Even if you get it to compile, the logic is different: in my approach, I first assemble XDG/bus, then check if that exists, then deref links.

XDG will always be set. That's some early config hackery that @giuseppe added years ago. What does not exist on macs is XDG + bus.

@@ -157,7 +157,13 @@ func (r *Runtime) reset(ctx context.Context) error {
}
}

xdgRuntimeDir := filepath.Clean(os.Getenv("XDG_RUNTIME_DIR"))
xdgRuntimeDir := os.Getenv("XDG_RUNTIME_DIR")
if xdgRuntimeDir != "" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, I think this is misleading because XDG is always, always going to be set very early on by config code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no change here if XDG_RUNTIME_DIR is not set or is set to "", Current code would not fail if XDG_RUNTIME_DIR=="" new code would, so I add his check.

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And, like above, I think you need an existence check before you EvalSymlinks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would the check do if it does not exists?

Still call
return godbus.Dial(fmt.Sprintf("unix:path=%s", path))
?

If the file does not exists EvalSymlinks will return that it does not exists.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know enough about this systemd/private path to comment. But:

  • old code: just returns a string with the path, whether the path exists or not (leave it to caller to deal with problems)
  • new code: barfs if path does not exist. This is new behavior. I don't know if it's good new behavior or bad new behavior... but it's a change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the old code will barf when godbus.Dial attempts to connect to a non existing socket
The new code will report the non existing socket earlier, as I read it.


if runtimeDir != "" {
rootlessRuntimeDir, rootlessRuntimeDirError = filepath.EvalSymlinks(runtimeDir)
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kind of made me nervous to return early, but AFAICT it's perfectly fine, no code paths are affected, and this actually seems cleaner. PR LGTM but this has too many ramifications for me.

@rhatdan
Copy link
Member Author

rhatdan commented Oct 19, 2022

@containers/podman-maintainers PTAL

Copy link
Member

@Luap99 Luap99 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add the test from my PR #14668 to make sure it actually fixes the issue.

@edsantiago
Copy link
Member

Thanks for the test, @Luap99. Here's a version that doesn't depend on /var/run existing and being a symlink.

@test "podman rootless netns works when XDG_RUNTIME_DIR includes symlinks" {
    # regression test for https://github.com/containers/podman/issues/14606
    is_rootless || skip "only meaningful for rootless"

    # Create a tmpdir symlink pointing to /run, and use it briefly
    ln -s /run $PODMAN_TMPDIR/run
    local tmp_run=$PODMAN_TMPDIR/run/user/$(id -u)
    test -d $tmp_run || skip "/run/user/MYUID unavailable"

    # This 'run' would previously fail with:
    #    IPAM error: failed to open database ....
    XDG_RUNTIME_DIR=$tmp_run run_podman run --network bridge --rm $IMAGE ip a
    assert "$output" =~ "eth0"
}

(warning: if you run this test with podman @ main, or podman without this patch, you destroy everything and need to run podman system reset before you can run podman again. No idea why, don't really care).

@rhatdan rhatdan force-pushed the XDG_RUNTIME_DIR branch 2 times, most recently from 2b42abf to ba5e896 Compare October 28, 2022 09:47
Partial Fix for containers#14606

[NO NEW TESTS NEEDED]

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
@rhatdan
Copy link
Member Author

rhatdan commented Oct 29, 2022

@Luap99 @edsantiago PTAL

@edsantiago
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Oct 31, 2022
@openshift-merge-robot openshift-merge-robot merged commit ee896b2 into containers:main Oct 31, 2022
@rhatdan rhatdan deleted the XDG_RUNTIME_DIR branch December 1, 2022 22:00
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 20, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. release-note-none
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants