CI/CD & GitHub Actions (50 Qs)•Part 3: Enterprise Scale, Compliance & Production Hardening (Senior / Staff)
Secrets Masking and Redaction: How GitHub Actions protects sensitive data in logs and how to avoid accidental leaks.
senior LevelCode ExampleState ManagementCI/CD & DevOps
In Simple Words:
GitHub Actions automatically masks any value registered as a secret in repository settings or set via ::add-mask:: by replacing occurrences with *** in execution logs.
bash
# Registering a dynamic secret generated in a step
echo "::add-mask::$TEMP_TOKEN"
echo "TEMP_TOKEN=$TEMP_TOKEN" >> "$GITHUB_ENV"
Common Leak Vectors & Mitigations:
- Encoded Secrets: Base64 or URL-encoded secrets are not masked by default. Always register both raw and encoded representations if logs might print them.
- Command Tracing: Avoid
set -xin bash scripts when secrets are exported as environment variables. - Structured Formats: Dumping complete JSON payloads with
jqorprint_rcan reveal secret subkeys. Use explicit parsing instead of object dumps.