Skip to content

fix: resolve /etc/resolv.conf symlink on separate mounts#35

Merged
tito merged 2 commits intomainfrom
fix/resolv-conf-symlink-on-separate-mount
Mar 20, 2026
Merged

fix: resolve /etc/resolv.conf symlink on separate mounts#35
tito merged 2 commits intomainfrom
fix/resolv-conf-symlink-on-separate-mount

Conversation

@tito
Copy link
Copy Markdown
Contributor

@tito tito commented Mar 20, 2026

Summary

Fixes #25 (resolv.conf part)

  • On systems using systemd-resolved, /etc/resolv.conf is a symlink to /run/systemd/resolve/stub-resolv.conf. After bwrap's non-recursive --ro-bind / /, the /run tmpfs is empty so the symlink target is unreachable, causing bwrap: Can't create file at /etc/resolv.conf.
  • The previous fix only handled cross-device symlinks (sameDevice check), which missed cases where /run is a separate mount but device IDs happen to match.
  • Adds isSeparateMount() that compares a path's device ID with its parent's, reliably detecting separate mounts.
  • Adds resolveSymlinkForBind() helper that generates bwrap --tmpfs/--dir args to make symlink targets reachable.
  • The DNS override now binds to the resolved target path directly, avoiding bwrap's symlink following entirely.

Test plan

  • Unit tests for isSeparateMount(), resolveSymlinkForBind() (non-symlink, nonexistent, cross-mount, resolv.conf)
  • Integration test: cat /etc/resolv.conf succeeds inside sandbox
  • Manual test on a systemd-resolved system: greywall -- curl https://greyhaven.co

tito added 2 commits March 19, 2026 19:29
On systems using systemd-resolved, /etc/resolv.conf is a symlink to
/run/systemd/resolve/stub-resolv.conf. After bwrap's non-recursive
--ro-bind / /, the /run tmpfs is empty so the symlink target is
unreachable, causing "Can't create file at /etc/resolv.conf".

The previous fix only handled cross-device symlinks (sameDevice check),
which missed cases where /run is a separate mount but happens to share
a device ID with /.

Changes:
- Add isSeparateMount() that compares a path's device ID with its
  parent's, reliably detecting separate mounts like /run as tmpfs
- Add resolveSymlinkForBind() helper that generates bwrap --tmpfs/--dir
  args to make symlink targets reachable inside the sandbox
- Bind DNS override resolv.conf to the resolved target path directly,
  avoiding bwrap's symlink following for the destination
- Add unit tests for the new helpers and an integration test verifying
  /etc/resolv.conf is readable inside the sandbox
Replaced by isSeparateMount in the resolv.conf symlink fix.
@tito tito merged commit 91cf626 into main Mar 20, 2026
4 checks passed
@tito tito deleted the fix/resolv-conf-symlink-on-separate-mount branch March 20, 2026 13:12
@remip2 remip2 mentioned this pull request Mar 24, 2026
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.

bwrap: Can't create file at /etc/resolv.conf: No such file or directory

1 participant