Skip to content

fix(docker): ship /etc/passwd and /etc/group as regular files - #1347

Merged
kalbasit merged 3 commits into
mainfrom
user/wnasreddine/fix-docker-etc-passwd
Jun 7, 2026
Merged

kalbasit merged 3 commits into
mainfrom
user/wnasreddine/fix-docker-etc-passwd

Conversation

@kalbasit

@kalbasit kalbasit commented Jun 7, 2026

Copy link
Copy Markdown
Owner

Summary

The image added /etc/passwd and /etc/group via a buildEnv, which makes them absolute symlinks into the nix store (/etc/passwd -> /nix/store/…-passwd/etc/passwd). Recent containerd securejoins etc/passwd during container creation and rejects the absolute symlink as escaping the rootfs, so every ncps pod fails to start:

failed to create containerd container: … openat etc/passwd: path escapes from parent

This is a latent production failure on recent k8s/containerd (reproduced on kindest/node:v1.35.0), and it blocked the entire k8s-tests Kind suite.

Fix

Materialize /etc/passwd and /etc/group as real files in fakeRootCommands (re-materializing the read-only store-symlinked /etc as a writable real directory first), with identical content (root + ncps uid/gid 1000). Adds a checks.docker-image-etc-files regression guard asserting both are regular files (not symlinks).

OpenSpec change: fix-docker-etc-passwd (new capability container-image-etc-files).

Test plan

  • checks.docker-image-etc-files builds green (both are regular files)
  • Before/after on Kind: old (symlinked) image → CreateContainerError with the exact error; fixed image → pod Completed
  • disallowedRequisites (no shell/coreutils) still holds; task fmt/lint clean

@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Jun 7, 2026
@coderabbitai

coderabbitai Bot commented Jun 7, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Summary by CodeRabbit

  • Bug Fixes

    • Prevented container startup failures on strict runtimes by ensuring /etc/passwd and /etc/group are materialized as regular files (not symlinks) with preserved root and ncps entries.
  • Tests

    • Added an automated packaging check that inspects built images and asserts those paths are regular files containing the expected entries.
  • Documentation

    • Added spec, design, proposal, and task docs describing the issue, validation scenarios, rollout plan, and trade-offs.

Walkthrough

Rematerialize /etc/passwd and /etc/group as regular files in the Docker image (instead of Nix-store symlinks), add a Nix check that replays image layers and enforces both files are regular, and add OpenSpec docs recording the requirement and validation.

Changes

Docker Image /etc Files Fix

