Hardening CI Pipelines Against Secret Exposure
CI logs and artifact uploads are common leakage points. A hardened pipeline minimizes secret footprint and detects accidental exposure quickly.
Step 1: Replace static secrets with short-lived tokens
permissions:
id-token: write
contents: read
Step 2: Mask and block sensitive patterns in logs
echo "::add-mask::$API_TOKEN"
./run_tests.sh 2>&1 | ./redact_secrets.py
Step 3: Scan artifacts before publish
trufflehog filesystem ./build-artifacts --fail
Pitfall
Storing long-lived deployment keys as generic repository secrets with broad access.