Skip to content

Commit 58139da

Browse files
ammarioclaude
andcommitted
fix: mount to resolved symlink target path using readlink
Root cause: When mounting to /etc/resolv.conf (a symlink), mount follows the symlink but our placeholder file might not be at the expected location in the mount namespace. Solution: Use readlink -f to get the actual target path before mounting: mount --bind /etc/netns/.../resolv.conf $(readlink -f /etc/resolv.conf || echo /etc/resolv.conf) This ensures we mount to the correct location whether /etc/resolv.conf is a regular file or a symlink. Tested on ml-1 with external DNS (8.8.8.8) - all 23 tests pass, host resolv.conf remains untouched. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 95ed568 commit 58139da

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/jail/linux/mod.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -544,10 +544,13 @@ impl Jail for LinuxJail {
544544

545545
// Build wrapper shell command that:
546546
// 1. Creates symlink target placeholder (if needed)
547-
// 2. Bind-mounts our custom resolv.conf
547+
// 2. Bind-mounts our custom resolv.conf to the RESOLVED path (following symlinks)
548548
// 3. Execs the user command
549+
//
550+
// CRITICAL: We mount to $(readlink -f /etc/resolv.conf) not /etc/resolv.conf directly,
551+
// because mount follows symlinks and we need the actual target path.
549552
let shell_cmd = format!(
550-
"mkdir -p /run/systemd/resolve && touch /run/systemd/resolve/stub-resolv.conf && mount --bind {} /etc/resolv.conf && exec {}",
553+
"mkdir -p /run/systemd/resolve && touch /run/systemd/resolve/stub-resolv.conf && mount --bind {} $(readlink -f /etc/resolv.conf || echo /etc/resolv.conf) && exec {}",
551554
resolv_path,
552555
escaped_parts.join(" ")
553556
);

0 commit comments

Comments
 (0)