Repository navigation
ci(release): Bump craft to 3.9.0 and update config #177
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: Resolve scan range | |
| id: range | |
| env: | |
| GH_TOKEN: ${{ github.token }} | |
| run: | | |
| event="${{ github.event_name }}" | |
| if [ "$event" = "pull_request" ]; then | |
| commits="${{ github.event.pull_request.commits }}" | |
| # Generations back to the fork point, plus one commit past it. | |
| depth=$((commits + 2)) | |
| ref="refs/pull/${{ github.event.pull_request.number }}/head" | |
| base_tip="${{ github.event.pull_request.base.sha }}" | |
| head="${{ github.event.pull_request.head.sha }}" | |
| else | |
| base_tip="${{ github.event.merge_group.base_sha }}" | |
| head="${{ github.event.merge_group.head_sha }}" | |
| ref="${{ github.event.merge_group.head_ref }}" | |
| fi | |
| if [ -z "$base_tip" ] || [ -z "$head" ] || [ -z "$ref" ]; then | |
| echo "::error::No scan range for ${event}" | |
| exit 1 | |
| fi | |
| # base.sha is the tip of the base branch. A pull request that | |
| # branched earlier does not contain that tip. The merge base does, | |
| # and it is the commit --since-commit has to exclude. | |
| compare=$(gh api "repos/${GITHUB_REPOSITORY}/compare/${base_tip}...${head}") | |
| base=$(jq -r '.merge_base_commit.sha' <<<"$compare") | |
| if ! [[ "$base" =~ ^[0-9a-f]{40}$ ]]; then | |
| echo "::error::Could not resolve merge base" | |
| exit 1 | |
| fi | |
| if [ "$event" != "pull_request" ]; then | |
| # The queue commit is a merge, so pull_request.commits is absent. | |
| count=$(jq -r '.total_commits' <<<"$compare") | |
| if ! [[ "$count" =~ ^[0-9]+$ ]]; then | |
| echo "::error::Could not count commits in the merge group" | |
| exit 1 | |
| fi | |
| depth=$((count + 2)) | |
| fi | |
| echo "depth=$depth" >> "$GITHUB_OUTPUT" | |
| echo "ref=$ref" >> "$GITHUB_OUTPUT" | |
| echo "base=$base" >> "$GITHUB_OUTPUT" | |
| echo "head=$head" >> "$GITHUB_OUTPUT" | |
| echo "Scan ${head} since ${base} (fetch-depth ${depth})" | |
| - name: Checkout Code | |
| uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| with: | |
| ref: ${{ steps.range.outputs.ref }} | |
| fetch-depth: ${{ steps.range.outputs.depth }} | |
| - 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 | |
| env: | |
| BASE: ${{ steps.range.outputs.base }} | |
| HEAD: ${{ steps.range.outputs.head }} | |
| run: | | |
| # A depth-1 fetch of a base tip that is not an ancestor leaves no | |
| # path between the two commits. TruffleHog then errors with | |
| # "unable to resolve merge base", scans nothing, and exits 0. | |
| if ! git cat-file -e "${BASE}^{commit}" 2>/dev/null || ! git merge-base --is-ancestor "$BASE" "$HEAD"; then | |
| echo "Deepening history until ${BASE} is an ancestor of ${HEAD}" | |
| git fetch --no-tags --deepen=100 origin || exit 1 | |
| fi | |
| if ! git merge-base --is-ancestor "$BASE" "$HEAD"; then | |
| echo "::error::${BASE} is not an ancestor of ${HEAD}; refusing to scan" | |
| exit 1 | |
| fi | |
| echo "Scanning commits after ${BASE} through ${HEAD}" | |
| git rev-list --count "${BASE}..${HEAD}" || true | |
| # --since-commit scans the diff range. On a file:// repo TruffleHog | |
| # still checks the worktree out a second time unless told to trust | |
| # this checkout. That second checkout is what fills the disk. | |
| args=( | |
| git file://. | |
| --since-commit "$BASE" | |
| --branch "$HEAD" | |
| --trust-local-git-config | |
| --only-verified | |
| --github-actions | |
| --fail | |
| --no-update | |
| --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 |