aws-sdk-java: EKS Pod Identity - Cannot get credentials
Describe the bug
Using Java SDK 1.12.596, the pod with Pod Identity addon is not able to get AWS credentials via SDK. On the same pod, using AWS CLI v1, it can successfully get its credentials.
On AWS CLI v1
root@f6bd48d86-7x4qn:/# aws --version
aws-cli/1.31.5 Python/3.10.12 Linux/5.10.198-187.748.amzn2.x86_64 botocore/1.33.5
root@f6bd48d86-7x4qn:/# aws ec2 describe-instances
{
"Reservations": [
{
"Groups": [],
"Instances": [
{
"AmiLaunchIndex": 0,
"ImageId": "<redacted",
"InstanceId": "<redacted>",
"InstanceType": "c5.large",
.
.
.
Expected Behavior
Successfully runs the AWS command (E.g. EC2 describe-instances) and prints out its output
Current Behavior
kubectl exec pod/f6bd48d86-7x4qn -c test -it -- bash
root@f6bd48d86-7x4qn:/# curl localhost:8080/version
1.12.596
root@test-f6bd48d86-7x4qn:/# curl localhost:8080/AZ
{"timestamp":"2023-12-01T06:44:30.270+00:00","status":500,"error":"Internal Server Error","path":"/AZ"}
root@f6bd48d86-7x4qn:/# exit
exit
Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [EnvironmentVariableCredentialsProvider: Unable to load AWS credentials from environment variables (AWS_ACCESS_KEY_ID (or AWS_ACCESS_KEY) and AWS_SECRET_KEY (or AWS_SECRET_ACCESS_KEY)), SystemPropertiesCredentialsProvider: Unable to load AWS credentials from Java system properties (aws.accessKeyId and aws.secretKey), WebIdentityTokenCredentialsProvider: You must specify a value for roleArn and roleSessionName, com.amazonaws.auth.profile.ProfileCredentialsProvider@b35605f: profile file cannot be null, com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper@4bed011b: The full URI (http://169.254.170.23/v1/credentials) contained withing environment variable AWS_CONTAINER_CREDENTIALS_FULL_URI has an invalid host. Host should resolve to a loopback address or have the full URI be HTTPS.]] with root cause
com.amazonaws.SdkClientException: Unable to load AWS credentials from any provider in the chain: [EnvironmentVariableCredentialsProvider: Unable to load AWS credentials from environment variables (AWS_ACCESS_KEY_ID (or AWS_ACCESS_KEY) and AWS_SECRET_KEY (or AWS_SECRET_ACCESS_KEY)), SystemPropertiesCredentialsProvider: Unable to load AWS credentials from Java system properties (aws.accessKeyId and aws.secretKey), WebIdentityTokenCredentialsProvider: You must specify a value for roleArn and roleSessionName, com.amazonaws.auth.profile.ProfileCredentialsProvider@b35605f: profile file cannot be null, com.amazonaws.auth.EC2ContainerCredentialsProviderWrapper@4bed011b: The full URI (http://169.254.170.23/v1/credentials) contained withing environment variable AWS_CONTAINER_CREDENTIALS_FULL_URI has an invalid host. Host should resolve to a loopback address or have the full URI be HTTPS.]
at com.amazonaws.auth.AWSCredentialsProviderChain.getCredentials(AWSCredentialsProviderChain.java:142) ~[aws-java-sdk-core-1.12.596.jar!/:na]
Reproduction Steps
Run a pod with Java AWS SDK that calls AWS API with pod identity configured
@GetMapping("/AZ")
String getAZ() {
String node_name = System.getenv("NODE_NAME");
final AmazonEC2 ec2 = AmazonEC2ClientBuilder.defaultClient();
DescribeInstancesRequest request = new DescribeInstancesRequest().withFilters(new Filter("network-interface.addresses.private-dns-name", Collections.singletonList(node_name)));
DescribeInstancesResult result = ec2.describeInstances(request);
String az;
Optional<Instance> instance;
if (result.getReservations() != null) {
instance = result.getReservations().stream().flatMap(reservation -> reservation.getInstances().stream()).findFirst();
if (instance.isPresent()) {
az = instance.get().getPlacement().getAvailabilityZone();
}
else {
System.out.printf(
"No instances found with %s%n",
node_name);
return "No instance found";
}
}
else {
return "API Error";
}
Deployment YAML
apiVersion: apps/v1
kind: Deployment
metadata:
name: test
spec:
selector:
matchLabels:
app: test
template:
metadata:
labels:
app: test
spec:
serviceAccountName: test-serviceaccount
containers:
- name: test
image: <redacted>
env:
- name: NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
Possible Solution
Fix the credential chain for Pod Identity
Additional Information/Context
No response
AWS Java SDK version used
1.12.596
JDK version used
11
Operating System and version
eclipse-temurin:11
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 1
- Comments: 16 (5 by maintainers)
Commits related to this issue
- Backported EKS Pod Identity support into ContainerCredentialsProvider Added support for the AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE environment variable in the FullUriCredentialsEndpointProvider, whic... — committed to weeniearms/aws-sdk-java by weeniearms 3 years ago
- Backported EKS Pod Identity support into ContainerCredentialsProvider Added support for the AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE environment variable in the FullUriCredentialsEndpointProvider, whic... — committed to weeniearms/aws-sdk-java by weeniearms 3 years ago
Good news, everyone! We’ve added support for EKS Pod Identity in v1, starting in SDK version
1.12.746.I’ll reach out to the EKS documentation team again, and ask to update the list here to reflect the change.
Yes, I’ll reach out to the EKS documentation team and ask to clarify here the Java SDK v1 does not support EKS Pod Identity.
The changelog entry is the service release note that is automatically sent to all the AWS SDKs when a service feature is released that day. Service features usually don’t require changes on the SDK side, but in the case of Pod Identities the Container Credential Provider process required some changes, and those changes were implemented in Java SDK v2 only, they won’t be in v1.
I’m wondering what’s reasonable to expect from SDK v1 updates, given that in:
https://aws.amazon.com/es/blogs/developer/announcing-end-of-support-for-aws-sdk-for-java-v1-x-on-december-31-2025/#:~:text=Between July 31, 2024 and,or changes to existing services
we are still in General Availability period, and
just saying.
there is no plan to support EKS Pod identity in AWS SDK V1? rewriting entire services is not an option in most cases.
Hey it looks like they changed documentation yesterday:
<lastBuildDate>Mon, 19 Feb 2024 04:47:18 GMT</lastBuildDate>I see now EKS is supporting v1: https://docs.aws.amazon.com/pdfs/eks/latest/userguide/eks-ug.pdf#pod-id-minimum-sdk and the error keeps happening.
Wondering if the problem got solved in following versions or what!
cc @rijulGogia