Skip to content

fix(redact): mask kubectl secret reads and shell-expanded flags (RIG-11965) - #223

Merged
rigel-nemo[bot] merged 13 commits into
mainfrom
harness/rig-11965-mask-kubectl-secret-reads-and-shell
Nov 23, 2026
Merged

rigel-nemo[bot] merged 13 commits into
mainfrom
harness/rig-11965-mask-kubectl-secret-reads-and-shell

Conversation

@rigel-mintaka

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

Copy link
Copy Markdown
Contributor

What does this do

Masks the whole output of any kubectl/oc/k read that the gate cannot fully parse. Masking is the control; no command is blocked.

Supersedes #214 (RIG-11725). This PR includes #214's commits, so closing #214 alone does not remove them.

Why do we need it

The per-line Secret pass cannot see reads whose shell or flag shape hides the output format, and per-case fixes kept missing shapes (RIG-11965 ruling, option A).

Summary

  • Fail closed: wrappers, substitutions, pipes, short-flag clusters (-Ao), brace and glob expansion mask.
  • Raw reads mask: exec, attach, debug, run, cp, get --raw, create token, config view --raw.

Verification

  • Red first: each leak row failed at its base commit, then passed.
  • pytest tests/agent/test_redact*.py tests/agent/test_compaction_redaction_boundaries.py on mattpc-wsl at the PR head: 988 passed.
  • Keep rows still show content: get pods, get pods -o wide, logs, describe configmap, config view without flags.

Risks

  • Over-masking is accepted by design (for example -o jsonpath, pipes to filters, -n run).
  • Open high, describe (RIG-12026): workload describe prints Args and CRD Spec: values unmasked. Pod describe still masks Environment: values. The RIG-11887 bans on these forms stay until RIG-12026 closes.
  • Kubectl plugins and oc extract, oc whoami -t, oc rsh, oc sa get-token are not yet covered; tracked in RIG-11984.

Spec impact

None to a public contract. Internal redaction behavior only. The RIG-11887 live masking check must include the reads listed in its comment.

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

Refs RIG-11965

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

rigel-mintaka and others added 9 commits November 22, 2026 00:13
…11965)

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>
…Go-map tails, deep JSON

- Secret reads through go-template or jsonpath mask the whole output.
- kubectl set env --list masks NAME=value values.
- Go-map values run to the segment end, fail closed past ] and word:.
- JSON nesting past the depth cap masks the rest of the text.
- Secret reads with go-template, template, custom-columns or jsonpath output mask the whole output.
- kubectl is found at any token (kubectl.exe, sudo, sh -c); secrets.v1 and -f secret.yaml count as Secret reads.
- kubectl set env --list=... masks NAME=value values.
- Go-map segments end only at the next map[name:/map[value: key.
A glob in an unquoted token (*, ?, [, ], ~) expands in bash after shlex
reads it as one token, so [-]ojsonpath can become a flag. Treat the glob
characters like the other shell metacharacters: mask the whole output,
and the command still runs. Red first: 2 glob rows failed at the brace
commit.
@linear-code

linear-code Bot commented Nov 22, 2026

Copy link
Copy Markdown

RIG-11965

@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
…slashes (RIG-11965)

The shell joins kube''ctl, "kube"ctl and kube\ctl into kubectl, but the gate
read the raw first word, so these reads passed unmasked. The gate now masks
any command whose first raw word holds a quote or backslash, and the mention
check strips them first. Mask-only: the command still runs. Red first: 4
split rows failed with plain values.
The shell can build the kubectl name from quotes, backslashes, $, backticks,
parens, braces or a line continuation. The gate now masks any read whose first
raw word has a character outside [A-Za-z0-9._/+-], and the mention check
strips those characters (and ${...} expansions) before the name match. Mask-only:
the command still runs. Red first: 5 built-name rows and 4 split rows failed
with plain values; a keep row for a plain kubectl name stays unmasked.
…965)

Removing shell-building characters could join kubectl to the word before it
(echo x<newline>kubectl, ${IFS}, echo)kubectl), and the mention check then missed
it. The mention check now runs two copies: removed (joins split names) and
spaced (separates glued names). A hit in either counts. Red first: 7 glued-name
rows failed with plain values; the keep row for a plain kubectl name stays
unmasked.
…IG-11965)

Nemo's condition for #223: describe on deployments still masks container env
values, and logs output still goes through the value redactor. Adds one row each.
No code change.
@rigel-mintaka

Copy link
Copy Markdown
Contributor Author

All-clear at 494a268
Base: main

@rigel-nemo

rigel-nemo Bot commented Nov 23, 2026

Copy link
Copy Markdown

Checks read:

@rigel-nemo
rigel-nemo Bot merged commit 1e70985 into main Nov 23, 2026
6 of 10 checks passed
@rigel-nemo
rigel-nemo Bot deleted the harness/rig-11965-mask-kubectl-secret-reads-and-shell branch November 23, 2026 00:53
@rigel-mintaka

Copy link
Copy Markdown
Contributor Author

Correction to this merged PR's Risks section (RIG-12026 ruling): the describe gap is fixed by #228 (with #233), restacked on main at f74aa8f / 6cad125 and cleared. The plugin and oc reads are covered by #226 and #232. Merge order: #226, #228, #232, #233. The RIG-11887 bans on these forms stay until RIG-12026 closes.

This branch had an error being deployed

1 failed deployment
ci — 494a2684 Deployed Nov 22, 2026 by rigel-mintaka via CI (x86_64-linux) #1060
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