Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .changeset/36679-secret-rewrap-confirmation-exit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@objectstack/cli': patch
---

fix(cli)!: `os secret rewrap --apply` without `--yes` in a non-interactive shell exits 1

Clause-②: no (narrowing)
Metadata-protocol: none

<!-- adr-0087: not-required (no-migration-prescription) no metadata, stored shape or export moves; the remedy is a flag on the caller's command line -->

**BREAKING** (an exit status narrows), shipped as `patch`: the change is not to the metadata protocol.

- **FROM:** `os secret rewrap --apply` on a database with a version-1 `sys_secret` row to re-wrap, without `--yes`, with stdin not a terminal, text face: nothing opened or written, `Aborted — no row was opened or written.`, exit `0`.
- **TO:** nothing opened or written, `Confirmation required. Re-run with --yes to re-wrap. No row was opened or written.`, exit `1`.
- **Unchanged:** answering `n` at the `[y/N]` prompt in a terminal still prints `Aborted — …` and exits `0`; `--json` without `--yes` already exited `1` with `confirmation_required`; a run with `--yes` re-wraps as before; a dry run, or an `--apply` run with nothing to re-wrap, asks nothing and keeps the exit status it had (`0` when the run is not otherwise refused; a missing data key or an incomplete reference union still exits `1`).
- **The fix for a script:** pass `--yes` to re-wrap; drop `--apply` to get only the dry-run report.

This is the rule the `os migrate` commands and `os db orphans --delete` / `os secret orphans --delete` already follow: a run that did not get its confirmation is a refused run, so a script, CI job or cron reading `$?` never takes it for a key rotation that happened.
9 changes: 9 additions & 0 deletions packages/cli/src/commands/secret/rewrap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,20 @@ export default class SecretRewrap extends Command {
return;
}

// A run that did not get its confirmation opens and writes nothing and
// exits 1, naming the flag that gives it — the `os migrate` family's
// rule, which `os db orphans` / `os secret orphans` follow too. An
// operator who answers `n` at the prompt declined on purpose: exit 0.
if (flags.apply && plan.attempts > 0 && !flags.yes) {
if (json) {
await emitJson({ error: 'confirmation_required', hint: 'pass --yes' }, 1, { compact: true });
return;
}
if (!process.stdin.isTTY) {
printWarning(`Confirmation required. Re-run with --yes to re-wrap. No row was opened or written.${journalNote}`);
this.exit(1);
return;
}
const ok = await confirm(
chalk.yellow(` Open, re-seal, verify and write up to ${plan.attempts} sys_secret row(s)? [y/N] `),
);
Expand Down
Loading
Loading