Skip to content

Fix: Auto-detect unprivileged user and use XDG_RUNTIME_DIR for default root#465

Merged
cmainas merged 1 commit intourunc-dev:main-pr465from
sidneychang:set_root_auto
Feb 20, 2026
Merged

Fix: Auto-detect unprivileged user and use XDG_RUNTIME_DIR for default root#465
cmainas merged 1 commit intourunc-dev:main-pr465from
sidneychang:set_root_auto

Conversation

@sidneychang
Copy link
Contributor

@sidneychang sidneychang commented Feb 9, 2026

Description

This change mirrors runc’s behavior when running as a non-root user (or as root inside a user namespace). In these cases, the runtime now automatically falls back to using $XDG_RUNTIME_DIR as the default runtime root, instead of requiring callers to explicitly pass --root.

By honoring $XDG_RUNTIME_DIR by default in these environments, urunc now aligns with runc’s behavior and integrates more smoothly with Podman.

Related issues

How was this tested?

LLM usage

N/A

Checklist

  • I have read the contribution guide.
  • The linter passes locally (make lint).
  • The e2e tests of at least one tool pass locally (make test_ctr, make test_nerdctl, make test_docker, make test_crictl).
  • If LLMs were used: I have read the llm policy.

@netlify
Copy link

netlify bot commented Feb 9, 2026

Deploy Preview for urunc canceled.

Name Link
🔨 Latest commit a1b89e5
🔍 Latest deploy log https://app.netlify.com/projects/urunc/deploys/6998859e495b4100082648e5

@cmainas
Copy link
Contributor

cmainas commented Feb 9, 2026

Hello @sidneychang ,

thank you for this PR. The idea looks good, but maybe we could make use of urunc;s configuration instead of the XDG_RUNTIME_DIR for easier configuration. Let;s iterate over it in the podman issue first #114

Copy link
Contributor

@cmainas cmainas left a comment

Choose a reason for hiding this comment

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

Thank you @sidneychang for this addition. I have added a few comments to slightly improve the code.

// for the default root directory (e.g. /run/user/UID/runc instead of /run/urunc).
// It returns true for non-root processes and for root inside a user namespace
// when not running as the "root" user (e.g. rootless Podman).
func ShouldHonorXDGRuntimeDir() bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add this function in https://github.com/urunc-dev/urunc/blob/main/cmd/urunc/utils.go to avoid creating a new package.


func main() {
root := "/run/urunc"
xdgDirUsed := false
Copy link
Contributor

Choose a reason for hiding this comment

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

We can move this code inside the if !cmd.IsSet("root") statement and then perform the check if we should use the XDG_RUNTME_DIR

// auto-pruned.
if err := os.MkdirAll(root, 0o700); err != nil {
fmt.Fprintln(os.Stderr, "the path in $XDG_RUNTIME_DIR must be writable by the user")
fatal(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid using fatal. Return the error instead.

}
if err := os.Chmod(root, os.FileMode(0o700)|os.ModeSticky); err != nil {
fmt.Fprintln(os.Stderr, "you should check permission of the path in $XDG_RUNTIME_DIR")
fatal(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Avoid using fatal. Return the error instead.

},
Before: func(_ context.Context, cmd *cli.Command) (context.Context, error) {
if !cmd.IsSet("root") && xdgDirUsed {
// According to the XDG specification, we need to set anything in
Copy link
Contributor

Choose a reason for hiding this comment

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

We can move the XDG_RUNTIME_DIR preparation in a single small function.

@sidneychang sidneychang force-pushed the set_root_auto branch 2 times, most recently from 9b6dac5 to 248a6c6 Compare February 20, 2026 07:42
@sidneychang
Copy link
Contributor Author

Hi @cmainas,

Thanks for the review — all comments have been addressed.

@cmainas
Copy link
Contributor

cmainas commented Feb 20, 2026

Thank you @sidneychang for the changes. Could you rebase over the main branch, so we can merge it?

@sidneychang sidneychang force-pushed the set_root_auto branch 2 times, most recently from f1bab24 to a8ceeb2 Compare February 20, 2026 14:46
@sidneychang
Copy link
Contributor Author

Hi @cmainas,
I’ve rebased the branch on top of main.

@cmainas
Copy link
Contributor

cmainas commented Feb 20, 2026

Thank you @sidneychang , would it be possible to rebase once more, just to be on the safe side?

Mirror runc behavior: when running as non-root (or root inside a user
namespace), honor $XDG_RUNTIME_DIR for the default runtime root so
callers do not need to pass --root.
Signed-off-by: sidneychang <2190206983@qq.com>
@cmainas
Copy link
Contributor

cmainas commented Feb 20, 2026

To fix the linter issue with spelling, you will need to add the word userns in https://github.com/urunc-dev/urunc/blob/main/.github/linters/urunc-dict.txt

@sidneychang
Copy link
Contributor Author

Hi @cmainas,

The other CI checks look good, but cspell was failing due to userns being flagged as an unknown word, so I’ve added it to urunc-dict.txt.

There’s also a failure in TestNerdctl/Hvt-mirage-net:
Failed test: ping failed: failed to create Pinger: addr cannot be empty
I’m not sure why this is happening, as this PR doesn’t modify any network-related logic. Could we try re-running the CI to see if it was transient?

@urunc-bot urunc-bot bot changed the base branch from main to main-pr465 February 20, 2026 16:16
Copy link
Contributor

@cmainas cmainas left a comment

Choose a reason for hiding this comment

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

Thank you @sidneychang for this addition!

@cmainas cmainas merged commit 18845e0 into urunc-dev:main-pr465 Feb 20, 2026
34 checks passed
github-actions bot pushed a commit that referenced this pull request Feb 20, 2026
PR: #465
Mirror runc behavior: when running as non-root (or root inside a user
namespace), honor $XDG_RUNTIME_DIR for the default runtime root so
callers do not need to pass --root.
Signed-off-by: sidneychang <2190206983@qq.com>
Reviewed-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Approved-by: Charalampos Mainas <cmainas@nubificus.co.uk>
urunc-bot bot pushed a commit that referenced this pull request Feb 20, 2026
PR: #465
Mirror runc behavior: when running as non-root (or root inside a user
namespace), honor $XDG_RUNTIME_DIR for the default runtime root so
callers do not need to pass --root.
Signed-off-by: sidneychang <2190206983@qq.com>
Reviewed-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Approved-by: Charalampos Mainas <cmainas@nubificus.co.uk>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Check integration of urunc with podman

2 participants

Comments