diff --git a/cmd/bd/dolt_autopush.go b/cmd/bd/dolt_autopush.go index 82130d2db..de0a99ea6 100644 --- a/cmd/bd/dolt_autopush.go +++ b/cmd/bd/dolt_autopush.go @@ -142,6 +142,9 @@ func maybeAutoPush(ctx context.Context) { if err := st.Push(ctx); err != nil { if !isQuiet() && !jsonOutput { fmt.Fprintf(os.Stderr, "Warning: dolt auto-push failed: %v\n", err) + if isDivergedHistoryErr(err) { + printDivergedHistoryGuidance("push") + } } debug.Logf("dolt auto-push: push error: %v\n", err) return diff --git a/cmd/bd/github.go b/cmd/bd/github.go index c9f2a9c46..b44638f0b 100644 --- a/cmd/bd/github.go +++ b/cmd/bd/github.go @@ -187,6 +187,22 @@ func getGitHubConfig() GitHubConfig { // getGitHubConfigValue reads a GitHub configuration value from store or environment. func getGitHubConfigValue(ctx context.Context, key string) string { + // Secret keys (e.g. github.token) are stored in config.yaml, not the + // Dolt database, to avoid leaking secrets when pushing to remotes. + if config.IsYamlOnlyKey(key) { + if value := config.GetString(key); value != "" { + return value + } + // Fall back to environment variable + envKey := githubConfigToEnvVar(key) + if envKey != "" { + if value := os.Getenv(envKey); value != "" { + return value + } + } + return "" + } + // Try to read from store (works in direct mode) if store != nil { value, _ := store.GetConfig(ctx, key) diff --git a/cmd/bd/linear.go b/cmd/bd/linear.go index e60838a9f..83c025b5a 100644 --- a/cmd/bd/linear.go +++ b/cmd/bd/linear.go @@ -557,6 +557,21 @@ func maskAPIKey(key string) string { // getLinearConfig reads a Linear configuration value. Returns the value and its source. // Priority: project config > environment variable. func getLinearConfig(ctx context.Context, key string) (value string, source string) { + // Secret keys (e.g. linear.api_key) are stored in config.yaml, not the + // Dolt database, to avoid leaking secrets when pushing to remotes. + if config.IsYamlOnlyKey(key) { + if value := config.GetString(key); value != "" { + return value, "project config (config.yaml)" + } + envKey := linearConfigToEnvVar(key) + if envKey != "" { + if value := os.Getenv(envKey); value != "" { + return value, fmt.Sprintf("environment variable (%s)", envKey) + } + } + return "", "" + } + // Try to read from store (works in direct mode) if store != nil { value, _ = store.GetConfig(ctx, key) // Best effort: empty value is valid fallback diff --git a/cmd/bd/store_reopen_test.go b/cmd/bd/store_reopen_test.go index a7539d56c..d80655083 100644 --- a/cmd/bd/store_reopen_test.go +++ b/cmd/bd/store_reopen_test.go @@ -151,6 +151,9 @@ func TestResolveCommandBeadsDir_NoCWDFallbackForExplicitPath(t *testing.T) { } func TestGetGitHubConfigValue_UsesMetadataWhenStoreNil(t *testing.T) { + // github.token is now a YAML-only key (not stored in Dolt DB) to avoid + // leaking secrets when pushing to remotes. Test that the env-var fallback + // still works when the store is nil. originalStore := store originalDBPath := dbPath defer func() { @@ -159,14 +162,10 @@ func TestGetGitHubConfigValue_UsesMetadataWhenStoreNil(t *testing.T) { }() ctx := context.Background() - testDBPath := filepath.Join(t.TempDir(), "dolt") - testStore := newTestStoreIsolatedDB(t, testDBPath, "cfg") - if err := testStore.SetConfig(ctx, "github.token", "ghp_test_token"); err != nil { - t.Fatalf("SetConfig: %v", err) - } - store = nil - dbPath = testDBPath + dbPath = "" + + t.Setenv("GITHUB_TOKEN", "ghp_test_token") if got := getGitHubConfigValue(ctx, "github.token"); got != "ghp_test_token" { t.Fatalf("getGitHubConfigValue() = %q, want %q", got, "ghp_test_token") diff --git a/internal/config/yaml_config.go b/internal/config/yaml_config.go index 4fcda5da6..3d03cddf2 100644 --- a/internal/config/yaml_config.go +++ b/internal/config/yaml_config.go @@ -65,6 +65,12 @@ var YamlOnlyKeys = map[string]bool{ // Dolt server settings "dolt.idle-timeout": true, // Idle auto-stop timeout (default "30m", "0" disables) "dolt.shared-server": true, // Shared Dolt server at ~/.beads/shared-server/ (GH#2377) + + // Secrets: tokens and API keys must NOT be stored in the Dolt database + // because that data is pushed to remotes, triggering secret-scanning + // blocks on GitHub. Store them in local config.yaml instead. + "github.token": true, + "linear.api_key": true, } // IsYamlOnlyKey returns true if the given key should be stored in config.yaml diff --git a/internal/config/yaml_config_test.go b/internal/config/yaml_config_test.go index f8b35f525..81a555173 100644 --- a/internal/config/yaml_config_test.go +++ b/internal/config/yaml_config_test.go @@ -37,10 +37,13 @@ func TestIsYamlOnlyKey(t *testing.T) { {"backup.git-repo", true}, {"backup.future-key", true}, // prefix match + // Secret keys (stored in yaml to avoid leaking via Dolt push) + {"github.token", true}, + {"linear.api_key", true}, + // Non-yaml keys (should return false) {"jira.url", false}, {"jira.project", false}, - {"linear.api_key", false}, {"github.org", false}, {"custom.setting", false}, {"status.custom", false},