Compare commits

...
Sign in to create a new pull request.

13 commits

Author SHA1 Message Date
Eddie the Engineer
2d85a4c5b7 merge: bring in origin/main (54 commits) to resolve PR #6997 conflict
internal/storage/embeddeddolt/federation_credentials_test.go conflicted
only in its import block: this PR adds "bytes" (for the warning-capture
buffer) and #6995 adds "crypto/rand" (for rotateCredentialKey) at the same
position, with an empty common ancestor; both sides also added "io", which
merged once. The resolution is the sorted union of both imports.

Everything else auto-merged. The test file's bodies sit in separate hunks
(this PR's warning test after TestWithPeerAuth, #6995's key-mismatch tests
after TestWithPeerAuth_RestoresAbsentEnv) with no shared declarations, and
internal/storage/embeddeddolt/federation.go keeps both sides' deltas intact:
#6995 edits decryptPassword and GetFederationPeer, while this PR adds the
warning call inside withPeerAuth after the peer lookup, so a decrypt failure
still fails closed before the warning can run.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-01 08:24:12 +00:00
Eddie the Engineer
a775174454 Merge latest base into adopted PR head (adopt-pr base refresh, merge mode) 2026-09-30 06:29:21 +00:00
Eddie the Engineer
69c7687a4d fix(embeddeddolt): keep the tier and prompt for the password in the remedy
Review fixup for #5215 (adopt-pr review loop, iteration 1). Both review
lanes approved (scorecard 974/1000, no blockers or majors). This fixes
the two gated minors, both in the add-peer command the new warning
prints.

