Repository navigation
fix(cli): open the migration target through a held descriptor, and say what that narrows - #1178
Conversation
🦋 Changeset detectedLatest commit: 6ef635c The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
[Medium impact] The PR appears safe to merge within its stated limits.
|
nostream-cli migrate pg-to-lmdbnow opens its target through a held descriptor instead of its path.Two windows, two different outcomes, and the difference is the point:
verifyused to stat the path after the open, so a target renamed during the open and restored before the check compared the original inode against itself. The descriptor is now the handle, and a rename lands in the pinned inode: closed, with a swap test per arm.unsafe/ffi site, whichCLAUDE.md:81-84forbids.Fixes #1162. (On this repository
Closesis inert againstrewrite/main: the issue needs closing by hand after the merge.)The window
TargetPinpins the target directory — it holds aFileandfstats it — but base passed the path toLmdbBackend::openandverifyre-statted the path afterwards. Rename the target during the open and restore it before the check, and the check compares the original inode against itself: the store lands in the replacement and the command reports success.Now the descriptor is the handle:
TargetPin::root()returns/proc/self/fd/<n>where/proc/self/fdis a directory (runtime probe, nocfg(target_os)in production code), else the path unchanged.open_target, both verifying arms and the manifest read/write/sync all resolve through it. The--verifyarm and the completed-manifest arm never pinned at all before this change; they do now.What it does not close — and the tree says so
heed canonicalises the path (
heed-0.20.5/src/env.rs:239) and then opens the canonical path (:305), so the fd spelling stops being fd-relative at the syscall that matters. This narrows the window to that pair; it does not close it, and closing it needs a secondunsafe/ffi site, whichCLAUDE.md:81-84forbids. Measured on a name-swapping thread, 300 rounds: 21 pinned, 0 in the wrong directory, 279 refused.Every claim in the tree, the ADR and the changeset says
narrows. Nothing says it closes.The class this job found in its own spec
The mechanism changed the vocabulary of every error path, and the spec's requirement 8 named the right rule while enumerating the wrong sites. The ux lens caught it by running the binary — a store that would not open printed:
and now prints:
operator_message(message, root, target)is applied at all 12CliError::Migratesites in the manifest functions and at both openers, and the testa_store_that_will_not_open_names_the_target_not_the_descriptorpins it — it fails on the pre-fix tree with the line above.Evidence
Verified 9 tables); bare reads the replacement (No manifest at …, exit 1). Inverting either arm fails only its own test./proc/self/fd/N/migration-manifest.json.tmpis refusedEEXISTbycreate_new, the victim untouched, mode 0600, the rename and dir-fsync landing in the pinned directory. That control had only ever been exercised on the path arm.ENOENTrather than silently falling back to the name, and the handle isCLOEXEC.cargo test --workspace --all-features, both clippy passes,--no-default-features, and the release build are green;migrate_cli45 (base 42).The one limit a future reader needs in plain words
after_pin()below the open keeps every test green.Known limits
runprobes the source beforecreate_target, so without a reachable Postgres it never reaches its pin; that one call is guarded by the AC 5/6 greps and the compiler.pin.verifyatmigrate.rs:139bounds what an attacker gains there today.pin.root()count (5) whenroot()stopped taking an argument — a weaker check, recorded.--verifynow needs read permission on the target where base needed only search (pinning opens the directory). Accepted and recorded in the ADR: a migration target is writable by definition, and the refusal names the operator's path./proc: the runtime probe falls back to today's path behaviour, andverifyremains the check there.Cost
$2.16 against $1.25 expected — the operator accepted ~$1.6 before the last two passes; the excess above that is a second approver read after a record escalation. What the money bought: recon, a two-pass spec red-team, the build plus two rework passes (one of them the operator's test for the
--verifyarm, one the round-1 operator-message defect), review round 1 with four lenses and a two-lens closing round. The overrun bought the message fix and two lens notes, not scope.