From 0f8c10e7a1c4c993d5638d12cc873b26fa91c945 Mon Sep 17 00:00:00 2001 From: Nenad Novakovic Date: Mon, 30 Nov 2026 21:22:22 +0100 Subject: [PATCH] Add org-wide Claude Security scan merge gate Runs the Claude Security plugin's GitHub Action on every pull request, enforced through the "Require org CI" ruleset like the other org gates. Based on the plugin's CI guide (pull request review sample), pinned to the v0.13.0 release commit the docs give, scanning with Opus. The key is the org secret ANTHROPIC_SECURITY_API_KEY (private repos only). Repos without it, public ones included, skip with a warning so the gate never blocks merges just for a missing key. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/org-claude-security.yml | 109 ++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 .github/workflows/org-claude-security.yml diff --git a/.github/workflows/org-claude-security.yml b/.github/workflows/org-claude-security.yml new file mode 100644 index 0000000..4ab1775 --- /dev/null +++ b/.github/workflows/org-claude-security.yml @@ -0,0 +1,109 @@ +name: Claude Security + +# Org-wide pull request security scan, using the Claude Security plugin's GitHub Action. +# Enforced across every Devilos repo via the "Require org CI" ruleset, so there is +# deliberately NO copy of this file in each repo. +# Based on the plugin's CI guide, whose sample steps are kept as they are: +# https://github.com/anthropics/claude-plugins-official/blob/main/plugins/claude-security/CI.md +# +# Auth: a Claude API key scoped to its own Claude Console workspace (with a monthly spend +# limit), stored as the ORG secret ANTHROPIC_SECURITY_API_KEY with "Private repositories" +# visibility. The action takes no Claude subscription token, so the org's +# CLAUDE_CODE_OAUTH_TOKEN can't be used here, and uw-v4's own ANTHROPIC_API_KEY repo +# secret would shadow an org secret of that name. Public repos don't get the key and skip +# the scan on purpose: a review on a public PR could disclose a live vulnerability. +# +# Ruleset-required workflows only run on pull_request / merge_group events, so there is +# no scheduled whole-repo scan here. See CI.md "Scheduled scans" to add one per repo. +on: + pull_request: + # Scan when a pull request opens, gets commits, leaves draft or changes its base branch. + # Keep ready_for_review: drafts pass with no scan, so a draft must be scanned when it is marked ready. + types: [opened, synchronize, reopened, ready_for_review, edited] + +permissions: + actions: read + contents: read + pull-requests: write + +concurrency: + group: org-claude-security-${{ github.repository }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event.action != 'edited' || github.event.changes.base != null }} + +jobs: + # This workflow is a MERGE GATE for the whole org, so it must not hard-fail just because + # a repo can't see the key (public repos, or before the org secret exists). Skip with a + # warning instead. The key itself never leaves the scan step. + key-check: + name: Claude Security key check + runs-on: ubuntu-24.04 + permissions: {} + outputs: + enabled: ${{ steps.guard.outputs.enabled }} + steps: + - id: guard + env: + HAS_KEY: ${{ secrets.ANTHROPIC_SECURITY_API_KEY != '' }} + REPO: ${{ github.repository }} + run: | + if [ "$HAS_KEY" = "true" ]; then + echo "enabled=true" >> "$GITHUB_OUTPUT" + else + echo "::warning::ANTHROPIC_SECURITY_API_KEY is not available to $REPO, so the Claude Security scan is skipped." + echo "enabled=false" >> "$GITHUB_OUTPUT" + fi + + claude-security: + needs: key-check + # Sample condition kept: it skips the merge queue, and Dependabot's runs on branches of + # the repository. Skipped runs pass. + if: >- + needs.key-check.outputs.enabled == 'true' + && github.event_name != 'merge_group' + && (github.actor != 'dependabot[bot]' + || github.event.pull_request.head.repo.full_name != github.repository) + runs-on: ubuntu-24.04 # Only GitHub-hosted Linux runners work. + timeout-minutes: 240 + outputs: + report: ${{ steps.claude-security.outputs.report }} + steps: &steps + # Keep this step as it is. + - uses: actions/checkout@v5 + with: + ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 + persist-credentials: false + + - id: claude-security + # Pinned to the release commit the docs give (v0.13.0). The action runs with sudo, + # so never pin a branch. Update from https://code.claude.com/docs/en/claude-security + uses: anthropics/claude-plugins-official/plugins/claude-security@d0d514288960e7a78e1a76e4a3ec694416458726 + with: + anthropic_api_key: ${{ secrets.ANTHROPIC_SECURITY_API_KEY }} + # Draft fixes in the second job. + suggest_patches: later + # Empty in the first job. The second job passes the first job's report. + report: ${{ needs.claude-security.outputs.report }} + # PostHog's self-driving fixes open PRs as the posthog-eu GitHub App. The action + # fails the job for any app not listed here, and this workflow is a merge gate. + # Same decision as the org Claude Code Review workflow. + allowed_bots: posthog-eu[bot] + # Opus instead of the default Fable: the CI guide says it does well on smaller + # PR scans at a much lower cost. Change to fable for a deeper (pricier) scan. + model: opus + # Which findings fail the job (and so block the merge): the default, `high`, + # is any CRITICAL or HIGH finding. + # fail_on: high + + # Keep this step as it is: without it, "Re-run all jobs" posts the comments again. + - name: Receipt ${{ steps.claude-security.outputs.receipt }} + if: always() + run: "true" + + # Suggested fixes, after the first job has ended. The same steps. + claude-security-fixes: + needs: [key-check, claude-security] + if: ${{ !cancelled() && needs.claude-security.outputs.report != '' }} + runs-on: ubuntu-24.04 + timeout-minutes: 240 + steps: *steps