Skip to content

fix: drop the client's XDG_RUNTIME_DIR from rootful OCI hook env - #5380

Open
sapnasingh4852-source wants to merge 1 commit into
containerd:mainfrom
sapnasingh4852-source:fix/oci-hook-env-xdg-runtime-dir
Open

sapnasingh4852-source wants to merge 1 commit into
containerd:mainfrom
sapnasingh4852-source:fix/oci-hook-env-xdg-runtime-dir

Conversation

@sapnasingh4852-source

Copy link
Copy Markdown

What this does

Stops rootful OCI hooks from inheriting the client's XDG_RUNTIME_DIR.

withNerdctlOCIHook passes the whole os.Environ() to the hook. When the container is created over SSH, XDG_RUNTIME_DIR points at /run/user/<uid>. After a reboot that path does not exist until the user logs in, so containerd's LoadDefaultProfile cannot create its temp file, the createRuntime hook fails with unable to apply apparmor profile, and restart-policy containers loop until the user logs in.

The new ociHookEnv helper drops XDG_RUNTIME_DIR when not rootless, so the loader falls back to the system temp directory. Rootless containers keep the variable because the rootless runtime directory lives there. PATH=/usr/sbin:/sbin is still appended for iptables (#1536).

Test

TestOCIHookEnv asserts the variable is dropped for rootful, kept for rootless, and that the sbin PATH entry is present.

go test ./pkg/cmd/container/ -run TestOCIHookEnv -v
--- PASS: TestOCIHookEnv (0.00s)

I did not re-run the full reboot repro from #5377. The fix targets the failing line directly: with XDG_RUNTIME_DIR absent from the hook env, os.CreateTemp(os.Getenv("XDG_RUNTIME_DIR"), ...) uses the system temp directory, as the issue suggests.

Fixes #5377.

Signed-off-by: sapna singh sapnaghato4852@gmail.com

Rootful containers created over SSH inherit the client's XDG_RUNTIME_DIR.
After a reboot that path does not exist until the user logs in, so the
createRuntime hook's AppArmor loader fails to create its temp file and
restart-policy containers loop until the user logs in.

Rootless containers keep XDG_RUNTIME_DIR since the rootless runtime
directory lives there.

Signed-off-by: sapna singh <sapnaghato4852@gmail.com>
@AkihiroSuda

AkihiroSuda commented Nov 30, 2026 •

Copy link
Copy Markdown
Member

I did not re-run the full reboot repro from #5377.

Why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants