Authenticate to Claude by Workload Identity Federation #44

Closed
chris-kreidl wants to merge 1 commit from session/anthropic-wif into main
chris-kreidl commented 2026-11-02 15:12:24 +00:00 (Migrated from github.com)

What changed

  • src/ai/client.ts: anthropic() uses Workload Identity Federation when ANTHROPIC_FEDERATION_RULE_ID is set. It passes credentials: oidcFederationProvider(...) with getVercelOidcToken() as the identity token provider. The token is read fresh on each exchange because Vercel rotates it. The SDK caches the Claude token and refreshes it before expiry. A rule ID without the organization and service account IDs throws rather than falling back.
  • Without the federation env (local development), the client is unchanged: ant auth login profile or ANTHROPIC_API_KEY.
  • .env.example, README env table, PROGRESS, decisions, history.

How it was checked

  • federationFromEnv unit tests (off / on / partial config); full suite 1308 pass; typecheck, lint, format check.
  • bun run build bundles the SDK's lib/credentials import and @vercel/functions/oidc.
  • Not yet checked: a real token exchange. That needs the Console and Vercel setup below.

Before merging (owner)

Merging without this breaks AI calls in production (the old key has expired anyway).

  1. Vercel → project → Settings → Security → OIDC Federation: on, Team issuer.
  2. Claude Console: a service account in the app's workspace; a federation issuer https://oidc.vercel.com/<team-slug> (discovery); a rule with scope workspace:inference, audience https://vercel.com/<team-slug>, subject owner:<team-slug>:project:trainer:environment:production.
  3. Vercel Production env: ANTHROPIC_FEDERATION_RULE_ID, ANTHROPIC_ORGANIZATION_ID, ANTHROPIC_SERVICE_ACCOUNT_ID; remove ANTHROPIC_API_KEY.
  4. Optionally first prove it on a preview, with a second rule for environment:preview that you archive afterwards. Try one coach message and one logged session, which runs a re-plan through waitUntil.

Then run prompts/92-review.md in a fresh session.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features

    • Production AI access can now authenticate through Vercel identity federation, without a production API key.
    • Local development can use the ant CLI profile; an API key remains supported.
  • Documentation

    • Updated setup guidance with the required production federation settings and local authentication options.
## What changed - `src/ai/client.ts`: `anthropic()` uses Workload Identity Federation when `ANTHROPIC_FEDERATION_RULE_ID` is set. It passes `credentials: oidcFederationProvider(...)` with `getVercelOidcToken()` as the identity token provider. The token is read fresh on each exchange because Vercel rotates it. The SDK caches the Claude token and refreshes it before expiry. A rule ID without the organization and service account IDs throws rather than falling back. - Without the federation env (local development), the client is unchanged: `ant auth login` profile or `ANTHROPIC_API_KEY`. - `.env.example`, README env table, PROGRESS, decisions, history. ## How it was checked - `federationFromEnv` unit tests (off / on / partial config); full suite 1308 pass; typecheck, lint, format check. - `bun run build` bundles the SDK's `lib/credentials` import and `@vercel/functions/oidc`. - **Not yet checked:** a real token exchange. That needs the Console and Vercel setup below. ## Before merging (owner) Merging without this breaks AI calls in production (the old key has expired anyway). 1. Vercel → project → Settings → Security → OIDC Federation: on, Team issuer. 2. Claude Console: a service account in the app's workspace; a federation issuer `https://oidc.vercel.com/<team-slug>` (discovery); a rule with scope `workspace:inference`, audience `https://vercel.com/<team-slug>`, subject `owner:<team-slug>:project:trainer:environment:production`. 3. Vercel Production env: `ANTHROPIC_FEDERATION_RULE_ID`, `ANTHROPIC_ORGANIZATION_ID`, `ANTHROPIC_SERVICE_ACCOUNT_ID`; remove `ANTHROPIC_API_KEY`. 4. Optionally first prove it on a preview, with a second rule for `environment:preview` that you archive afterwards. Try one coach message and one logged session, which runs a re-plan through `waitUntil`. Then run `prompts/92-review.md` in a fresh session. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> <!-- coderabbit-ai-generated:v1 --> ## Summary by CodeRabbit * **New Features** * Production AI access can now authenticate through Vercel identity federation, without a production API key. * Local development can use the `ant` CLI profile; an API key remains supported. * **Documentation** * Updated setup guidance with the required production federation settings and local authentication options. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
coderabbitai[bot] commented 2026-11-02 15:12:38 +00:00 (Migrated from github.com)

Review in Change Stack →

Recent review info
Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Free
  • Run ID: 6779d588-1a97-4abf-afed-989e7188df3d
Commits

Reviewing files that changed from the base of the PR and between f3c32f5ddc and 838d41f313.

Files selected for processing: 7
  • .env.example
  • README.md
  • docs/PROGRESS.md
  • docs/decisions.md
  • docs/history.md
  • src/ai/client.test.ts
  • src/ai/client.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Walkthrough

Anthropic client creation now supports Vercel OIDC Workload Identity Federation when federation settings are configured. Local authentication and production environment requirements are documented, and tests cover federation configuration parsing.

Changes: Anthropic authentication

