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:
Ankur
2026-11-29 13:25:58 +05:30
co-authored by Claude Sonnet 5.5
parent 98ed878675
commit 8f69e7bf50
46 changed files with 1729 additions and 0 deletions
@@ -0,0 +1,35 @@
# NOT APPLIED to a real cluster. Client id and names are examples. AKS workload identity: DefaultAzureCredential picks
# the federated token up from the environment the webhook injects. Use the azure-default profile, or the azure
# profile with a managed identity if the pod runs on a host that has one assigned.
apiVersion: v1
kind: ServiceAccount
metadata:
name: spring-ai
namespace: ai
annotations:
azure.workload.identity/client-id: 00000000-0000-0000-0000-000000000000
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-ai
namespace: ai
spec:
replicas: 2
selector:
matchLabels: { app: spring-ai }
template:
metadata:
labels:
app: spring-ai
azure.workload.identity/use: "true"
spec:
serviceAccountName: spring-ai
containers:
- name: app
image: registry.example.com/spring-ai-cloud-providers:1.0.0
env:
- name: SPRING_PROFILES_ACTIVE
value: azure-default
- name: AZURE_OPENAI_ENDPOINT
value: https://my-openai-resource.openai.azure.com/openai/v1
+17
View File
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# NOT RUN against a real subscription. Names are examples. Gives an App Service app a system-assigned managed
# identity, lets it call one Azure OpenAI resource with Entra ID, then turns key authentication off.
set -euo pipefail
RG=my-rg; APP=my-spring-ai-app; AOAI=my-openai-resource
az webapp identity assign --resource-group "$RG" --name "$APP"
PRINCIPAL_ID=$(az webapp identity show --resource-group "$RG" --name "$APP" --query principalId -o tsv)
SCOPE=$(az cognitiveservices account show --resource-group "$RG" --name "$AOAI" --query id -o tsv)
# The data-plane role. Owner and Contributor on the resource do not let a caller run inference with Entra ID.
az role assignment create --assignee-object-id "$PRINCIPAL_ID" --assignee-principal-type ServicePrincipal \
--role "Cognitive Services OpenAI User" --scope "$SCOPE"
# Entra ID authentication needs a custom subdomain on the resource (https://<name>.openai.azure.com).
# Then switch API keys off, so a leaked key stops being a way in:
az resource update --ids "$SCOPE" --set properties.disableLocalAuth=true
@@ -0,0 +1,17 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "InvokeOneModelOnly",
"Effect": "Allow",
"Action": [
"bedrock:InvokeModel",
"bedrock:InvokeModelWithResponseStream"
],
"Resource": [
"arn:aws:bedrock:*::foundation-model/anthropic.claude-sonnet-4-5-20250929-v1:0",
"arn:aws:bedrock:us-east-1:111122223333:inference-profile/us.anthropic.claude-sonnet-4-5-20250929-v1:0"
]
}
]
}
+35
View File
@@ -0,0 +1,35 @@
# NOT APPLIED to a real cluster. Account id, OIDC provider id and names are examples.
# IRSA: the annotation is the whole link between the pod and the IAM role. The application sets no AWS key.
apiVersion: v1
kind: ServiceAccount
metadata:
name: spring-ai
namespace: ai
annotations:
eks.amazonaws.com/role-arn: arn:aws:iam::111122223333:role/spring-ai-bedrock
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: spring-ai
namespace: ai
spec:
replicas: 2
selector:
matchLabels: { app: spring-ai }
template:
metadata:
labels: { app: spring-ai }
spec:
serviceAccountName: spring-ai
containers:
- name: app
image: registry.example.com/spring-ai-cloud-providers:1.0.0
env:
- name: SPRING_PROFILES_ACTIVE
value: bedrock
# IRSA's webhook injects AWS_ROLE_ARN and AWS_WEB_IDENTITY_TOKEN_FILE (confirmed in AWS's docs); check with
# `kubectl describe pod` whether AWS_REGION is there too. Spring AI ignores AWS_REGION for Bedrock
# (output/02-bedrock-region-trap.txt), so set the region property explicitly:
- name: SPRING_AI_BEDROCK_AWS_REGION
value: us-east-1
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# NOT RUN against a real account. Names and ids are examples. EKS Pod Identity instead of IRSA: no OIDC provider,
# and the pod receives AWS_CONTAINER_CREDENTIALS_FULL_URI (see output/06-bedrock-pod-identity.txt for that path).
set -euo pipefail
aws iam create-role --role-name spring-ai-bedrock \
--assume-role-policy-document file://deploy/pod-identity-trust-policy.json
aws iam put-role-policy --role-name spring-ai-bedrock --policy-name invoke-one-model \
--policy-document file://deploy/bedrock-invoke-policy.json
aws eks create-pod-identity-association --cluster-name my-cluster --namespace ai \
--service-account spring-ai --role-arn arn:aws:iam::111122223333:role/spring-ai-bedrock
@@ -0,0 +1,18 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Federated": "arn:aws:iam::111122223333:oidc-provider/oidc.eks.us-east-1.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE"
},
"Action": "sts:AssumeRoleWithWebIdentity",
"Condition": {
"StringEquals": {
"oidc.eks.us-east-1.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE:aud": "sts.amazonaws.com",
"oidc.eks.us-east-1.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE:sub": "system:serviceaccount:ai:spring-ai"
}
}
}
]
}
@@ -0,0 +1,11 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowEksAuthToAssumeRoleForPodIdentity",
"Effect": "Allow",
"Principal": { "Service": "pods.eks.amazonaws.com" },
"Action": [ "sts:AssumeRole", "sts:TagSession" ]
}
]
}