Skip to content

fix(console): redact MAD_SECRETS_* values in printed/raised commands#150

Open
mkuznet1 wants to merge 2 commits into
ROCm:developfrom
mkuznet1:fix/mask-mad-secrets-hftoken
Open

fix(console): redact MAD_SECRETS_* values in printed/raised commands#150
mkuznet1 wants to merge 2 commits into
ROCm:developfrom
mkuznet1:fix/mask-mad-secrets-hftoken

Conversation

@mkuznet1

Copy link
Copy Markdown
Contributor

Summary

Docker run/build commands and the Docker options: line were printed to
stdout (and embedded into raised RuntimeError messages) with
MAD_SECRETS_HFTOKEN in plaintext. This leaked the HuggingFace token into
SLURM *.out files and per-node run_logs, which are persisted on shared
storage.
This PR adds a central redact_secrets() helper in core.console and applies
it 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.py
    • New redact_secrets() helper + _REDACTED marker.
    • _SECRET_ASSIGN_RE masks MAD_SECRETS*=value in any form (-e / --env /
      --build-arg / bare), keeping the key, masking the value.
    • _TOKEN_PATTERNS fallback masks known credential shapes
      (hf_…, sk-…, ghp_/gho_/…, xox[abprs]-…).
    • Applied in Console.sh verbose stdout and in the RuntimeError message.
  • src/madengine/execution/container_runner.py
    • Docker options: line now prints via redact_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.

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.
@mkuznet1 mkuznet1 self-assigned this Jun 30, 2026
@mkuznet1 mkuznet1 added the enhancement New feature or request label Jun 30, 2026
@mkuznet1 mkuznet1 requested a review from Copilot June 30, 2026 14:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 in core.console and 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.

Comment thread src/madengine/core/console.py Outdated
Comment thread src/madengine/core/console.py Outdated
Comment thread src/madengine/core/console.py
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.
@mkuznet1 mkuznet1 marked this pull request as ready for review June 30, 2026 14:25
@mkuznet1 mkuznet1 requested a review from gargrahul as a code owner June 30, 2026 14:25
Copilot AI review requested due to automatic review settings June 30, 2026 14:25

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants