Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempting to access SQS when using AWS SSO fails #3870

Closed
andyfcdl opened this issue Mar 30, 2023 · 13 comments
Closed

Attempting to access SQS when using AWS SSO fails #3870

andyfcdl opened this issue Mar 30, 2023 · 13 comments
Assignees
Labels
bug This issue is a bug. investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 This is a standard priority issue

Comments

@andyfcdl
Copy link

Describe the bug

We are using aws sso to get session credentials. Wehn we use this we can use the Jaka SDK to query S3 etc., but are failing to be able to do anything with SQS utilising the Java SDK v2, although the AWS CLI and Python apps work just fine..

Our basic issue is we received a 403 error when calling the API, for example to list queues and a message of the form 'Access to the resource https://sqs.eu-west-1.amazonaws.com/ is denied'

Expected Behavior

AWS SDK v2 interacting with SQS when we are logged on via aws sso should allow interations to just work.

Current Behavior

We receive a 403 error when calling the API, for example to list queues and a message of the form 'Access to the resource https://sqs.eu-west-1.amazonaws.com/ is denied'

Reproduction Steps

Log in to AWS using SSO against a profile other than default. This profile uses a different role specifc to what we need to do.

Using code as per

        SqsClient sqs = SqsClient.builder()
                .region(Region.EU_WEST_1)
                .credentialsProvider(DefaultCredentialsProvider.builder().profileName("dev-profile").build())
                .build();
        ListQueuesResponse lq_result = sqs.listQueues(ListQueuesRequest.builder().build()); // fails here
        for (String url : lq_result.queueUrls()) {
            System.out.println(url);
        }

Possible Solution

No response

Additional Information/Context

We have used the AWS CLI to connect and this work.

aws sqs list-queues --profile=dev-profile

We have also used a small python script, below, and this also works

import boto3

# Create SQS client
session = boto3.Session(profile_name='dev-profile')
sqs = session.client('sqs')

# List SQS queues
response = sqs.list_queues()

print(response['QueueUrls'])

AWS Java SDK version used

2.20.34

JDK version used

openjdk version "1.8.0_342" OpenJDK Runtime Environment Corretto-8.342.07.3 (build 1.8.0_342-b07) OpenJDK 64-Bit Server VM Corretto-8.342.07.3 (build 25.342-b07, mixed mode)

Operating System and version

Windows 10

@andyfcdl andyfcdl added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Mar 30, 2023
@debora-ito
Copy link
Member

Does it work if you use the ProfileCredentialsProvider directly, instead of using the Default credential chain?

SqsClient sqs = SqsClient.builder()
                .region(Region.EU_WEST_1)
                .credentialsProvider(ProfileCredentialsProvider.create("dev-profile"))
                .build();

@debora-ito debora-ito added p2 This is a standard priority issue response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. and removed needs-triage This issue or PR still needs to be triaged. labels Apr 5, 2023
@debora-ito debora-ito self-assigned this Apr 5, 2023
@andyfcdl
Copy link
Author

andyfcdl commented Apr 5, 2023

Does it work if you use the ProfileCredentialsProvider directly, instead of using the Default credential chain?

SqsClient sqs = SqsClient.builder()
                .region(Region.EU_WEST_1)
                .credentialsProvider(ProfileCredentialsProvider.create("dev-profile"))
                .build();

No. Tried this, and a number of other variations of the way to create an sqsClient instance and none work. all result in an access denied when used via the Java SDK.

@github-actions github-actions bot removed the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 10 days. label Apr 5, 2023
@andyfcdl
Copy link
Author

@debora-ito Is there any update on this?

@debora-ito
Copy link
Member

debora-ito commented Apr 18, 2023

@andyfcdl sorry, no updates yet. I'll work in setting up a SSO profile to repro this.

@debora-ito debora-ito added the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Apr 19, 2023
@debora-ito
Copy link
Member

Might be related to #3679, still working to confirm is the same case.

@andyfcdl
Copy link
Author

