aws / aws-sdk-java-v2

The official AWS SDK for Java - Version 2
Apache License 2.0
2.2k stars 853 forks source link

AWS SDK STS doesn't autorefresh cross account s3 token #5556

Open kalyc opened 2 months ago

kalyc commented 2 months ago

Describe the bug

Hi I am facing similar issue. I have used StsAssumeRoleCredentialsProvider on cross account role but the access token doesn't appear to be auto-refreshing. This is trying to access cross account s3 bucket.

     StsClient stsClient = StsClient.builder().region(Region.of(jobProperties.getAwsRegion())).build();

    AssumeRoleRequest assumeRoleRequest = AssumeRoleRequest.builder()
                .roleArn(ROLE_ARN)
                .roleSessionName("name")
               .durationSeconds(3600)
                .build();

        StsAssumeRoleCredentialsProvider provider = StsAssumeRoleCredentialsProvider.builder()
            .stsClient(stsClient)
            .refreshRequest(assumeRoleRequest)
            .build();

Expected Behavior

Expect that the token is auto-refreshed and the requests to s3 are successful

Current Behavior

Getting 403 forbidden error messsage. Have confirmed that the permissions on the bucket and role are consistent and as I expect.

Reproduction Steps

Setup cross account bucket and try to access it by using the assume role code snippet above.

Possible Solution

No response

Additional Information/Context

No response

AWS Java SDK version used

2.20.81

JDK version used

17

Operating System and version

Mac Sonoma 14.16.1