fix: reject expired promotion launches #90
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: "Security Gate: Secret Scanning" | |
| on: | |
| push: | |
| branches: ["**"] | |
| pull_request: | |
| branches: [main, master] | |
| permissions: {} | |
| jobs: | |
| trufflehog: | |
| name: Scan for Verified Secrets | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read # Required to scan the code in the PR | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v7 | |
| with: | |
| fetch-depth: 0 # necessary to support the scoping requirements below | |
| - name: Resolve scan range | |
| id: scan_range | |
| env: | |
| EVENT_NAME: ${{ github.event_name }} | |
| PR_BASE_SHA: ${{ github.event.pull_request.base.sha }} | |
| PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
| PUSH_BASE_SHA: ${{ github.event.before }} | |
| PUSH_HEAD_SHA: ${{ github.sha }} | |
| DEFAULT_BRANCH: ${{ github.event.repository.default_branch }} | |
| run: | | |
| set -euo pipefail | |
| zero_sha="0000000000000000000000000000000000000000" | |
| if [[ "$EVENT_NAME" == "pull_request" ]]; then | |
| base="$PR_BASE_SHA" | |
| head="$PR_HEAD_SHA" | |
| else | |
| base="$PUSH_BASE_SHA" | |
| head="$PUSH_HEAD_SHA" | |
| if [[ "$base" == "$zero_sha" ]]; then | |
| base="" | |
| elif [[ -z "$base" ]]; then | |
| base="origin/$DEFAULT_BRANCH" | |
| fi | |
| fi | |
| echo "base=$base" >> "$GITHUB_OUTPUT" | |
| echo "head=$head" >> "$GITHUB_OUTPUT" | |
| - name: TruffleHog OSS | |
| id: trufflehog | |
| continue-on-error: true | |
| env: | |
| BASE: ${{ steps.scan_range.outputs.base }} | |
| HEAD: ${{ steps.scan_range.outputs.head }} | |
| run: | | |
| set +e | |
| args=(git file:///tmp/ --branch "$HEAD" --fail --no-update --github-actions --only-verified --debug) | |
| if [[ -n "$BASE" ]]; then | |
| args+=(--since-commit "$BASE") | |
| fi | |
| docker run --rm -v "$PWD:/tmp" -w /tmp \ | |
| ghcr.io/trufflesecurity/trufflehog:3.95.6 \ | |
| "${args[@]}" | |
| exit_code=$? | |
| echo "exit_code=$exit_code" >> "$GITHUB_OUTPUT" | |
| exit "$exit_code" | |
| - name: Notify on Failure | |
| if: steps.trufflehog.outcome == 'failure' | |
| env: | |
| EXIT_CODE: ${{ steps.trufflehog.outputs.exit_code }} | |
| run: | | |
| if [[ "$EXIT_CODE" == "183" ]]; then | |
| echo "::error::Verified secrets found; rotate credentials." | |
| echo "::notice::Contact GitHub Support to purge cached secrets:" | |
| support_url="https://support.github.com/contact/" | |
| support_url+="private-information" | |
| echo "::notice::$support_url" | |
| else | |
| echo "::error::TruffleHog failed (exit $EXIT_CODE)." | |
| echo "::notice::See scanner logs for the underlying error." | |
| fi | |
| exit 1 |