ci: drop whole-value ::add-mask:: on multi-line secrets (PEM lines 2..n were logged unmasked) #107

Merged
founder merged 1 commit from ci/add-mask-per-line-only into main 2026-08-16 22:35:40 +00:00
Owner

Problem

decrypt_env in .forgejo/actions/decrypt-secrets/action.yml did

echo "::add-mask::${value}"
while IFS= read -r line; do
  [[ -n "$line" ]] || continue
  echo "::add-mask::${line}"
done <<<"$value"

For a multi-line value (APPSTORE_KEY is a PKCS#8 PEM) the runner parses the first echo as one ::add-mask:: command for line 1, and lines 2..n go to stdout as ordinary log lines — before the per-line masks in the loop are registered, so they are logged unmasked. A whole-value mask can never match a log line once the value contains a newline, so it buys nothing.

Demo with a 3-line fake PEM (what the runner sees on stdout, in order):

BEFORE                                          AFTER
1  ::add-mask::-----BEGIN PRIVATE KEY-----      1  ::add-mask::-----BEGIN PRIVATE KEY-----
2  MIIEvQIBADANBgkqhkiG9w0BAQEFAASC   <-- raw   2  ::add-mask::MIIEvQIBADANBgkqhkiG9w0BAQEFAASC
3  -----END PRIVATE KEY-----          <-- raw   3  ::add-mask::-----END PRIVATE KEY-----
4  ::add-mask::-----BEGIN PRIVATE KEY-----
5  ::add-mask::MIIEvQIBADANBgkqhkiG9w0BAQEFAASC
6  ::add-mask::-----END PRIVATE KEY-----
plain-text lines in log: 2                      plain-text lines in log: 0

Fix

Remove the whole-value echo "::add-mask::${value}" and keep only the per-line loop — exactly what mask_value in .forgejo/actions/openbao-secrets/action.yml already does. No other behaviour changed ($GITHUB_ENV heredoc export is identical).

Fixed:

  • .forgejo/actions/decrypt-secrets/action.yml — decrypt_env
  • .forgejo/workflows/cloud-tofu.yml — export_env_secret (same pattern)

Audit of the other add-mask::${value} hits

grep -rn 'add-mask::\${value}\|add-mask::\$value' .forgejo Scripts also matches deploy-api.yml ×4 (emit_optional_secret, emit_optional_secret_b64, in both the age and openbao jobs). Those values are provably single-line (tr -d '\r\n', base64 -w0 / base64 | tr -d '\n'), so the whole-value mask is correct there and they are left untouched. Same for the other variable masks I checked (cloud-tofu.yml jwt/grafana/garage, openbao-secrets jwt/bao_token, Scripts/namespace-runner-source-bootstrap.sh, Scripts/update-planetscale-secret.sh): all tr -d '\r\n' / sed … | head -n1 / opaque single-line tokens.

Verification

  • Extracted both run: scripts with yq and ran bash -n — clean.
  • shellcheck -s bash findings are byte-identical before/after for the decrypt-secrets step (only pre-existing ${{ }} / SC2129 / SC1090 noise); the cloud-tofu step has zero findings before and after.
  • Behavioural demo above.

🤖 Generated with Claude Code

## Problem `decrypt_env` in `.forgejo/actions/decrypt-secrets/action.yml` did ```bash echo "::add-mask::${value}" while IFS= read -r line; do [[ -n "$line" ]] || continue echo "::add-mask::${line}" done <<<"$value" ``` For a multi-line value (`APPSTORE_KEY` is a PKCS#8 PEM) the runner parses the first `echo` as one `::add-mask::` command for line 1, and **lines 2..n go to stdout as ordinary log lines** — before the per-line masks in the loop are registered, so they are logged unmasked. A whole-value mask can never match a log line once the value contains a newline, so it buys nothing. Demo with a 3-line fake PEM (what the runner sees on stdout, in order): ``` BEFORE AFTER 1 ::add-mask::-----BEGIN PRIVATE KEY----- 1 ::add-mask::-----BEGIN PRIVATE KEY----- 2 MIIEvQIBADANBgkqhkiG9w0BAQEFAASC <-- raw 2 ::add-mask::MIIEvQIBADANBgkqhkiG9w0BAQEFAASC 3 -----END PRIVATE KEY----- <-- raw 3 ::add-mask::-----END PRIVATE KEY----- 4 ::add-mask::-----BEGIN PRIVATE KEY----- 5 ::add-mask::MIIEvQIBADANBgkqhkiG9w0BAQEFAASC 6 ::add-mask::-----END PRIVATE KEY----- plain-text lines in log: 2 plain-text lines in log: 0 ``` ## Fix Remove the whole-value `echo "::add-mask::${value}"` and keep only the per-line loop — exactly what `mask_value` in `.forgejo/actions/openbao-secrets/action.yml` already does. No other behaviour changed (`$GITHUB_ENV` heredoc export is identical). Fixed: - `.forgejo/actions/decrypt-secrets/action.yml` — `decrypt_env` - `.forgejo/workflows/cloud-tofu.yml` — `export_env_secret` (same pattern) ## Audit of the other `add-mask::${value}` hits `grep -rn 'add-mask::\${value}\|add-mask::\$value' .forgejo Scripts` also matches `deploy-api.yml` ×4 (`emit_optional_secret`, `emit_optional_secret_b64`, in both the age and openbao jobs). Those values are provably single-line (`tr -d '\r\n'`, `base64 -w0` / `base64 | tr -d '\n'`), so the whole-value mask is correct there and they are left untouched. Same for the other variable masks I checked (`cloud-tofu.yml` jwt/grafana/garage, `openbao-secrets` jwt/bao_token, `Scripts/namespace-runner-source-bootstrap.sh`, `Scripts/update-planetscale-secret.sh`): all `tr -d '\r\n'` / `sed … | head -n1` / opaque single-line tokens. ## Verification - Extracted both `run:` scripts with `yq` and ran `bash -n` — clean. - `shellcheck -s bash` findings are byte-identical before/after for the decrypt-secrets step (only pre-existing `${{ }}` / SC2129 / SC1090 noise); the cloud-tofu step has zero findings before and after. - Behavioural demo above. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ci: drop whole-value ::add-mask:: on multi-line secrets — it printed lines 2..n of the PEM to the log before their masks existed
Some checks failed
build-release.yml / ci: drop whole-value ::add-mask:: on multi-line secrets — it printed lines 2..n of the PEM to the log before their masks existed (push) Failing after 0s
build-release.yml / ci: drop whole-value ::add-mask:: on multi-line secrets — it printed lines 2..n of the PEM to the log before their masks existed (pull_request) Failing after 0s
Release: If Needed / Check (Release Needed) (push) Successful in 8s
Infra: Cloud OpenTofu / Infra (Cloud OpenTofu) (push) Successful in 1m1s
Release: Signing Preflight / Release (Signing Preflight) (push) Successful in 1m14s
Deploy: API / Deploy (API) (push) Has been cancelled
Deploy: Web / Deploy (Web) (push) Has been cancelled
59b33adec7
`echo "::add-mask::${value}"` on a multi-line value (APPSTORE_KEY is a
PKCS#8 PEM) is parsed by the runner as one `::add-mask::` command for line 1
followed by lines 2..n as ordinary stdout, and those land in the job log
verbatim because the per-line masks in the loop that follows have not been
registered yet. A whole-value mask can never match a log line once the value
contains a newline, so it buys nothing; keep only the per-line loop, exactly
as .forgejo/actions/openbao-secrets/action.yml (mask_value) already does.

Fixed:
- .forgejo/actions/decrypt-secrets/action.yml  decrypt_env
- .forgejo/workflows/cloud-tofu.yml            export_env_secret

Audited and left alone (whole-value mask on a provably single-line value —
`tr -d '\r\n'`, `base64 -w0`/`tr -d '\n'`, `sed | head -n1`, opaque tokens):
deploy-api.yml emit_optional_secret / emit_optional_secret_b64 (both jobs),
cloud-tofu.yml jwt/grafana/garage, openbao-secrets jwt/bao_token,
Scripts/namespace-runner-source-bootstrap.sh, Scripts/update-planetscale-secret.sh.

Verified: `bash -n` on both extracted `run:` scripts is clean; shellcheck
findings are byte-identical before/after (cloud-tofu step: none). A 3-line
fake PEM through the old function puts 2 raw lines on stdout; the new one 0.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
founder deleted branch ci/add-mask-per-line-only 2026-08-16 22:35:40 +00:00
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
key-store/key.store!107
No description provided.