Skip to content

fix(agent): redact containers without secret names, multiline secrets and cut lines - #482

Merged
samuelmbabhazi merged 5 commits into
mainfrom
fix/470-471-log-redaction
Nov 25, 2026
Merged

samuelmbabhazi merged 5 commits into
mainfrom
fix/470-471-log-redaction

Conversation

@samuelmbabhazi

@samuelmbabhazi samuelmbabhazi commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

What changed

Two P1 findings from the 2026-11-25 audit, both in the log shipper's secret redaction (ADR 0029).

#470: containers that predate the sk.secret_env label.

  • The agent now sets the label on every container it creates, empty when the spec has no secret, so "known to have no secret" is distinct from "unknown".
  • When the label is missing, the shipper uses LegacyRedactor: every environment value of 8 bytes or more is redacted from that container's backlog and new lines. It logs once per follow that the container should be redeployed for exact redaction.
  • The label holds names only. No value goes into labels or the journal.

#471: multiline secrets and the 16 KiB cut.

  • Docker output arrives line by line, so each line of a multiline value (8 bytes or more, \r trimmed) becomes a value of its own. Lines are still redacted one by one: stdout and stderr are never joined.
  • RedactCutEnd handles a line cut at its bound: when it ends with the start of a value (8 bytes or more of it), that start is replaced. It runs on the raw line before Redact and takes the longest start over all values, so a shorter secret inside the start cannot hide the rest. The search uses the KMP failure function and runs in linear time: secrets are up to 64 KiB, and a naive suffix scan of a crafted 16 KiB line would be quadratic.

Why

Both paths could send secret values intact to VictoriaLogs, where environment.read readers can see them.

How it was tested

  • Unit tests for the redactor:
    • multiline values, CRLF, a missing label;
    • a cut start, the longest start winning over a shorter value inside it;
    • cutStart against a naive scan on self-overlapping values.
  • Unit tests through the shipper: missing label, empty label, multiline secret, cut line.
  • All new tests were run against the old shipper.go and redact.go and fail there.
  • Real Docker (-tags integration, run on a lab node), on disposable BusyBox containers with no network:
    • an old container printing a synthetic secret before and after the shipper starts, so both backlog and new output are covered;
    • an old container without secrets, and a new one with an empty label;
    • a labelled 3-line CRLF secret printed on stdout and stderr;
    • a secret cut at the 16 KiB bound.
  • go test -race ./agent/... and golangci-lint (with the integration tag) are clean.

Security considerations

  • Over-redaction for old containers is deliberate. Values like production or the image's PATH are masked until the application is redeployed. That is the more secure and reversible choice.
  • Remaining limits, documented in SPEC §logs and ADR 0029:
    • lines of a multiline value under 8 bytes;
    • values the application transforms;
    • secrets mounted as files.
  • No new shell invocation. The sh -c in the integration tests is the fixture script inside the disposable container.

Closes #470
Closes #471

… and cut lines

A container created before the sk.secret_env label had no names, so its
secret values were shipped as written (#470). The agent now sets the
label on every container, empty without secrets, and the shipper redacts
every environment value of a container that lacks it.

A multiline secret never matched one line of output (#471): each of its
lines of 8 bytes or more is now a value of its own, CRLF included. A
line cut at 16 KiB that ends with the start of a secret loses that
start, found in linear time before the whole values are replaced.

Closes #470
Closes #471

Signed-off-by: samuel mbabhazi <[email protected]>
@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 55 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 92437e7 and 5fb5c40.

Files selected for processing: 9

  • agent/internal/actions/container_spec.go
  • agent/internal/actions/container_test.go
  • agent/internal/logship/real_shipper_test.go
  • agent/internal/logship/redact.go
  • agent/internal/logship/redact_test.go
  • agent/internal/logship/shipper.go
  • agent/internal/logship/shipper_test.go
  • docs/SPEC.md
  • docs/adr/0029-logs-through-the-control-plane.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

…lit a whole secret

Review of #482: on a cut line, redacting the start of a value first could
cut a whole secret that ends the line, when its end is also the start of
a value, and its first part was then shipped. Each value is now matched
once over the line as read, by its failure function: every occurrence,
overlapping ones included, and the start at a cut. The union of these
spans is redacted. The legacy-container note is logged once per
container.

Signed-off-by: samuel mbabhazi <[email protected]>
@samuelmbabhazi

Copy link
Copy Markdown
Collaborator Author

Code review (high), findings and what was done in edb61c2:

  1. Important: a cut start could split a whole secret. On a cut line, redacting a value's start first could hide a whole value that ends the line, when its end is also the start of a value (the same one or another), so abcdefgh_ of TOKEN=abcdefgh_abcdefgh was shipped. Reproduced on the previous redactor: log abcdefgh_[redacted] and log sk_fake_xyz_[redacted], and an overlapping occurrence left [redacted]ab.
    • Fixed: each value is matched once over the raw line with its KMP failure function. That pass finds every occurrence (overlapping ones included) and, on a cut line, the start it ends with. The union of these spans is redacted.
    • Tests:
      • both cases above, and overlapping occurrences;
      • a randomized comparison of the spans against a byte-by-byte scan, 20 000 cases over a two-letter alphabet.
  2. Redeploys reusing a container without the label. This does not happen in practice. Container names carry the release number (containerName(application, release.number, index)), so a redeploy always creates new containers, with the label. Reuse only happens when the same create is replayed. The docs now say so.
  3. The legacy note was logged on every follow. It is now logged once per container ID.
  4. The test failure message could panic on a short line. Fixed.
  5. The CRLF unit test fed \r line ends, which Docker's reader strips. It now feeds what the reader really emits.

The real Docker tests were run again on the lab node: all 5 pass. go test -race ./agent/... and golangci-lint are clean.

@samuelmbabhazi
samuelmbabhazi merged commit 566210a into main Nov 25, 2026
25 of 27 checks passed
@samuelmbabhazi
samuelmbabhazi deleted the fix/470-471-log-redaction branch November 25, 2026 13:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redact multiline environment secrets before emitting container logs Prevent log shipping from exposing secrets in pre-upgrade containers

1 participant