Skip to content

Commit 3c30b02

Browse files
authored
ci: migrate claude-code-action workflows to Workload Identity Federation (anthropics#662)
Replaces the static ANTHROPIC_API_KEY repo secret with Workload Identity Federation across the 6 workflows that invoke claude-code-action: the action exchanges this job's GitHub OIDC token for a short-lived access token. The federation rule is bound to this repository (repository_id-pinned). - Adds permissions: id-token: write to all 6 (none had it). - Pins claude-code-action to v1.0.132 — the WIF inputs landed in v1.0.130; @v1 is a moving tag. - No anthropic_workspace_id — the rule targets the org's default workspace, so the input is optional. The two notebook-execution steps (notebook-quality.yml, notebook- tests.yml) that pass ANTHROPIC_API_KEY as an env var to nbconvert/ pytest are NOT migrated here — those need a separate inline OIDC exchange (TODO comments added). Both gracefully degrade when the secret is absent: notebook-tests has an explicit skip-guard, and notebook-quality catches per-notebook failures.
1 parent 39a350b commit 3c30b02

6 files changed

Lines changed: 58 additions & 12 deletions

File tree

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
permissions:
2424
contents: read
2525
pull-requests: write
26+
id-token: write # Anthropic Workload Identity Federation
2627
steps:
2728
- name: Set PR number
2829
id: pr-number
@@ -66,9 +67,14 @@ jobs:
6667

6768
- name: Run Claude Link Review
6869
if: steps.changed-files.outputs.has_files == 'true'
69-
uses: anthropics/claude-code-action@v1
70+
uses: anthropics/claude-code-action@bbfaf8e1ffe3e688f7ab65ceee78de241e24a238 # v1.0.132 (>=v1.0.130 for WIF inputs)
7071
with:
71-
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
72+
# Anthropic auth via Workload Identity Federation — the action
73+
# exchanges this job's GitHub OIDC token (id-token: write above)
74+
# for a short-lived access token instead of a static API key.
75+
anthropic_federation_rule_id: fdrl_01SqmTwzmEE547mtaYN1mqHL
76+
anthropic_organization_id: 1ec12c5c-6542-4da8-bf2f-c15919aef01c
77+
anthropic_service_account_id: svac_01BHcCBa1UWFvNrHMqJjuaUZ
7278
github_token: ${{ secrets.GITHUB_TOKEN }}
7379
prompt: |
7480
/link-review

.github/workflows/claude-model-check.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ on:
1717
permissions:
1818
contents: read
1919
pull-requests: write
20+
id-token: write # Anthropic Workload Identity Federation
2021

2122
jobs:
2223
model-check:
@@ -67,9 +68,14 @@ jobs:
6768

6869
- name: Claude Model Validation
6970
if: steps.changed-files.outputs.has_files == 'true'
70-
uses: anthropics/claude-code-action@v1
71+
uses: anthropics/claude-code-action@bbfaf8e1ffe3e688f7ab65ceee78de241e24a238 # v1.0.132 (>=v1.0.130 for WIF inputs)
7172
with:
72-
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
73+
# Anthropic auth via Workload Identity Federation — the action
74+
# exchanges this job's GitHub OIDC token (id-token: write above)
75+
# for a short-lived access token instead of a static API key.
76+
anthropic_federation_rule_id: fdrl_01SqmTwzmEE547mtaYN1mqHL
77+
anthropic_organization_id: 1ec12c5c-6542-4da8-bf2f-c15919aef01c
78+
anthropic_service_account_id: svac_01BHcCBa1UWFvNrHMqJjuaUZ
7379
github_token: ${{ secrets.GITHUB_TOKEN }}
7480
prompt: |
7581
/model-check

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
permissions:
2525
contents: read
2626
pull-requests: write
27+
id-token: write # Anthropic Workload Identity Federation
2728
steps:
2829
- name: Set PR number
2930
id: pr-number
@@ -41,9 +42,14 @@ jobs:
4142
ref: ${{ github.event_name == 'workflow_dispatch' && format('refs/pull/{0}/head', inputs.pr_number) || '' }}
4243

4344
- name: Run Claude PR Review
44-
uses: anthropics/claude-code-action@v1
45+
uses: anthropics/claude-code-action@bbfaf8e1ffe3e688f7ab65ceee78de241e24a238 # v1.0.132 (>=v1.0.130 for WIF inputs)
4546
with:
46-
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
47+
# Anthropic auth via Workload Identity Federation — the action
48+
# exchanges this job's GitHub OIDC token (id-token: write above)
49+
# for a short-lived access token instead of a static API key.
50+
anthropic_federation_rule_id: fdrl_01SqmTwzmEE547mtaYN1mqHL
51+
anthropic_organization_id: 1ec12c5c-6542-4da8-bf2f-c15919aef01c
52+
anthropic_service_account_id: svac_01BHcCBa1UWFvNrHMqJjuaUZ
4753
github_token: ${{ secrets.GITHUB_TOKEN }}
4854
prompt: |
4955
/review-pr-ci ${{ steps.pr-number.outputs.number }}

.github/workflows/lint-format.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ on:
1717
permissions:
1818
contents: read
1919
pull-requests: write
20+
id-token: write # Anthropic Workload Identity Federation
2021

2122
jobs:
2223
lint-and-format:
@@ -117,9 +118,14 @@ jobs:
117118
github.event.pull_request.head.repo.full_name == github.repository &&
118119
(steps.format-check.outputs.has_format_issues == 'true' ||
119120
steps.lint-check.outputs.has_lint_issues == 'true')
120-
uses: anthropics/claude-code-action@v1
121+
uses: anthropics/claude-code-action@bbfaf8e1ffe3e688f7ab65ceee78de241e24a238 # v1.0.132 (>=v1.0.130 for WIF inputs)
121122
with:
122-
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
123+
# Anthropic auth via Workload Identity Federation — the action
124+
# exchanges this job's GitHub OIDC token (id-token: write above)
125+
# for a short-lived access token instead of a static API key.
126+
anthropic_federation_rule_id: fdrl_01SqmTwzmEE547mtaYN1mqHL
127+
anthropic_organization_id: 1ec12c5c-6542-4da8-bf2f-c15919aef01c
128+
anthropic_service_account_id: svac_01BHcCBa1UWFvNrHMqJjuaUZ
123129
github_token: ${{ secrets.GITHUB_TOKEN }}
124130
prompt: |
125131
The linting and formatting checks found issues.

.github/workflows/notebook-quality.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ on:
1414
permissions:
1515
contents: read
1616
pull-requests: write
17+
id-token: write # Anthropic Workload Identity Federation
1718

1819
jobs:
1920
validate-notebooks:
@@ -55,9 +56,14 @@ jobs:
5556

5657
- name: Summarize validation issues with Claude
5758
if: github.event_name == 'pull_request' && steps.validate.outputs.has_issues == 'true'
58-
uses: anthropics/claude-code-action@v1
59+
uses: anthropics/claude-code-action@bbfaf8e1ffe3e688f7ab65ceee78de241e24a238 # v1.0.132 (>=v1.0.130 for WIF inputs)
5960
with:
60-
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
61+
# Anthropic auth via Workload Identity Federation — the action
62+
# exchanges this job's GitHub OIDC token (id-token: write above)
63+
# for a short-lived access token instead of a static API key.
64+
anthropic_federation_rule_id: fdrl_01SqmTwzmEE547mtaYN1mqHL
65+
anthropic_organization_id: 1ec12c5c-6542-4da8-bf2f-c15919aef01c
66+
anthropic_service_account_id: svac_01BHcCBa1UWFvNrHMqJjuaUZ
6167
github_token: ${{ secrets.GITHUB_TOKEN }}
6268
prompt: |
6369
The notebook validation found these issues:
@@ -82,6 +88,11 @@ jobs:
8288
PR_NUMBER: ${{ github.event.pull_request.number }}
8389

8490
# Only run API tests on main branch or for maintainers (costs money)
91+
# TODO: this step still reads the static ANTHROPIC_API_KEY secret. The
92+
# claude-code-action steps above use Workload Identity Federation; this
93+
# direct-API step needs a separate inline OIDC mint+exchange (or the
94+
# anthropic SDK's WIF env-var trio). Non-fatal in the meantime — each
95+
# notebook execution failure is caught by the `|| echo` below.
8596
- name: Execute notebooks (API Testing)
8697
if: |
8798
github.event_name == 'push' ||

.github/workflows/notebook-tests.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ on:
1616
permissions:
1717
contents: read
1818
pull-requests: write
19+
id-token: write # Anthropic Workload Identity Federation
1920

2021
jobs:
2122
test-notebooks:
@@ -126,9 +127,14 @@ jobs:
126127
github.event_name == 'pull_request' &&
127128
steps.changed-notebooks.outputs.has_notebooks == 'true' &&
128129
steps.structure-tests.outputs.has_failures == 'true'
129-
uses: anthropics/claude-code-action@v1
130+
uses: anthropics/claude-code-action@bbfaf8e1ffe3e688f7ab65ceee78de241e24a238 # v1.0.132 (>=v1.0.130 for WIF inputs)
130131
with:
131-
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
132+
# Anthropic auth via Workload Identity Federation — the action
133+
# exchanges this job's GitHub OIDC token (id-token: write above)
134+
# for a short-lived access token instead of a static API key.
135+
anthropic_federation_rule_id: fdrl_01SqmTwzmEE547mtaYN1mqHL
136+
anthropic_organization_id: 1ec12c5c-6542-4da8-bf2f-c15919aef01c
137+
anthropic_service_account_id: svac_01BHcCBa1UWFvNrHMqJjuaUZ
132138
github_token: ${{ secrets.GITHUB_TOKEN }}
133139
prompt: |
134140
The notebook tests found issues in the changed notebooks.
@@ -157,6 +163,11 @@ jobs:
157163
env:
158164
PR_NUMBER: ${{ github.event.pull_request.number }}
159165

166+
# TODO: this step still reads the static ANTHROPIC_API_KEY secret. The
167+
# claude-code-action step above uses Workload Identity Federation; this
168+
# direct-API step needs a separate inline OIDC mint+exchange (or the
169+
# anthropic SDK's WIF env-var trio). Gracefully skips when the secret
170+
# is absent (the `[ -z "$ANTHROPIC_API_KEY" ]` guard below).
160171
- name: Run notebook execution tests (maintainers only)
161172
id: execution-tests
162173
if: |

0 commit comments

Comments
 (0)