Skip to content

Commit dfe073a

Browse files
authored
Merge pull request #1370 from codeflash-ai/claude-workflow-perms
feat: secure Claude workflow and add merge permissions
2 parents dd0cca9 + cb9248e commit dfe073a

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

.github/workflows/claude.yml

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ on:
1414

1515
jobs:
1616
# Automatic PR review (can fix linting issues and push)
17+
# Blocked for fork PRs to prevent malicious code execution
1718
pr-review:
18-
if: github.event_name == 'pull_request' && github.actor != 'claude[bot]'
19+
if: |
20+
github.event_name == 'pull_request' &&
21+
github.actor != 'claude[bot]' &&
22+
github.event.pull_request.head.repo.full_name == github.repository
1923
runs-on: ubuntu-latest
2024
permissions:
2125
contents: write
@@ -44,6 +48,7 @@ jobs:
4448
with:
4549
use_foundry: "true"
4650
use_sticky_comment: true
51+
allowed_bots: "claude[bot]"
4752
prompt: |
4853
REPO: ${{ github.repository }}
4954
PR NUMBER: ${{ github.event.pull_request.number }}
@@ -124,13 +129,31 @@ jobs:
124129
ANTHROPIC_FOUNDRY_API_KEY: ${{ secrets.AZURE_ANTHROPIC_API_KEY }}
125130
ANTHROPIC_FOUNDRY_BASE_URL: ${{ secrets.AZURE_ANTHROPIC_ENDPOINT }}
126131

127-
# @claude mentions (can edit and push)
132+
# @claude mentions (can edit and push) - restricted to maintainers only
128133
claude-mention:
129134
if: |
130-
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
131-
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
132-
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
133-
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
135+
(
136+
github.event_name == 'issue_comment' &&
137+
contains(github.event.comment.body, '@claude') &&
138+
(github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR')
139+
) ||
140+
(
141+
github.event_name == 'pull_request_review_comment' &&
142+
contains(github.event.comment.body, '@claude') &&
143+
(github.event.comment.author_association == 'OWNER' || github.event.comment.author_association == 'MEMBER' || github.event.comment.author_association == 'COLLABORATOR') &&
144+
github.event.pull_request.head.repo.full_name == github.repository
145+
) ||
146+
(
147+
github.event_name == 'pull_request_review' &&
148+
contains(github.event.review.body, '@claude') &&
149+
(github.event.review.author_association == 'OWNER' || github.event.review.author_association == 'MEMBER' || github.event.review.author_association == 'COLLABORATOR') &&
150+
github.event.pull_request.head.repo.full_name == github.repository
151+
) ||
152+
(
153+
github.event_name == 'issues' &&
154+
(contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')) &&
155+
(github.event.issue.author_association == 'OWNER' || github.event.issue.author_association == 'MEMBER' || github.event.issue.author_association == 'COLLABORATOR')
156+
)
134157
runs-on: ubuntu-latest
135158
permissions:
136159
contents: write
@@ -171,7 +194,7 @@ jobs:
171194
uses: anthropics/claude-code-action@v1
172195
with:
173196
use_foundry: "true"
174-
claude_args: '--allowedTools "Read,Edit,Write,Glob,Grep,Bash(git status*),Bash(git diff*),Bash(git add *),Bash(git commit *),Bash(git push*),Bash(git log*),Bash(uv run prek *),Bash(prek *),Bash(uv run ruff *),Bash(uv run pytest *),Bash(uv run mypy *),Bash(uv run coverage *),Bash(gh pr comment*),Bash(gh pr view*),Bash(gh pr diff*)"'
197+
claude_args: '--allowedTools "Read,Edit,Write,Glob,Grep,Bash(git status*),Bash(git diff*),Bash(git add *),Bash(git commit *),Bash(git push*),Bash(git log*),Bash(git merge*),Bash(git fetch*),Bash(git checkout*),Bash(git branch*),Bash(uv run prek *),Bash(prek *),Bash(uv run ruff *),Bash(uv run pytest *),Bash(uv run mypy *),Bash(uv run coverage *),Bash(gh pr comment*),Bash(gh pr view*),Bash(gh pr diff*),Bash(gh pr merge*),Bash(gh pr close*)"'
175198
additional_permissions: |
176199
actions: read
177200
env:

0 commit comments

Comments
 (0)