Skip to content

Commit 31dcf44

Browse files
fix: scrub secret values from CI log artifacts before upload
Upstream OGX redacts known field names (api_key, api_token, password) but any provider whose secret uses a different field name would appear in plaintext in the uploaded log artifacts. Add a defense-in-depth scrub step that replaces actual secret env-var values with ***REDACTED*** in all log files before the upload-artifact step. Also add a pre-commit hook (check-secret-scrub) that ensures the scrub list stays in sync with smoke.sh — it greps for secret-looking env vars (KEY, TOKEN, PASSWORD, SECRET, CREDENTIAL) passed to the container and fails if any are missing from the workflow's scrub list. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Nathan Weinberg <nweinber@redhat.com>
1 parent 5d61459 commit 31dcf44

3 files changed

Lines changed: 73 additions & 0 deletions

File tree

.github/workflows/redhat-distro-container.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,25 @@ jobs:
299299
done
300300
fi
301301
302+
# Scrub secret values from log files before upload (CWE-532)
303+
python3 -c "
304+
import os, glob
305+
secrets = [os.environ.get(v, '') for v in [
306+
'VLLM_API_TOKEN', 'VLLM_EMBEDDING_API_TOKEN',
307+
'OPENAI_API_KEY', 'GEMINI_API_KEY', 'ANTHROPIC_API_KEY',
308+
'POSTGRES_PASSWORD', 'PGVECTOR_PASSWORD',
309+
'GOOGLE_APPLICATION_CREDENTIALS',
310+
]]
311+
secrets = [s for s in secrets if len(s) >= 4]
312+
for f in glob.glob('logs/*.log'):
313+
with open(f, 'r', errors='replace') as fh:
314+
content = fh.read()
315+
for s in secrets:
316+
content = content.replace(s, '***REDACTED***')
317+
with open(f, 'w') as fh:
318+
fh.write(content)
319+
"
320+
302321
- name: Upload logs as artifacts
303322
if: always()
304323
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,10 @@ repos:
6464
files: ^(build/(build\.yaml|build\.env)|distribution/config\.yaml)$
6565
additional_dependencies:
6666
- pyyaml==6.0.2
67+
68+
- id: check-secret-scrub
69+
name: CI log-scrub list matches smoke.sh secrets
70+
entry: ./tests/check_secret_scrub_list.sh
71+
language: script
72+
pass_filenames: false
73+
files: ^(tests/smoke\.sh|\.github/workflows/redhat-distro-container\.yml)$

tests/check_secret_scrub_list.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/bin/bash
2+
# Ensure every secret-looking env var passed to the OGX container in smoke.sh
3+
# is listed in the CI workflow's log-scrub step. Exits non-zero on drift.
4+
5+
set -euo pipefail
6+
7+
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
8+
SMOKE="$REPO_ROOT/tests/smoke.sh"
9+
WORKFLOW="$REPO_ROOT/.github/workflows/redhat-distro-container.yml"
10+
11+
# Extract env var names passed via --env to the docker container in smoke.sh
12+
smoke_vars=$(grep -oP '(?<=--env ")([A-Z_]+)(?==)' "$SMOKE" | sort -u)
13+
14+
# Filter to secret-looking names
15+
secret_pattern='KEY|TOKEN|PASSWORD|SECRET|CREDENTIAL'
16+
smoke_secrets=$(echo "$smoke_vars" | grep -E "$secret_pattern" || true)
17+
18+
if [ -z "$smoke_secrets" ]; then
19+
echo "No secret-looking env vars found in smoke.sh (unexpected)"
20+
exit 1
21+
fi
22+
23+
# Extract the var names from the workflow's scrub list
24+
scrub_vars=$(grep -oP "'[A-Z_]+'" "$WORKFLOW" \
25+
| tr -d "'" \
26+
| grep -E "$secret_pattern" \
27+
| sort -u)
28+
29+
missing=()
30+
while IFS= read -r var; do
31+
if ! echo "$scrub_vars" | grep -qx "$var"; then
32+
missing+=("$var")
33+
fi
34+
done <<< "$smoke_secrets"
35+
36+
if [ ${#missing[@]} -gt 0 ]; then
37+
echo "ERROR: Secret env var(s) passed to the OGX container in smoke.sh"
38+
echo "are missing from the CI log-scrub list in redhat-distro-container.yml:"
39+
for v in "${missing[@]}"; do
40+
echo " - $v"
41+
done
42+
echo ""
43+
echo "Add them to the Python scrub snippet in the 'Gather logs' step."
44+
exit 1
45+
fi
46+
47+
echo "All secret env vars in smoke.sh are in the CI log-scrub list."

0 commit comments

Comments
 (0)