Skip to content

Commit 93bef01

Browse files
riglarclaude
andauthored
ci: authenticate the Claude action by workload identity federation (#255)
Swap the CLAUDE_CODE_OAUTH_TOKEN secret for the action's built-in OIDC exchange, so the workflows need no stored secret. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 43cdf5f commit 93bef01

2 files changed

Lines changed: 29 additions & 3 deletions

File tree

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

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ on:
1313
jobs:
1414
claude-review:
1515
# Skip PRs we shouldn't (or can't) review:
16-
# - Dependabot / forks: no CLAUDE_CODE_OAUTH_TOKEN, so the action would fail.
16+
# - Dependabot / forks: no OIDC token to exchange, so the action would fail.
1717
# - release-please release PRs: just version bumps + changelog — nothing to
1818
# review, and it must never block a release.
1919
# - Back-merge PRs (production -> dev, opened by release-please.yml): only
@@ -44,7 +44,13 @@ jobs:
4444
id: claude-review
4545
uses: anthropics/claude-code-action@v1
4646
with:
47-
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
47+
# Workload identity federation: the action swaps the job's GitHub OIDC
48+
# token (hence `id-token: write`) for a short-lived Anthropic token.
49+
# No stored secret. These IDs aren't secret either.
50+
anthropic_federation_rule_id: fdrl_01TQKFjxagS7QzsRp6royjYN
51+
anthropic_organization_id: 43f1fdcd-16a2-46c9-902d-f939b82bb4f4
52+
anthropic_service_account_id: svac_01TcDsbHiTCxQ5m7aNHrBgLg
53+
anthropic_workspace_id: wrkspc_01SadkG1A6MDwLr3FVD1VmyN
4854
plugin_marketplaces: 'https://github.com/anthropics/claude-code.git'
4955
plugins: 'code-review@claude-code-plugins'
5056
# --comment is required for the review to be posted to the PR: the
@@ -76,12 +82,26 @@ jobs:
7682
# The plugin also stops early on PRs it judges trivial. The prompt above
7783
# tells Claude to post a one-line note in that case, so a deliberate skip
7884
# leaves a comment and only a real failure trips this check.
85+
#
86+
# Nor is a PR that edits THIS file: the action refuses to run unless the
87+
# workflow is identical to the default branch's ("Workflow validation
88+
# failed"), a deliberate guard against a PR rewriting its own reviewer. It
89+
# exits green having posted nothing, so pass with a notice instead.
7990
- name: Check a review comment was posted
8091
env:
8192
GH_TOKEN: ${{ github.token }}
8293
REPO: ${{ github.repository }}
8394
PR: ${{ github.event.pull_request.number }}
95+
SELF: ${{ github.workflow_ref }}
8496
run: |
97+
# workflow_ref is "owner/repo/.github/workflows/<file>@<ref>".
98+
self_path="${SELF#"$REPO"/}"
99+
self_path="${self_path%@*}"
100+
if gh api "repos/$REPO/pulls/$PR/files" --paginate --jq '.[].filename' | grep -qxF "$self_path"; then
101+
echo "::notice::This PR edits $self_path, so the review action skipped it by design (it only runs the default branch's version of its own workflow). No review on this PR."
102+
exit 0
103+
fi
104+
85105
# Prints the time of every claude[bot] comment, inline comment and review.
86106
claude_posts() {
87107
gh api "repos/$REPO/issues/$PR/comments" --paginate \

‎.github/workflows/claude.yml‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,13 @@ jobs:
3434
id: claude
3535
uses: anthropics/claude-code-action@v1
3636
with:
37-
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
37+
# Workload identity federation: the action swaps the job's GitHub OIDC
38+
# token (hence `id-token: write`) for a short-lived Anthropic token.
39+
# No stored secret. These IDs aren't secret either.
40+
anthropic_federation_rule_id: fdrl_01TQKFjxagS7QzsRp6royjYN
41+
anthropic_organization_id: 43f1fdcd-16a2-46c9-902d-f939b82bb4f4
42+
anthropic_service_account_id: svac_01TcDsbHiTCxQ5m7aNHrBgLg
43+
anthropic_workspace_id: wrkspc_01SadkG1A6MDwLr3FVD1VmyN
3844

3945
# This is an optional setting that allows Claude to read CI results on PRs
4046
additional_permissions: |

0 commit comments

Comments
 (0)