Skip to content

feat(ai-proxy): support Workload Identity / metadata server for GCP auth#13733

Open
namannagar89 wants to merge 1 commit into
apache:masterfrom
namannagar89:feat/ai-proxy-gcp-metadata-server
Open

feat(ai-proxy): support Workload Identity / metadata server for GCP auth#13733
namannagar89 wants to merge 1 commit into
apache:masterfrom
namannagar89:feat/ai-proxy-gcp-metadata-server

Conversation

@namannagar89

Copy link
Copy Markdown

Description

ai-proxy / ai-proxy-multi GCP (Vertex AI) auth currently supports only a static service-account JSON key: apisix/utils/google-cloud-oauth.lua signs a JWT with the private key and exchanges it for an access token. When APISIX runs on GKE with Workload Identity (or anywhere Application Default Credentials are available), this forces a long-lived SA key purely for APISIX — a downgrade from the keyless posture the platform otherwise provides.

This PR adds a metadata-server (ADC / Workload Identity) auth path.

What changed

  • apisix/utils/google-cloud-oauth.lua: when no SA key is available (or use_metadata_server: true), fetch the token from the GCE/GKE metadata server (GET /computeMetadata/v1/instance/service-accounts/default/token, header Metadata-Flavor: Google). Host overridable via GCE_METADATA_HOST. Existing token caching (max_ttl / expire_early_secs) is reused unchanged, since the metadata response carries expires_in.
  • apisix/plugins/ai-transport/auth.lua: pass use_metadata_server / metadata_host through.
  • apisix/plugins/ai-proxy/schema.lua: add auth.gcp.use_metadata_server (boolean, default false).
  • t/plugin/ai-proxy-gcp-metadata.t: tests — default selection (no key → metadata; key → JWT), token fetch from a mock metadata endpoint, and GCE_METADATA_HOST override.
  • docs (en + zh) for ai-proxy and ai-proxy-multi.

Behavior

  • No behavior change when a key is configured (service_account_json / GCP_SERVICE_ACCOUNT) — the JWT flow is unchanged.
  • With no key configured, the plugin now uses the metadata server automatically instead of failing.

Related issue

Closes #13732

Checklist

  • Tests added (t/plugin/ai-proxy-gcp-metadata.t)
  • Docs updated (en + zh, both plugins)
  • luacheck clean
  • markdownlint-cli@0.25.0 clean

ai-proxy's GCP (Vertex AI) auth previously required a static service account
JSON key: google-cloud-oauth signs a JWT with the private key and exchanges it
for an access token. On GKE with Workload Identity this forces a long-lived key
purely for APISIX.

Add a metadata-server (Application Default Credentials) path: when no service
account key is configured (neither `service_account_json` nor the
`GCP_SERVICE_ACCOUNT` env), or when `use_metadata_server: true` is set,
google-cloud-oauth fetches the access token from the GCE/GKE metadata server
(`/computeMetadata/v1/instance/service-accounts/default/token`, `Metadata-Flavor:
Google`). The host is overridable via `GCE_METADATA_HOST`. Existing token caching
(max_ttl / expire_early_secs) is reused unchanged.

- utils/google-cloud-oauth.lua: metadata-server token fetch + auto/explicit selection
- ai-transport/auth.lua: pass use_metadata_server / metadata_host through
- ai-proxy/schema.lua: add auth.gcp.use_metadata_server
- t/plugin/ai-proxy-gcp-metadata.t: tests (default selection, token fetch, env host)
- docs (en/zh) for ai-proxy and ai-proxy-multi

Closes apache#13732

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Signed-off-by: namannagar89 <naman.nagar@livspace.com>
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(ai-proxy): support GCP Application Default Credentials / Workload Identity (metadata server) for Vertex AI auth

1 participant