Add cloud-providers module: keyless Spring AI on Amazon Bedrock (AWS default credential chain under IRSA and EKS Pod Identity) and Azure OpenAI (managed identity, Microsoft Entra ID bearer tokens), an audit advisor, and the traps reproduced (leftover static key beats the role, AWS_REGION ignored by Bedrock auto-configuration, short-lived credentials refetched per call, azure-identity missing, leftover OPENAI_API_KEY, other modalities defaulting to OpenAI, SigV4 session token in AWS SDK DEBUG logs). No AWS account or Azure subscription used: a local server stands in for STS, Bedrock, the Azure identity endpoint and Azure OpenAI; the Spring AI, AWS SDK and azure-identity code is real. Spring Boot 4.2.0, Spring AI 2.1.0, Java 25.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b5uEyg58znuchZ8C8i
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
98ed878675
commit
8f69e7bf50
@@ -0,0 +1,15 @@
|
||||
# What happened to spring-ai-starter-model-azure-openai?
|
||||
|
||||
A. Versions on Maven Central (maven-metadata.xml)
|
||||
spring-ai-starter-model-azure-openai newest listed version=2.0.0-M4
|
||||
spring-ai-starter-model-openai newest listed version=2.1.0
|
||||
spring-ai-starter-model-bedrock-converse newest listed version=2.1.0
|
||||
|
||||
B. Does the Spring AI 2.1.0 BOM manage the Azure starter?
|
||||
spring-ai-starter-model-azure-openai NOT managed
|
||||
spring-ai-azure-openai NOT managed
|
||||
spring-ai-starter-model-openai managed
|
||||
spring-ai-starter-model-bedrock-converse managed
|
||||
|
||||
C. Maven asked to resolve the Azure starter with no version under that BOM
|
||||
'dependencies.dependency.version' for org.springframework.ai:spring-ai-starter-model-azure-openai:jar is missing. @ line 4, column 27
|
||||
@@ -0,0 +1,23 @@
|
||||
# Bedrock with IRSA: no key in the application, the default chain finds the projected token
|
||||
|
||||
Environment the pod gets (the only configuration the application receives):
|
||||
AWS_ROLE_ARN = arn:aws:iam::111122223333:role/spring-ai-bedrock
|
||||
AWS_WEB_IDENTITY_TOKEN_FILE = <projected service account token>
|
||||
(AWS_ENDPOINT_URL_* point at the local stub; on EKS they are absent)
|
||||
spring.ai.bedrock.aws.access-key / secret-key / session-token: not set
|
||||
|
||||
Application output:
|
||||
INFO audit - provider=bedrock principal=arn:aws:sts::111122223333:assumed-role/spring-ai-bedrock/pod-session model=us.anthropic.claude-sonnet-4-5-20250929-v1:0 outcome=OK inputTokens=12 outputTokens=7 ms=<n>
|
||||
ANSWER 1: Hello from the Bedrock stub.
|
||||
|
||||
STS received 1 AssumeRoleWithWebIdentity call(s) (1 GetCallerIdentity for the audit identity)
|
||||
Authorization header on AssumeRoleWithWebIdentity: null (this call is not signed)
|
||||
RoleArn = arn:aws:iam::111122223333:role/spring-ai-bedrock
|
||||
RoleSessionName starts with = aws-sdk-java-
|
||||
WebIdentityToken equals the token file content: true
|
||||
|
||||
Bedrock received POST /model/us.anthropic.claude-sonnet-4-5-20250929-v1:0/converse
|
||||
signed by access key id : ASIASTUB0000... (temporary: starts with ASIA)
|
||||
signing service / region: bedrock / us-east-1
|
||||
x-amz-security-token signed: true
|
||||
X-Amz-Security-Token header present: true
|
||||
@@ -0,0 +1,8 @@
|
||||
# Region: AWS_REGION=eu-west-1 is set, which region does Spring AI sign for?
|
||||
|
||||
AWS_REGION=eu-west-1 in the environment in all four runs.
|
||||
|
||||
nothing else set -> Bedrock request signed for region us-east-1
|
||||
spring.ai.bedrock.aws.region=${AWS_REGION} -> Bedrock request signed for region eu-west-1
|
||||
spring.ai.bedrock.aws.region=eu-west-1 -> Bedrock request signed for region eu-west-1
|
||||
own AwsRegionProvider bean (DefaultAwsRegionProviderChain) -> Bedrock request signed for region eu-west-1
|
||||
@@ -0,0 +1,7 @@
|
||||
# Precedence: IRSA is configured, and a static key is also present somewhere
|
||||
|
||||
IRSA variables are set in all three runs. What signs the Bedrock request?
|
||||
|
||||
nothing else -> ASIASTUB0000001 AssumeRoleWithWebIdentity calls: 1
|
||||
AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY set -> AKIALEFTOVERENVKEY1 AssumeRoleWithWebIdentity calls: 0
|
||||
spring.ai.bedrock.aws.access-key/secret-key -> AKIALEFTOVERPROPKEY AssumeRoleWithWebIdentity calls: 0
|
||||
@@ -0,0 +1,8 @@
|
||||
# Bedrock with no credential source at all (a laptop, or a pod whose service account is not annotated)
|
||||
|
||||
Environment: AWS_EC2_METADATA_DISABLED=true, nothing else.
|
||||
|
||||
WARN audit - provider=bedrock principal=unresolved model=us.anthropic.claude-sonnet-4-5-20250929-v1:0 outcome=FAILED error=SdkClientException ms=<n>
|
||||
FAILED 1: SdkClientException / root cause SdkClientException: Unable to load credentials from any of the providers in the chain AwsCredentialsProviderChain(credentialsProviders=[SystemPropertyCredentialsProvider(), EnvironmentVariableCredentialsProvider(), WebIdentityTokenFileCredentialsProvider(), ProfileCredentialsProvider(profileName=default, profileFile=ProfileFile(sections=[])), ContainerCredentialsProvider(), InstanceProfileCredentialsProvider()]) : [SystemPropertyCredentialsProvider(): Unable to load credentials from system settings. Access key must be specified either via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId)., EnvironmentVariableCredentialsProvider(): Unable to load credentials from system settings. Access key must be specified either via environment variable (AWS_ACCESS_KEY_ID) or system property (aws.accessKeyId)., WebIdentityTokenFileCredentialsProvider(): Either the environment variable AWS_WEB_IDENTITY_TOKEN_FILE or the javaproperty aws.webIdentityTokenFile must be set., ProfileCredentialsProvider(profileName=default, profileFile=ProfileFile(sections=[])): Profile file contained no credentials for profile 'default': ProfileFile(sections=[]), ContainerCredentialsProvider(): Cannot fetch credentials from container - neither AWS_CONTAINER_CREDENTIALS_FULL_URI or AWS_CONTAINER_CREDENTIALS_RELATIVE_URI environment variables are set., InstanceProfileCredentialsProvider(): IMDS credentials have been disabled by environment variable or system property.]
|
||||
|
||||
Requests that reached the Bedrock stub: 0
|
||||
@@ -0,0 +1,6 @@
|
||||
# How often does the SDK go back to STS? Five Bedrock calls, three credential lifetimes
|
||||
|
||||
STS credential lifetime AssumeRoleWithWebIdentity distinct access key ids on Bedrock calls
|
||||
3600 s 1 1 (of 5 calls)
|
||||
300 s 1 1 (of 5 calls)
|
||||
30 s 6 5 (of 5 calls)
|
||||
@@ -0,0 +1,10 @@
|
||||
# EKS Pod Identity: same application, a different environment, nothing changed in the code
|
||||
|
||||
Environment: AWS_CONTAINER_CREDENTIALS_FULL_URI, AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE (what the Pod Identity webhook injects)
|
||||
no AWS_ROLE_ARN, no AWS_WEB_IDENTITY_TOKEN_FILE
|
||||
|
||||
ANSWER 1: Hello from the Bedrock stub.
|
||||
Credentials endpoint calls : 1
|
||||
Authorization header equals the token file : true
|
||||
AssumeRoleWithWebIdentity calls : 0
|
||||
Bedrock request signed by : ASIAPODID000...
|
||||
@@ -0,0 +1,26 @@
|
||||
# Azure OpenAI with a managed identity: no api-key, a bearer token from the identity endpoint
|
||||
|
||||
Environment: IDENTITY_ENDPOINT and IDENTITY_HEADER (what App Service injects), no AZURE_CLIENT_SECRET, no api-key.
|
||||
|
||||
profile azure (exit 0)
|
||||
INFO audit - provider=azure principal=oid=00000000-0000-0000-0000-00000000a11c,tid=11111111-2222-3333-4444-555555555555 model=gpt-4o-mini outcome=OK inputTokens=11 outputTokens=6 ms=<n>
|
||||
ANSWER 1: Hello from the Azure stub.
|
||||
identity endpoint calls : 1
|
||||
identity request query : api-version=2019-08-01&resource=https://cognitiveservices.azure.com
|
||||
chat request path : POST /openai/v1/chat/completions
|
||||
Authorization : Bearer eyJhbG... (3 segments, 262 chars)
|
||||
token claim aud : https://cognitiveservices.azure.com
|
||||
request body model : gpt-4o-mini
|
||||
api-key header : null
|
||||
|
||||
profile azure-default (exit 0)
|
||||
INFO audit - provider=azure principal=DefaultAzureCredential(unresolved) model=gpt-4o-mini outcome=OK inputTokens=11 outputTokens=6 ms=<n>
|
||||
ANSWER 1: Hello from the Azure stub.
|
||||
identity endpoint calls : 1
|
||||
identity request query : api-version=2019-08-01&resource=https://cognitiveservices.azure.com
|
||||
chat request path : POST /openai/v1/chat/completions
|
||||
Authorization : Bearer eyJhbG... (3 segments, 262 chars)
|
||||
token claim aud : https://cognitiveservices.azure.com
|
||||
request body model : gpt-4o-mini
|
||||
api-key header : null
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# Entra ID is configured, and OPENAI_API_KEY is also in the environment
|
||||
|
||||
profile azure-default, identity endpoint available, OPENAI_API_KEY=<leftover> set (exit 0)
|
||||
INFO audit - provider=azure principal=DefaultAzureCredential(unresolved) model=gpt-4o-mini outcome=OK inputTokens=11 outputTokens=6 ms=<n>
|
||||
ANSWER 1: Hello from the Azure stub.
|
||||
identity endpoint calls : 0
|
||||
api-key header : <leftover value, sent as is>
|
||||
Authorization header : null
|
||||
@@ -0,0 +1,6 @@
|
||||
# How often is the identity endpoint called? Five chat calls, three token lifetimes
|
||||
|
||||
token lifetime profile azure profile azure-default
|
||||
3600 s 1 identity calls 1 identity calls
|
||||
600 s 1 identity calls 1 identity calls
|
||||
240 s 11 identity calls 10 identity calls
|
||||
@@ -0,0 +1,7 @@
|
||||
# profile azure-default with azure-identity removed from the classpath
|
||||
|
||||
Classpath: the application's own classpath minus azure-identity-*.jar.
|
||||
|
||||
Microsoft Foundry was detected, but no credential was provided. If you want to use passwordless authentication, you need to add the Azure Identity library (groupId=`com.azure`, artifactId=`azure-identity`)
|
||||
|
||||
exit code: 1, identity endpoint calls: 0, chat calls: 0
|
||||
@@ -0,0 +1,8 @@
|
||||
# Managed identity not usable: the identity endpoint refuses the request
|
||||
|
||||
Environment: IDENTITY_HEADER does not match what the endpoint expects.
|
||||
|
||||
WARN audit - provider=azure principal=unresolved model=gpt-4o-mini outcome=FAILED error=ClientAuthenticationException ms=<n>
|
||||
FAILED 1: ClientAuthenticationException / root cause MsalServiceException: [Managed Identity] Error Code: bad identity header Error Message: null
|
||||
|
||||
identity endpoint calls: 2, chat calls that reached the stub: 0
|
||||
@@ -0,0 +1,7 @@
|
||||
# Only chat is used, but the OpenAI starter is on the classpath: what starts?
|
||||
|
||||
profile bedrock, spring.ai.model.chat=bedrock-converse, no OpenAI key.
|
||||
|
||||
with spring.ai.model.audio.speech=none (this module's setting): exit 0
|
||||
with spring.ai.model.audio.speech unset (the default, here set to its default value openai): exit 1
|
||||
Error creating bean with name 'openAiSdkAudioSpeechModel' defined in class path resource [org/springframework/ai/model/openai/autoconfigure/OpenAiAudioSpeechAutoConfiguration.class]: Failed to instantiate [org.springframework.ai.openai.OpenAiAudioSpeechModel]: Factory method 'openAiSdkAudioSpeechModel' threw exception with message: At least one credential source must be specified: credential (apiKey), workloadIdentity, or adminApiKey
|
||||
@@ -0,0 +1,25 @@
|
||||
# Audit lines, and a search of the whole log for every secret the run handled
|
||||
|
||||
Audit lines from the Bedrock run (two calls, default log levels):
|
||||
INFO audit - provider=bedrock principal=arn:aws:sts::111122223333:assumed-role/spring-ai-bedrock/pod-session model=us.anthropic.claude-sonnet-4-5-20250929-v1:0 outcome=OK inputTokens=12 outputTokens=7 ms=<n>
|
||||
INFO audit - provider=bedrock principal=arn:aws:sts::111122223333:assumed-role/spring-ai-bedrock/pod-session model=us.anthropic.claude-sonnet-4-5-20250929-v1:0 outcome=OK inputTokens=12 outputTokens=7 ms=<n>
|
||||
Audit lines from the Azure run (two calls, DEBUG on com.azure, MSAL, okhttp, Spring AI):
|
||||
INFO audit - provider=azure principal=oid=00000000-0000-0000-0000-00000000a11c,tid=11111111-2222-3333-4444-555555555555 model=gpt-4o-mini outcome=OK inputTokens=11 outputTokens=6 ms=<n>
|
||||
INFO audit - provider=azure principal=oid=00000000-0000-0000-0000-00000000a11c,tid=11111111-2222-3333-4444-555555555555 model=gpt-4o-mini outcome=OK inputTokens=11 outputTokens=6 ms=<n>
|
||||
|
||||
Searched each whole log for every secret the run handled:
|
||||
|
||||
Bedrock, default levels Bedrock, DEBUG on awssdk + Spring AI Azure, DEBUG
|
||||
STS secret access key not found not found -
|
||||
STS session token not found FOUND -
|
||||
Web identity token (projected) not found not found -
|
||||
Azure access token (JWT) - - not found
|
||||
Azure token payload segment - - not found
|
||||
IDENTITY_HEADER value - - not found
|
||||
Prompt text not found not found not found
|
||||
|
||||
Log size: Bedrock default 9 lines, Bedrock DEBUG 273 lines, Azure DEBUG 49 lines
|
||||
The session token in the DEBUG log comes from the SigV4 signer's canonical request:
|
||||
DEBUG DefaultV4RequestSigner - AWS4 Canonical Request: POST
|
||||
...
|
||||
x-amz-security-token:stub-session-token-1
|
||||
Reference in New Issue
Block a user