mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
fix(cli): preserve ordinary diagnostics during credential redaction
This commit is contained in:
1 parent
5147b16052
commit
bfc9ed852b
3 files changed
+40
-3
No files matched your search
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user