podman icon indicating copy to clipboard operation
podman copied to clipboard

Podman storage gets corrupted when pulling an image

Open dozenposture opened this issue 1 year ago • 13 comments

Issue Description

I'm trying to get an image to run with Podman, defined as a quadlet file. systemctl --user start authentiek-server.service fails with exit code 125:

Sep 10 09:49:52 host authentik-server[711811]: time="2025-09-10T09:49:52+02:00" level=error msg="Image ghcr.io/goauthentik/server:2025.4.4 exists in local storage but may be corrupted (remove the image to resolve the issue): loading primary layer store data: error removing stale temp dir /home/podman/.local/share/containers/storage/overlay/tempdirs/temp-dir-1618383482: unlinkat /home/podman/.local/share/containers/storage/overlay/tempdirs/temp-dir-1618383482/1-c7ce558278b619ac541fc61a1267e58df72ccf8e624c87002b313a8a65f17207: directory not empty"
Sep 10 09:49:52 host authentik-server[711811]: Trying to pull ghcr.io/goauthentik/server:2025.4.4...
Sep 10 09:49:52 host authentik-server[711811]: Pulling image //ghcr.io/goauthentik/server:2025.4.4 inside systemd: setting pull timeout to 5m0s
Sep 10 09:49:56 host authentik-server[711811]: Getting image source signatures
Sep 10 09:49:56 host authentik-server[711811]: Copying blob sha256:15b2a750b48ae57cf27d2f075e6375860496c115f0e61bed5c7b97d3a1d54c0e
...
Sep 10 09:49:56 host authentik-server[711811]: Copying blob sha256:648fcb0e95e6aacd293cb96fc78f7feedd197e41e792f52bac248272ef46b0ce
Sep 10 09:49:56 host authentik-server[711811]: Error: unable to copy from source docker://ghcr.io/goauthentik/server:2025.4.4: copying system image from manifest list: trying to reuse blob sha256:61320b01ae5e0798393ef25f2dc72faf43703e60ba089b07d7170acbabbf8f62 at destination: looking for layers with digest "sha256:61320b01ae5e0798393ef25f2dc72faf43703e60ba089b07d7170acbabbf8f62": loading primary layer store data: error removing stale temp dir /home/podman/.local/share/containers/storage/overlay/tempdirs/temp-dir-1618383482: unlinkat /home/podman/.local/share/containers/storage/overlay/tempdirs/temp-dir-1618383482/1-c7ce558278b619ac541fc61a1267e58df72ccf8e624c87002b313a8a65f17207: directory not empty
Sep 10 09:49:56 host podman[711811]: 2025-09-10 09:49:56.132091414 +0200 CEST m=+3.537743714 image pull-error  ghcr.io/goauthentik/server:2025.4.4 unable to copy from source docker://ghcr.io/goauthentik/server:2025.4.4: copying system image from manifest list: trying to reuse blob sha256:61320b01ae5e0798393ef25f2dc72faf43703e60ba089b07d7170acbabbf8f62 at destination: looking for layers with digest "sha256:61320b01ae5e0798393ef25f2dc72faf43703e60ba089b07d7170acbabbf8f62": loading primary layer store data: error removing stale temp dir /home/podman/.local/share/containers/storage/overlay/tempdirs/temp-dir-1618383482: unlinkat /home/podman/.local/share/containers/storage/overlay/tempdirs/temp-dir-1618383482/1-c7ce558278b619ac541fc61a1267e58df72ccf8e624c87002b313a8a65f17207: directory not empty
Sep 10 09:49:56 host systemd[1170]: authentik-server.service: Main process exited, code=exited, status=125/n/a

I don't think is an issue with that image in particular, I've tried a more recent one (ghcr.io/goauthentik/server:2025.8.1) and I get the same issue if I try to run ghcr.io/haveagitgat/tdarr:latest.

The issue appears only when I execute the command systemctl --user start authentiek-server.service. If I run the command podman pull ghcr.io/goauthentik/server:2025.4.4 I don't get any issue but the container fails to start with the systemctl command anyway:

