feat(govern): redact values assigned to credential-like names in text

What does this MR do and why?

glab govern audit sync only redacts a value by its name when the name is a JSON key. A secret in an unknown format is sent as it is in a command such as export MY_API_TOKEN=..., or in a .env or YAML file the agent writes.

This applies the same credential names (sensitiveKey) to NAME=value and NAME: value in text, and replaces the value with [REDACTED:credential].

  • The pattern only matches the name and its separator. The value is read by assignedValue, so a name inside another value is still found, for example args: --token=..., $env:DB_PASSWORD = "..." or url=https://h/p?token=....
  • A quoted value runs to its closing quote, including escaped quotes such as \"...\". Any other value ends at a space, quote, backslash, bracket or separator.
  • To avoid false positives, the value must have a digit and must not start with $, <, {, [, &, (, =, / or ~. This keeps type annotations (token: Optional[str], apiKey: ApiKeyType), comparisons (password == ...), calls whose name has no digit (getToken(ctx)), paths (PWD=/home/...), variables, placeholders and prose such as password: see 1Password.
  • Values are read for at most 256 characters, and only the start of a longer value is replaced. Redaction stays linear: about 1 MB of adversarial input (chained a=, next_token=, quoted and escaped values) takes 60 to 200 ms.

Known limits, as with the rest of the redaction this is best effort:

  • A value without a digit is kept, such as password: correcthorsebattery.
  • An unquoted value is only redacted up to a ,, ;, & or bracket in it, so a password such as Secr3tP@ss(x) keeps (x).
  • A call whose function name has a digit and 8 or more characters is redacted, for example password = hashlib.sha256(pw).
  • Some common names, such as OPENAI_API_KEY and PGPASSWORD, aren't in the credential name list yet. That's tracked separately in #8728.

How to validate

go test ./internal/commands/govern/audit/sync/ -run TestRedact

The new cases in TestRedactSecrets cover the redacted values and the false positives above.

Closes #8695

Edited by Jean van der Walt

Merge request reports

Loading
Loading