ref(attachments): Remove duplicated meta handling #10639
Workflow file for this run
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: Secret Scan | |
| on: [pull_request, merge_group] | |
| jobs: | |
| secret-scan: | |
| name: Secret Scan | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: "read" | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - name: Install Cosign | |
| id: cosign | |
| continue-on-error: true | |
| # v4 of the action install v3 of the CLI. v4 of the CLI will deprecate some features so be aware. | |
| uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 | |
| - name: Pin Trufflehog to a known good release | |
| id: trufflehog_release | |
| if: ${{ steps.cosign.outcome == 'success' }} | |
| continue-on-error: true | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| RELEASES=$(gh api repos/trufflesecurity/trufflehog/releases --jq '.[1:3][].tag_name') | |
| LATEST_TAG_NAME="" | |
| for tag in $RELEASES; do | |
| version="${tag#v}" | |
| url="https://github.com/trufflesecurity/trufflehog/releases/download/${tag}/trufflehog_${version}_linux_amd64.tar.gz" | |
| if curl --head --fail --silent --show-error --retry 8 --retry-max-time 120 "$url" > /dev/null 2>&1; then | |
| LATEST_TAG_NAME="$tag" | |
| break | |
| fi | |
| echo "::warning::Release ${tag} assets unavailable, trying next" | |
| done | |
| if [[ -z "$LATEST_TAG_NAME" ]]; then | |
| echo "::warning::No usable TruffleHog release found" | |
| exit 1 | |
| fi | |
| echo "Using TruffleHog version: $LATEST_TAG_NAME" | |
| echo "latest_tag_name=$LATEST_TAG_NAME" >> "$GITHUB_OUTPUT" | |
| echo "latest_release=${LATEST_TAG_NAME#v}" >> "$GITHUB_OUTPUT" | |
| - name: Download and verify TruffleHog release | |
| id: download | |
| if: ${{ steps.trufflehog_release.outcome == 'success' }} | |
| continue-on-error: true | |
| env: | |
| TRUFFLEHOG_TAG: ${{ steps.trufflehog_release.outputs.latest_tag_name }} | |
| TRUFFLEHOG_VERSION: ${{ steps.trufflehog_release.outputs.latest_release }} | |
| run: | | |
| base="https://github.com/trufflesecurity/trufflehog/releases/download/${TRUFFLEHOG_TAG}" | |
| for file in \ | |
| "trufflehog_${TRUFFLEHOG_VERSION}_checksums.txt" \ | |
| "trufflehog_${TRUFFLEHOG_VERSION}_checksums.txt.pem" \ | |
| "trufflehog_${TRUFFLEHOG_VERSION}_checksums.txt.sig" \ | |
| "trufflehog_${TRUFFLEHOG_VERSION}_linux_amd64.tar.gz" | |
| do | |
| curl -fsSL --retry 3 --retry-delay 5 --retry-all-errors \ | |
| -w '%{url_effective} %{http_code}\n' -O "${base}/${file}" | |
| done | |
| cosign verify-blob "trufflehog_${TRUFFLEHOG_VERSION}_checksums.txt" \ | |
| --certificate "trufflehog_${TRUFFLEHOG_VERSION}_checksums.txt.pem" \ | |
| --signature "trufflehog_${TRUFFLEHOG_VERSION}_checksums.txt.sig" \ | |
| --certificate-identity-regexp 'https://github\.com/trufflesecurity/trufflehog/\.github/workflows/.+' \ | |
| --certificate-oidc-issuer "https://token.actions.githubusercontent.com" | |
| sha256sum --ignore-missing -c "trufflehog_${TRUFFLEHOG_VERSION}_checksums.txt" | |
| - name: Extract TruffleHog | |
| id: extract | |
| if: ${{ steps.download.outcome == 'success' }} | |
| env: | |
| TRUFFLEHOG_VERSION: ${{ steps.trufflehog_release.outputs.latest_release }} | |
| run: | | |
| tar xzf "trufflehog_${TRUFFLEHOG_VERSION}_linux_amd64.tar.gz" -C /usr/local/bin | |
| chmod +x /usr/local/bin/trufflehog | |
| - name: Run TruffleHog scan | |
| if: ${{ steps.extract.outcome == 'success' }} | |
| continue-on-error: true | |
| id: scan | |
| run: | | |
| args=(git file://. --only-verified --github-actions --fail --exclude-detectors="datadogtoken,lob") | |
| if [ -e .secret_scan_ignore ]; then | |
| args+=(--exclude-paths=.secret_scan_ignore) | |
| fi | |
| trufflehog "${args[@]}" | |
| - name: Report scan skipped | |
| if: ${{ !cancelled() && steps.scan.outcome == 'skipped' }} | |
| env: | |
| COSIGN_OUTCOME: ${{ steps.cosign.outcome }} | |
| RELEASE_OUTCOME: ${{ steps.trufflehog_release.outcome }} | |
| DOWNLOAD_OUTCOME: ${{ steps.download.outcome }} | |
| EXTRACT_OUTCOME: ${{ steps.extract.outcome }} | |
| run: | | |
| echo "::warning::TruffleHog unavailable, this change was not scanned: cosign=$COSIGN_OUTCOME release=$RELEASE_OUTCOME download=$DOWNLOAD_OUTCOME extract=$EXTRACT_OUTCOME" | |
| - name: Send Alert to SIEM | |
| if: ${{ !cancelled() }} | |
| env: | |
| SIEM_WEBHOOK_URL: ${{ vars.SECRET_SCAN_SIEM_WEBHOOK_URL }} | |
| SCAN_OUTCOME: ${{ steps.scan.outcome }} | |
| REPO: ${{ github.repository }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| PR_CREATED_AT: ${{ github.event.pull_request.created_at }} | |
| PR_ACTOR: ${{ github.event.pull_request.user.login }} | |
| EVENT_ACTOR: ${{ github.actor }} | |
| run: | | |
| if [[ -z "$SIEM_WEBHOOK_URL" ]]; then | |
| exit 0 | |
| fi | |
| # On merge_group events there is no pull_request context, so PR-derived | |
| # fields are empty. Use current timestamp as next best effort. | |
| created_at="${PR_CREATED_AT:-$(date -u +%Y-%m-%dT%H:%M:%SZ)}" | |
| actor="${PR_ACTOR:-$EVENT_ACTOR}" | |
| if [[ -n "$PR_NUMBER" ]]; then | |
| pull_request="https://github.com/${REPO}/pull/${PR_NUMBER}" | |
| else | |
| pull_request="" | |
| fi | |
| if [[ "$SCAN_OUTCOME" == "skipped" ]]; then | |
| status="setup_failed" | |
| else | |
| status="$SCAN_OUTCOME" | |
| fi | |
| jq -n \ | |
| --arg event "github_secret_scanning" \ | |
| --arg status "$status" \ | |
| --arg createdAt "$created_at" \ | |
| --arg repo "$REPO" \ | |
| --arg pull_request "$pull_request" \ | |
| --arg actor "$actor" \ | |
| '{event: $event, status: $status, createdAt: $createdAt, repo: $repo, pull_request: $pull_request, actor: $actor}' \ | |
| | curl --fail --silent --show-error \ | |
| -H "Content-Type: application/json" \ | |
| --data @- \ | |
| "$SIEM_WEBHOOK_URL" \ | |
| || echo "::warning::SIEM alert failed (non-blocking)" | |
| - name: Fail workflow if secret detected | |
| if: ${{ !cancelled() && steps.scan.outcome == 'failure' }} | |
| run: exit 1 |