podman@host:~> podman pull ghcr.io/goauthentik/server:2025.4.4
Trying to pull ghcr.io/goauthentik/server:2025.4.4...
Getting image source signatures
Copying blob 15b2a750b48a skipped: already exists
...
Copying config 96abf2164c done   |
Writing manifest to image destination
96abf2164c7947bdbb3a90ca2087322fdf2979e8a29b129ada3aae08a8e9cfba

I've already tried to delete the image and pulling again, same result.

Steps to reproduce the issue

Steps to reproduce the issue

  1. Try to run ghcr.io/goauthentik/server:2025.4.4 or ghcr.io/haveagitgat/tdarr:latest
  2. Issue pulling the image when starting the container with systemctl --user command

Describe the results you received

podman@host:~> systemctl --user restart authentik-server.service
Job for authentik-server.service failed because a timeout was exceeded.
See "systemctl --user status authentik-server.service" and "journalctl --user -xeu authentik-server.service" for details.

Describe the results you expected

To have a running container from the given image

podman info output

podman@host:~> podman info
host:
  arch: amd64
  buildahVersion: 1.41.3
  cgroupControllers:
  - pids
  cgroupManager: systemd
  cgroupVersion: v2
  conmon:
    package: conmon-2.1.13-1.2.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.1.13, commit: unknown'
  cpuUtilization:
    idlePercent: 86.75
    systemPercent: 5.57
    userPercent: 7.68
  cpus: 4
  databaseBackend: sqlite
  distribution:
    distribution: opensuse-tumbleweed
    version: "20250903"
  eventLogger: journald
  freeLocks: 2004
  hostname: host
  idMappings:
    gidmap:
    - container_id: 0
      host_id: 1002
      size: 1
    - container_id: 1
      host_id: 231072
      size: 65536
    uidmap:
    - container_id: 0
      host_id: 1002
      size: 1
    - container_id: 1
      host_id: 231072
      size: 65536
  kernel: 6.16.3-1-default
  linkmode: dynamic
  logDriver: journald
  memFree: 483172352
  memTotal: 7982845952
  networkBackend: netavark
  networkBackendInfo:
    backend: netavark
    dns:
      package: aardvark-dns-1.16.0-1.1.x86_64
      path: /usr/libexec/podman/aardvark-dns
      version: aardvark-dns 1.16.0
    package: netavark-1.15.2-1.1.x86_64
    path: /usr/libexec/podman/netavark
    version: netavark 1.15.2
  ociRuntime:
    name: crun
    package: crun-1.22-1.1.x86_64
    path: /usr/bin/crun
    version: |-
      crun version 1.22
      commit: 4de19b63a85efd9ea8503452179c371181750130
      rundir: /run/user/1002/crun
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +LIBKRUN +WASM:wasmedge +YAJL
  os: linux
  pasta:
    executable: /usr/bin/pasta
    package: passt-20250611.0293c6f-3.2.x86_64
    version: |
      pasta 20250611.0293c6f-3.2
      Copyright Red Hat
      GNU General Public License, version 2 or later
        <https://www.gnu.org/licenses/old-licenses/gpl-2.0.html>
      This is free software: you are free to change and redistribute it.
      There is NO WARRANTY, to the extent permitted by law.
  remoteSocket:
    exists: true
    path: /run/user/1002/podman/podman.sock
  rootlessNetworkCmd: pasta
  security:
    apparmorEnabled: false
    capabilities: CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
    rootless: true
    seccompEnabled: true
    seccompProfilePath: /usr/share/containers/seccomp.json
    selinuxEnabled: true
  serviceIsRemote: false
  slirp4netns:
    executable: ""
    package: ""
    version: ""
  swapFree: 5704228864
  swapTotal: 7982841856
  uptime: 11h 10m 46.00s (Approximately 0.46 days)
  variant: ""
plugins:
  authorization: null
  log:
  - k8s-file
  - none
  - passthrough
  - journald
  network:
  - bridge
  - macvlan
  - ipvlan
  volume:
  - local
