Skip to content

fix(macOS): prevent self-referential ~/.aws/.aws symlink#1778

Open
ecmiram wants to merge 1 commit into
runfinch:mainfrom
ecmiram:fix/finch-aws-symlink-cycle
Open

fix(macOS): prevent self-referential ~/.aws/.aws symlink#1778
ecmiram wants to merge 1 commit into
runfinch:mainfrom
ecmiram:fix/finch-aws-symlink-cycle

Conversation

@ecmiram

@ecmiram ecmiram commented Jun 30, 2026

Copy link
Copy Markdown

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:

[ -L /root/.aws ] || sudo ln -fs "$AWS_DIR" /root/.aws

Two problems compound here:

  1. Without -n, when /root/.aws is already a symlink to a directory,
    ln -s dereferences it and nests the new link inside the target.
    On the host (via the writable home mount) this surfaces as:

    ~/.aws/.aws -> ~/.aws
    

    which breaks recursive traversal of ~/.aws — e.g. cp -r ~/.aws
    aborts with "directory causes a cycle".

  2. The [ -L /root/.aws ] guard doesn't prevent re-firing: it runs as the
    unprivileged VM user against root-owned /root (0700), so the stat
    fails and the test is always false — the ln runs on every shell.

Adding -n (--no-dereference) makes the link replacement idempotent, so
repeated 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 -fsn and ~/.aws/.aws no longer regenerates (creds
preserved). make test-unit + golangci-lint pass.

  • I've reviewed the guidance in CONTRIBUTING.md

License Acceptance

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

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]>
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