diff --git a/seaweed-block/cmd/sw-block/log_collect_redact.go b/seaweed-block/cmd/sw-block/log_collect_redact.go index 9641b0cbd6..e838f3a543 100644 --- a/seaweed-block/cmd/sw-block/log_collect_redact.go +++ b/seaweed-block/cmd/sw-block/log_collect_redact.go @@ -34,7 +34,7 @@ func bundleSensitiveKey(k string) bool { return k == "key" } func (r *bundleRedactor) remember(s string) { - if s == "" || s == bundleRedacted { + if len(s) < 8 || s == bundleRedacted { return } if len(r.secrets) > 4096 { @@ -102,6 +102,11 @@ func (r *bundleRedactor) discoverValue(v any) { } func (r *bundleRedactor) discoverText(text string) { for _, m := range bundleSecretValue.FindAllStringSubmatch(text, 4097) { + prefix := strings.TrimSpace(m[1]) + // Bare prose is masked in place, but is not a source of global secrets. + if !strings.ContainsAny(prefix, "=:") && !strings.HasPrefix(prefix, "-") { + continue + } for _, s := range m[2:] { r.remember(s) if decoded, e := strconv.Unquote(`"` + s + `"`); e == nil { diff --git a/seaweed-block/cmd/sw-block/log_collect_test.go b/seaweed-block/cmd/sw-block/log_collect_test.go index a18e1abb9b..3cd8d583b9 100644 --- a/seaweed-block/cmd/sw-block/log_collect_test.go +++ b/seaweed-block/cmd/sw-block/log_collect_test.go @@ -263,3 +263,33 @@ func TestLogCollectKeepsLocalLogsWhenTheMasterDoesNotAnswer(t *testing.T) { t.Fatalf("master failure lost local logs: %v %s", err, raw) } } + +func TestLogCollectKeepsOrdinaryWordsAndGenerationsWhileRedactingTokens(t *testing.T) { + addr, closeMaster := startInspectionMaster(t) + defer closeMaster() + dir := t.TempDir() + file := filepath.Join(dir, "daemon.log") + bundle := filepath.Join(dir, "bundle") + stamp := time.Now().UTC().Format("2006/01/02 15:04:05.000000") + const secret = "7e0adc2391fa44d09d6f0a77b8c2f196" + text := fmt.Sprintf("%s lease token is stale for volume v1 / deletion tokens=2 gen=12->13 / this is fine\n%s token=%s\n%s opaque %s\n", stamp, stamp, secret, stamp, secret) + text += stamp + " lease token unavailable / status remains unavailable\n" + os.WriteFile(file, []byte(text), 0600) + var out, errout bytes.Buffer + code := run([]string{"shell", "-master", addr, "-c", fmt.Sprintf("log.collect -out '%s' -log-file '%s'", filepath.ToSlash(bundle), filepath.ToSlash(file))}, &out, &errout) + if code != 3 { + t.Fatalf("exit%d %s", code, &errout) + } + raw, err := os.ReadFile(filepath.Join(bundle, "file-001.log")) + if err != nil { + t.Fatal(err) + } + for _, safe := range []string{stamp, "this is fine", "gen=12->13", "status remains unavailable"} { + if !bytes.Contains(raw, []byte(safe)) { + t.Fatalf("ordinary evidence %q destroyed: %s", safe, raw) + } + } + if bytes.Contains(raw, []byte(secret)) { + t.Fatalf("planted token escaped: %s", raw) + } +} diff --git a/seaweed-block/docs/design/log-collect.md b/seaweed-block/docs/design/log-collect.md index a036af83f9..0afdc2a596 100644 --- a/seaweed-block/docs/design/log-collect.md +++ b/seaweed-block/docs/design/log-collect.md @@ -87,8 +87,10 @@ The same boundary sanitizes structured status, startup arguments, logs and manifest errors. Sensitive key/value and flag names include password, token, credential, authorization, API/access/private/TLS/control/client/signing key, JWT and HMAC. Bearer and Basic authorization, URL user information and private-key PEM blocks are masked. -Identified credential values, including JSON/URL-escaped forms, are also removed -from other collected text. Unknown fields under a credential container are removed. +Explicitly identified credential values of at least eight bytes, including +JSON/URL-escaped forms, are also removed from other collected text. Bare whitespace +prose never teaches global replacement rules; ordinary words, dates and generation +numbers must remain readable. Shorter values are masked in their keyed/flag context. Unknown fields under a credential container are removed. Claim IDs remain support identifiers; they are not credentials. Ordinary diagnostic lines and typed observations remain useful. No configuration tree, environment,