Skip to content

Fix layer extraction of hard links to symlinks - #398

Merged
libracoder merged 1 commit into
libracoder:mainfrom
gruckion:fix/supabase-symlink-hardlinks
Nov 16, 2026
Merged

libracoder merged 1 commit into
libracoder:mainfrom
gruckion:fix/supabase-symlink-hardlinks

Conversation

@gruckion

@gruckion gruckion commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

What this changes and why

Unpacking Supabase's Nix-built PostgreSQL image fails before the container starts because tar-rs canonicalizes a hard-link source and follows its absolute symlink target outside the temporary layer directory.

Resolve source and destination parents through Kiri's existing confined inroot helper, then use linkat without AT_SYMLINK_FOLLOW. This preserves the source inode, including dangling symlinks, while keeping parent resolution inside the layer. The shared Linux guest code covers the Mac VM, Linux and WSL; no dependency or security-check bypass is added.

Related: #302 and #322. That PR handles absolute paths in hard-link headers only and leaves relative hard links on tar-rs. The Supabase failure here uses a relative hard-link header pointing to an absolute symlink, so it still needs this fix. This change handles all hard-link entries; there is implementation overlap to coordinate if #322 lands first.

How you tested it

Tested on macOS 26.7.3 (Apple silicon), with Linux guest tests in a disposable privileged Alpine/Rust container.

  • Added a regression that failed on upstream with the same ENOENT as the Supabase image, plus regular/relative/dangling link, inode-identity, symlinked-parent and traversal checks.
  • All 68 Linux guest tests pass. Mac workspace: 390 passed, 4 ignored. UI/parity: 542 PASS checks.
  • Rebuilt the guest and Mac host; the original, unmodified public.ecr.aws/supabase/postgres:15.8.1.085 image now boots, accepts SQL writes/reads, and retains the committed row after restart. Image ID: sha256:a5a0c2b809d5415edff7c010d9facf29063cb138f88ed3a66efdf24b83e79a96.
  • Workspace and Linux-guest Clippy pass. The Linux-guest warning multiset matches unchanged upstream main, with no diagnostics in the changed file. git diff --check passes.

Full compatibility validation (2026-11-16): tests/e2e.sh completed with 550 passed, 0 failed, 6 skipped against the isolated patched Kiri instance. The six skips are installed-instance domain-router checks. An initial completed run had 549 pass / 1 fail on an immediate nginx startup-log assertion; that assertion then passed in 10 targeted repeats and the full second run.

Validation limits: Default cargo fmt --all -- --check also fails on unchanged upstream main; this patch retains the surrounding compact layout. Native Windows execution and the complete Supabase Auth/Storage stack were not tested.

Rechecked against upstream main 5789abe on 2026-11-16: the affected layers.rs is unchanged from the tested base, and git diff --check still passes. The earlier runtime validation above has not been rerun against this newer main.

Pattern and behavior audit

A fresh review compared the patch with existing inroot/sys filesystem helpers and the pinned tar 0.4.46 hard-link implementation. Confined parent resolution, fd ownership, syscall error handling and test fixtures follow existing patterns. Existing hard-link destination and inode-metadata behavior are preserved. No blocking findings; all 68 Linux guest tests rerun successfully on 2026-11-16.

How you found it

  • I use Kiri and ran into this myself
  • I found it by reading the code or comparing with Docker
  • Someone else reported it

AI tools used to write this change: yes — Codex assisted with reproduction, source investigation, implementation, regression tests and PR preparation.

Checklist

  • I have at most 3 pull requests open on Kiri, this one included
  • Workspace and Linux-guest cargo clippy complete successfully (existing upstream warnings; no diagnostics in the changed file)
  • Mac workspace tests, Linux guest tests and UI/parity checks pass as detailed above
  • git diff --check passes
  • Repository-wide cargo fmt --all -- --check is clean: rerun with Rust 1.97.1 on both versions; unchanged base has 4,319 diff sections, this branch 4,331. New code follows the surrounding compact style too. Making the whole check green would require a separate repository-wide formatting change.
  • macOS runtime: original Supabase PostgreSQL image boots, SQL and restart persistence pass
  • Shared Linux guest: all 68 unit tests pass in the isolated Linux test container
  • Native Windows/WSL runtime validation (not performed; the shared guest implementation has no platform-specific branch)
  • Full Docker compatibility e2e suite: 550 passed, 0 failed, 6 isolated-instance domain checks skipped (initial transient nginx log failure disclosed above)

Supabase's Nix-built Postgres image hard-links symlinks with absolute targets. tar-rs canonicalizes the final source, so unpacking fails before the container starts.

Resolve parent directories through the existing confined inroot helper and create the hard link with linkat flags 0, preserving the source inode without following the final symlink. Cover regular, absolute and dangling symlink sources, symlinked parents, and source/destination escapes.
@libracoder
libracoder merged commit c40d86c into libracoder:main Nov 16, 2026
7 checks passed
libracoder pushed a commit that referenced this pull request Nov 16, 2026
Supabase's Nix-built Postgres image hard-links symlinks with absolute targets. tar-rs canonicalizes the final source, so unpacking fails before the container starts.

Resolve parent directories through the existing confined inroot helper and create the hard link with linkat flags 0, preserving the source inode without following the final symlink. Cover regular, absolute and dangling symlink sources, symlinked parents, and source/destination escapes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants