Skip to content

clean can permanently delete unrelated Stellar identities (keys rm --force on the global keystore) #601

Closed

Description

@Dgetsylver

Summary

stellar scaffold clean deletes every account listed under [[development.accounts]] by shelling out to stellar keys rm --force <name> (clean.rs#L148-L191). It has no way of knowing whether Scaffold created that identity. The command is run without --config-dir, so it acts on whichever keystore stellar-cli resolves, normally the global one (~/.config/stellar). The only exception is when XDG_CONFIG_HOME or a loaded .env happens to point somewhere else.

build does not notice name collisions either. If an identity with the dev account's name already exists, it reuses it and only prints An identity with the name '…' already exists. So when a project's dev account shares a name with a key the developer uses elsewhere (alice, admin, deployer, issuer, …), clean permanently deletes that secret key. There is no confirmation: stellar-cli ≥ 26 supports keys rm --force, which skips the prompt (see cmd/soroban-cli/src/commands/keys/rm.rs in stellar-cli v27). The only guard is whether the same name also appears in another environment of the same environments.toml.

The same function has three more problems:

  • It uses return instead of continue (clean.rs#L157). The first account that is shared with another environment stops cleanup for all remaining accounts.
  • It depends on the version of the host stellar binary. On stellar-cli 25.x the flag doesn't exist and removal fails with error: unexpected argument '--force' found.
  • The "not found" filter (#L122, #L170) doesn't match stellar-cli's real message (no contract found with alias '…'). Every run therefore prints warnings for aliases that simply don't exist.

Repro (isolated keystore, safe)

export XDG_CONFIG_HOME=$(mktemp -d)      # isolate the keystore
stellar scaffold init demo --template react -p npm -y && cd demo
stellar keys generate me                 # stand-in for a key you care about
stellar scaffold clean
ls "$XDG_CONFIG_HOME/stellar/identity"   # stellar-cli >= 26: me.toml is gone

With stellar-cli 25.2.0 as the host, the clean step prints this instead:

⚠️  Warning: Failed to remove account me: error: unexpected argument '--force' found

Suggested fix

  • Only remove identities that Scaffold itself created, for example by recording them under target/stellar/… when handle_accounts generates them. Alternatives: keep dev identities in a project-local config dir, or at minimum prompt before deleting (with --yes for CI).
  • Call the embedded stellar-cli library, as build already does, instead of the host stellar binary. That removes the version coupling.
  • Change return to continue.
  • Match stellar-cli's actual "not found" message, or check that the alias exists before removing it.

Acceptance criteria

  • clean never deletes an identity it didn't create, or asks before doing so.
  • It behaves the same whatever version of stellar is installed.

Reproduced the stellar-cli 25.2.0 failure with stellar-scaffold-cli 0.0.27. The --force behaviour of stellar-cli ≥ 26 was confirmed from the v27 source.

Activity

  1. zachfedor commented on Oct 17, 2026

    @zachfedor
    Contributor

    Fixed by #630

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions