Skip to content

CLI exec sanitize secrets too - #6877

Open
6543 wants to merge 7 commits into
woodpecker-ci:mainfrom
6543-forks:cli-exec-sanitize-secrets-too
Open

CLI exec sanitize secrets too#6877
6543 wants to merge 7 commits into
woodpecker-ci:mainfrom
6543-forks:cli-exec-sanitize-secrets-too

Conversation

@6543

@6543 6543 commented Jul 20, 2026

Copy link
Copy Markdown
Member

the cli exec should mimic server-agent execution, and share as much code as possible ...

... this addresses secrets masking and refactor it a bit to make it more modular

claude and others added 4 commits July 20, 2026 22:28
The agent masks secret values before streaming step logs, but local
`woodpecker exec` wrote step output to the terminal raw, leaking secrets
passed via --secrets/--secrets-file.

Add a reusable io.Writer decorator (shared.NewSecretsWriter) that masks
secrets before forwarding, and wrap the exec log writer with it.
Run a dummy-backend pipeline with --secrets and assert the secret value
never reaches the terminal output while the masked form does.

Fails on the unfixed LineWriter, passes with the secrets writer in place.

Co-authored-by: Codex <codex@openai.com>
Fprintf errors (e.g. broken pipe on stderr) were silently swallowed,
misreporting successful writes upstream. Return the error and report
zero bytes consumed. Make the output writer injectable for testing.

Adopted from an external patch suggestion.

Co-authored-by: Codex <codex@openai.com>
Generalize the secrets writer into shared.NewSanitizeWriter(dst, fn):
an io.Writer decorator taking a pluggable SanitizeFunc, so the masking
algorithm can be swapped later without touching writers.
shared.NewSecretsWriter stays as the convenience wrapper using the
secrets replacer.

Move the agent onto the same decorator: strip the built-in replacer from
the agent LineWriter and wrap its log stream with the shared secrets
writer, matching the cli exec path. One masking implementation for both.
@woodpecker-bot

woodpecker-bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Surge PR preview deployment succeeded. View it at https://woodpecker-ci-woodpecker-pr-6877.surge.sh

@6543
6543 marked this pull request as ready for review July 20, 2026 20:56
@6543 6543 added enhancement improve existing features cli labels Jul 20, 2026
@codecov

codecov Bot commented Jul 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 48.53%. Comparing base (c873bcb) to head (1ae3d6f).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6877      +/-   ##
==========================================
+ Coverage   48.45%   48.53%   +0.08%     
==========================================
  Files         443      445       +2     
  Lines       29955    29977      +22     
==========================================
+ Hits        14514    14549      +35     
+ Misses      14215    14209       -6     
+ Partials     1226     1219       -7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@6543
6543 requested a review from a team July 28, 2026 00:06
@qwerty287

Copy link
Copy Markdown
Contributor

This looks good to me - but do we really need a separate SanitizeWriter? Can't we just directly have SecretReplaceWriter? Yes, I know that's less modular, but it's very unlikely we need to sanitize something else, right?

@6543

6543 commented Aug 8, 2026

Copy link
Copy Markdown
Member Author

I was looking into getting rid of sendingval secrets to agents to sanitize things

@6543

6543 commented Aug 8, 2026

Copy link
Copy Markdown
Member Author

still if you you want to i'll remove it and stick those changes into anotherbpull

@qwerty287

Copy link
Copy Markdown
Contributor

The comment was not about the structure of the PR, but the code only.

You add a SanitizeWriter that is built to be modular - but we don't need that. We can just build a SecretsReplaceWriter with a fixed sanitizing function (if you don't get what I mean, I can send you a diff)

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

Labels

cli enhancement improve existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants