Redaction¶
redact
¶
Redact secrets from text before it is recorded or shown.
Command output from a sandbox (the tails of setup and validate steps) ends up
in run records, bot comments and job logs. :func:redact replaces what looks
like a credential with :data:REDACTED:
- the value of an
Authorization,Proxy-Authorization,Cookie,Set-Cookie,X-Api-KeyorApi-Keyheader, and aBearerorBasiccredential anywhere; - the user information of a URL (
https://user:token@hostbecomeshttps://[REDACTED]@host); - tokens with a well-known shape: OpenAI and Anthropic keys, GitHub, GitLab, npm and Slack tokens, AWS access key ids, Google API keys and OAuth access tokens, JSON Web Tokens and OpenShell credential placeholders;
- the value in
NAME=valueor"name": "value"when the name looks like a credential (token, secret, password, key, credential, auth, cookie or the word pat); - every literal value given in secrets, such as the credentials the host
holds (:func:
secret_values).
It is a best-effort filter for accidental leaks, not a guarantee: a secret with no recognizable shape that the host does not hold passes through.
is_secret_name(name)
¶
secret_values(env)
¶
The values of env whose names look like credentials, longest first.
Values shorter than :data:MIN_SECRET_LENGTH are left out, as are values
that are not strings. Surrounding whitespace is stripped, so a key read
from a file with a trailing newline still matches. Each line of a
multi-line value (a PEM key, a JSON credential) is included too, because
step tails are redacted line by line.
Source code in src/agentic_ci/redact.py
redact(text, secrets=())
¶
Return text with credentials replaced by :data:REDACTED (see the module docstring).