containers / podman

Podman: A tool for managing OCI containers and pods.
https://podman.io
Apache License 2.0
23.25k stars 2.37k forks source link

run -P: TOCTOU in port allocation: bind: address already in use #19048

Open edsantiago opened 1 year ago

edsantiago commented 1 year ago

The local port allocated with run -P seems unsafe when multiple jobs start at once:

$ podman [options] run --name portcheck -dt -P --health-cmd curl -f http://localhost/ quay.io/libpod/alpine_nginx:latest
Error: rootlessport listen tcp 0.0.0.0:43185: bind: address already in use

And it's not just rootless:

# podman [options] run -dt -P --health-cmd curl -f http://localhost/ quay.io/libpod/alpine_nginx:latest
Error: cannot listen on the TCP port: listen tcp4 :42611: bind: address already in use

In both cases the ports had been grabbed by a different nginx test.

From my look last night I think this is a podman/rootlessport bug, not something that can be fixed in e2e tests. So even though this is infrequent, it's something that can probably manifest in the field.

Luap99 commented 1 year ago

You are correct this is a race within podman. The current flow is allocate the ports once on container creation which obviously leads to race conditions with other processes. It is a long standing issue: https://github.com/containers/podman/issues/10205#issuecomment-1010055023

github-actions[bot] commented 1 year ago

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

github-actions[bot] commented 1 year ago

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