Restart-policy containers loop on "unable to apply apparmor profile" after reboot until the creating user logs in (OCI hook inherits the client's XDG_RUNTIME_DIR)
维护者通常 3 天内回复
评估
调研方向
Start by tracing withNerdctlOCIHook and the createRuntime hook's loadAppArmor() path, then inspect how the hook environment supplies XDG_RUNTIME_DIR to containerd's LoadDefaultProfile. Reproduce with the issue's restart-policy steps and an unset runtime directory. Done when rootful containers restart after reboot without the creating user logging in, with a regression test covering the missing runtime directory.
由索引模型根据 Issue 内容生成。
描述
Description
After a reboot, rootful containers with a restart policy loop on:
runc create failed: ... unable to apply apparmor profile: apparmor failed to apply profile: write /proc/self/attr/apparmor/exec: no such file or directory
They recover on their own as soon as the user who created them logs in.
Cause: withNerdctlOCIHook stores the client's whole os.Environ() as the hooks' env. The createRuntime hook's loadAppArmor() calls containerd's LoadDefaultProfile, which writes its temp file to os.CreateTemp(os.Getenv("XDG_RUNTIME_DIR"), ...). If the containers were created over SSH, that path is something like /run/user/0, which doesn't exist after boot until that user logs in. The load fails (logged only in oci-hook.createRuntime.log), and runc then fails with the error above:
failed to load AppArmor profile "nerdctl-default" error="open /run/user/4242/nerdctl-default3219038152: no such file or directory"
Steps to reproduce the issue
As root, with no other nerdctl containers restarting meanwhile:
nerdctl apparmor load
XDG_RUNTIME_DIR=/run/user/4242 nerdctl run -d --name aa-repro --restart=always alpine sleep infinity
echo -n nerdctl-default > /sys/kernel/security/apparmor/.remove # simulate reboot
kill -9 "$(nerdctl inspect aa-repro --format '{{.State.Pid}}')"
nerdctl logs aa-repro # fails every ~10 s
mkdir -m 700 /run/user/4242 # simulate login: container starts within seconds
Describe the results you received and expected
Expected: containers start after boot without anyone logging in. Possible fixes: don't put XDG_RUNTIME_DIR in the hook env (rootful), or fall back to os.TempDir() when it's missing.
Workaround: a oneshot systemd unit that runs nerdctl apparmor load, ordered Before=containerd.service.
What version of nerdctl are you using?
v2.3.5 (reproduced). Same code in v2.4.2.
Are you using a variant of nerdctl? (e.g., Rancher Desktop)
None
Host information
Debian 13, kernel 6.12.117, AppArmor 4.1.0, containerd v2.3.3, runc 1.5.1, rootful.
- 主要语言
- Go
- 星标
- 10.5k
- 派生
- 853
- 平均合并
- 6 天 14 小时
- 30 天内合并 PR
- 38
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
containerd/nerdctl 的其他 Issue
-
Test and examples: update wordpress images (to silence potential false security alerts)可能已有人在做 @Guurdeep 于 20 天前认领。 未关闭area/ci documentation priority/low
难度 2/5 1-3 小时 新手友好度 74/100
containerd/nerdctl#5283 · 2 条评论 ·
维护者通常 3 天内回复
-
`nerdctl kill` shouldn't set `containerd.io/restart.explicitly-stopped` label for non-stop signals可能重新可做 关联的 PR 已关闭且未合并。 未关闭bug
难度 2/5 1-3 小时 新手友好度 82/100
containerd/nerdctl#5171 · 3 条评论 ·
维护者通常 3 天内回复
-
area/project
难度 1/5 1 小时以内 新手友好度 25/100
containerd/nerdctl#5383 · 5 条评论 ·
维护者通常 3 天内回复
-
难度 4/5 3-5 天 新手友好度 45/100
containerd/nerdctl#5355 ·
维护者通常 3 天内回复
-
v2.4.3 planning未关闭area/project
难度 5/5 一周以上 新手友好度 12/100
containerd/nerdctl#5353 · 2 个 reaction ·
维护者通常 3 天内回复
查看 containerd/nerdctl 的全部 Issue
相似的 Issue
-
P3 tech debt
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
kind/feature needs-triage priority/unprioritized
难度 2/5 1-3 小时 新手友好度 75/100
NVIDIA/k8s-test-infra#1504 ·
维护者通常 1 天内回复
-
Area/Infrastructure Aspect/Infra Resources Type/Bug
难度 2/5 1-3 小时 新手友好度 78/100
wso2/agent-manager#2717 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 83/100
open-policy-agent/opa#9685 · 1 条评论 ·
维护者通常 1 天内回复