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)

Aperta
#5,377 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 3 giorni

@Shubhranshu153 ci sta già lavorando.

Dal 2/12/2026.

  • #5380 di @sapnasingh4852-source — chiusa senza merge

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
72/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
go
Ambito
backend, devops

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
Go
Stelle
10.5k
Fork
853
Merge medio
6g 14h
PR unite (30g)
38

Preparare l'ambiente

  • Include un Dockerfile o un file Docker Compose
  • Nessun modello di pull request
  • Nessuna guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di containerd/nerdctl

Tutte le issue di containerd/nerdctl

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.