Skip to content

filesync: keep a symlink's permission bits out of a host directory's digest - #15168

Merged
sipsma merged 3 commits into
dagger:mainfrom
dshaw:filesync-symlink-mode
Nov 17, 2026
Merged

sipsma merged 3 commits into
dagger:mainfrom
dshaw:filesync-symlink-mode

Conversation

@dshaw

@dshaw dshaw commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #15167

The digest of a host directory depends on a symlink's permission bits, so the same tree has one digest from a macOS client and another from a Linux client.

Reproduce

Needs only the CLI. Same digests on v1.0.0-beta.25 and v1.0.0-beta.27, and with a CLI built from main (3991a28b9d) against a v1.0.0-beta.27 engine.

dir=$(mktemp -d) && mkdir "$dir/tree" && printf 'hello\n' > "$dir/tree/notes.md"
chmod 0644 "$dir/tree/notes.md" && chmod 0755 "$dir/tree"
for mask in 022 077 000; do
  rm -f "$dir/tree/latest.md"
  (umask "$mask" && ln -s notes.md "$dir/tree/latest.md")
  dagger -s -m core api call host directory --path "$dir/tree" digest; echo
done

macOS client:

sha256:523803c60cb8901facae3403e1ee65710e315844a184924338b167822bf7cb0d   # lrwxr-xr-x
sha256:4e830ea5782c3d95ea6ff697f3aadc3ccd2674b3a081442444e45bf80c37628f   # lrwx------
sha256:e1ee8b8ac2b9f38cb4c86044a5f5b1be6668c06e6ad4a27b222656447f5857c4   # lrwxrwxrwx

Linux client, same engine: sha256:e1ee8b8a… three times, since a symlink is always 0777 there.

Cause

  • normalizeLocalImportStat clears uid, gid and xattrs before the client sends a stat, and sends the mode as the host reports it.
  • statHash hashes the mode it was sent.
  • localFS.Symlink creates the link in the mirror and rewriteMetadata skips chmod for symlinks, so the mirror's link is 0777 whatever was sent.

This is the case #13389 fixed for host xattrs: metadata that cannot round-trip through the Linux mirror is not source identity.

Change

  • Client: send 0777 for a symlink, next to the other normalization.
  • Engine: hash a symlink as 0777, so a client older than this change gets the same digest (the engine accepts clients back to v0.19.0).

A file's and a directory's bits are still sent and hashed.

A macOS client's digest of a tree with symlinks changes once. A Linux client's does not.

Tested

  • TestSyncDigestIgnoresSymlinkPermissions syncs one tree with the link reported as 0755 and as 0777 and compares the digests, cold and warm. It fails without the hash.go change and passes with it.
  • TestNormalizeLocalImportStatSymlinkPermissions for the client.
  • go test ./engine/filesync/ ./engine/client/ passes.
  • The client half, on macOS against an unmodified v1.0.0-beta.27 engine: a CLI built from main prints the three digests above; a CLI built from this branch prints sha256:e1ee8b8a… three times.
  • The engine half, on macOS against an engine built from this branch with hack/build: the released v1.0.0-beta.27 CLI and a CLI built from main both print sha256:e1ee8b8a… three times.

Not tested: an engine built from main as the like-for-like engine without the change (the released v1.0.0-beta.27 engine stands in for it), the integration suite, and a Windows client.

Checklist

  • dagger check '*:lint' passes.
  • dagger check golangci-lint:lint-all passes.
  • dagger generate run on the branch: every generator finished and it reports no changes to apply.
  • Release note written with changie new.
  • Commit is signed off.

…digest

A symlink has permission bits of its own on macOS, taken from the umask it
was created under. On Linux a symlink is always 0777. The client sent the
host's bits, the engine hashed them, and the mirror's link was 0777 either
way, since Linux has no bits to set on it. So one tree had one digest from a
macOS client and another from a Linux client:

    $ ln -s notes.md tree/latest.md    # macOS, umask 022: lrwxr-xr-x
    $ dagger -m core api call host directory --path tree digest
    sha256:523803c6...
    # the same tree from a Linux client, or with the link made under umask 000
    sha256:e1ee8b8a...

This is the case dagger#13389 fixed for host xattrs: metadata that cannot
round-trip through the Linux mirror is not source identity.

Send 0777 for a symlink from the client, next to the uid, gid and xattrs it
already normalizes. Hash a symlink as 0777 in the engine too, so a client
older than this change gets the same digest: the engine accepts clients back
to v0.19.0. A file's and a directory's bits are still sent and hashed.

A macOS client's digest of a tree with symlinks changes once. A Linux
client's does not.

Fixes dagger#15167

Signed-off-by: Dan Shaw <[email protected]>
@dshaw
dshaw marked this pull request as ready for review November 13, 2026 23:51
@sipsma
sipsma merged commit d55538f into dagger:main Nov 17, 2026
97 checks passed
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.

🐞 A host directory's digest depends on a symlink's permission bits, so macOS and Linux clients disagree

2 participants