From e006830d813a8926d2e056219aff1a6cccf3e0e1 Mon Sep 17 00:00:00 2001 From: Russell Clarey Date: Fri, 13 Nov 2026 15:03:41 +0000 Subject: [PATCH 1/3] Mask JFrog token in configure-npm.sh configure-npm.sh writes JFROG_ACCESS_TOKEN verbatim into ~/.npmrc and ~/.yarnrc.yml. It did not mask the value itself, so it relied on jfrog-oidc-token.sh having run first in the same job. Add the same ::add-mask:: call configure-pip.sh uses so the script is self-contained. Co-authored-by: Isaac --- .github/scripts/configure-npm.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/scripts/configure-npm.sh b/.github/scripts/configure-npm.sh index 79b42df6a..a5f3db311 100644 --- a/.github/scripts/configure-npm.sh +++ b/.github/scripts/configure-npm.sh @@ -5,6 +5,11 @@ set -euo pipefail JFROG_NPM_REGISTRY="https://databricks.jfrog.io/artifactory/api/npm/db-npm/" +# The token is written verbatim into ~/.npmrc and ~/.yarnrc.yml below. It is +# already masked by jfrog-oidc-token.sh, but mask it here too so this script +# does not depend on that step having run first in the same job. +echo "::add-mask::${JFROG_ACCESS_TOKEN}" + # Configure npm CLI cat > ~/.npmrc << EOF registry=${JFROG_NPM_REGISTRY} From 618092dcf2c9aaaee46d70a685ee005c0c5d065b Mon Sep 17 00:00:00 2001 From: Russell Clarey Date: Fri, 13 Nov 2026 15:06:00 +0000 Subject: [PATCH 2/3] Add regression test for credential masking in CI scripts The JFrog credential scripts must emit ::add-mask:: for each secret before the value reaches GITHUB_ENV, GITHUB_OUTPUT or an rc file, or the value ends up in public Actions logs (see b4cec4ee). Add a hermetic bash test that runs jfrog-oidc-token.sh, configure-npm.sh and configure-pip.sh as steps of one job, with a stubbed curl and fake credentials. A DEBUG/EXIT trap loaded via BASH_ENV checks, before every command, that each secret already in a sink has a matching mask line earlier in the job log. This also catches a mask that is moved after the export. Control scripts confirm the checker flags unmasked, late-masked and unmasked-derived values, and accepts a correct one. Run it on pull requests from a new workflow with contents: read and no secrets. Co-authored-by: Isaac --- .github/scripts/tests/secret-masking.sh | 162 ++++++++++++++++++++++ .github/workflows/secret-masking-test.yml | 22 +++ 2 files changed, 184 insertions(+) create mode 100644 .github/scripts/tests/secret-masking.sh create mode 100644 .github/workflows/secret-masking-test.yml diff --git a/.github/scripts/tests/secret-masking.sh b/.github/scripts/tests/secret-masking.sh new file mode 100644 index 000000000..7c165c28d --- /dev/null +++ b/.github/scripts/tests/secret-masking.sh @@ -0,0 +1,162 @@ +#!/usr/bin/env bash +# Regression test for the JFrog token masking fix (commit b4cec4ee). +# +# Every secret that a credential script writes to $GITHUB_ENV, $GITHUB_OUTPUT +# or an rc file must first be announced with "::add-mask::" on stdout. +# Otherwise the value ends up in public Actions logs. +# +# The test runs the scripts the way unit-tests.yml does: one job, several +# steps, a shared job log, and $GITHUB_ENV loaded into later steps. curl is +# stubbed and every credential is fake, so nothing touches the network. +# +# Ordering is checked live. A DEBUG trap (loaded through BASH_ENV) runs before +# every command a step executes. It records a violation if a secret is already +# in a sink without a matching ::add-mask:: line earlier in the job log. That +# catches the mask being removed, or moved after the export. +# +# Usage: bash .github/scripts/tests/secret-masking.sh +set -euo pipefail + +TESTS_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SCRIPTS_DIR="$(cd "$TESTS_DIR/.." && pwd)" + +FAKE_JFROG_TOKEN="fake-jfrog-access-token-0000" +FAKE_ID_TOKEN="fake-github-oidc-id-token-0000" +export FAKE_JFROG_TOKEN FAKE_ID_TOKEN + +WORK="$(mktemp -d)" +trap 'rm -rf "$WORK"' EXIT + +fail() { + echo "FAIL: $*" >&2 + exit 1 +} + +# Stub curl: fake GitHub OIDC token and fake JFrog token exchange. +mkdir -p "$WORK/bin" +cat > "$WORK/bin/curl" << 'EOF' +#!/usr/bin/env bash +case "$*" in + *"audience="*) echo "{\"value\": \"${FAKE_ID_TOKEN}\"}" ;; + *"/access/api/v1/oidc/token"*) echo "{\"access_token\": \"${FAKE_JFROG_TOKEN}\"}" ;; + *) echo "curl stub: unexpected call: $*" >&2; exit 1 ;; +esac +EOF +chmod +x "$WORK/bin/curl" + +# Loaded via BASH_ENV into every step. Runs before each command. +cat > "$WORK/check-masking.sh" << 'EOF' +__check_secret_masking() { + local token="$FAKE_JFROG_TOKEN" file line value + # A sink that holds the token needs the token masked earlier in the job log. + for file in "$GITHUB_ENV" "$GITHUB_OUTPUT" "$HOME/.npmrc" "$HOME/.yarnrc.yml"; do + [[ -s "$file" ]] || continue + grep -qF -- "$token" "$file" || continue + grep -qxF -- "::add-mask::$token" "$JOB_LOG" \ + || echo "token in $file before ::add-mask::" >> "$VIOLATIONS" + done + # Derived values (e.g. PIP_INDEX_URL embeds the token) must be masked as a whole. + for file in "$GITHUB_ENV" "$GITHUB_OUTPUT"; do + [[ -s "$file" ]] || continue + while IFS= read -r line; do + [[ "$line" == *"$token"* ]] || continue + value="${line#*=}" + grep -qxF -- "::add-mask::$value" "$JOB_LOG" \ + || echo "$(basename "$file") entry ${line%%=*} not masked as a whole value" >> "$VIOLATIONS" + done < "$file" + done + return 0 +} +trap '__check_secret_masking' DEBUG +trap '__check_secret_masking' EXIT +EOF + +# run_job NAME SCRIPT... : runs the scripts as steps of one job. +# Sets LAST_JOB to the job's state directory. +run_job() { + local name="$1" step entry job + shift + job="$WORK/job-$name" + LAST_JOB="$job" + mkdir -p "$job/home" + : > "$job/github_env" + : > "$job/github_output" + : > "$job/job.log" + : > "$job/violations" + for step in "$@"; do + ( + # Like the runner: later steps see what earlier steps wrote to $GITHUB_ENV. + while IFS= read -r entry; do + [[ -n "$entry" ]] && export "${entry%%=*}=${entry#*=}" + done < "$job/github_env" + export HOME="$job/home" GITHUB_ENV="$job/github_env" GITHUB_OUTPUT="$job/github_output" + export JOB_LOG="$job/job.log" VIOLATIONS="$job/violations" + export ACTIONS_ID_TOKEN_REQUEST_TOKEN="fake-request-token" + export ACTIONS_ID_TOKEN_REQUEST_URL="https://oidc.invalid/token?api-version=2.0" + export PATH="$WORK/bin:$PATH" BASH_ENV="$WORK/check-masking.sh" + bash "$step" >> "$job/job.log" 2>&1 + ) || { cat "$job/job.log" >&2; fail "$(basename "$step") exited non-zero in job $name"; } + done + sort -u "$job/violations" -o "$job/violations" +} + +# --- 1. The real credential scripts, in the order unit-tests.yml runs them --- +run_job real \ + "$SCRIPTS_DIR/jfrog-oidc-token.sh" \ + "$SCRIPTS_DIR/configure-npm.sh" \ + "$SCRIPTS_DIR/configure-pip.sh" +job="$LAST_JOB" + +if [[ -s "$job/violations" ]]; then + cat "$job/violations" >&2 + cat "$job/job.log" >&2 + fail "credential scripts write secrets before masking them" +fi + +# Non-vacuous: the scripts must actually have written the secrets we check for. +grep -qxF "JFROG_ACCESS_TOKEN=$FAKE_JFROG_TOKEN" "$job/github_env" \ + || fail "JFROG_ACCESS_TOKEN was not written to GITHUB_ENV (stub or script changed?)" +pip_url="$(grep '^PIP_INDEX_URL=' "$job/github_env" | cut -d= -f2- || true)" +[[ "$pip_url" == *"$FAKE_JFROG_TOKEN"* ]] \ + || fail "PIP_INDEX_URL with embedded token was not written to GITHUB_ENV" +grep -qF "_authToken=$FAKE_JFROG_TOKEN" "$job/home/.npmrc" \ + || fail "token was not written to ~/.npmrc" +grep -qxF "::add-mask::$FAKE_JFROG_TOKEN" "$job/job.log" \ + || fail "no ::add-mask:: line for the JFrog token" +grep -qxF "::add-mask::$pip_url" "$job/job.log" \ + || fail "no ::add-mask:: line for the composite PIP_INDEX_URL" +echo "ok: real credential scripts mask the JFrog token and PIP_INDEX_URL before writing them" + +# --- 2. Controls: the checker must catch bad patterns and accept good ones --- +controls="$WORK/controls" +mkdir -p "$controls" + +cat > "$controls/clean.sh" << 'EOF' +echo "::add-mask::${FAKE_JFROG_TOKEN}" +echo "JFROG_ACCESS_TOKEN=${FAKE_JFROG_TOKEN}" >> "$GITHUB_ENV" +EOF + +cat > "$controls/no-mask.sh" << 'EOF' +echo "JFROG_ACCESS_TOKEN=${FAKE_JFROG_TOKEN}" >> "$GITHUB_ENV" +EOF + +cat > "$controls/mask-after-export.sh" << 'EOF' +echo "JFROG_ACCESS_TOKEN=${FAKE_JFROG_TOKEN}" >> "$GITHUB_ENV" +echo "::add-mask::${FAKE_JFROG_TOKEN}" +EOF + +cat > "$controls/unmasked-derived-value.sh" << 'EOF' +echo "::add-mask::${FAKE_JFROG_TOKEN}" +echo "PIP_INDEX_URL=https://user:${FAKE_JFROG_TOKEN}@example.invalid/simple" >> "$GITHUB_ENV" +EOF + +run_job control-clean "$controls/clean.sh" +[[ ! -s "$LAST_JOB/violations" ]] || { cat "$LAST_JOB/violations" >&2; fail "checker flagged the clean control"; } + +for control in no-mask mask-after-export unmasked-derived-value; do + run_job "control-$control" "$controls/$control.sh" + [[ -s "$LAST_JOB/violations" ]] || fail "checker missed the '$control' control" + echo "ok: checker flags control '$control': $(head -1 "$LAST_JOB/violations")" +done + +echo "All secret masking checks passed." diff --git a/.github/workflows/secret-masking-test.yml b/.github/workflows/secret-masking-test.yml new file mode 100644 index 000000000..19e82f495 --- /dev/null +++ b/.github/workflows/secret-masking-test.yml @@ -0,0 +1,22 @@ +name: Secret masking tests + +on: + pull_request: + +permissions: + contents: read + +jobs: + secret-masking: + name: Credential scripts mask secrets + runs-on: + group: databricks-protected-runner-group + labels: linux-ubuntu-latest + + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + + - name: Run secret masking regression test + run: bash .github/scripts/tests/secret-masking.sh From eac8970544bcc457ddba12fe4ff022b3287c13b4 Mon Sep 17 00:00:00 2001 From: "russell.clarey" Date: Fri, 20 Nov 2026 10:27:58 +0000 Subject: [PATCH 3/3] Indent secret-masking-test.yml with two spaces The workflow was written on release/3.x, which indents .github YAML with four spaces. On main, .github/.prettierrc.yml sets tabWidth 2 and every other workflow follows it. Whitespace only. Co-authored-by: Isaac --- .github/workflows/secret-masking-test.yml | 26 +++++++++++------------ 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/secret-masking-test.yml b/.github/workflows/secret-masking-test.yml index 19e82f495..c097aa251 100644 --- a/.github/workflows/secret-masking-test.yml +++ b/.github/workflows/secret-masking-test.yml @@ -1,22 +1,22 @@ name: Secret masking tests on: - pull_request: + pull_request: permissions: - contents: read + contents: read jobs: - secret-masking: - name: Credential scripts mask secrets - runs-on: - group: databricks-protected-runner-group - labels: linux-ubuntu-latest + secret-masking: + name: Credential scripts mask secrets + runs-on: + group: databricks-protected-runner-group + labels: linux-ubuntu-latest - steps: - - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - with: - persist-credentials: false + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false - - name: Run secret masking regression test - run: bash .github/scripts/tests/secret-masking.sh + - name: Run secret masking regression test + run: bash .github/scripts/tests/secret-masking.sh