Skip to content

fix(migrate): non-destructive .env restore + bundle off synced Desktop - #972

Merged
qingyun-wu merged 2 commits into
mainfrom
fix/migrate-sh-safety
May 21, 2026
Merged

qingyun-wu merged 2 commits into
mainfrom
fix/migrate-sh-safety

Conversation

@sonichi

@sonichi sonichi commented May 21, 2026

Copy link
Copy Markdown
Owner

Problem

A migrate.sh restore wiped the real GEMINI_API_KEY (and other keys) from a live .env on 2026-05-21 — replaced with placeholder values, no backup, no warning. Two root issues:

  1. Destructive restore — cp "$BUNDLE_DIR/.env" "$REPO/.env" overwrites unconditionally. A stale / placeholder-key bundle .env silently destroys real credentials with nothing to recover from.
  2. Bundle on the iCloud-synced Desktop — BUNDLE="$HOME/Desktop/sutando-migration", and the bundle includes .env with real secrets, unscrubbed. On Macs with iCloud "Desktop & Documents" sync, that pushes unscrubbed credentials to the cloud.

Fix

  1. Restore backs up any existing .env → .env.bak.<timestamp> before overwriting.
  2. Bundle moves to ~/.sutando/migration-bundle (not sync-backed).

bash -n clean. Both fixes requested by Chi.

🤖 Generated with Claude Code

sonichi and others added 2 commits May 21, 2026 07:56
… Desktop

Two safety fixes after a migrate.sh restore wiped real .env keys (2026-05-21):

1. Restore now backs up any existing .env to .env.bak.<timestamp> before
   overwriting. A stale or placeholder-key bundle .env can no longer
   silently destroy real credentials with no recovery path.

2. The bundle moves from ~/Desktop/sutando-migration to
   ~/.sutando/migration-bundle. The bundle carries .env with real secrets;
   ~/Desktop is iCloud-synced on many Macs, which would push unscrubbed
   credentials to the cloud. ~/.sutando/ is not sync-backed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>

@qingyun-wu qingyun-wu left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[core: legacy]

Approve — both fixes are correct and the consequences (silent secret loss + iCloud-synced unscrubbed .env) are exactly the kind of thing you can only catch by getting bit once.

Looks good:

  • Restore backup uses date +%Y%m%d-%H%M%S timestamp → human-sortable, no risk of collision on rapid retries. Backup happens before the overwrite, so even if the cp from bundle fails the original is preserved.
  • Bundle path moved to ~/.sutando/migration-bundle (consistent with ~/.sutando/workspace, ~/.sutando/bin, etc. — keeps Sutando state confined to one hidden home dir).
  • Comment on the BUNDLE= line cites the iCloud risk explicitly — future-me will know why this isn't ~/Desktop.

Two small follow-up opportunities (non-blocking, not for this PR):

  1. The backup .env.bak.<ts> files accumulate forever — first one already showed up in git status today (.env.bak.1778727358). Worth adding .env.bak.* to .gitignore so they don't snow into commits. Trivial follow-up; I'd file as P3.

  2. The bundle itself still contains the unscrubbed .env. The path move solves the iCloud-cloud-leak side of it, but a co-worker who borrows the bundle to bootstrap their own install would receive your live API keys. A migrate.sh --scrub flag (or even a default scrub-then-include-template) would close that hole. P2-ish but separate scope.

CI green, single-file change, bash -n clean per body. Good to merge.

@qingyun-wu
qingyun-wu merged commit e4cc341 into main May 21, 2026
2 checks passed
@qingyun-wu
qingyun-wu deleted the fix/migrate-sh-safety branch May 21, 2026 16:40
liususan091219 pushed a commit to liususan091219/sutando-fork that referenced this pull request May 28, 2026
… Desktop (sonichi#972)

Two safety fixes after a migrate.sh restore wiped real .env keys (2026-05-21):

1. Restore now backs up any existing .env to .env.bak.<timestamp> before
   overwriting. A stale or placeholder-key bundle .env can no longer
   silently destroy real credentials with no recovery path.

2. The bundle moves from ~/Desktop/sutando-migration to
   ~/.sutando/migration-bundle. The bundle carries .env with real secrets;
   ~/Desktop is iCloud-synced on many Macs, which would push unscrubbed
   credentials to the cloud. ~/.sutando/ is not sync-backed.

Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-authored-by: Qingyun Wu <qingyun0327@gmail.com>
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