Skip to content

feat: add Vertex AI support via use-vertex inputs#98

Open
nh3500 wants to merge 1 commit intoanthropics:mainfrom
Dcard:feat/vertex-ai-support
Open

feat: add Vertex AI support via use-vertex inputs#98
nh3500 wants to merge 1 commit intoanthropics:mainfrom
Dcard:feat/vertex-ai-support

Conversation

@nh3500
Copy link
Copy Markdown

@nh3500 nh3500 commented Apr 29, 2026

Summary

Adds an optional Vertex AI path to the action, alongside the existing claude-api-key flow. Motivation: organizations that have standardized on Google Cloud often want Claude billing and access centralized in Vertex AI rather than managing per-repo ANTHROPIC_API_KEY secrets — for those teams, the current required-API-key surface makes this action unusable.

This change is fully backward-compatible: every existing default preserves the current behavior, and only the addition of new optional kwargs to FindingsFilter requires touching one existing test assertion.

What changes

New action inputs

Input Default Notes
use-vertex 'false' Enables Vertex AI mode
vertex-region 'global' Vertex region (e.g. global, us-east5)
vertex-project-id '' GCP project hosting Vertex AI; required when use-vertex is true

claude-api-key is now required: false (was true). The action's auth pre-flight check now passes if either an API key or use-vertex + vertex-project-id are provided. The direct-API call sites are unchanged.

Code changes

The action has two Claude call points:

  1. Main security auditSimpleClaudeRunner spawns the claude CLI as a subprocess. Claude Code natively supports Vertex via CLAUDE_CODE_USE_VERTEX=1 + ANTHROPIC_VERTEX_PROJECT_ID + CLOUD_ML_REGION. No code change needed — just env passthrough in action.yml.
  2. False-positive findings filterClaudeAPIClient constructs Anthropic(api_key=...) directly. Now accepts use_vertex=True and constructs AnthropicVertex(region=..., project_id=...) instead. Auth uses Application Default Credentials, so callers must run google-github-actions/auth before invoking this action.

The proactive validate_api_access() probe is skipped in Vertex mode. Reason: it currently calls claude-3-5-haiku-20241022 as a low-cost test, but on Vertex that specific model must be enabled in the caller's GCP project, which is not guaranteed and would produce confusing failures. Real auth/quota errors still surface on the first actual filter call (which has its own retry/error handling), so the pre-flight probe added no value in Vertex mode.

Example usage

- uses: google-github-actions/auth@v2
  with:
    workload_identity_provider: ${{ vars.GCP_WORKLOAD_IDENTITY_PROVIDER }}
    service_account: ${{ vars.GCP_SERVICE_ACCOUNT }}

- uses: anthropics/claude-code-security-review@main
  with:
    use-vertex: 'true'
    vertex-project-id: my-gcp-project
    vertex-region: global

Tests

  • Added test_claude_api_client.py covering both constructors, env-var fallback, missing-project error path, and the validation-skip behavior in Vertex mode.
  • Added two Vertex coverage cases in test_helper_functions.py for initialize_findings_filter:
    • Vertex env vars enable filtering with the right kwargs
    • Vertex flag without ANTHROPIC_VERTEX_PROJECT_ID falls back to hard-exclusions-only
  • Updated one existing kwargs assertion to include the new optional fields.
  • Full suite: 183/183 passing locally (was 173; 10 new tests added).

Backward compatibility

Every change is additive:

  • All new inputs default to off / empty
  • All new constructor kwargs default to False / None
  • Existing direct-API path is byte-for-byte unchanged at runtime when use-vertex is not set

Existing users see no behavior difference and don't need to change their workflow files.

Why this is worth merging

  • Removes a hard dependency on ANTHROPIC_API_KEY for GCP-centric orgs — Vertex auth via WIF is more secure (short-lived tokens, IAM-controlled, no per-repo secret management).
  • Consolidates billing for orgs that already pay for Claude through Vertex.
  • Aligns with claude-code-action which already accepts use_vertex: 'true' — this brings the security review action to parity.

Test plan

  • Unit tests added and passing locally (183/183)
  • Maintainer to validate against an actual Vertex-backed run if there's an internal test setup
  • (After merge) bump our consumer workflow to upstream @v...

…roject-id

The action currently requires an Anthropic API key and routes all calls
to api.anthropic.com. This makes it unusable for organizations that
have standardized on Google Cloud and want to consolidate Claude
billing/access through Vertex AI.

This change adds an optional Vertex AI path. The main `claude` CLI
subprocess already supports Vertex out of the box via the
`CLAUDE_CODE_USE_VERTEX` / `ANTHROPIC_VERTEX_PROJECT_ID` /
`CLOUD_ML_REGION` env vars; the only Python code that hardcoded the
direct-API client was the false-positive findings filter
(`ClaudeAPIClient`), which now accepts `use_vertex=True` and
constructs `AnthropicVertex(region=..., project_id=...)` instead of
`Anthropic(api_key=...)`.

Auth for Vertex mode is taken from Application Default Credentials, so
callers run `google-github-actions/auth` (or equivalent) before this
action — the action itself doesn't take credentials directly.

Action surface:
- New inputs: `use-vertex` (default false), `vertex-region` (default
  'global'), `vertex-project-id`.
- `claude-api-key` is now optional (was required); the auth check
  passes if either an API key OR `use-vertex` + project-id are set.
- New env passthrough to the runtime: CLAUDE_CODE_USE_VERTEX,
  ANTHROPIC_VERTEX_PROJECT_ID, CLOUD_ML_REGION.

Behavior on the existing direct-API path is unchanged: all defaults
preserve the old behavior, and the existing test suite passes without
modification beyond a kwargs assertion update for the new optional
fields.

Tests:
- Added test_claude_api_client.py covering both direct and Vertex
  constructors, env-var fallback, missing-project error, and the
  Vertex-skips-proactive-validation behavior.
- Added two Vertex coverage cases in test_helper_functions.py for
  `initialize_findings_filter` (vertex env enables filtering;
  vertex-without-project falls back to hard exclusions).
- Full suite: 183/183 passing locally.

Why skip validation in Vertex mode: the existing validate_api_access
sends a probe request to `claude-3-5-haiku-20241022`. On Vertex, that
specific model has to be enabled in the caller's GCP project, which
isn't guaranteed and would produce confusing failures. Real auth/quota
issues will surface on the first actual filter call, which already has
retry and error handling, so the pre-flight probe adds no value here.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant