|
| 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_secrets.sh invocation |
| 24 | +scrub_vars=$(grep -A10 'scrub_secrets\.sh' "$WORKFLOW" \ |
| 25 | + | grep -oP '\b[A-Z][A-Z_]{2,}\b' \ |
| 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