registries:
  search:
  - registry.opensuse.org
  - registry.suse.com
  - docker.io
store:
  configFile: /home/podman/.config/containers/storage.conf
  containerStore:
    number: 34
    paused: 0
    running: 34
    stopped: 0
  graphDriverName: overlay
  graphOptions: {}
  graphRoot: /home/podman/.local/share/containers/storage
  graphRootAllocated: 255522574336
  graphRootUsed: 89003753472
  graphStatus:
    Backing Filesystem: btrfs
    Native Overlay Diff: "true"
    Supports d_type: "true"
    Supports shifting: "false"
    Supports volatile: "true"
    Using metacopy: "false"
  imageCopyTmpDir: /var/tmp
  imageStore:
    number: 31
  runRoot: /run/user/1002/containers
  transientStore: false
  volumePath: /home/podman/.local/share/containers/storage/volumes
version:
  APIVersion: 5.6.0
  Built: 1756711675
  BuiltTime: Mon Sep  1 09:27:55 2025
  GitCommit: ""
  GoVersion: go1.24.6
  Os: linux
  OsArch: linux/amd64
  Version: 5.6.0

Podman in a container

No

Privileged Or Rootless

Rootless

Upstream Latest Release

Yes

Additional environment details

Additional environment details

Additional information

Additional information like issue happens only occasionally or issue happens with a particular architecture or on a particular setting

dozenposture avatar Sep 10 '25 08:09 dozenposture

would be good to know what authentiek-server.service does and how it is defined.

Do you have any SELinux denial message in the audit log?

giuseppe avatar Sep 10 '25 08:09 giuseppe

Thank you @giuseppe for your quick reply. Regarding the SELinux message, I see nothing related (but interesting to see messages like this...):

host~ # ausearch -m avc --start 09/09/2025
----
time->Tue Sep  9 23:08:15 2025
type=AVC msg=audit(1757452095.913:126): avc:  denied  { setattr } for  pid=9326 comm="chown" name="" dev="pipefs" ino=48316 scontext=system_u:system_r:container_t:s0:c649,c786 tcontext=unconfined_u:unconfined_r:container_runtime_t:s0 tclass=fifo_file permissive=0
----
time->Tue Sep  9 23:08:15 2025
type=AVC msg=audit(1757452095.913:127): avc:  denied  { setattr } for  pid=9326 comm="chown" name="" dev="pipefs" ino=48317 scontext=system_u:system_r:container_t:s0:c649,c786 tcontext=unconfined_u:unconfined_r:container_runtime_t:s0 tclass=fifo_file permissive=0

This is the quadlet definition:

[Unit]
Description=Authenitk
After=local-fs.target custom-app-network.service

[Container]
Image=ghcr.io/goauthentik/server:2025.4.4
ContainerName=authentik-server
HostName=authentik-server.internal
AutoUpdate=registry
Environment=AUTHENTIK_POSTGRESQL__HOST=host.containers.internal:5432
Environment=AUTHENTIK_POSTGRESQL__NAME=authentik
Environment=AUTHENTIK_POSTGRESQL__PASSWORD=password
Environment=AUTHENTIK_POSTGRESQL__USER=authentik
Environment=AUTHENTIK_REDIS__HOST=host.containers.internal:6379
Environment=AUTHENTIK_SECRET_KEY=5QK7auACOH1h6adEzmR7PErDp0MsdobipPAYGCNTN6lH8E3M9Wc5g8rb+xwJf1ccP9CUfwndn9CvYZFO
Network=custom-app.network
PublishPort=9000:9000
PublishPort=9443:9443
User=0
UserNS=keep-id
Volume=${CONFIG_DIR}/authentik/media:/media:Z
Volume=${CONFIG_DIR}/authentik/custom-templates:/templates:Z

# Health Checks
HealthStartPeriod=5m
HealthCmd=CMD-SHELL curl -f --insecure http://localhost:8080 || exit 1
HealthInterval=30s
HealthRetries=2
HealthOnFailure=kill

