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)

未关闭
#5,377 0 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 3 天内回复

@Shubhranshu153 已经在做这个了。

开始于 2026年12月2日。

  • #5380 来自 @sapnasingh4852-source —— 已关闭,未合并

评估

难度
3/5
预计耗时
1-2 天
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
go
领域
backend, devops

调研方向

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 内容生成。

描述

area/rootless bug
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 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

containerd/nerdctl 的其他 Issue

查看 containerd/nerdctl 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。