| summary | Generated scripts chmod the owned /etc/hosts to 644 so non-root service images can read it; without it name resolution fell through to DNS and failed. |
|---|
Lane: lightweight — ≲30 LOC net, ≤2 files, no new file, no public-API change, a single straightforward test.
Fix pod-internal name resolution for service images that run as a non-root
user. On Podman 5.x/6.x, a 0.4.0 script emits hostsfile=$(mktemp) — mode
0600, owned by the invoking user — and bind-mounts it read-only as
/etc/hosts into every container. A non-root process cannot read a 0600
root-owned file, so glibc skips /etc/hosts, falls through to DNS, and every
lookup fails with could not translate host name "db": Temporary failure in name resolution. Root-user images were unaffected, which is why the 0.4.0
mechanism passed validation (all probes ran as root).
Emit one line, chmod 644 "$hostsfile", immediately after the printf that
writes the file and before the first podman run mounts it. The file holds
only hostname → 127.0.0.1 and extra_hosts (hostname → ip) lines — nothing
secret — so world-readable is correct. umask cannot substitute: mktemp
forces 0600 regardless. Truth home: architecture/supported-subset.md
(networking / owned-/etc/hosts bullet).
Reproduced on real Podman 5.8.1 (via quay.io/podman/stable:v5.8.1): a
non-root member gets cat: /etc/hosts: Permission denied and
socket.gaierror without the chmod; resolves db → 127.0.0.1 with it.
compose2pod/emit.py— append thechmod 644 "$hostsfile"line after the hosts-file write.tests/test_emit.py— assert the chmod line is emitted, ordered after the write and before the firstpodman run.
- Failing test first —
pytest -k test_hosts_file_made_world_readablefails:assert 'chmod 644 "$hostsfile"' in lines. - Apply the change.
- Test passes.
-
just test-ci— 1402 passed, 100% coverage. -
just lint-ci— clean. - End-to-end on Podman 5.8.1 — fixed-generator script runs a non-root app
that resolves
db.