Repository navigation
Redact secrets from logged completions - #8585
Open
sergiopaniego wants to merge 5 commits into
Open
sergiopaniego wants to merge 5 commits into
sergiopaniego wants to merge 5 commits into
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. Pages changed in this PR: |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Trainers that log completions now replace credentials with
<REDACTED>before the completions reach any log.With tools and environments, a completion carries what the tool or environment returned, so a model that prints its environment puts the trainer's credentials (for example
HF_TOKEN) in the logged completions. From there they reach the console, Trackio and W&B tables, the parquet files inoutput_dir, and the Hub dataset set withlog_completions_hub_repo.redact_secrets(intrl/trainer/utils.py) replaces:HF_TOKEN,*_API_KEY,*_SECRET*,*_PASSWORD), when they are at least 8 characters longsk-, GitHub, AWS access key IDs and PEM private keysIt walks strings nested in lists and dicts, so conversational prompts and completions, tool messages and extra columns are covered. Images and numbers are left as they are.
It runs where each trainer collects the texts it logs, so every destination gets the redacted text:
GRPOTrainer,RLOOTrainerlog_extracolumnsDistillationTrainer,GOLDTrainer,IWOPDTrainerAsyncGRPOTrainer, async distillation rollout workerprint_prompt_completions_sampleIt's always on, with no option to turn it off. The cost is a string replace per secret on the logged texts, once per logging step.
The GRPO docs get a warning in the Agent Training section: don't give tools and environments credentials they don't need, and the redaction is a safety net, not a guarantee (a secret split or encoded in the output is not caught).
The approach follows agent harnesses that scrub their trajectories: Harbor and OpenHands replace the values of credential env vars, and Trackio's trace scrubber and LangSmith's secret anonymizer match token formats. The downstream sinks don't protect against this: W&B and Trackio tables store the text as is, and the Hub's secret scanning only sends an email and doesn't cover LFS files such as parquet.
Before submitting
Tests:
TestRedactSecretsintests/test_utils.py: credential env values, token formats, a non-credential variable with a similar name (TOKENIZERS_PARALLELISM) left alone, and non-string values.test_train_with_tools_log_completions_redacts_secretsintests/test_grpo_trainer.py: a tool returns an API key from the environment during GRPO training, and the completions parquet holds<REDACTED>instead. It fails without the change.mainthe fake secrets show up 111 times across those outputs, with this PR 0 times.AI writing disclosure
Who can review?
Anyone in the community is free to review the PR once the tests have passed.
Note
Low Risk
Changes only affect logged text before export, not training or reward computation; low risk of functional regression aside from altered completion log content.
Overview
Adds automatic secret scrubbing for all completion logging paths so credentials never reach parquet files, W&B, Trackio, or the console unchanged.
A new
redact_secretshelper intrl/trainer/utils.pywalks nested strings, lists, and dicts and replaces credential-like environment variable values (names matching*_TOKEN,*_API_KEY, etc., when values are ≥8 chars) and common token shapes (HF, OpenAIsk-, GitHub, AWS, GCP, Slack, PEM private keys) with<REDACTED>. It is wired in at log-collection time for GRPO/RLOO (prompts, completions, andlog_extracolumns), Distillation, GOLD, IWOPD, AsyncGRPO, and the async distillation rollout worker—always on when logging, with no toggle.GRPO agent-training docs now warn that tools inherit the trainer env and redaction is a safety net, not a full guarantee. Unit tests cover
redact_secretsbehavior and an end-to-end GRPO run where a tool reads an API key from the environment and logged completions show<REDACTED>.Reviewed by Cursor Bugbot for commit 4e6a90f. Bugbot is set up for automated code reviews on this repo. Configure here.