diff options
| author | tobin <tobin@anthropic.com> | 2026-11-16 23:11:36 +0000 |
|---|---|---|
| committer | tobin <tobin@anthropic.com> | 2026-11-16 23:11:36 +0000 |
| commit | 2194995c95cda1b2fb3eb9bf137445feb76d2494 (patch) | |
| tree | b263350a331eba362a4e835e378d9d1022b4f563 | |
| parent | fd30cee3ecd5a8ee772733c5d20c0f2bae2da2f0 (diff) | |
Scan testplugin-workflow-hardening-test
| -rw-r--r-- | .claude-plugin/marketplace.json | 2 | ||||
| -rw-r--r-- | .github/workflows/bump-plugin-shas.yml | 2 | ||||
| -rw-r--r-- | .github/workflows/scan-plugins.yml | 113 | ||||
| -rw-r--r-- | .github/workflows/validate-plugins.yml | 2 |
4 files changed, 87 insertions, 32 deletions
diff --git a/.claude-plugin/marketplace.json b/.claude-plugin/marketplace.json index 0543b213..ac8379f9 100644 --- a/.claude-plugin/marketplace.json +++ b/.claude-plugin/marketplace.json @@ -38,7 +38,7 @@ }, { "name": "adobe-for-creativity", - "description": "Harness Adobe's creative AI-powered tools to edit images, automate design workflows, and bring creative visions to life — from background removal to vectorization and professional retouching.", + "description": "Harness Adobe's creative AI-powered tools to edit images, automate design workflows, and bring creative visions to life — from background removal to vectorization and professional retouching. ", "author": { "name": "Adobe" }, diff --git a/.github/workflows/bump-plugin-shas.yml b/.github/workflows/bump-plugin-shas.yml index 81c3be4b..a04b45f9 100644 --- a/.github/workflows/bump-plugin-shas.yml +++ b/.github/workflows/bump-plugin-shas.yml @@ -61,7 +61,7 @@ jobs: # createCommitOnBranch-based bump so commits are signed by GitHub and # satisfy the org-level required_signatures ruleset on main. - - uses: anthropics/claude-plugins-community/.github/actions/bump-plugin-shas@9247660a88cf3f49456a2f6464d66fe4ea4f4a77 + - uses: anthropics/claude-plugins-community/.github/actions/bump-plugin-shas@ba5763b94426b25a3c4e41c3831b5bafeb93398b id: bump with: marketplace-path: .claude-plugin/marketplace.json diff --git a/.github/workflows/scan-plugins.yml b/.github/workflows/scan-plugins.yml index 28369843..e9d93e2a 100644 --- a/.github/workflows/scan-plugins.yml +++ b/.github/workflows/scan-plugins.yml @@ -12,8 +12,12 @@ name: Scan Plugins # workflow force-resets bump/plugin-shas every night, which makes the same # SHAs reappear in the diff on consecutive nights — without a cache, the # scan would re-burn ~90s of Claude time per entry per night. The cache is -# keyed on the policy hash so a prompt or schema change invalidates all -# verdicts and triggers a clean re-scan. +# keyed on the hash of the policy the run actually uses, so a prompt or +# schema change invalidates all verdicts and triggers a clean re-scan. The +# cache directory and that policy live under the runner's temp directory, +# outside the checkout; verdicts are only read back from an actual +# actions/cache restore, and only on workflow_dispatch runs — a pull_request +# run always reviews its changed entries fresh. # # Failure handling: a cached `passes:false` verdict still fails the job. The # Revert Failed Bumps workflow (revert-failed-bumps.yml) reacts to that by @@ -43,8 +47,9 @@ concurrency: env: MARKETPLACE: .claude-plugin/marketplace.json - CACHE_DIR: ${{ github.workspace }}/.scan-cache CACHE_TTL_DAYS: '30' + # CACHE_DIR and POLICY_PROMPT are exported by the "Prepare scan directories + # and policy" step; both point under the runner's temp directory. jobs: scan: @@ -83,22 +88,65 @@ jobs: # The previous "Require ANTHROPIC_API_KEY" fail-closed guard is # therefore no longer needed. - # Verdict cache, keyed on the policy content hash. A prompt change - # invalidates every cached verdict — that is intentional. The save key - # includes run_id so each run writes a fresh cache; restore-keys picks - # the most recent one. Verdicts older than CACHE_TTL_DAYS are pruned on - # restore to bound cache size as the marketplace grows. - - name: Restore verdict cache + # The verdict cache and the policy the scan runs with both live under + # the runner's temp directory, never inside the PR checkout. On + # pull_request the policy files (.github/policy/) are read from the base + # commit: a PR that edits the policy is scanned under the policy already + # on the base branch, and its edit takes effect for scans after it + # merges. A workflow_dispatch run uses the dispatched ref's own copy. + # The step also emits the hash the cache is keyed on. + - name: Prepare scan directories and policy if: steps.changes.outputs.relevant == 'true' + id: policy + env: + EVENT_NAME: ${{ github.event_name }} + BASE_SHA: ${{ github.event.pull_request.base.sha }} + run: | + set -euo pipefail + cache_dir="$RUNNER_TEMP/scan-cache" + policy_dir="$RUNNER_TEMP/scan-policy" + rm -rf "$cache_dir" "$policy_dir" + mkdir -p "$cache_dir" "$policy_dir" + if [[ "$EVENT_NAME" == "pull_request" ]]; then + if ! git cat-file -e "${BASE_SHA}:.github/policy/prompt.md" 2>/dev/null; then + echo "::error::.github/policy/prompt.md does not exist at base commit ${BASE_SHA}; the scan policy has to be on the base branch before it can be used." + exit 1 + fi + git archive --format=tar "$BASE_SHA" .github/policy | tar -x -C "$policy_dir" --strip-components=2 + else + cp -R .github/policy/. "$policy_dir/" + fi + policy_hash="$(cd "$policy_dir" && find . -type f -print0 | sort -z | xargs -0r sha256sum | sha256sum | cut -c1-16)" + { + echo "CACHE_DIR=$cache_dir" + echo "POLICY_PROMPT=$policy_dir/prompt.md" + } >> "$GITHUB_ENV" + echo "hash=$policy_hash" >> "$GITHUB_OUTPUT" + echo "::notice::Scan policy $policy_hash from $([[ "$EVENT_NAME" == "pull_request" ]] && echo "base commit ${BASE_SHA:0:12}" || echo "the dispatched ref")." + + # Verdict cache, keyed on the policy content hash from the step above. + # A prompt change invalidates every cached verdict — that is + # intentional. The save key includes run_id so each run writes a fresh + # cache; restore-keys picks the most recent one. Verdicts older than + # CACHE_TTL_DAYS are pruned on restore to bound cache size as the + # marketplace grows. + # + # The cache is only used on workflow_dispatch (the nightly bump path), + # never on pull_request: a pull_request run can write arbitrary entries + # into its own cache scope (it runs the PR's copy of this file), so a + # verdict restored there proves nothing. PR runs review their changed + # entries fresh each time. + - name: Restore verdict cache + if: steps.changes.outputs.relevant == 'true' && github.event_name != 'pull_request' id: cache-restore uses: actions/cache/restore@v4 with: - path: .scan-cache + path: ${{ env.CACHE_DIR }} # run_attempt so a re-run can save its own verdicts (cache keys are # immutable; without it a re-run would silently fail to save). - key: scan-verdicts-${{ hashFiles('.github/policy/**') }}-${{ github.run_id }}-${{ github.run_attempt }} + key: scan-verdicts-${{ steps.policy.outputs.hash }}-${{ github.run_id }}-${{ github.run_attempt }} restore-keys: | - scan-verdicts-${{ hashFiles('.github/policy/**') }}- + scan-verdicts-${{ steps.policy.outputs.hash }}- # Split the diff into cached (skip) and uncached (scan) entries. The # cache key is "<name>@<sha>" — a SHA is immutable, so a verdict for a @@ -110,12 +158,14 @@ jobs: BASE_REF: ${{ steps.changes.outputs.base_ref }} SCAN_ALL: ${{ inputs.scan_all || 'false' }} TTL_DAYS: ${{ env.CACHE_TTL_DAYS }} + CACHE_MATCHED_KEY: ${{ steps.cache-restore.outputs.cache-matched-key }} run: | set -euo pipefail mkdir -p "$CACHE_DIR" - # Initialize / prune the verdict map. - if [[ -f "$CACHE_DIR/verdicts.json" ]] && jq -e 'type == "object"' "$CACHE_DIR/verdicts.json" >/dev/null 2>&1; then + # Initialize / prune the verdict map. A verdicts.json is only trusted + # when actions/cache actually restored one in the step above. + if [[ -n "$CACHE_MATCHED_KEY" && -f "$CACHE_DIR/verdicts.json" ]] && jq -e 'type == "object"' "$CACHE_DIR/verdicts.json" >/dev/null 2>&1; then # Drop entries older than TTL. Verdicts are immutable per (plugin, sha) # but pruning keeps the cache from accumulating forever. cutoff="$(date -u -d "-${TTL_DAYS} days" +%Y-%m-%dT%H:%M:%SZ)" @@ -194,9 +244,9 @@ jobs: # The verdict (cached + fresh) is what gates the job, not the action's # exit code, and the revert workflow needs the artifact even on failure. continue-on-error: true - # Pinned to claude-plugins-community#34 (WIF input support). - # TODO: re-pin to a main-branch SHA once #34 merges. - uses: anthropics/claude-plugins-community/.github/actions/scan-plugins@426e469f322952061102b286b378c0c9733a0934 + # Pin to the claude-plugins-community main-branch commit that carries + # the scan-plugins review-session hardening. + uses: anthropics/claude-plugins-community/.github/actions/scan-plugins@ba5763b94426b25a3c4e41c3831b5bafeb93398b with: # Anthropic auth via Workload Identity Federation — the action # mints a GitHub OIDC token (id-token: write above) and the claude @@ -205,10 +255,13 @@ jobs: anthropic-federation-rule-id: fdrl_0147kJdru6bZKTtzwFNEqsDf anthropic-organization-id: 1ec12c5c-6542-4da8-bf2f-c15919aef01c anthropic-service-account-id: svac_01DnC3BtPHGjYJEGeuUUXZ8v - marketplace-path: .scan-cache/scan-targets.json - policy-prompt: .github/policy/prompt.md + marketplace-path: ${{ env.CACHE_DIR }}/scan-targets.json + policy-prompt: ${{ env.POLICY_PROMPT }} fail-on-findings: "true" - claude-cli-version: latest + # A fixed, reviewed release rather than "latest": how the review + # session is confined rests on CLI behaviour, so move this + # deliberately (check a new release against the scan-plugins action first). + claude-cli-version: "2.1.296" # Merge fresh verdicts into the cache and assemble this run's full # verdict set (cached + fresh) for downstream consumers. Runs even when @@ -247,10 +300,12 @@ jobs: # short-lived OIDC JWT (masked) and the CLI's exchanged bearer # rather than a long-lived sk-ant- key, which bounds the blast # radius of a prompt-injection exfil to a token that expires in - # minutes. The sk-ant- scrubber stays as defense-in-depth (covers - # any future static-key fallback) so key-shaped strings still never - # reach the cache, artifact, or PR comment. - jq -c '(.. | strings) |= gsub("sk-ant-[A-Za-z0-9_-]{8,}"; "[REDACTED]")' \ + # minutes. Scrub both shapes — sk-ant- keys and JWTs (three + # base64url segments, the first two starting "eyJ") — so + # credential-shaped strings never reach the cache, artifact, or PR + # comment whatever the auth path. + jq -c '(.. | strings) |= (gsub("sk-ant-[A-Za-z0-9_-]{8,}"; "[REDACTED]") + | gsub("eyJ[A-Za-z0-9_-]{8,}\\.eyJ[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}"; "[REDACTED]"))' \ "$CACHE_DIR/scanned-raw.json" > "$CACHE_DIR/scanned-raw.json.tmp" mv "$CACHE_DIR/scanned-raw.json.tmp" "$CACHE_DIR/scanned-raw.json" @@ -346,18 +401,18 @@ jobs: with: name: scan-verdicts path: | - .scan-cache/run-verdicts.json - .scan-cache/run-failed.json + ${{ env.CACHE_DIR }}/run-verdicts.json + ${{ env.CACHE_DIR }}/run-failed.json retention-days: 7 # Save even when the scan failed — fail verdicts are what stop us from # re-burning Claude time on a known-bad SHA every night. - name: Save verdict cache - if: always() && steps.changes.outputs.relevant == 'true' + if: always() && steps.changes.outputs.relevant == 'true' && env.CACHE_DIR != '' && github.event_name != 'pull_request' uses: actions/cache/save@v4 with: - path: .scan-cache - key: scan-verdicts-${{ hashFiles('.github/policy/**') }}-${{ github.run_id }}-${{ github.run_attempt }} + path: ${{ env.CACHE_DIR }} + key: scan-verdicts-${{ steps.policy.outputs.hash }}-${{ github.run_id }}-${{ github.run_attempt }} # Required-check gate. Fails on either fresh or cached policy failures — # a known-bad SHA must keep failing until it is reverted or upstream diff --git a/.github/workflows/validate-plugins.yml b/.github/workflows/validate-plugins.yml index 8be7c60e..247fa0fb 100644 --- a/.github/workflows/validate-plugins.yml +++ b/.github/workflows/validate-plugins.yml @@ -79,7 +79,7 @@ jobs: - name: Validate marketplace.json if: steps.marketplace.outputs.changed == 'true' - uses: anthropics/claude-plugins-community/.github/actions/validate-plugins@163301d1904c0a994539f5226ce0fcd65b8652bf + uses: anthropics/claude-plugins-community/.github/actions/validate-plugins@ba5763b94426b25a3c4e41c3831b5bafeb93398b with: marketplace-path: .claude-plugin/marketplace.json skip-local-folders: "true" |
