* fix(embeddeddolt): use stored peer credentials for federation sync
bd federation add-peer promises stored credentials are used automatically
when syncing, but the embedded Fetch/PushTo/PullFrom paths read only the
DOLT_REMOTE_USER environment variable, so first sync against any
authenticated Dolt server presented the wrong identity. This is the
peer-path remainder of the class fixed for default remotes in #2543.
withPeerAuth mirrors server mode's withPeerCredentials: peer-store lookup
first, environment fallback for unknown remotes and credential-free peers
(federation sync iterates every dolt remote, so non-peer remotes must
keep their behavior). Stored credentials override the process-wide
DOLT_REMOTE_USER/DOLT_REMOTE_PASSWORD pair as a unit under a
federationEnvMutex, mirroring package dolt: the in-process Dolt engine
reads them from the process environment, so the override is serialized
and both variables are restored (or re-unset) afterward, including on
callback failure. A stored empty field unsets its variable rather than
inheriting an ambient value.
Fixes#5080
Agent-Signature: claude-code-claude-fable-5-unknown-reasoning on behalf of Michael Pursifull
* docs(embeddeddolt): clarify federationEnvMutex is separate from package dolt's lock
Review nit on #5085: the 'mirroring' phrasing read as if the two
packages shared one mutex. State explicitly that they are separate
locks and why per-package serialization suffices.
* fix(federation): actionable error when peer credentials cannot be decrypted
A database pulled to a second machine carries federation_peers rows
its local .beads-credential-key cannot decrypt, and every peer
operation died with a raw cipher error while bd federation status
blamed the network (Unreachable:). The failure semantics were right
(fail closed, matching server mode); the message said nothing about
the machine-local key or the fix.
Add storage.ErrCredentialKeyMismatch plus a shared wording helper
CredentialKeyMismatchError naming the key file as context and the
remediation (re-run bd federation add-peer on this machine). Both
backends wrap their decrypt failures with it: embeddeddolt at its
single decrypt funnel, dolt at its two read paths. GetFederationPeer
wraps now name the peer. bd federation status classifies the sentinel
with errors.Is and prints Local credential error instead of
Unreachable; the --json shape is unchanged and now pinned by test.
When the error fires is unchanged: same call sites, same fail-closed
semantics, no fallback to ambient credentials.
Tests pin the decrypt-failure branch in both backends (embeddeddolt
against a real store with a rotated key, dolt via sqlmock) and the
status classification end to end in the gated CLI harness.
Refs #5080
* fix(embeddeddolt): classify short ciphertext as credential-key mismatch
A stored peer password blob shorter than the GCM nonce returned a bare
'ciphertext too short' error, bypassing CredentialKeyMismatchError, so
federation status read that local corruption as an unreachable peer.
Route the branch through the same sentinel as a failed GCM open; the
remediation (re-add the peer on this machine) is identical.
Adds a short-ciphertext regression at the decrypt funnel.
Refs: gastownhall/beads#5214 (review, gap 1)
* fix(embeddeddolt): bind stored credentials to the remote URL; serialize env fallbacks
Two fixes to the shared withPeerAuth seam from the consolidation review:
- Stored peer credentials are now bound to the peer's canonical remote
URL, not only to a matching remote name. AddRemoteIfNotExists keeps
an existing same-name remote regardless of its URL, so a redirected
remote could receive the stored password. withPeerAuth now verifies
the live dolt_remotes URL against the peer row before any credential
is installed, failing closed on divergence and on a missing remote.
- The plain-remote and empty-credential fallback callbacks now run
under federationEnvMutex too. They previously called remoteAuthUser()
and the operation itself outside the lock, so a fallback operation
could observe a concurrent stored-peer operation's temporarily
installed DOLT_REMOTE_USER/DOLT_REMOTE_PASSWORD pair.
Adds three regressions: diverged-URL fail-closed, missing-remote
fail-closed, and env-fallback-does-not-observe-peer-credentials.
Refs: gastownhall/beads#5085 (review)
* style(dolt): use US spelling in the decrypt-funnel comments
The repo's misspell linter rejects 'Labelling' and 'labelled'. Comment
text only; no behavior change.
Refs: gastownhall/beads#5214 (CI)
* review: name the resolved credential-key path in the mismatch error
Maintainer review fixup for PR #5214 (adopt-pr iteration 1). Addresses the one
minor and the one nit from the review synthesis; both reviewers found 0 blockers
and 0 majors and the quality scorecard is approve (898/850).
Minor (Debuggability & Operability). All three CredentialKeyMismatchError call
sites passed the bare const credentialKeyFile, so the message claimed "the key
file .beads-credential-key is machine-local" without saying where it is. On the
dolt backend that basename is genuinely ambiguous: initCredentialKey resolves it
against s.beadsDir and falls back to the legacy s.dbPath as a transparent
migration, so during the migration window two files with that name can exist
carrying different keys. Pass filepath.Join(s.beadsDir, credentialKeyFile)
instead, at dolt/credentials.go and both embeddeddolt/federation.go sites. No
signature change: the parameter was already named keyFile and its doc comment
already describes it as machine-local.
beadsDir is provably non-empty at all three sites in production, verified in
source rather than assumed: dolt only reaches the funnel with a non-nil key, and
initCredentialKey leaves the key nil when beadsDir is empty; embeddeddolt's
ensureCredentialKey errors out when it is empty.
This lengthens a message the author pre-declared as a judgment call. The
synthesis adjudicated that carve-out deliberately: it covers the message's
wording and its single-line form, not which file the text identifies.
Nit (Test Evidence Quality). dolt's withPeerCredentials is the seam that carries
the sentinel into `bd federation status` on the default backend and had no
fails-closed pin, unlike its embedded twin TestWithPeerAuth_KeyMismatchFailsClosed.
Added one subtest on the existing sqlmock harness asserting the callback does not
run and the sentinel survives the seam's own wrap.
Both pins were proven non-vacuous by mutation, not assumed:
- Reverting the three call sites to the bare const reds all three dolt subtests
and all three embeddeddolt tests, with the original bare-basename text in the
diff output.
- Making withPeerCredentials swallow the decrypt error reds only the new subtest,
on exactly the two properties the nit named (callback ran; no failure).
The dolt test needed beadsDir set on its hand-built store: filepath.Join("",
credentialKeyFile) is the bare basename, so with beadsDir left empty the
resolved-path assertion would have passed vacuously. The embeddeddolt pin's
package-level const became a function of the store for the same reason — its
store has a real temp beadsDir, so the clause now pins the resolved path.
Validation: go vet rc=0 on all three packages; internal/storage, dolt
(3 tests incl. both negative/narrowing tests) and embeddeddolt (3 credential
tests) green; cmd/bd TestEmbeddedFederation 12/12 green including the PR's own
status_credential_key_mismatch e2e subtest. make bazel-sync-check rc=0 with zero
tracked drift — no new files and zero import changes, so no BUILD srcs or deps
can move.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
---------
Co-authored-by: Michael Pursifull <mike@arcaven.com>
Co-authored-by: Gas City Adopt-PR <adopt-pr@gascity.local>
Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: Eddie the Engineer <adopt-pr@gascity.com>