You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 95be192
Browse filesBrowse the repository at this point in the historyBrowse files
fix: world-readable owned /etc/hosts for non-root images (#81)
mktemp creates the script-owned /etc/hosts 0600; a non-root service image
could not read the bind-mounted file, so name resolution fell through to
DNS and failed ("could not translate host name: Temporary failure in name
resolution"). Emit chmod 644 on the hosts file so any container uid can read
it. Reproduced and fixed against real Podman 5.8.1.
Bundled: require_string_keys now returns the validated keys as set[str] so the
11 unsupported-key sorted() paths type-check under ty 0.0.62 (no behavior change).
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.
3
+
---
4
+
5
+
# Change: chmod the owned /etc/hosts world-readable
6
+
7
+
**Lane:** lightweight — ≲30 LOC net, ≤2 files, no new file, no public-API
8
+
change, a single straightforward test.
9
+
10
+
## Goal
11
+
12
+
Fix pod-internal name resolution for service images that run as a **non-root**
13
+
user. On Podman 5.x/6.x, a 0.4.0 script emits `hostsfile=$(mktemp)` — mode
14
+
`0600`, owned by the invoking user — and bind-mounts it read-only as
15
+
`/etc/hosts` into every container. A non-root process cannot read a `0600`
16
+
root-owned file, so glibc skips `/etc/hosts`, falls through to DNS, and every
17
+
lookup fails with `could not translate host name "db": Temporary failure in
18
+
name resolution`. Root-user images were unaffected, which is why the 0.4.0
19
+
mechanism passed validation (all probes ran as root).
20
+
21
+
## Approach
22
+
23
+
Emit one line, `chmod 644 "$hostsfile"`, immediately after the `printf` that
24
+
writes the file and before the first `podman run` mounts it. The file holds
25
+
only `hostname → 127.0.0.1` and `extra_hosts` (`hostname → ip`) lines — nothing
26
+
secret — so world-readable is correct. `umask` cannot substitute: `mktemp`
27
+
forces `0600` regardless. Truth home: `architecture/supported-subset.md`
28
+
(networking / owned-`/etc/hosts` bullet).
29
+
30
+
Reproduced on real Podman 5.8.1 (via `quay.io/podman/stable:v5.8.1`): a
31
+
non-root member gets `cat: /etc/hosts: Permission denied` and
32
+
`socket.gaierror` without the chmod; resolves `db → 127.0.0.1` with it.
33
+
34
+
## Files
35
+
36
+
-`compose2pod/emit.py` — append the `chmod 644 "$hostsfile"` line after the
37
+
hosts-file write.
38
+
-`tests/test_emit.py` — assert the chmod line is emitted, ordered after the
39
+
write and before the first `podman run`.
40
+
41
+
## Verification
42
+
43
+
-[x] Failing test first — `pytest -k test_hosts_file_made_world_readable`
44
+
fails: `assert 'chmod 644 "$hostsfile"' in lines`.
45
+
-[x] Apply the change.
46
+
-[x] Test passes.
47
+
-[x]`just test-ci` — 1402 passed, 100% coverage.
48
+
-[x]`just lint-ci` — clean.
49
+
-[x] End-to-end on Podman 5.8.1 — fixed-generator script runs a non-root app
0 commit comments