Layer / File(s) Summary
Docker package /etc files materialization
nix/packages/docker.nix
Removed /etc/passwd and /etc/group from imageContents buildEnv and added fakeRootCommands that rematerialize /etc and write regular /etc/passwd and /etc/group with root and ncps uid/gid entries at image-build time.
Docker image regression check
nix/checks/flake-module.nix
Added docker-image-etc-files derivation that extracts the built Docker tar, replays manifest.json layers with OCI whiteout semantics, computes final state for /etc/passwd and /etc/group, and fails if either is not a regular file.
OpenSpec specifications and documentation
openspec/specs/container-image-etc-files/spec.md, openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/*
Added spec, design, proposal, and task documents requiring /etc/passwd and /etc/group to be regular files containing root (0) and ncps (1000) entries, and documenting regression validation steps and results.

Sequence Diagram(s)

sequenceDiagram
  participant BuildEnv
  participant FakeRootCommands
  participant ImageFS
  BuildEnv->>ImageFS: earlier flow produced /etc symlinks into /nix/store
  FakeRootCommands->>ImageFS: detect /etc symlink, copy contents and rematerialize /etc as directory
  FakeRootCommands->>ImageFS: write /etc/passwd (regular file with root + ncps uids)
  FakeRootCommands->>ImageFS: write /etc/group (regular file with root + ncps gids)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • kalbasit/ncps#1293: Related CI change that enumerates and runs checks.<system>.<name>; will exercise the new checks.docker-image-etc-files.
  • kalbasit/ncps#1249: Related restructuring of the checks attrset enumeration/topology that couples with the new check.

Suggested labels

size:M, merge-stack

"I'm a rabbit in the build, nibbling at symlink woes,
I stitch /etc from bits where fakeroot wind blows.
Passwd and group now sleep as plain files tight,
Pods wake calm and start — hop, everything's right. 🐇"

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: materializing /etc/passwd and /etc/group as regular files in the Docker image instead of symlinks.
Description check ✅ Passed The description clearly relates to the changeset, explaining the production problem with absolute symlinks, the fix implementation, and test coverage.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request resolves an issue where /etc/passwd and /etc/group are created as absolute symlinks in the built Docker image, causing container creation failures on strict runtimes like containerd. The changes materialize these files as regular files via fakeRootCommands and introduce a regression check to verify their file types. The review feedback highlights two important improvements: first, a safety concern in the shell script where an empty readlink output could lead to copying the entire root filesystem; second, a recommendation to filter and sort the files in the regression check to prevent running tar on non-tar files and to ensure deterministic behavior.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread nix/packages/docker.nix Resolved
Comment thread nix/checks/flake-module.nix Resolved

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@nix/checks/flake-module.nix`:
- Around line 271-285: The current check collects all file listings then uses
`find img -type f` + `tail -1` to decide the final state of /etc/passwd and
/etc/group, which ignores layer ordering and whiteouts; change the logic to read
`manifest.json`'s `Layers` array and process each listed layer in manifest
order, parsing each layer tar in turn and applying whiteout semantics (e.g.,
files like `etc/.wh.passwd` or `etc/.wh.*` remove prior entries) to build the
effective final entry for /etc/passwd and /etc/group instead of using the
aggregated `listings.txt` + `tail -1`; update the code points that
create/consume `listings.txt` and the `for name in passwd group` block to
consult the computed final state (honoring whiteouts) and then assert
regular-file vs missing accordingly.

In `@openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/design.md`:
- Around line 20-33: The design doc mentions using extraCommands but the actual
implementation in nix/packages/docker.nix uses fakeRootCommands; update the
documentation in
openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/design.md to match the
implementation (or alternatively change the implementation to use
extraCommands), and explicitly reference the symbol used in code
(fakeRootCommands) and why it was chosen (effects on file materialization /
securejoin) so future readers/editors are not confused.

In `@openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/proposal.md`:
- Around line 14-16: Update the proposal text to use the actual hook name
fakeRootCommands instead of extraCommands: state that nix/packages/docker.nix
now materializes /etc/passwd and /etc/group via the
dockerTools.buildLayeredImage fakeRootCommands hook (which writes the files
directly) rather than placing them into the buildEnv contents (which would
create store symlinks); also keep the notes about identical content (root + ncps
uid/gid 1000) and the disallowedRequisites guard, and mention adding the
packaging regression check asserting the files are regular (non-symlink) files
with the expected entries.
- Around line 5-8: The fenced code block in proposal.md containing the error
snippet starting with "failed to create containerd container: mount callback
failed on …: openat etc/passwd: path escapes from parent" is missing a fence
language and triggers MD040; update that code block to include a language tag
such as `text` (e.g., change ``` to ```text) so markdownlint no longer flags it.
Ensure you modify the fenced block where that exact error string appears in
openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/proposal.md.

In `@openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/tasks.md`:
- Around line 9-10: Update the task description to reflect that `/etc/passwd`
and `/etc/group` are materialized via fakeRootCommands rather than
extraCommands: edit the entry referencing dockerTools.buildLayeredImage in the
archived task so it mentions fakeRootCommands (as implemented in
nix/packages/docker.nix) and retains the rest of the details (here-doc, create
`etc/` first, keep `root` + `ncps` uid/gid 1000 and the rebuilt-image
assertion).
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 6de48cd2-e056-4431-b914-0eeb2a9d6b6b

📥 Commits

Reviewing files that changed from the base of the PR and between 03c55ce and d510e49.

📒 Files selected for processing (8)
  • nix/checks/flake-module.nix
  • nix/packages/docker.nix
  • openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/.openspec.yaml
  • openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/design.md
  • openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/proposal.md
  • openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/specs/container-image-etc-files/spec.md
  • openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/tasks.md
  • openspec/specs/container-image-etc-files/spec.md

Comment thread nix/checks/flake-module.nix Resolved
@kalbasit
kalbasit force-pushed the user/wnasreddine/fix-cdc-incomplete-nar-serve branch from 03c55ce to 7c713f8 Compare June 7, 2026 14:32
kalbasit added a commit that referenced this pull request Jun 7, 2026
Address PR #1347 review:
- docker.nix (gemini): copy through the /etc symlink (cp -a etc/. etc.tmp/)
  instead of readlink -f, so a failed readlink can never expand to
  'cp -a /. etc/' (copying the sandbox root).
- flake checks (coderabbit/gemini): replay layers in manifest.json order and
  apply whiteout semantics (etc/.wh.*) to compute the effective final state of
  /etc/passwd & /etc/group, instead of aggregating all listings + tail -1
  (which ignored layer order/whiteouts and was non-deterministic).
- archived fix-docker-etc-passwd docs: correct extraCommands -> fakeRootCommands
  (the implemented hook) and add a 'text' fence language.

Threads: PRRT_kwDONV6tZs6HofUb, PRRT_kwDONV6tZs6HofUf, PRRT_kwDONV6tZs6HogAS,
PRRT_kwDONV6tZs6HogAT, PRRT_kwDONV6tZs6HogAU, PRRT_kwDONV6tZs6HogAW,
PRRT_kwDONV6tZs6HogAX

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@kalbasit
kalbasit force-pushed the user/wnasreddine/fix-docker-etc-passwd branch from d510e49 to 3d06e81 Compare June 7, 2026 14:32
Base automatically changed from user/wnasreddine/fix-cdc-incomplete-nar-serve to main June 7, 2026 14:39
kalbasit and others added 3 commits June 7, 2026 14:39
The image added /etc/passwd and /etc/group via a buildEnv, which makes
them absolute symlinks into the nix store
(/etc/passwd -> /nix/store/...-passwd/etc/passwd). Recent containerd
securejoins etc/passwd during container creation and rejects the
absolute symlink as escaping the rootfs, so EVERY ncps pod fails to
start: 'failed to create containerd container: ... openat etc/passwd:
path escapes from parent'. This is a latent production failure on recent
k8s/containerd, and it blocked the entire k8s-tests Kind suite.

Materialize /etc/passwd and /etc/group as real files in fakeRootCommands
(re-materializing the read-only store-symlinked /etc as a writable real
directory first), with identical content. Add a checks.docker-image-etc-files
regression guard that asserts both are regular files (not symlinks).

Verified on Kind: the old (symlinked) image fails with the exact error;
the fixed image starts and runs to Completed.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Address PR #1347 review:
- docker.nix (gemini): copy through the /etc symlink (cp -a etc/. etc.tmp/)
  instead of readlink -f, so a failed readlink can never expand to
  'cp -a /. etc/' (copying the sandbox root).
- flake checks (coderabbit/gemini): replay layers in manifest.json order and
  apply whiteout semantics (etc/.wh.*) to compute the effective final state of
  /etc/passwd & /etc/group, instead of aggregating all listings + tail -1
  (which ignored layer order/whiteouts and was non-deterministic).
- archived fix-docker-etc-passwd docs: correct extraCommands -> fakeRootCommands
  (the implemented hook) and add a 'text' fence language.

Threads: PRRT_kwDONV6tZs6HofUb, PRRT_kwDONV6tZs6HofUf, PRRT_kwDONV6tZs6HogAS,
PRRT_kwDONV6tZs6HogAT, PRRT_kwDONV6tZs6HogAU, PRRT_kwDONV6tZs6HogAW,
PRRT_kwDONV6tZs6HogAX

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@kalbasit
kalbasit force-pushed the user/wnasreddine/fix-docker-etc-passwd branch from 3d06e81 to f61201e Compare June 7, 2026 14:39
@kalbasit
kalbasit enabled auto-merge (squash) June 7, 2026 14:39

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/proposal.md`:
- Line 15: The proposal text overstates the packaging regression check: update
proposal.md to remove or rephrase "with the expected entries" so it only claims
the files are regular, OR extend the actual check in flake-module.nix to also
verify contents by adding assertions that /etc/passwd and /etc/group contain the
expected entries (e.g., grep/regex checks for the required user/group lines) in
addition to the existing regular-file type assertion; locate the current
assertions for /etc/passwd and /etc/group in flake-module.nix and either change
the prose in proposal.md or add content-matching assertions next to those
checks.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8b61a6fd-752c-4558-8567-03231065f462

📥 Commits

Reviewing files that changed from the base of the PR and between 3d06e81 and f61201e.

📒 Files selected for processing (8)
  • nix/checks/flake-module.nix
  • nix/packages/docker.nix
  • openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/.openspec.yaml
  • openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/design.md
  • openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/proposal.md
  • openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/specs/container-image-etc-files/spec.md
  • openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/tasks.md
  • openspec/specs/container-image-etc-files/spec.md
✅ Files skipped from review due to trivial changes (5)
  • openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/.openspec.yaml
  • openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/tasks.md
  • openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/specs/container-image-etc-files/spec.md
  • openspec/specs/container-image-etc-files/spec.md
  • openspec/changes/archive/2026-06-06-fix-docker-etc-passwd/design.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • nix/packages/docker.nix

@kalbasit
kalbasit merged commit f94b6a6 into main Jun 7, 2026
36 checks passed
@kalbasit
kalbasit deleted the user/wnasreddine/fix-docker-etc-passwd branch June 7, 2026 15:01
kalbasit added a commit that referenced this pull request Jun 8, 2026
## Summary

The `[Unreleased]` section was populated in #1309 but skewed toward the
recent CDC-drain, in-flight-staging, and Ent-migration work, omitting
several user-facing features and fixes that also landed since v0.9.4.
This backfills the missing notable changes, each cross-referenced by PR.

**Added**
- `ncps fsck` command + Helm fsck CronJob (#975, #996, #998, #999,
#1000, #1004, #1006, #1176)
- Closure pinning HTTP endpoints `POST`/`DELETE /pin/{hash}.narinfo`,
`GET /pins` (#1108)
- pprof server via `--pprof-addr` (#1063)
- CDC lazy chunking as a feature + `--cache-cdc-lazy-cleanup-schedule` +
recovery cron (#1082, #1083, #1089, #1096)
- Helm: auto `GOMEMLIMIT` (#1061), configurable temp volume /
`volumeClaimTemplate` (#1074, #1077), SQLite `Recreate` strategy (#1012)
- Startup storage reporting + deprecated-narinfo warning (#959, #961)
- `docker-dev` image (#1097)

**Fixed**
- `store/tmp` no longer wiped on startup (#1313)
- `nix-hash` NAR verification (#1101)
- Prometheus counters primed at startup (#1337, #1343)
- 404 on un-reassemblable chunked NARs (#1319), purged narinfo no longer
500 (#1318), fail-fast tmp validation (#1086)
- Further CDC/cache reliability fixes (#1317, #1346, #1341, #1342,
#1331, #1347)

**Changed**
- CDC config now persisted in the DB config table (#971)

Dependency bumps, CI/test-only changes, and the internal Ent-conversion
PRs are intentionally excluded; the existing Ent-migration entry already
covers that work.

## Test plan

- [x] `nix fmt` reports no changes (docs-only edit)
- [x] CHANGELOG section structure intact
(Added/Fixed/Changed/Removed/Migration/CI)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working merge-stack size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant