podman icon indicating copy to clipboard operation
podman copied to clipboard

`createContainer` hook cannot be run with `--userns=auto` or `--userns=nomap`

Open hvenev-insait opened this issue 1 year ago • 6 comments

Issue Description

When Podman creates a container in a user namespace where the current user is not mapped, any OCI hook at the stage createContainer will fail to run.

The issue affects both privileged and rootless podman.

$ cat hooks/hook.json
{
	"version": "1.0.0",
	"hook": {
		"path": "/bin/true"
	},
	"when": {"always": true},
	"stages": ["createContainer"]
}
$ podman --hooks-dir=hooks run --rm --userns=nomap fedora:latest echo hi
Error: OCI runtime error: crun: {"msg":"error executing hook `/bin/true` (exit code: 1)","level":"error","time":"2025-12-01T14:04:03.199675Z"}
$ podman --hooks-dir=hooks run --rm --userns=host fedora:latest echo hi
hi
$ podman --hooks-dir=hooks run --rm --userns=keep-id fedora:latest echo hi
hi
$ sudo podman --hooks-dir=hooks run --rm --userns=auto fedora:latest echo hi
Error: OCI runtime error: crun: {"msg":"error executing hook `/bin/true` (exit code: 1)","level":"error","time":"2025-12-01T14:04:09.519875Z"}
$ sudo podman --hooks-dir=hooks run --rm --userns=host fedora:latest echo hi
hi

Steps to reproduce the issue

Steps to reproduce the issue

  1. Create a hook as described above.
  2. Try to run a container with --userns=nomap or --userns=auto.
  3. Observe that it fails to start.

Describe the results you received

Error: OCI runtime error: crun: {"msg":"error executing hook `/bin/true` (exit code: 1)","level":"error","time":"2025-12-01T14:04:09.519875Z"}

Describe the results you expected

The hook (/bin/true) runs successfully.

podman info output

host:
  arch: amd64
  buildahVersion: 1.42.0
  cgroupControllers:
  - memory
  - pids
  cgroupManager: systemd
  cgroupVersion: v2
  conmon:
    package: conmon-2.1.13-1.fc42.x86_64
    path: /usr/bin/conmon
    version: 'conmon version 2.1.13, commit: '
  cpuUtilization:
    idlePercent: 99.01
    systemPercent: 0.12
    userPercent: 0.87
  cpus: 32
  databaseBackend: sqlite
  distribution:
    distribution: fedora
    version: "42"
  eventLogger: journald
  freeLocks: 2044
  hostname: iws.m.venev.name
  idMappings:
    gidmap:
    - container_id: 0
      host_id: 10000
      size: 1
    - container_id: 1
      host_id: 100000
      size: 65536
    uidmap:
    - container_id: 0
      host_id: 10000
      size: 1
    - container_id: 1
      host_id: 100000
      size: 65536
  kernel: 6.17.4-1-hvenev-baremetal.x86_64
  linkmode: dynamic
  logDriver: none
  memFree: 21672517632
  memTotal: 66080198656
  networkBackend: netavark
  networkBackendInfo:
    backend: netavark
    dns:
      package: aardvark-dns-1.17.0-1.fc42.x86_64
      path: /usr/libexec/podman/aardvark-dns
      version: aardvark-dns 1.17.0
    package: Unknown
    path: /etc/containers/helper-wrappers/netavark
    version: netavark 1.17.0
  ociRuntime:
    name: crun
    package: crun-1.25.1-1.fc42.x86_64
    path: /usr/bin/crun
    version: |-
      crun version 1.25.1
      commit: 156ae065d4a322d149c7307034f98d9637aa92a2
      rundir: /run/user/10000/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-0^20250919.g623dbf6-1.fc42.x86_64
    version: |
      pasta 0^20250919.g623dbf6-1.fc42.x86_64
      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/10000/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: false
  serviceIsRemote: false
  slirp4netns:
    executable: ""
    package: ""
    version: ""
  swapFree: 77824
  swapTotal: 8006918144
  uptime: 868h 37m 13.00s (Approximately 36.17 days)
  variant: ""
plugins:
  authorization: null
  log:
  - k8s-file
  - none
  - passthrough
  - journald
  network:
  - bridge
  - macvlan
  - ipvlan
  volume:
  - local
registries:
  insait.ai:
    Blocked: false
    Insecure: false
    Location: gateway.insait.ai
    MirrorByDigestOnly: false
    Mirrors: null
    Prefix: insait.ai
    PullFromMirror: ""
store:
  configFile: /home/hristo/.config/containers/storage.conf
  containerStore:
    number: 2
    paused: 0
    running: 2
    stopped: 0
  graphDriverName: overlay
  graphOptions:
    overlay.mountopt: nodev,index=off,xino=off
  graphRoot: /home/hristo/.local/share/containers/storage
  graphRootAllocated: 2044270215168
  graphRootUsed: 1496688406528
  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: 71
  runRoot: /run/user/10000/containers
  transientStore: true
  volumePath: /home/hristo/.local/share/containers/storage/volumes
version:
  APIVersion: 5.7.0
  BuildOrigin: Fedora Project
  Built: 1762819200
  BuiltTime: Tue Nov 11 02:00:00 2025
  GitCommit: 0370128fc8dcae93533334324ef838db8f8da8cb
  GoVersion: go1.24.9
  Os: linux
  OsArch: linux/amd64
  Version: 5.7.0

Podman in a container

No

Privileged Or Rootless

None

Upstream Latest Release

Yes

Additional environment details

No response

Additional information

No response

hvenev-insait avatar Dec 01 '25 14:12 hvenev-insait

A friendly reminder that this issue had no activity for 30 days.

github-actions[bot] avatar Jan 01 '26 00:01 github-actions[bot]

Happy new year!

The issue is still present in Podman 5.7.1.

hvenev-insait avatar Jan 01 '26 01:01 hvenev-insait

I stumbled upon something similar earlier this week, and my hunch is that this is an crun issue. AFAICT, createContainer gets passed along to the OCI runtime, and after precursory look at the code, I don't see anything that jumps out to me as Podman doing something wrong. When I get a free sec, I'm curious to see if the same thing happens with runc.

JCBird1012 avatar Feb 13 '26 19:02 JCBird1012

[podman@8ed1b00431f3 ~]$ cat hooks/hooks.json
{
	"version": "1.0.0",
	"hook": {
		"path": "/bin/true"
	},
	"when": {"always": true},
	"stages": ["createContainer"]
}

With runc -

[podman@8ed1b00431f3 ~]$ podman system info | grep runc
    name: runc
    package: runc-1.4.0-1
    path: /usr/bin/runc
      runc version 1.4.0
[podman@8ed1b00431f3 ~]$ podman --hooks-dir=hooks run --rm --userns=nomap alpine:edge echo hi
hi
[podman@8ed1b00431f3 ~]$ podman --hooks-dir=hooks run --rm --userns=host alpine:edge echo hi
hi
[podman@8ed1b00431f3 ~]$ podman --hooks-dir=hooks run --rm --userns=keep-id alpine:edge echo hi
hi

With crun -

[podman@8ed1b00431f3 ~]$ podman system info | grep crun
    name: crun
    package: crun-1.26-3
    path: /usr/bin/crun
      crun version 1.26
      rundir: /tmp/storage-run-1000/crun
[podman@8ed1b00431f3 ~]$ podman --hooks-dir=hooks run --rm --userns=nomap alpine:edge echo hi
Error: OCI runtime error: crun: {"msg":"error executing hook `/bin/true` (exit code: 1)","level":"error","time":"2026-02-13T20:15:03.888165Z"}
[podman@8ed1b00431f3 ~]$ podman --hooks-dir=hooks run --rm --userns=host alpine:edge echo hi
hi

JCBird1012 avatar Feb 13 '26 20:02 JCBird1012

https://github.com/containers/crun/issues/1673 seems closely related.

Admittedly, I'm spitballing on what little I know about the spec - but from a quick glance, it seems underspecified here (around implicit hook working-directory behavior), so I don’t think this is a straightforward spec violation either way on crun's part or runc's part, but I don't know enough to say for sure.

I think a safer/less surprising behavior would be:

  • keep a strict failure when cwd is explicitly configured, but inaccessible, and
  • avoid forced implicit chdirfor hooks when no cwd is explicitly requested

If cwd is implicit and a hook needs directory access, failure should happen when the hook actually touches that path. The current chdir before behavior causes an earlier failure, even for hooks that wouldn’t have needed to touch that directory at all.

(sorry, all of that commentary would make more sense over there than here, but I wanted to get it out of my head)

@hvenev-insait - I'd recommend bringing this issue up over in crun - you might get some more traction there.

JCBird1012 avatar Feb 14 '26 21:02 JCBird1012

I'm experiencing the same error with Podman 5.4.2, in Debian 13, when using rootless containers (I've not tested this issue with rootful containers yet).

In my case, I'm not using the --userns option but the --uidmap and --gidmap options. The reason is that I prefer to have a more precise control over the permissions in my shared volumes. Anyway, the workaround seems to be the same in both cases: if you map the current user in the host to any user within the container, the error goes away.

For example, if your UID in the host is 1000, you can map it to the user 2000 in the container by passing the option --userns='auto:uidmapping=2000:0:1,gidmapping=2000:0:1 (for rootless containers, 0 in the host UID is really an intermediate UID that equals the host UID 1000) .

The idea is to choose, for the container-side, a dummy UID that is:

  1. Unprivileged (so not 0).
  2. Different from the UID used to run the application.
  3. Different from the dummy UID used in other container.

That way, if the app is compromised and the attacker escapes the namespace, your user in the host will still be safe (as long as there isn't ALSO a privilege escalation in the container and the attacker manages to run whatever as the dummy UID).

negora avatar Apr 24 '26 11:04 negora