feat(govern): redact common credential names such as OPENAI_API_KEY and PGPASSWORD

What does this MR do and why?

Follow-up to !4345 (merged). sensitiveKey decides which names have their values redacted, both for JSON keys in tool arguments and for NAME=value and NAME: value in text. It only matched a bare api_key or secret_key, and needed a - or _ before password, passwd and pwd. So common names were sent as they were.

These now match:

  • *_API_KEY, such as OPENAI_API_KEY and ANTHROPIC_API_KEY
  • *_SECRET_KEY, such as STRIPE_SECRET_KEY
  • *_PRIVATE_KEY, such as SSH_PRIVATE_KEY
  • *_PWD, such as MYSQL_PWD
  • names ending in password or passwd, with or without a separator, such as PGPASSWORD

Names that only contain those words, such as api_key_id, secret_key_name or password_file, are kept. Every name the old pattern matched still matches.

It also fixes the rule for paths. !4345 (merged) never redacted a value in text that started with / or ~, to keep PWD=/home/.... That also kept passwords and base64 secrets that start with /, such as about 1 in 64 AWS secret keys. Now only PWD holding a path is kept, in text and JSON, and PWD in an ODBC connection string (...;PWD=...;) is still redacted.

Known limits:

  • Names such as requirePassword or hasPassword now match, so a JSON value like "true" under them is redacted. Text isn't affected, because a value needs 8 characters and a digit.
  • A path under another credential name, such as SSH_PRIVATE_KEY: ~/.ssh/id_ed25519, is redacted.
  • camelCase names such as openaiApiKey and clientSecret still don't match, as before.

How to validate

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

Closes #8728

Merge request reports

Loading
Loading