Repository navigation
Require operator approval for rollbacks that run reverse migrations - #156
Conversation
An allowlisted socket peer can send a plain Rollback and run every reverse migration without an approval token. ADR-0019 amends ADR-0014 so any rollback that runs reverse migrations passes the approval gate, with a default key location and automatic token minting in the CLI. Point ADR-0014 and threat-model row TM-002 at the new ADR. Per-operation authorization for other requests stays open.
Once the rollback plan is known and before any side effect, a non-dry-run rollback with at least one reverse migration passes the ADR-0014 gate, whether or not accept_data_loss is set. A request that already passed the gate for accept_data_loss is not checked twice, so one token is consumed once. Dry runs report that approval is required and still verify a supplied token without consuming it. The audit event gains a reason field so alerts can tell the two triggers apart. agenticd uses .agentic/approval.key when --approval-key-file is absent, with the same mode check. The agentic CLI resolves the target and attaches a token when it can read the key, so operator commands do not change. The demo creates a key and starts the daemon with --allowed-uid, because a token binds to a peer uid. Tests cover refusal before side effects, single use, the missing-key message, no-schema-change rollbacks, key discovery and the CLI attaching a token.
An empty or wrong-length .agentic/approval.key leaves the daemon running without a key, so agentic rollback no longer fails on it for rollbacks that need no token. A key named with --key-file stays a hard error.
…irst The CLI now sends the resolved commit hash, not the ref name, in both the preview and the applied rollback, so the token, the preview and the applied commit name the same commit. It refuses to sign a resolved hash that is not 64 lowercase hex characters. An auto-minted token goes only on the confirmed, non-dry-run request and is minted after confirmation. A destructive preview still gets its own short-lived token, because the daemon refuses it without one. A token the user supplies is passed through unchanged. The unusable-default-key warning goes to stderr so --json output stays parseable. The daemon loads the down-migration files before the approval gate, so a missing or IRREVERSIBLE file is refused before the token is consumed and before an accepted audit event. The key-discovery tests create the state dir with mode 0700 so they pass under umask 002. Fix two comments: an unusable default key aborts daemon startup when the length is wrong, and the demo's step 10 has no schema change today.
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars.
|
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
Security findingsAdvisory findings (3)
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c522a44cf7
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
The rollback output gains approval_required, set when the plan runs reverse migrations or the request set accept_data_loss. It defaults to false when absent, so older clients and daemons are unaffected. The CLI mints a token for the applied request only if the preview it just got reported approval_required. A forward migration that lands between the preview and the apply is then refused by the daemon's gate and the operator previews again, instead of being reversed under a token minted for a plan nobody saw. With --yes the CLI previews silently, when it holds a key, to read the field. Before sending a minted token the CLI reads the socket peer uid and sends the token only if that uid owns the key file, with a warning on stderr otherwise. The CLI reads at most 33 bytes of the key file, as the daemon does. Add a Postgres-backed test in the reverse_migration suite: commit at schema A, migrate forward to B, refuse the rollback without a token, then reverse to A with a valid one.
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: 149e64598c
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
Tokens now carry a scope in the signed input, not in the token text. A DataLoss token signs the ADR-0014 input unchanged, so tokens from older issuers keep verifying for accept_data_loss. A ReverseMigration token signs the same fields under a distinct domain string. accept_data_loss needs a DataLoss token, so a reverse-migration token can no longer be replayed with accept_data_loss to switch off the IRREVERSIBLE check. A plain reverse-migration rollback accepts either scope. The CLI mints DataLoss for --accept-data-loss and ReverseMigration otherwise. Every request in a CLI auto-signing flow (resolving the target, the preview, the applied request) now goes over a connection whose peer uid is the key owner's. On a mismatch the CLI warns without naming uids, gives up on signing and carries on unsigned, and the daemon's gate refuses if a token was needed. With --accept-data-loss the applied request is signed after a successful preview even if an older daemon's reply omits approval_required. The CLI skips a default key path that is a symlink, FIFO or other special file, and the daemon treats such a default path as no key, so neither can block on it. A key named explicitly must be a regular file. ADR-0019 gains a decision for the scope binding and a note that the token authorizes the target commit, not a migration list.
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: 968775a250
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
…scope The offline issuer (agentic rollback --approval) takes --scope reverse-migration|data-loss, defaulting to data-loss so existing callers keep their tokens. The daemon's missing-token diagnostic now recommends --scope reverse-migration for an ordinary reverse-migration rollback, since a data-loss token would also authorize accept_data_loss, and keeps pointing accept_data_loss at --scope data-loss. Both keep the wire code approval_required. Open the key file with O_NOFOLLOW in the CLI and the daemon, so a symlink swapped in after the default-path check is never followed. The CLI applies the daemon's mode check: a key that group or other can access is refused with a chmod 600 hint, or skipped with a warning when it is the default. The accepted audit event carries the scope the token verified under, next to reason. Say precisely in the code comment and ADR-0019 that the down-migration files load before the gate only for a plain reverse-migration rollback; with accept_data_loss the gate still runs first. Tests drop the uid values from the CLI client test messages.
… unique O_NOFOLLOW now applies only to the auto-discovered default key path, in the CLI and the daemon. A key named with --approval-key-file, --key-file or the issuer is an operator choice and follows symlinks, because Kubernetes and Cloud Run secret volumes expose files through them. O_NONBLOCK and the regular-file and mode checks on the opened handle stay for both. A symlink at the default path is still skipped or treated as no key. ADR-0019 says so. The audit-scope test minted tokens that another test could mint byte for byte (same commit hash, uid and second), so its search could match that test's accept_data_loss line. It now mints with a timestamp offset no other test uses and also requires reason="reverse_migration" in the line.
Without issuance mode the scope flag was silently ignored. Make clap reject it and apply the data-loss default inside issuance only.
There was a problem hiding this comment.
🛡️ Codex Security Review · Automatically triggered
Here are some automated security review suggestions for this pull request.
Reviewed commit: fe75b29858
ℹ️ About Codex security reviews in GitHub
This is an experimental Codex feature. Security reviews are triggered when:
- You comment "@codex security review"
- A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review
Once complete, Codex will leave suggestions, or a comment if no findings are found.
A data-loss token also authorizes accept_data_loss, so it should be asked for explicitly. An accept_data_loss request with the narrower token fails with an error that names --scope data-loss.
Any allowlisted socket peer, including the adversarial sidecar worker, could send a plain rollback (
accept_data_loss=false) and make the daemon run every reverse migration not marked IRREVERSIBLE, with no operator approval. The owner decided to require the ADR-0014 approval token for any rollback that runs reverse migrations.ADR-0019 records the decision and amends ADR-0014. Tokens are now scoped: a reverse-migration token cannot authorize
accept_data_loss, while a data-loss token, including any minted before this change, covers both. The offline issuer takes--scope reverse-migration|data-loss.Daemon:
reason=reverse_migration.--approval-key-fileis not given, the daemon uses<repo>/.agentic/approval.key, with the same mode checks.CLI:
agenticattaches a token automatically when it can read the key. It pins the resolved commit hash, signs the apply only when the preview reportedapproval_required(a new additive output field) or--accept-data-loss, mints after confirmation, refuses to sign anything but a 64-hex hash, and sends a token only to a socket peer that owns the key file.run-demo.shcreates the key and runs with--allowed-uid.Breaking:
Proof: new tests cover the refusal before any side effect, success with a valid token, single use, refusal with no key, no token needed without a schema change, default key discovery and its mode check, and CLI pinning, late minting and the hash check. They fail without the change.
cargo test --workspace, the Postgres suites,run-demo.shand the SDK checks pass. The demo's rollback has no schema change, so the gate is exercised by the in-memory and CLI tests, not by the demo.Reviewed with sol-loop: 5 rounds with gpt-6.2-sol; its last finding is fixed in the final commit, and binding approval to the exact migration list was declined (ADR-0019 Consequences). Mythos 5.2 security review: approved (round 2).
Created with Claude Opus 5.5 and Claude Sonnet 5.5 in Claude Code.