Not sure that the token expiry is the case for us. I do an SSO login a couple of minutes before executing the code, to get a token with 8 hours left on it, and the python script works but the Java application fails when connecting to SQS, but adding some code in to talk to S3 works and it can, for example, list buckets using the SSO token. I have attached an anonymised debug log of what I see when attempting to call out to SQS.
The sample S3 code that is placed in the same file, just before the SQS calls is of the form

S3Client s3 = S3Client.builder()
.region(Region.EU_WEST_1)
.credentialsProvider(DefaultCredentialsProvider.builder().profileName("").build())
.build();
ListBucketsResponse result = s3.listBuckets();
System.out.println(" >>> Buckets");
for (Bucket bucket : result.buckets()) {
System.out.println(bucket.name());
}
and this works and log in and lists buckets.

I'm wondering if there is anything to do with the fact we need to use role_arn in the profile such that we get access via said role?

samplelog.log

@andyfcdl
Copy link
Author

This can be closed. We went through AWS support and found that we had some issues in our aws config file, and updates to the underlying SDK also helped.

Basically we had duplicated some lines in our profiles in the config file around SSO configuration and the Java SDK did not like this.

@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@jbowlerpopid
Copy link

This can be closed. We went through AWS support and found that we had some issues in our aws config file, and updates to the underlying SDK also helped.

Basically we had duplicated some lines in our profiles in the config file around SSO configuration and the Java SDK did not like this.

Hi, could you possibly be more specific? I'm struggling with the same thing. For some reason, the sdk is making a "get role credentials" request, and that fails with a 403.

@andyfcdl
Copy link
Author

Our core issue was in the ~/.aws/config and how we set up sso - we duplicated some of the sso lines from [default] into our individual profile config, and this caused the Java SDK to not recognise it correctly - once we tidied that up it all worked, i.e. sso details in the [default] section and just relevant info in the profile as per

[default]
sso_start_url = https://our-sso.awsapps.com/start
sso_region = region
sso_account_id = account id number
sso_role_name = role_name
region = region
output = json

[profile dev-profile]
role_arn = arn:aws:iam::xyzzy:role/company/stuff/role
source_profile=default
region = region

Turn on full wire level debug logging to see what it is trying as well -

@jbowlerpopid
Copy link

jbowlerpopid commented Dec 22, 2023

Our core issue was in the ~/.aws/config and how we set up sso - we duplicated some of the sso lines from [default] into our individual profile config, and this caused the Java SDK to not recognise it correctly - once we tidied that up it all worked, i.e. sso details in the [default] section and just relevant info in the profile as per

[default] sso_start_url = https://our-sso.awsapps.com/start sso_region = region sso_account_id = account id number sso_role_name = role_name region = region output = json

[profile dev-profile] role_arn = arn:aws:iam::xyzzy:role/company/stuff/role source_profile=default region = region

Turn on full wire level debug logging to see what it is trying as well -

Thanks for getting back to me. I still can't get it to work .. My "normal" profile works, it's when attempting to access our sandbox env on aws that it breaks. This is my config file (redacted)

[profile dev]
sso_session = default
sso_account_id = 
sso_role_name = 

[sso-session default]
sso_start_url = 
sso_region = us-east-1
sso_registration_scopes = sso:account:access

[profile sandboxtest]
sso_session = default
role_arn = 
source_profile = dev
region = us-east-1
sso_account_id = 
sso_role_name = OrganizationAccountAccessRole

I'm able to use the sandboxtest profile on cmd line just fine, the problem is with the java sdk.

@andyfcdl
Copy link
Author

andyfcdl commented Jan 2, 2024

Remove the duplicated sso_* sections and only have them in a [default] section, and give that a try.

@jbowlerpopid
Copy link

Remove the duplicated sso_* sections and only have them in a [default] section, and give that a try.

wow, this worked. thank you! also, i need to include sts on classpath.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. investigating This issue is being investigated and/or work is in progress to resolve the issue. p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

3 participants