- Change Impact: the printed command had no --sovereignty. add-peer
  upserts the whole row (issueops/federation.go: ON DUPLICATE KEY UPDATE
  ... sovereignty = VALUES(sovereignty)), so running it as printed on a
  T1-T4 peer cleared the tier (#5213, still open). The command now
  includes the peer's stored tier when it has one. The PR body says the
  --password form avoids #5213, but it does not: step 6 of #5213's own
  repro is add-peer with --password and without --sovereignty, and it
  clears the tier. The control below reproduces that.
- Security Surface: the command put the secret on the command line
  ('--password <password>'), where it ends up in shell history and in
  /proc/<pid>/cmdline. add-peer already prompts for the password without
  echo when --user is given without --password, so the warning now
  points to the prompt, as the verifyPeerRemoteURL message in this file
  already does.

The test gets a new case that pins the tiered wording verbatim, and the
existing open-pwd pin is updated.

Not changed:
- Readability nit (shell-quote the username): doltutil.ShellQuote is
  only used by this package's go_test today. Using it here would add a
  go_library dependency and a BUILD.bazel deps change for a nit that
  does not gate.
- Architectural Consistency (the server-mode internal/storage/dolt
  backend prints no such warning; does not gate): left for finalize to
  file as a follow-up bead.

Validation (ambient BEADS_*/BD_*/DOLT_* unset, TMPDIR=/tmp):
- go test -tags gms_pure_go -count=1 -run TestWithPeerAuth
  ./internal/storage/embeddeddolt/: all 8 tests pass, including all 8
  subtests of the warning test.
- Mutation: removing the branch that adds the tier fails only the new
  tiered subtest. The file was restored byte-identical.
- E2E with bd built from this tree: a T2 peer that stores a username
  and an empty password, used with DOLT_REMOTE_PASSWORD set in the
  environment, prints one warning. Running the printed command and
  typing a password at the prompt keeps sovereignty T2 and stores the
  password (checked with dolt sql), and the warning no longer appears.
  Control: the old '--password' command on a T3 peer stores the password
  but clears the tier.
- go vet -tags gms_pure_go ./internal/storage/embeddeddolt/, gofmt -l,
  git diff --check: clean. No imports or files were added, so there is
  no Bazel drift.

Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Gas City Adopt-PR
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-30 05:32:18 +00:00
Gas City Adopt-PR
3d67f7eeb6 Merge latest main into adopted PR head (adopt-pr gate, merge mode) 2026-09-30 01:07:33 +00:00
Michael Pursifull
f5999c88f4
Merge upstream main into fix/peer-empty-password-warning 2026-09-27 12:19:30 -05:00
Michael Pursifull
24595b56a1
Merge upstream/main into fix/peer-empty-password-warning
Brings the branch current with upstream (51 commits, including #5085 which merged). The warning this PR adds is independent of the withPeerAuth work #5085 landed, so the merge is clean; this clears the stale CI that predated #5085.
2026-09-18 11:42:05 -05:00
Michael Pursifull
11db4f7822
merge: main into fix/peer-empty-password-warning
Catches the branch up 329 commits. No conflicts: main did not touch
internal/storage/embeddeddolt/federation.go or its credentials test,
which are the only two files this branch changes.

Verified on darwin/arm64: gofmt and go vet clean, and
go test ./internal/storage/embeddeddolt/ passes. That package needs ICU
headers to build here, so it was run with CGO_CPPFLAGS pointed at the
brew icu4c prefix; without them the cgo dependency fails to compile on
upstream main too.

Refs: gastownhall/beads#5215 (review)
2026-09-08 10:34:04 -05:00
Michael Pursifull
f5cf0d0aa9
Merge remote-tracking branch 'upstream/main' into fix/peer-empty-password-warning 2026-09-08 10:30:53 -05:00
Steve Yegge
8c582c2aea Merge origin/main into fix/peer-empty-password-warning
Resolves the withPeerAuth conflict against the merged #5085 form: keeps
main's verifyPeerRemoteURL fail-closed check and fallback-path mutex,
inserts the ambient-password warning after the mutex is taken in the
stored-credentials path, and grafts the warning test onto main's test
file (imports + io.Discard suppression in newPeerAuthTestStore).
2026-08-07 13:35:34 -07:00
Michael Pursifull
575154c320
feat(embeddeddolt): warn when a stored peer suppresses an ambient DOLT_REMOTE_PASSWORD
A peer saved with a username but an empty password (Enter at the
interactive prompt) deliberately suppresses an ambient
DOLT_REMOTE_PASSWORD, the intended security default from the
withPeerAuth unit rule. A setup that used to authenticate off the
environment then fails with no hint about why (#5085 review,
follow-up 4).

Emit one stderr line when the resolved peer has a username, no stored
password, and DOLT_REMOTE_PASSWORD set, naming the peer and how to
store a password. Fired under federationEnvMutex before overrideEnv
rewrites the pair, so the value read is the ambient one and not
another peer's installed password. No credential behavior changes.

Tests pin the exact rendered line and the three silent cases (stored
password present, ambient unset, ambient empty), plus a direct-call
row pinning the all-empty-peer boundary.

Refs #5080
2026-07-31 22:51:53 -05:00
Michael Pursifull
e87e5cbe30
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.
2026-07-31 15:42:07 -05:00
Michael Pursifull
865fa17364
Merge upstream main (bfdc54b06) into fix/federation-peer-creds-v2 2026-07-31 15:41:50 -05:00
Michael Pursifull
8744d81db2
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
2026-07-26 14:31:15 -05:00
2 changed files with 189 additions and 0 deletions

View file

@ -197,6 +197,8 @@ func (s *EmbeddedDoltStore) withPeerAuth(ctx context.Context, peer string, fn fu
federationEnvMutex.Lock()
defer federationEnvMutex.Unlock()
warnStoredPeerSuppressesAmbientPassword(peer, p)
restoreUser := overrideEnv("DOLT_REMOTE_USER", p.Username)
restorePassword := overrideEnv("DOLT_REMOTE_PASSWORD", p.Password)
defer func() {
@ -207,6 +209,44 @@ func (s *EmbeddedDoltStore) withPeerAuth(ctx context.Context, peer string, fn fu
return fn(p.Username)
}
// federationWarnWriter receives the peer-credential diagnostics. Defaults to
// os.Stderr, matching the unconditional warnings this package writes from
// store.go; overridable in tests.
var federationWarnWriter io.Writer = os.Stderr
// warnStoredPeerSuppressesAmbientPassword emits one line when a peer stores a
// username but no password while DOLT_REMOTE_PASSWORD is set. Suppressing the
// ambient password is the intended security default, but a setup that used to
// authenticate off the environment then fails with no hint about why (GH#5085
// review). Call with federationEnvMutex held and before overrideEnv rewrites
// the pair, so the value read is the ambient one and not another peer's
// installed password.
func warnStoredPeerSuppressesAmbientPassword(peer string, p *storage.FederationPeer) {
// Defensive: withPeerAuth returns before this guard when both fields are empty.
if p.Username == "" || p.Password != "" {
return
}
// An ambient empty value is treated as no ambient password: unsetting it
// changes nothing the user could be puzzled by.
if os.Getenv("DOLT_REMOTE_PASSWORD") == "" {
return
}
// add-peer upserts the whole row, so a re-run without --sovereignty
// clears a stored tier (GH#5213): carry the stored tier into the
// suggested command. The password is left to add-peer's no-echo prompt
// rather than suggested as an argument that lands in shell history.
sovereignty := ""
if p.Sovereignty != "" {
sovereignty = " --sovereignty " + p.Sovereignty
}
fmt.Fprintf(federationWarnWriter,
"Warning: peer %[1]q stores a username with an empty password, "+
"which overrides the ambient DOLT_REMOTE_PASSWORD for this operation; "+
"store a password by re-running 'bd federation add-peer %[1]s <url> "+
"--user %[2]s%[3]s' and entering it at the prompt.\n",
peer, p.Username, sovereignty)
}
// verifyPeerRemoteURL fails closed when the live remote named peer does not
// carry the URL stored on the federation peer row. AddRemoteIfNotExists
// preserves an existing same-name remote regardless of its URL, so the name

View file

@ -3,6 +3,7 @@
package embeddeddolt
import (
"bytes"
"crypto/rand"
"database/sql"
"errors"
@ -20,6 +21,14 @@ import (
func newPeerAuthTestStore(t *testing.T) *EmbeddedDoltStore {
t.Helper()
ctx := t.Context()
// Several cases here deliberately build the state that warns about a
// suppressed ambient password; keep that off the test log unless a test
// installs its own writer to assert on it.
prevWarn := federationWarnWriter
federationWarnWriter = io.Discard
t.Cleanup(func() { federationWarnWriter = prevWarn })
beadsDir := filepath.Join(t.TempDir(), ".beads")
store, err := Open(ctx, beadsDir, "fedauth", "main")
if err != nil {
@ -145,6 +154,146 @@ func TestWithPeerAuth(t *testing.T) {
}
}
func TestWithPeerAuth_WarnsWhenStoredPeerSuppressesAmbientPassword(t *testing.T) {
// Pinned verbatim, not matched by substring: the peer name, the username,
// the stored tier, and the Warning: prefix are the parts an operator
// reads, so a wording change has to be made here deliberately.
const wantOpenPwdWarning = `Warning: peer "open-pwd" stores a username with an empty password, ` +
`which overrides the ambient DOLT_REMOTE_PASSWORD for this operation; ` +
`store a password by re-running 'bd federation add-peer open-pwd <url> ` +
`--user peeruser' and entering it at the prompt.` + "\n"
const wantTieredWarning = `Warning: peer "tiered" stores a username with an empty password, ` +
`which overrides the ambient DOLT_REMOTE_PASSWORD for this operation; ` +
`store a password by re-running 'bd federation add-peer tiered <url> ` +
`--user peeruser --sovereignty T2' and entering it at the prompt.` + "\n"
cases := []struct {
name string
peer *storage.FederationPeer
remote string
ambient string
ambientSet bool
// directPeer, when set, calls the warning helper itself instead of
// going through withPeerAuth, pinning the helper's own boundary.
directPeer *storage.FederationPeer
wantLine string
}{
{
name: "username with empty stored password suppresses ambient password",
peer: &storage.FederationPeer{
Name: "open-pwd",
RemoteURL: "https://peer.example/peerdb",
Username: "peeruser",
},
remote: "open-pwd", ambient: "envpass", ambientSet: true,
wantLine: wantOpenPwdWarning,
},
{
// add-peer upserts sovereignty along with the credentials, so the
// suggested re-run must carry the stored tier or it clears it.
name: "suggested re-add keeps the stored sovereignty tier",
peer: &storage.FederationPeer{
Name: "tiered",
RemoteURL: "https://peer.example/peerdb",
Username: "peeruser",
Sovereignty: "T2",
},
remote: "tiered", ambient: "envpass", ambientSet: true,
wantLine: wantTieredWarning,
},
{
name: "stored password suppresses nothing the operator can act on",
peer: &storage.FederationPeer{
Name: "team",
RemoteURL: "https://peer.example/peerdb",
Username: "peeruser",
Password: "peerpass",
},
remote: "team", ambient: "envpass", ambientSet: true,
},
{
name: "no ambient password to suppress",
peer: &storage.FederationPeer{
Name: "open-pwd",
RemoteURL: "https://peer.example/peerdb",
Username: "peeruser",
},
remote: "open-pwd",
},
{
name: "empty ambient password reads as no ambient password",
peer: &storage.FederationPeer{
Name: "open-pwd",
RemoteURL: "https://peer.example/peerdb",
Username: "peeruser",
},
remote: "open-pwd", ambient: "", ambientSet: true,
},
{
name: "peer without a username keeps the password puzzle out of scope",
peer: &storage.FederationPeer{
Name: "open-usr",
RemoteURL: "https://peer.example/peerdb",
Password: "peerpass",
},
remote: "open-usr", ambient: "envpass", ambientSet: true,
},
{
name: "unknown remote keeps the environment fallback",
remote: "not-a-peer", ambient: "envpass", ambientSet: true,
},
{
// withPeerAuth returns before the helper when a peer stores
// neither field, so a direct call is the only way to reach the
// helper's defensive empty-username clause.
name: "helper called directly with an all-empty peer stays silent",
directPeer: &storage.FederationPeer{},
remote: "empty-peer", ambient: "envpass", ambientSet: true,
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
ctx := t.Context()
t.Setenv("DOLT_REMOTE_USER", "envuser")
t.Setenv("DOLT_REMOTE_PASSWORD", tc.ambient)
if !tc.ambientSet {
_ = os.Unsetenv("DOLT_REMOTE_PASSWORD")
}
var warnings bytes.Buffer
captureWarnings := func() {
// Installed after any store: newPeerAuthTestStore points the
// writer at io.Discard for the rest of the suite.
prev := federationWarnWriter
federationWarnWriter = &warnings
t.Cleanup(func() { federationWarnWriter = prev })
}
if tc.directPeer != nil {
captureWarnings()
warnStoredPeerSuppressesAmbientPassword(tc.remote, tc.directPeer)
} else {
store := newPeerAuthTestStore(t)
if tc.peer != nil {
if err := store.AddFederationPeer(ctx, tc.peer); err != nil {
t.Fatalf("AddFederationPeer: %v", err)
}
}
captureWarnings()
if err := store.withPeerAuth(ctx, tc.remote, func(string) error { return nil }); err != nil {
t.Fatalf("withPeerAuth: %v", err)
}
}
if got := warnings.String(); got != tc.wantLine {
t.Errorf("warning = %q, want %q", got, tc.wantLine)
}
})
}
}
func TestWithPeerAuth_RestoresEnvWhenCallbackFails(t *testing.T) {
ctx := t.Context()
store := newPeerAuthTestStore(t)