This commit is contained in:
Rongjun GENG 2026-10-20 00:29:42 -07:00 • committed by GitHub
commit e065246b13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 134 additions and 65 deletions

View file

@ -139,6 +139,13 @@ func TestSetSettingProjectsTheWholeRequest(t *testing.T) {
// one place — and `Setting.redacted` would mean two different things depending on
// which operation produced it. Comparing the two responses is what makes a second
// projection impossible to add without failing here.
//
// THE CREDENTIAL-BEARING CASE RUNS AGAINST A FAKE ROLE (`&roleSettings{}`,
// which accepts any write), not workapi.ValidateSettingWrite. Since GH#7559
// the real role refuses notion.token — and every other config.IsYamlOnlyKey
// key — before this projection ever runs, so this case now exercises only the
// redaction PROJECTION in isolation: if a real server's role ever did accept
// a credential write, this is the shape the response would have to take.
func TestSetSettingAnswersWhatTheReadWouldAnswer(t *testing.T) {
for _, tc := range []struct {
name string
@ -146,7 +153,7 @@ func TestSetSettingAnswersWhatTheReadWouldAnswer(t *testing.T) {
value string
}{
{name: "an ordinary key", key: "status.custom", value: "awaiting_review:active"},
{name: "a credential-bearing key", key: "notion.token", value: "shhh-real-secret"},
{name: "a credential-bearing key, against a fake role that accepts it", key: "notion.token", value: "shhh-real-secret"},
{name: "a key stored empty", key: "notes", value: ""},
} {
t.Run(tc.name, func(t *testing.T) {
@ -173,15 +180,19 @@ func TestSetSettingAnswersWhatTheReadWouldAnswer(t *testing.T) {
}
// TestSetSettingWithholdsACredentialItJustAccepted is the doctrine, asserted
// directly rather than only through the equality above: the write is PERMITTED
// and the value does not come back.
// directly rather than only through the equality above: AGAINST A ROLE THAT
// ACCEPTS THE WRITE, the response is PERMITTED and the value does not come
// back.
//
// PERMITTED because redaction is a rule about DISCLOSURE. The role refuses no
// credential-bearing key — `bd config set`'s own secret guard is about writing
// one into a git-tracked config.yaml, a different plane with a different hazard —
// and a writer already holds the value, so refusing here would protect nothing
// while leaving a workspace's credentials visible as PRESENT and permanently
// unconfigurable through this door.
// IT RUNS AGAINST A FAKE ROLE (`&roleSettings{}`), not
// workapi.ValidateSettingWrite. Since GH#7559 the real role refuses every
// config.IsYamlOnlyKey key — including every tracker credential, writing
// them to a git-tracked config.yaml instead via `bd config set`'s own guard
// — because that plane is the Dolt config table, synced to every remote on
// push/pull. What this test pins is narrower: IF a role's write succeeds,
// the HTTP layer's redaction projection must withhold the value from its own
// answer regardless, which is what the handler owns and the only part of
// this doctrine the httpapi package can prove on its own.
func TestSetSettingWithholdsACredentialItJustAccepted(t *testing.T) {
const key = "notion.token"
if !config.IsSecretKey(key) {

View file

@ -9,6 +9,7 @@ import (
"net/url"
"strings"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/httpapi/apigen"
"github.com/steveyegge/beads/internal/httpclient/wire"
"github.com/steveyegge/beads/internal/types"
@ -241,6 +242,18 @@ func validateSettingWrite(key, value string) error {
if err := validateSettingKey(key); err != nil {
return err
}
// config.YamlOnlyKeys — startup settings and the tracker secrets — must
// live in the workspace's local config.yaml, never in this plane's
// row-per-key storage, which is the Dolt config table: a SYNCED table
// replicated to every remote on push/pull. `bd config set` already
// refuses these at its own door; this mirror and the server-side
// workapi.ValidateSettingWrite it is pinned to (wave2c_config_test.go's
// TestSettingWriteValidationMatchesTheSharedValidator) are two more doors
// onto the same plane and must refuse the same set (GH#7559).
if config.IsYamlOnlyKey(key) {
return invalid("%q must be set in the workspace's local config.yaml (bd config set %s <value>), not written here: "+
"this plane is the Dolt config table, which syncs to every remote on push/pull", key, key)
}
// The prefix is owned by `bd init --prefix`, `bd bootstrap` and
// `bd rename-prefix`, each of which does work this plane cannot: rewriting
// existing ids, or seeding a workspace that has none. Storing a new one here

View file

@ -26,29 +26,20 @@ import (
// SERVER's, and a stub transport would let this file assert whatever it liked
// about them.
// TestServedConfigWriteAnswersTheReadThatFollowsIt is the redaction doctrine,
// pinned on both sides of the one key it changes anything for.
// TestServedConfigWriteAnswersTheReadThatFollowsIt pins GH#7559 end to end
// against a real served role, beside the unrelated transcription property the
// ordinary key below it was always here to prove.
//
// The operation PERMITS a credential-bearing write and WITHHOLDS the value from
// its own answer — one projection serves the write and the read, so the body of
// a PUT is byte-identical to the body of the GET after it. That leaves a
// successful write whose `value` member is absent, and the role's result has no
// spelling for "withheld": reporting "" would tell a caller the plane holds
// nothing under that key, which is the write-side version of the confusion
// RedactedSettingError exists to prevent on the read side.
//
// So the client answers with the value it SENT, and this asserts why that is
// honest rather than convenient: the value really is stored, read RAW from the
// reference store past the wire that hid it.
//
// WHAT THIS CASE CANNOT SAY is that the ordinary key beside it is TRANSCRIBED
// off the answer rather than echoed from the request. Against a correct server
// the two are byte-identical — the operation promises the stored value equals
// the value sent for every key it accepts — so the difference is pinned where it
// is observable, against a transport that answers something else:
// TestSetSettingTranscribesTheAnswerRatherThanEchoingTheRequest. The ordinary
// key runs here anyway, because a client that transcribed the WRONG member would
// fail it.
// BEFORE GH#7559 this case pinned the redaction doctrine: a credential-bearing
// write was PERMITTED and only the ANSWER withheld the value. That doctrine
// was wrong for this door — the credential landed in the Dolt config table,
// a table `bd dolt push`/pull replicates to every remote — so the fix refuses
// the write instead of merely hiding its result. There is nothing left for
// this case to prove about REDACTION on a key workapi.ValidateSettingWrite now
// refuses outright; the httpapi package's fake-role tests
// (TestSetSettingAnswersWhatTheReadWouldAnswer, TestSetSettingWithholdsACredentialItJustAccepted)
// keep pinning what the redaction PROJECTION does if a role ever did accept
// such a write.
func TestServedConfigWriteAnswersTheReadThatFollowsIt(t *testing.T) {
e := newServedEnv(t, "hcfgw1")
ctx := t.Context()
@ -56,32 +47,28 @@ func TestServedConfigWriteAnswersTheReadThatFollowsIt(t *testing.T) {
const secretKey = "notion.token"
const secret = "shhh-real-secret"
res, err := settings.SetSetting(ctx, issueops.SetSettingRequest{Key: secretKey, Value: secret})
if err != nil {
t.Fatalf("SetSetting on a credential-bearing key = %v; the write is permitted and only the ANSWER withholds", err)
}
if res.Key != secretKey {
t.Errorf("SetSetting echoed key %q, want %q", res.Key, secretKey)
}
if res.Value != secret {
t.Errorf("SetSetting reported value %q, want %q: the answer withheld it, and \"\" would say the plane stores nothing there",
res.Value, secret)
_, err := settings.SetSetting(ctx, issueops.SetSettingRequest{Key: secretKey, Value: secret})
if !errors.Is(err, issueops.ErrValidation) {
t.Fatalf("SetSetting on a credential-bearing key = %v, want ErrValidation: "+
"this plane is the Dolt config table, synced to every remote on push/pull", err)
}
// Read RAW, past the role and past the wire: the point is that the value the
// response would not repeat IS the value the workspace now holds.
// Read RAW, past the role and past the wire: nothing was written.
stored, err := e.reference.GetConfig(ctx, secretKey)
if err != nil {
t.Fatalf("read the stored credential back from the reference store: %v", err)
t.Fatalf("read the reference store for the key that must not have been written: %v", err)
}
if stored != secret {
t.Errorf("the workspace stores %q under %q, want %q", stored, secretKey, secret)
if stored != "" {
t.Errorf("the workspace stores %q under %q, want nothing: the refused write must not have reached the store", stored, secretKey)
}
// And the READ that follows still withholds, which is the other half of "the
// PUT body is the GET body": a write does not unlock the key it just wrote.
// The READ side is unchanged by this fix and keeps its own doctrine: a
// GetSetting on a credential-bearing key withholds unconditionally, keyed
// on the KEY pattern rather than on whether anything is actually stored
// there — confirmed empirically (this is not something the write-side fix
// touches, so the refused write above leaves it exactly as it always was).
if _, err := settings.GetSetting(ctx, issueops.GetSettingRequest{Key: secretKey}); !errors.Is(err, ErrSettingRedacted) {
t.Errorf("GetSetting after the write = %v, want ErrSettingRedacted; the write does not unlock the read", err)
t.Errorf("GetSetting on a credential-bearing key = %v, want ErrSettingRedacted regardless of whether a write ever reached the store", err)
}
// The ordinary key is TRANSCRIBED, not echoed. The server answers this one
@ -90,7 +77,7 @@ func TestServedConfigWriteAnswersTheReadThatFollowsIt(t *testing.T) {
// something else.
const plainKey = "custom.hcfgw1-plain"
const plain = " spaces and , commas "
res, err = settings.SetSetting(ctx, issueops.SetSettingRequest{Key: plainKey, Value: plain})
res, err := settings.SetSetting(ctx, issueops.SetSettingRequest{Key: plainKey, Value: plain})
if err != nil {
t.Fatalf("SetSetting on an ordinary key: %v", err)
}

View file

@ -47,7 +47,7 @@ func TestSettingWriteValidationMatchesTheSharedValidator(t *testing.T) {
key string
value string
}{
{"an ordinary key", "routing.default", "core"},
{"an ordinary key", "notes", "core"},
{"an empty key", "", "x"},
{"a blank key", " ", "x"},
{"the protected key", issueops.SettingKeyIssuePrefix, "bd"},
@ -57,6 +57,10 @@ func TestSettingWriteValidationMatchesTheSharedValidator(t *testing.T) {
{"an empty custom status", issueops.SettingKeyStatusCustom, ""},
{"a custom type list", issueops.SettingKeyTypesCustom, "not:a:status"},
{"a key that only LOOKS protected", "issue_prefix_backup", "bd"},
// config.IsYamlOnlyKey, GH#7559: exact-match (a tracker secret) and
// prefix-match (a whole family, e.g. routing.*) both refuse here now.
{"a yaml-only key, exact match", "github.token", "ghp_x"},
{"a yaml-only key, prefix match", "routing.default", "core"},
} {
t.Run(tc.name, func(t *testing.T) {
mine := validateSettingWrite(tc.key, tc.value)
@ -203,13 +207,21 @@ func TestConfigWritesDialTheKeyInThePath(t *testing.T) {
// right answer: the projection withholds the value it just accepted, so there is
// nothing to transcribe and the request is the only honest source. Both arms in
// one case so neither can be satisfied by a body that always does one of them.
//
// BOTH ARMS USE AN ORDINARY KEY. The redacted/not-redacted branch is driven by
// the fake answer's own Redacted field, not by the key name, and since GH#7559
// a real credential-bearing key (or any other config.IsYamlOnlyKey key) never
// reaches this transport at all — validateSettingWrite refuses it client-side
// first. That doctrine has its own pin (TestSettingWriteValidationMatchesTheSharedValidator);
// this case is only about what the client does with the answer once a write is
// accepted.
func TestSetSettingTranscribesTheAnswerRatherThanEchoingTheRequest(t *testing.T) {
const sent = "what the caller sent"
stored := "what the server stored"
plain := &settingAnswerWire{answer: apigen.Setting{Key: "routing.default", Value: &stored}}
plain := &settingAnswerWire{answer: apigen.Setting{Key: "notes", Value: &stored}}
res, err := settingsOver(t, plain).SetSetting(context.Background(),
issueops.SetSettingRequest{Key: "routing.default", Value: sent})
issueops.SetSettingRequest{Key: "notes", Value: sent})
if err != nil {
t.Fatalf("SetSetting: %v", err)
}
@ -217,15 +229,15 @@ func TestSetSettingTranscribesTheAnswerRatherThanEchoingTheRequest(t *testing.T)
t.Errorf("SetSetting reported %q, want the answer's %q: the result is what the workspace holds, "+
"and echoing the request would report a value it does not", res.Value, stored)
}
if res.Key != "routing.default" {
if res.Key != "notes" {
t.Errorf("SetSetting reported key %q, want the answer's", res.Key)
}
withheld := &settingAnswerWire{answer: apigen.Setting{Key: "notion.token", Redacted: true}}
withheld := &settingAnswerWire{answer: apigen.Setting{Key: "custom.thing", Redacted: true}}
res, err = settingsOver(t, withheld).SetSetting(context.Background(),
issueops.SetSettingRequest{Key: "notion.token", Value: sent})
issueops.SetSettingRequest{Key: "custom.thing", Value: sent})
if err != nil {
t.Fatalf("SetSetting on a credential-bearing key: %v", err)
t.Fatalf("SetSetting on an answer that redacts: %v", err)
}
if res.Value != sent {
t.Errorf("SetSetting on a withheld answer reported %q, want the request's %q: \"\" would say the plane "+

View file

@ -48,14 +48,13 @@ type ConfigReader interface {
// clears the file and any row an older bd left behind. That matters because the
// config table's contents are replicated by `bd dolt push`.
//
// ONE DOOR IS STILL OPEN, and this comment deliberately does not claim
// otherwise: the routing lives in the CLI command, not at the write chokepoint,
// so PUT /v0/beads/config/notion.token — `bd serve`, and the dashboard behind
// it — still writes the row with no refusal. That hole is not Notion's; it is
// identical for github.token, jira.api_token, linear.api_key and ado.pat, which
// is why closing it belongs at the role (workapi.ValidateSettingWrite /
// SetSetting), where every tracker credential gets the rule in one change,
// rather than here. Tracked as follow-up to GH#6676.
// THE DOOR CLOSED IN GH#7559: PUT /v0/beads/config/notion.token — `bd
// serve`, and the dashboard behind it — now refuses the write at the role
// (workapi.ValidateSettingWrite and the httpclient-side mirror it is pinned
// to), the same chokepoint every tracker credential refuses through, since
// the routing used to live only in the CLI command, not at the write
// chokepoint, and github.token/jira.api_token/linear.api_key/ado.pat shared
// the identical hole.
//
// The database read below therefore remains, both as the upgrade path for a
// workspace configured before the key moved and as the reader for anything that

View file

@ -4,6 +4,7 @@ import (
"fmt"
"strings"
"github.com/steveyegge/beads/internal/config"
"github.com/steveyegge/beads/internal/storage/kvkeys"
"github.com/steveyegge/beads/internal/types"
"github.com/steveyegge/beads/issueops"
@ -42,6 +43,21 @@ func ValidateSettingWrite(key, value string) (string, error) {
if _, err := ValidateSettingKey(key); err != nil {
return "", err
}
// config.YamlOnlyKeys — startup settings and the tracker secrets
// (github.token, linear.api_key, jira.api_token, gitlab.token, ado.pat) —
// must live in the workspace's local config.yaml, never in this plane's
// row-per-key storage: that storage is the Dolt config table, which is a
// SYNCED table (bd dolt push/pull, DOLT_CLONE, DOLT_PULL all replicate
// it). `bd config set` already refuses these at its own door; this is
// the only other door onto this plane (the settings HTTP surface bd
// serve and its dashboard expose), and it had no such rule, so a secret
// PUT through it landed in the synced table and reached every remote on
// the next push (GH#7559).
if config.IsYamlOnlyKey(key) {
return "", fmt.Errorf("%w: %q must be set in the workspace's local config.yaml (bd config set %s <value>), not written here: "+
"this plane is the Dolt config table, which syncs to every remote on push/pull",
issueops.ErrValidation, key, key)
}
// The prefix is owned by bd init --prefix, bd bootstrap and bd
// rename-prefix. Refused HERE rather than at the front door because `bd
// config set` is not the only door that reaches this plane: before this

View file

@ -57,6 +57,37 @@ func TestValidateSettingWriteRefusesTheProtectedKeyInBothSpellings(t *testing.T)
}
}
// TestValidateSettingWriteRefusesYamlOnlyKeys pins GH#7559: `bd config set`
// already refuses a YamlOnlyKey write via config.IsYamlOnlyKey at its own
// door, but this plane's HTTP settings surface (bd serve and its dashboard,
// PUT /v0/beads/config/{key}) had no such rule, so a tracker secret
// (github.token, linear.api_key, jira.api_token, gitlab.token, ado.pat) sent
// through it landed as a plain row in the Dolt config table — a SYNCED
// table, replicated to every remote on the next bd dolt push/pull. The
// PoC's five secret keys, plus a non-secret YamlOnlyKey (the exact GH#536
// shape the map exists to prevent: a write that reports success but no
// reader ever consults), must all be refused here now.
func TestValidateSettingWriteRefusesYamlOnlyKeys(t *testing.T) {
for _, key := range []string{
// The PoC's five secrets.
"github.token", "linear.api_key", "jira.api_token", "gitlab.token", "ado.pat",
// A non-secret YamlOnlyKey: the rule is "this plane is the database,
// these settings are not database settings", not "secrets only".
"no-db",
} {
_, err := ValidateSettingWrite(key, "SECRET-OR-SETTING-VALUE")
if !errors.Is(err, issueops.ErrValidation) {
t.Fatalf("ValidateSettingWrite(%q) error = %v, want ErrValidation", key, err)
}
if strings.Contains(err.Error(), "SECRET-OR-SETTING-VALUE") {
t.Errorf("ValidateSettingWrite(%q) error echoes the value %v; a secret must never appear in an error message", key, err)
}
if !strings.Contains(err.Error(), "config.yaml") {
t.Errorf("ValidateSettingWrite(%q) message %q does not point the caller at config.yaml", key, err)
}
}
}
func TestValidateSettingWriteParsesTheCustomStatusValue(t *testing.T) {
for _, value := range []string{
"awaiting_review",