Skip to content

fix(hermes): mask Kubernetes Secret data and env values (RIG-11725) - #214

Closed
rigel-mintaka wants to merge 4 commits into
mainfrom
harness/rig-11725-mask-kubernetes-secret-data-and-env
Closed

rigel-mintaka wants to merge 4 commits into
mainfrom
harness/rig-11725-mask-kubernetes-secret-data-and-env

Conversation

@rigel-mintaka

@rigel-mintaka rigel-mintaka commented Nov 21, 2026 •

Copy link
Copy Markdown
Contributor

What does this do

Hermes tool-output redaction now masks Kubernetes Secret data and secret-named env values in YAML, JSON, kubectl describe and cut-off output.

Why do we need it

A kubectl get secret -o yaml, a Pod spec or a describe run through Hermes put Secret values in the transcript. The upstream agent extension already masks these, but Hermes did not.

Summary

  • Adds agent/redact_kubernetes.py. It masks Secret data/stringData and env values whose names hold a secret word, and it handles cut-off, listed and annotated objects.
  • Secret-word names stay visible only on an exact allowlist (_NOT_SECRET_NAMES).
  • A *_FILE value is masked unless it is an absolute path.
  • _strip_props walks the line once, so it runs in linear time.
  • Adds tests: Kubernetes leak rows, linear-scaling ratios, and visible rows.

Verification

  • Kubernetes tests: 250 passed. All *redact* tests: 1099 passed, 1 xfailed. ruff check is clean.
  • perf3 at 1 MiB: strip_props_amp_chain went from 3260 ms to 46 ms.
  • Review: 4 rounds; round 4 is CLEAN at 136515fe (4 low).
  • Step-up: Fix11725r3 (implement) ran 13 min over 8 requests with no edits, so implement-hard took round 3.

Risks

Known lows:

  • TOKEN_URL with a secret in the query leaks.
  • JDBC_URL=…?password= leaks; it is pre-existing and belongs to the base redactor.
  • A *_FILE value that starts with / stays visible.
  • The exact allowlist masks some harmless names, such as AUTH_TIMEOUT.

Spec impact

Spec-impact: none. Redaction only.

Checks skipped: nebula has no pre-push hook config; GitHub Actions ci.yaml runs its checks

Refs RIG-11725

Co-authored-by: Matt Wilkinson matt@rigel.build

rigel-mintaka and others added 4 commits November 21, 2026 18:51
Add a Kubernetes pass to redact_sensitive_text. It masks Secret data and
stringData values (YAML and JSON, including truncated JSON), env value
entries under a secret-named name (YAML, JSON either order, kubectl
describe Environment blocks). Keys, ConfigMap data, valueFrom and
non-secret env stay. All scans are linear; a 1 MB test runs under 1 s.

Refs RIG-11725

Co-authored-by: Matt Wilkinson <matt@rigel.build>
Move the Kubernetes pass to agent/redact_kubernetes.py, a span-based
module. JSON is read in one token pass with an object stack. Each object
is decided when it closes or when the text ends, so kubectl key order
(data before kind), cut-off output, Lists, SecretList and the
last-applied-configuration annotation are masked. YAML is read in one
line pass. Helm flow env, Go-map env and describe lines are covered.
Secret names add PASS, PWD and AUTH; _TTL, _PATH and _FILE names stay
visible. Every review probe row is a test; 1 MB perf rows run under 1 s.

Refs RIG-11725

Co-authored-by: Matt Wilkinson <matt@rigel.build>
Run the PEM block pass before the Kubernetes pass, and mask every
continuation line of a describe env value. A list item with no kind is
decided by its list (SecretList, or unknown at end of text). A kind cut
off mid-word counts as unknown. JSON env after a one-word jsonpath
prefix is checked again. Setting names (MAX_, _TOKENS, _ENABLED, _MODE,
_LENGTH, _DAYS and similar) stay visible through a name allowlist; the
_ID exemption is gone. file_read masks with the non-reusable sentinel.
JSON nesting is capped at 512.

Refs RIG-11725

Co-authored-by: Matt Wilkinson <matt@rigel.build>
…v names

Refs RIG-11725

Co-authored-by: Matt Wilkinson <matt@rigel.build>
@linear-code

linear-code Bot commented Nov 21, 2026

Copy link
Copy Markdown

RIG-11725

@rigel-mintaka

Copy link
Copy Markdown
Contributor Author

All-clear at 2d4fc6f
Base: main

All-clear at 2d4fc6f

Review round 4 is CLEAN at 136515fe (4 low, listed under Risks). The rebase onto main has an empty interdiff. Tests: 250 Kubernetes and 1099 redact tests pass; ruff is clean.

@rigel-mintaka rigel-mintaka added the review-before-ready PR touches secrets or auth paths; review on the draft head before ready label Nov 22, 2026
@rigel-nemo

rigel-nemo Bot commented Nov 22, 2026

Copy link
Copy Markdown

Hold: masking gaps at 2d4fc6f (read-only review; code not run).

High

  • go-template and jsonpath Secret reads pass through. redact.py:1568 calls redact_kubernetes without the command. A jsonpath or go-template read of .data.<key> has no data: or value: shape, so nothing masks it. orion#8767 masks all of stdout for these reads; this PR has no equivalent.
  • kubectl set env --list prints NAME=value unmasked. The KEY=value pass runs only when code_file is false (redact.py:1570). redact_terminal_output sets code_file=True for kubectl (:1830), and kubectl is not in _ENV_DUMP_COMMANDS.
  • Go-map values cut off at ] or word:. The regexes at redact_kubernetes.py:394 and :397 stop early, so a value such as ab] cd leaves its tail visible. The gomap_value_with_space row does not include either character.

Medium

  • No masking past the depth limit. _json_spans stops at _MAX_DEPTH (redact_kubernetes.py:165-166), and Secret data deeper than that is not masked. Fail closed instead: mask the rest of the output.

Low

  • redact.py:1568 has no try/except around redact_kubernetes. Mask the whole output on an exception.

The hold lifts at a new head that fixes the three high findings and the medium one, adds a leak-row test for each, and has an exact-head all-clear. The RIG-11887 bans stay until then.

@rigel-mintaka
rigel-mintaka marked this pull request as draft November 22, 2026 04:51
@rigel-mintaka

Copy link
Copy Markdown
Contributor Author

Hold: RIG-11965 option A first; fallback C after EOD 11-22 ET

@rigel-mintaka

Copy link
Copy Markdown
Contributor Author

Superseded: option A chain (includes these commits) ships as a new PR; link follows.

@rigel-mintaka
rigel-mintaka deleted the harness/rig-11725-mask-kubernetes-secret-data-and-env branch November 22, 2026 05:12
@rigel-mintaka

Copy link
Copy Markdown
Contributor Author

Superseded by #223, which includes this PR's commits and carries the option A fail-closed masker (RIG-11965). Closing this one as replaced.

This branch had an error being deployed

1 failed deployment
ci — 2d4fc6f9 Deployed Nov 21, 2026 by rigel-mintaka via CI (aarch64-linux) #1020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-before-ready PR touches secrets or auth paths; review on the draft head before ready

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant