feat(ai-proxy): support Workload Identity / metadata server for GCP auth#13733
Open
namannagar89 wants to merge 1 commit into
Open
feat(ai-proxy): support Workload Identity / metadata server for GCP auth#13733namannagar89 wants to merge 1 commit into
namannagar89 wants to merge 1 commit into
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
ai-proxy/ai-proxy-multiGCP (Vertex AI) auth currently supports only a static service-account JSON key:apisix/utils/google-cloud-oauth.luasigns 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 (oruse_metadata_server: true), fetch the token from the GCE/GKE metadata server (GET /computeMetadata/v1/instance/service-accounts/default/token, headerMetadata-Flavor: Google). Host overridable viaGCE_METADATA_HOST. Existing token caching (max_ttl/expire_early_secs) is reused unchanged, since the metadata response carriesexpires_in.apisix/plugins/ai-transport/auth.lua: passuse_metadata_server/metadata_hostthrough.apisix/plugins/ai-proxy/schema.lua: addauth.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, andGCE_METADATA_HOSToverride.ai-proxyandai-proxy-multi.Behavior
service_account_json/GCP_SERVICE_ACCOUNT) — the JWT flow is unchanged.Related issue
Closes #13732
Checklist
t/plugin/ai-proxy-gcp-metadata.t)luacheckcleanmarkdownlint-cli@0.25.0clean