Skip to content

fix(security): secrets held by name, value or role join the redaction set and the child scrub, serve token from a file - #690

Merged
ajianaz merged 4 commits into
developfrom
security/secrets-by-role
Nov 13, 2026
Merged

ajianaz merged 4 commits into
developfrom
security/secrets-by-role

Conversation

@ajianaz

@ajianaz ajianaz commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What

Every secret tole holds, whether by name, by value or by role, now joins both the redaction set and the child-environment scrub (ENV-1). tole serve can also read its bearer token from a file, so the token does not have to sit in the process arguments.

Why

#682 (audit of #594): the scrub and the redactor recognised a secret only by its variable NAME (API_KEY, SECRET, TOKEN, PASSWORD, ...). As a result:

  • DB_PASS, PGPASS, DATABASE_URL, REDIS_URL=redis://:pw@..., SENTRY_DSN, OPENAI_KEY, STRIPE_SK, NPM_AUTH and SESSION_COOKIE reached run_command, job_start and cron children and were never redacted.
  • A webhook key named by hmac_key_env = "GH_HOOK_KEY" (or read from hmac_key_file) was neither scrubbed nor redacted. With that key, anyone can sign deliveries.
  • tole serve --token <value> left the token readable in /proc/<pid>/cmdline and outside the secret set.
  • ${NAME} web header expansions were redacted, but NAME still reached every child.

Changes

  • Name rule (secrets::is_secret_name, shared by the scrub and the redactor):
    • Still matched as before: the old markers, plus PASSPHRASE anywhere in the name.
    • Endings now matched: PASS, _KEY, _DSN, _SK, _COOKIE, _AUTH, _BEARER and DATABASE_URL.
    • Beginnings now matched: AUTH_ and BEARER_.
    • Kept ordinary, by explicit exception: SSH_AUTH_SOCK (the git tool needs it), GPG_KEY (official language images export a key fingerprint under that name), names ending PUBLIC_KEY, PUB_KEY or PUBKEY, and names ending BYPASS.
    • Checked by a test as staying ordinary: GIT_AUTHOR_*, XDG_SESSION_TYPE, DBUS_SESSION_BUS_ADDRESS, MONKEY, KEYBOARD, PWD, REDIS_URL, TOLE_BASE_URL.
  • Value rule (secrets::is_secret_var, used by the scrub):
    • A variable is also a secret when its value is a URL with a password, whatever it is called. SecretSet::collect now collects that password, so it is redacted too.
    • A variable is also a secret when its value is one the process holds (SecretSet::holds).
    • Proxy settings (*_PROXY, any case) are exempt from removal for their URL password, because every network command behind an authenticated proxy needs them. Their password is still redacted.
  • Secrets held by role:
    • secrets::add_role_secret / role_secrets record a value under a label and install it in the process set.
    • hooks::hold_keys records every webhook route key as hooks.<route>. tole serve and tole hook test call it.
    • serve_token records the serve token.
    • provider_chain::process_secrets folds role secrets into each session's set.
    • SecretSet::from_env now includes the ${NAME} header expansions, so the process set knows them before any session exists.
  • Child agents also keep TOLE_BASE_URL, OPENAI_BASE_URL and TOLE_FALLBACK_BASE_URL, which the scrub now removes when they carry a password (child_env::PROVIDER_SECRETS).
  • [secrets] keys may also be *_URL / *_URI names, so a connection string scrubbed for its value can be granted back.
  • tole serve --token-file <path>:
    • The file must be a regular file (no link, no FIFO), at most 4 KiB. Surrounding whitespace is dropped, and an empty file is an error.
    • It conflicts with --token.
    • --token <value> still works, with a warning naming TOLE_SERVE_TOKEN and --token-file.
    • Errors never carry the token.
  • Docs:
    • Threat model: ENV-1 row, egress row, and a new "process arguments" row.
    • secrets-integrations-design.md §9.
    • README remote-approvals example.
    • CHANGELOG: a BREAKING entry with a migration note, and the --token-file entry.

Decisions to check

  • Name families. I chose endings and beginnings rather than more substrings, so AUTHOR, SESSION and KEYBOARD stay ordinary. I did not add SESSION as a marker: it is too broad (XDG_SESSION_TYPE). REDIS_URL and other *_URL names are secrets by value (when they carry a password), not by name. DATABASE_URL is a secret by name, as you asked.
  • Proxy exemption. A credentialed HTTPS_PROXY keeps reaching children, and its password is redacted. Removing it would break cargo, git and curl behind such a proxy, with no grant to restore it unless the name is [A-Z0-9_].
  • --token is warned, not removed. Removing it would break existing service units. Residual: tole approvals --token (a client) keeps the argument form; TOLE_SERVE_TOKEN works there.
  • Header expansions with arbitrary names cannot be granted through [secrets]. The key validation accepts secret-shaped names and *_URL / *_URI names. Such a variable is bound to tole's own web backend, which reads it in-process.
  • Behaviour change (BREAKING, in the CHANGELOG with a migration note): a command that used to see DB_PASS, DATABASE_URL, OPENAI_KEY or a password-bearing *_URL now needs a [secrets] grant.

Testing

  • secrets::tests::the_name_rule_covers_the_pass_key_dsn_and_auth_families: the audit's name list (less the *_URL names, which are covered by value), and a list of ordinary names that must stay ordinary.
  • secrets::tests::a_variable_is_a_secret_by_its_value: a URL password under any name, a value held by role, the proxy exemption, and the collected password redacted.
  • crates/tole-core/tests/secrets_by_role.rs (its own process, real environment): a webhook-style role secret under an odd name, REDIS_URL with a password, DB_PASS and a ${HDR_SETTING} header expansion are all absent from a scrubbed run_command child's printenv. An ordinary variable and the proxy setting stay. All of them are redacted from text under their names.
  • hooks::tests::hold_keys_makes_every_route_key_a_process_secret: a key from a variable with an innocent name is redacted as «hooks.gh» and known to the scrub.
  • serve::tests::the_serve_token_prefers_the_file_and_never_echoes_a_value: precedence, the empty and missing file, no token in errors, and the token redacted as «TOLE_SERVE_TOKEN».
  • crates/tole-cli/tests/serve_token.rs (real binary):
    • With --token-file, the server accepts the file's token (200) and refuses another (401), and /proc/<pid>/cmdline does not contain the token.
    • --token prints the warning.
    • An empty file stops the server.
    • --token together with --token-file is refused.
  • Red on develop and mutation checks: each was run and failed as expected.
    • Disabling the name endings fails the name-rule test.
    • A name-only scrub fails secrets_by_role ("child env holds" the role value).
    • A no-op hold_keys fails the hooks test.
    • Dropping the token registration fails the serve token test.
  • Gates on the merged head: cargo fmt --all --check, cargo clippy --workspace --all-targets --all-features -- -D warnings, cargo test --workspace, cargo test -p tole-core --no-default-features, the no-mcp CI profile, and cora review --no-llm --base origin/develop (no issues).

Closes #682

@github-actions

Copy link
Copy Markdown

🔍 Cora AI Code Review

✅ No issues found. Code looks good!


Review powered by cora-code · BYOK · MIT

@ajianaz
ajianaz merged commit d385f06 into develop Nov 13, 2026
19 checks passed
@ajianaz
ajianaz deleted the security/secrets-by-role branch November 20, 2026 08:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

security(secrets): secrets tole knows by role (webhook keys, serve --token, URL passwords, *_PASS, *_KEY) are neither scrubbed nor redacted

2 participants