Skip to content

Commit 6035d91

Browse files
iangmaiaclaude
andcommitted
Secure Claude workflows: gate authors, drop issues trigger, pin SHAs, drop id-token
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 1d88d75 commit 6035d91

2 files changed

Lines changed: 26 additions & 24 deletions

File tree

.github/workflows/claude-code-review.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,16 @@ jobs:
2525
permissions:
2626
contents: read
2727
pull-requests: write
28-
id-token: write
2928

3029
steps:
3130
- name: Checkout repository
32-
uses: actions/checkout@v7
31+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
3332
with:
3433
fetch-depth: 1
3534

3635
- name: Run Claude Code Review
3736
id: claude-review
38-
uses: anthropics/claude-code-action@v1
37+
uses: anthropics/claude-code-action@4d7e1f0cd85743fdc93b1c8040ab54395da024e2 # v1.0.149
3938
with:
4039
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
4140
track_progress: true
@@ -53,5 +52,3 @@ jobs:
5352
5453
claude_args: |
5554
--allowedTools "mcp__github_inline_comment__create_inline_comment,Bash(gh pr diff:*),Bash(gh pr view:*)"
56-
57-

.github/workflows/claude.yml

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,51 @@ on:
55
types: [created]
66
pull_request_review_comment:
77
types: [created]
8-
issues:
9-
types: [opened]
108
pull_request_review:
119
types: [submitted]
1210

1311
jobs:
1412
claude:
13+
# Only run when @claude is mentioned AND the author is a trusted
14+
# org member/collaborator. This is defense-in-depth on top of the
15+
# action's built-in write-access check.
1516
if: |
16-
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
17-
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
18-
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
19-
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
17+
(
18+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
19+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
20+
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude'))
21+
) &&
22+
(
23+
github.event.comment.author_association == 'OWNER' ||
24+
github.event.comment.author_association == 'MEMBER' ||
25+
github.event.comment.author_association == 'COLLABORATOR' ||
26+
github.event.review.author_association == 'OWNER' ||
27+
github.event.review.author_association == 'MEMBER' ||
28+
github.event.review.author_association == 'COLLABORATOR'
29+
)
2030
runs-on: ubuntu-latest
2131
permissions:
22-
contents: write
32+
contents: write # Downgrade to `read` if Claude should not push commits/branches
2333
pull-requests: write
2434
issues: write
25-
id-token: write
2635
actions: read # Required for Claude to read CI results on PRs
2736
steps:
2837
- name: Checkout repository
29-
uses: actions/checkout@v7
38+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
3039
with:
3140
fetch-depth: 1
3241

3342
- name: Run Claude Code
3443
id: claude
35-
uses: anthropics/claude-code-action@v1
44+
uses: anthropics/claude-code-action@4d7e1f0cd85743fdc93b1c8040ab54395da024e2 # v1.0.149
3645
with:
3746
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
3847

39-
# This is an optional setting that allows Claude to read CI results on PRs
48+
# Allows Claude to read CI results on PRs
4049
additional_permissions: |
4150
actions: read
4251
43-
# Optional: Give a custom prompt to Claude. If this is not specified, Claude will perform the instructions specified in the comment that tagged it.
44-
# prompt: 'Update the pull request description to include a summary of changes.'
45-
46-
# Optional: Add claude_args to customize behavior and configuration
47-
# See https://github.com/anthropics/claude-code-action/blob/main/docs/usage.md
48-
# or https://code.claude.com/docs/en/cli-reference for available options
49-
# claude_args: '--allowed-tools Bash(gh pr *)'
50-
52+
# Tools are intentionally left at the action's tag-mode defaults: file edits
53+
# are confined to the workspace (acceptEdits) and arbitrary Bash is blocked.
54+
# Do NOT add Edit/Write to a custom --allowedTools — the action omits them on
55+
# purpose; listing them grants blanket write access to the whole runner.

0 commit comments

Comments
 (0)