Layer / File(s) Summary
Authentication configuration and setup
.env.example, README.md, docs/PROGRESS.md, docs/decisions.md, docs/history.md
The environment examples and project documentation describe local ant auth login use, production federation identifiers, and federation setup and verification steps.
Federation configuration and client creation
src/ai/client.ts, src/ai/client.test.ts
federationFromEnv returns null when no rule ID is set and requires organization and service-account IDs when one is set. anthropic() creates a federation-backed client when configured and otherwise creates a plain client. Tests cover the helper’s configuration cases.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Application
  participant AnthropicClient
  participant OidcProvider
  participant VercelToken
  participant AnthropicAPI
  Application->>AnthropicClient: Request shared client
  AnthropicClient->>OidcProvider: Configure federation identifiers and token provider
  Application->>AnthropicAPI: Send request using shared client
  OidcProvider->>VercelToken: Retrieve Vercel OIDC token
  VercelToken-->>OidcProvider: Return OIDC token
  OidcProvider->>AnthropicAPI: Exchange token and authenticate request
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Note

Summarized by CodeRabbit Free

Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Essentials by visiting https://app.coderabbit.ai/settings/billing.

I’m a rabbit with a config to review,
Three IDs hop into the env view.
Vercel brings a token to the call,
Local profiles still work for all.
I nibble the tests, then bound away.

<!-- coderabbit-ai-generated:v1 --> <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/chris-kreidl/trainer/pull/44?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> <details> <summary><strong><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/info.svg" width="16" height="16" align="absmiddle" alt=""></picture> Recent review info</strong></summary> <dl> <dd> <!-- review_info_content --> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/cog.svg" width="16" height="16" align="absmiddle" alt=""></picture> Run configuration</strong></summary> <dl> <dd> - **Source mode**: Auto - **Repository**: Unavailable - **Branch**: Unavailable - **File**: No configuration file from this repository applied - **Commit**: Unavailable - **Layers**: Organization UI - **Review profile**: ASSERTIVE - **Plan**: Free - **Run ID**: `6779d588-1a97-4abf-afed-989e7188df3d` </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/git-commit-horizontal.svg" width="16" height="16" align="absmiddle" alt=""></picture> Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between f3c32f5ddc79f4c5f2bd00e0a1ab8a4dc30a49bf and 838d41f313a66f7e4651550a43becc5b18b8c6b7. </dd> </dl> </details> <details> <summary><strong><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner-dark.svg"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-comment-icons-v1/file-plus-corner.svg" width="16" height="16" align="absmiddle" alt=""></picture> Files selected for processing: 7</strong></summary> <dl> <dd> * `.env.example` * `README.md` * `docs/PROGRESS.md` * `docs/decisions.md` * `docs/history.md` * `src/ai/client.test.ts` * `src/ai/client.ts` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>Walkthrough</strong></summary> <dl> <dd> Anthropic client creation now supports Vercel OIDC Workload Identity Federation when federation settings are configured. Local authentication and production environment requirements are documented, and tests cover federation configuration parsing. **Changes: Anthropic authentication** |Layer / File(s)|Summary| |:---|:---| |**Authentication configuration and setup** <br> `.env.example`, `README.md`, `docs/PROGRESS.md`, `docs/decisions.md`, `docs/history.md`|The environment examples and project documentation describe local `ant auth login` use, production federation identifiers, and federation setup and verification steps.| |**Federation configuration and client creation** <br> `src/ai/client.ts`, `src/ai/client.test.ts`|`federationFromEnv` returns `null` when no rule ID is set and requires organization and service-account IDs when one is set. `anthropic()` creates a federation-backed client when configured and otherwise creates a plain client. Tests cover the helper’s configuration cases.| **Estimated code review effort:** 3 (Moderate) | ~20 minutes ## Sequence Diagram(s) ```mermaid sequenceDiagram participant Application participant AnthropicClient participant OidcProvider participant VercelToken participant AnthropicAPI Application->>AnthropicClient: Request shared client AnthropicClient->>OidcProvider: Configure federation identifiers and token provider Application->>AnthropicAPI: Send request using shared client OidcProvider->>VercelToken: Retrieve Vercel OIDC token VercelToken-->>OidcProvider: Return OIDC token OidcProvider->>AnthropicAPI: Exchange token and authenticate request ``` </dd> </dl> </details> <!-- walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> > [!NOTE] > <details> > <summary><strong>Summarized by CodeRabbit Free</strong></summary> > <dl> > <dd> > > Your organization is on the Free plan. CodeRabbit will generate a high-level summary and a walkthrough for each pull request. For a comprehensive line-by-line review, please upgrade your subscription to CodeRabbit Essentials by visiting <https://app.coderabbit.ai/settings/billing>. > > </dd> > </dl> > </details> <!-- poem_footer_start --> <sub>I’m a rabbit with a config to review,<br>Three IDs hop into the env view.<br>Vercel brings a token to the call,<br>Local profiles still work for all.<br>I nibble the tests, then bound away.</sub> <!-- poem_footer_end --> <!-- tips_end -->
chris-kreidl commented 2026-11-20 14:24:14 +00:00 (Migrated from github.com)

Closing as not planned: Workload Identity Federation isn't going to happen.

Closing as not planned: Workload Identity Federation isn't going to happen.

Pull request closed

Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
ckreidl/trainer!44
No description provided.