fix: chmod the owned /etc/hosts world-readable for non-root images#81
Merged
Conversation
mktemp creates the script-owned hosts file 0600, owned by the invoking user. Bind-mounted read-only as /etc/hosts, a service image running as a non-root user cannot read it: glibc skips /etc/hosts, falls through to DNS, and pod-internal name resolution fails with "could not translate host name: Temporary failure in name resolution". Root-user images were unaffected, which is why the 0.4.0 owned-/etc/hosts mechanism passed validation. Emit chmod 644 on the hosts file after writing it and before the first podman run mounts it. The file holds only hostname/extra_hosts lines, so world-readable is correct. Reproduced and fixed against real Podman 5.8.1.
ty 0.0.62 tightened sorted()'s bound: set(mapping) over an untyped compose mapping infers set[object], which does not satisfy SupportsRichComparison, so the 11 unsupported-key error paths that do sorted(set(mapping) - KNOWN) failed the type gate. require_string_keys already proves every key is str; have it return the keys as set[str] so each check builds on a statically sortable type (require_string_keys(...) - KNOWN) and drops a redundant re-iteration. No runtime behavior change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A 0.4.0-generated script writes the pod's owned
/etc/hostsviahostsfile=$(mktemp)— mode 0600, owned by the invoking user — and bind-mounts it read-only into every container. A service image that runs as a non-root user cannot read a 0600 root-owned file, so glibc skips/etc/hosts, falls through to DNS, and pod-internal name resolution fails:Root-user images were unaffected, which is why the 0.4.0 owned-
/etc/hostsmechanism passed validation — every probe ran as root. This bites any real-world image with aUSERdirective (the common case in corporate CI).Fix
Emit
chmod 644 "$hostsfile"immediately after theprintfthat writes the file and before the firstpodman runmounts it. The file holds onlyhostname → 127.0.0.1andextra_hosts(hostname → ip) lines — nothing secret — so world-readable is correct.umaskcannot substitute:mktempforces 0600 regardless.Verification
quay.io/podman/stable:v5.8.1): a non-root member getscat: /etc/hosts: Permission denied+socket.gaierrorwithout the chmod; resolvesdb → 127.0.0.1with it.user: "1000"app that resolvesdbon 5.8.1.test_hosts_file_made_world_readable), then fix.just test-ci— 1402 passed, 100% coverage.just lint-ci— clean.Rationale:
planning/changes/2026-07-22.01-world-readable-hosts-file.md. Architecture promoted inarchitecture/supported-subset.md(owned-/etc/hostsbullet).Bundled: ty 0.0.62 lint fix (2nd commit)
CI resolves
tyfresh each run (uv.lock is git-ignored), and 0.0.62 tightenedsorted()'s bound so the 11 pre-existingsorted(set(mapping) - KNOWN)unsupported-key paths (set[object]is notSupportsRichComparison) broke lint — unrelated to the hosts fix but blocking every PR.require_string_keysalready proves keys arestr; it now returns them asset[str]so each check consumes a statically sortable set. No runtime behavior change.