fix(console): redact MAD_SECRETS_* values in printed/raised commands#150
Open
mkuznet1 wants to merge 2 commits into
Open
fix(console): redact MAD_SECRETS_* values in printed/raised commands#150mkuznet1 wants to merge 2 commits into
mkuznet1 wants to merge 2 commits into
Conversation
docker run/build commands and the "Docker options:" line were printed with MAD_SECRETS_HFTOKEN in plaintext, leaking the HF token into SLURM and run logs. Add a central redact_secrets() helper in core.console and apply it at every command print/exception site (Console.sh stdout, the RuntimeError message, and container_runner Docker options). Only the logged representation is scrubbed; the executed command is unchanged.
There was a problem hiding this comment.
Pull request overview
This PR prevents credential leakage by redacting MAD_SECRETS_* values (and other token-shaped secrets) from any Docker command text that gets printed to stdout or included in raised RuntimeError messages, without changing the command actually executed.
Changes:
- Added a centralized
redact_secrets()helper incore.consoleand applied it to verbose command logging and subprocess failure errors. - Updated container execution logging to redact secrets in the printed
Docker options:line.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/madengine/core/console.py | Adds redact_secrets() and applies it to command printing and exception messages. |
| src/madengine/execution/container_runner.py | Redacts secrets in the Docker options: log line. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Address PR ROCm#150 review feedback on the MAD_SECRETS redaction helper: - _SECRET_ASSIGN_RE now also masks single-/double-quoted values that may contain spaces, and empty values, so shell-quoted env/build-arg forms are fully redacted instead of leaving the tail visible. - Fix redact_secrets() docstring to reflect the Optional[str] signature. - Add TestRedactSecrets covering env/build-arg, quoted values, known token shapes, None/empty passthrough, and the raised RuntimeError message.
Comment on lines
+21
to
+23
| _SECRET_ASSIGN_RE = re.compile( | ||
| r"""(MAD_SECRETS[A-Za-z0-9_]*\s*=)("[^"]*"|'[^']*'|\S*)""" | ||
| ) |
Comment on lines
+72
to
+77
| def test_redacts_build_arg(self): | ||
| cmd = f"docker build --build-arg MAD_SECRETS_HFTOKEN={_FAKE_HF} ./docker" | ||
| out = console.redact_secrets(cmd) | ||
| assert _FAKE_HF not in out | ||
| assert "MAD_SECRETS_HFTOKEN=***REDACTED***" in out | ||
|
|
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.
Summary
Docker
run/buildcommands and theDocker options:line were printed tostdout (and embedded into raised
RuntimeErrormessages) withMAD_SECRETS_HFTOKENin plaintext. This leaked the HuggingFace token intoSLURM
*.outfiles and per-noderun_logs, which are persisted on sharedstorage.
This PR adds a central
redact_secrets()helper incore.consoleand appliesit at every command print / exception site. Only the logged representation is
scrubbed — the executed command is unchanged, so container builds/runs still
receive the real secret.
Changes
src/madengine/core/console.pyredact_secrets()helper +_REDACTEDmarker._SECRET_ASSIGN_REmasksMAD_SECRETS*=valuein any form (-e/--env/--build-arg/ bare), keeping the key, masking the value._TOKEN_PATTERNSfallback masks known credential shapes(
hf_…,sk-…,ghp_/gho_/…,xox[abprs]-…).Console.shverbose stdout and in theRuntimeErrormessage.src/madengine/execution/container_runner.pyDocker options:line now prints viaredact_secrets(docker_options).Why this approach
Masking at the single logging/printing layer (rather than at each call site)
guarantees coverage of the three known leak points and is resilient to new
token formats via the fallback patterns, without touching the command actually
executed.