fix(macOS): prevent self-referential ~/.aws/.aws symlink#1778
Open
ecmiram wants to merge 1 commit into
Open
Conversation
The VM-provisioning line appended to the guest's ~/.bashrc used
`ln -fs "$AWS_DIR" /root/.aws`. Without -n, when /root/.aws already
exists as a symlink to a directory, `ln -s` dereferences it and creates
the link *inside* the target instead of replacing it, surfacing on the
host through the writable home mount as a self-referential link:
~/.aws/.aws -> ~/.aws
This breaks recursive traversal of ~/.aws (e.g. `cp -r ~/.aws` aborts
with "directory causes a cycle"). The guard `[ -L /root/.aws ]` does not
prevent re-firing because it runs as the unprivileged VM user against
root-owned /root (0700), so the stat fails and the test is always false.
Add -n (--no-dereference) so repeated runs replace the symlink in place
instead of nesting, making the operation idempotent.
Signed-off-by: ecmiram <[email protected]>
ayush-panta
approved these changes
Jul 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue #, if available: Reported and confirmed in the runfinch community Slack #finch-interest:
Description of changes:
The line added to the guest's ~/.bashrc uses:
Two problems compound here:
Without
-n, when/root/.awsis already a symlink to a directory,ln -sdereferences it and nests the new link inside the target.On the host (via the writable home mount) this surfaces as:
which breaks recursive traversal of
~/.aws— e.g.cp -r ~/.awsaborts with "directory causes a cycle".
The
[ -L /root/.aws ]guard doesn't prevent re-firing: it runs as theunprivileged VM user against root-owned
/root(0700), so the statfails and the test is always false — the
lnruns on every shell.Adding
-n(--no-dereference) makes the link replacement idempotent, sorepeated runs replace the symlink in place instead of nesting.
Testing done:
Reproduced end-to-end, then verified in an isolated dev VM that the patched
binary writes
ln -fsnand~/.aws/.awsno longer regenerates (credspreserved).
make test-unit+golangci-lintpass.License Acceptance
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.