Scope Vertex AI credentials to cloud-platform#6596
Open
subhashpolisetti wants to merge 1 commit into
Open
Conversation
In Vertex AI mode, `GoogleGenAiChatAutoConfiguration` loaded the service account credentials from `credentials-uri` via `GoogleCredentials.fromStream` and applied them without an OAuth scope. Such credentials are scopeless, so Vertex AI rejects the access-token refresh with `invalid_scope` and no chat request can complete. This affects only the explicit `credentials-uri` path; the Application Default Credentials path is scoped by the underlying SDK. Scope the loaded credentials to `cloud-platform`, matching the scope the SDK applies to Application Default Credentials, so that service account keys supplied through `credentials-uri` authenticate successfully. Fixes spring-projects#6595 Signed-off-by: subhash polisetti <subhashr161347@gmail.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.
Problem
In Vertex AI mode, the google-genai starter loads the service-account
credentials from
spring.ai.google.genai.credentials-uriand currentlyapplies them to the client without an OAuth scope.
GoogleCredentials.fromStreamreturns scopeless credentials, so Vertex AI rejects the access-token
refresh with
invalid_scopeand no chat request can complete:Only the explicit
credentials-uripath is affected; the ApplicationDefault Credentials path is scoped by the underlying SDK. There is no
configuration workaround today: there is no scope property, and the
Clientbean is@ConditionalOnMissingBeanwith no customizer, so theonly escape is replacing the entire bean.
Fix
Scope the credentials loaded from
credentials-uritocloud-platform,matching the scope the SDK applies to Application Default Credentials.
Testing
Adds
GoogleGenAiChatAutoConfigurationTests, which is fullyself-contained (no network, no real key, no environment variables — it
generates a throwaway RSA keypair and a synthetic service-account JSON):
GoogleCredentials.fromStreamcarry no scope;cloud-platform.I also verified the behavior end to end against a real Google Cloud
service-account key. The unit test can only assert the scope offline,
because
invalid_scopeis returned by a live token exchange — the exactcall the SDK makes (
refreshIfExpired()on the provided credentials):Fixes #6595