Repository navigation
d1 backup sweep: authenticate with the real secrets key - #152
Conversation
- `d1_backup::tick` built its `D1Ctx` with `SecretsKey::test_key()`, so the derived operator token never matched the fleet's and every scheduled backup 401d. The sweep now takes the server key (derived from config, threaded from `serve` through `spawn_backup_task`). - Guard: `SecretsKey::test_key` and `AccessKey::test_key` are now `#[cfg(test)]`, unreachable from production builds. - Test: `tick_backs_up_with_the_servers_real_key` runs the sweep against a token-enforcing fake cello keyed with a real non-test key and asserts a dump is stored (fails with a mismatched key).
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
|
Security review record (head
|
fix(d1): sweep backs up with the server's real key
Problem
The scheduled hourly D1 backup sweep never succeeded after #115
(2026-11-06).
d1_backup::tickbuilt itsD1CtxwithSecretsKey::test_key()(crates/outer/src/d1_backup.rs, old line ~802),so the
CELLO_OPERATOR_TOKENit derived for everycello d1invocationnever matched the token the fleet holds — the fleet's token is derived
from the real key (
SecretsKey::derive(&config.outer_secret)inserve,crates/outer/src/main.rs, passed intoFleetManagerviaManagerSettings::secrets_key). Every scheduled backup 401d and the sweeplogged a warning and moved on.
On-demand
backup_databasewas unaffected: it buildsD1Ctx::from_state,which clones the real
mcp.secrets_key.Verified by reading the paths, not by guessing:
FleetManager::newstoressecrets_keyfrom config(
fleet/manager.rs), andd1_exec/d1_exportsendoperator_token_env(&ctx.secrets_key, slug)asCELLO_OPERATOR_TOKEN(
http/console_data/d1.rs:848,926). The guarded fleet listenerrequires that token.
tickhardcodedSecretsKey::test_key()into the samectx.secrets_keyslot, so the two tokens differed by HKDF input.Change
d1_backup::ticktakessecrets_key: &SecretsKeyand uses it for thesweep's
D1Ctx;spawn_backup_tasktakes the owned key and passes itthrough each loop.
serveclones the config-derived key intosweep_secretsand hands itto
spawn_backup_task(crates/outer/src/main.rs).SecretsKey::test_key()andAccessKey::test_key()are now#[cfg(test)], so production codecannot reference them (a future use fails to compile). Audited every
test_key()caller: the sweep was the only production one — all otherssit inside
#[cfg(test)]modules (mcp/tools/data.rsalready used thereal key from state).
Test
New
d1_backup::tests::tick_backs_up_with_the_servers_real_key: seeds adue app, fronts the fake
cellowith a wrapper that 401s unlessCELLO_OPERATOR_TOKENequalsoperator_token(&real_key, "acme")(
real_keyfromderive, nevertest_key), stubs the fleet health gateso
ensure_awakeshort-circuits, runstickwith the real key, andasserts one dump row plus non-empty bytes in the store.
Fail-before proof: with the sweep's key replaced by a mismatched derived
key (reproducing what
test_key()did — a token the fleet rejects), thenew test fails (no dump stored); with the fix it passes.
Gates
cargo fmt --all --check— cleancargo clippy --locked --all-targets -- -D warnings— cleancargo test --locked(full) — 1280 passed, 0 failedscripts/check-pins.sh— cleanCatch-up after deploy
Prod is being wiped anyway, so no existing app needs a manual backup or
catch-up pass after this deploys — there is nothing worth restoring yet.
The next hourly sweep after deploy will take the first real scheduled
backups. Worth a glance at the
d1 backup storedlog lines post-deployto confirm the 401s are gone.
Summary by CodeRabbit