[Service]
Restart=on-failure

[Install]
WantedBy=multi-user.target default.target

dozenposture avatar Sep 10 '25 08:09 dozenposture

would it be possible to try again disabling temporarily selinux (setenforce 0)?

It might be a dontaudit rule, and to see it in the logs, you first need to run semodule -DB

giuseppe avatar Sep 10 '25 08:09 giuseppe

I ran setenforce 0 and then systemctl --user restart authentik-server, I get the same issue.

dozenposture avatar Sep 10 '25 08:09 dozenposture

@giuseppe I just tried the same quadlet file in rootful, it works without any problem.

dozenposture avatar Sep 10 '25 09:09 dozenposture

Can you run podman system check and maybe with the --repair option to see if it fixes the storage.

Luap99 avatar Sep 10 '25 09:09 Luap99

Also to ask the obvious what is in /home/podman/.local/share/containers/storage/overlay/tempdirs/temp-dir-1618383482/1-c7ce558278b619ac541fc61a1267e58df72ccf8e624c87002b313a8a65f17207? Can you remove the dir yourselves.

AFAIK the directory not empty error should only happen if there are still files in it but in we use the golang function RemoveAll() which should delete it recursively. So either something adds file to it while it tries to get deletes (unlikely) or there is some other error condition for ENOTEMPTY that I am unaware of.

Luap99 avatar Sep 10 '25 10:09 Luap99

@Luap99 inside that directory, there was an empty directory called merged. I removed it and restarted the container, same issue.

I think the issue might be else where though: as a test I disabled all quadlets and rebooted the system. I then deleted directory ~/.local/share/containers/storage. I started a single container (postgres pgvector v16) and run podman system check, The latter already returns error like this:

Damaged layer c859be561ea8e463cec133c916779079a09f601334cfdeabd8c6396863ef238a:
138 errors occurred:
	* layer c859be561ea8e463cec133c916779079a09f601334cfdeabd8c6396863ef238a: /etc(mtime:0x68ba35c1→0x68c151ce), layer content modified
	* layer c859be561ea8e463cec133c916779079a09f601334cfdeabd8c6396863ef238a: /etc/alternatives(mtime:0x689e2890→0x68c151cd), layer content modified
	* layer c859be561ea8e463cec133c916779079a09f601334cfdeabd8c6396863ef238a: /etc/dpkg(mtime:0x68ba3599→0x68c151cd), layer content modified

That container running, doesn't seem to have any issue though.

dozenposture avatar Sep 10 '25 10:09 dozenposture

it could be that podman inside the systemd service gets a different run dir so that it doesn't see the pause process that is already running and creates a new user+mount namespace and it messes up with the mounts.

Do you have any custom configuration for systemd to harden services? Anything like private mounts?

giuseppe avatar Sep 10 '25 13:09 giuseppe

I'm not sure if I have any custom configuration for systemd to be honest. is there any command I can run so I can provide the output?

dozenposture avatar Sep 10 '25 14:09 dozenposture

@giuseppe and @Luap99, I think I've found the issue: the container starts to run immediately if I drop UserNS=keep-id from my quadlet file. As soon as I define UserNS=keep-id, I get the issue subject of this thread. How this is related to the given image error, I have no idea.

dozenposture avatar Sep 10 '25 14:09 dozenposture

How large is the image? As rootless UserNS=keep-id has to copy + chown the entire image so that can take a while and maybe you run itno the systemd start timeout and then podman was killed in a bad state?

That would match the error message systemd gives you.

failed because a timeout was exceeded.

Try setting a high TimeoutStartSec= value under the [Service] section.

Luap99 avatar Sep 10 '25 17:09 Luap99

Hi both, thank you so much for your quick replies and help!

@Luap99 I think that was the issue. Being the image fairly large (1.31GB) I think I was hitting a timeout. Adding TimeoutStartSec=9000 to the [Service] section, did the trick. User mapped, no timeout issues.

Thanks again!

dozenposture avatar Sep 11 '25 12:09 dozenposture