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

AWS CLI works but boto3 reports Token has expired and refresh failed #4119

Closed
shadycuz opened this issue May 7, 2024 · 2 comments
Closed
Assignees
Labels
bug This issue is a confirmed bug. closed-for-staleness credentials p3 This is a minor priority issue response-requested Waiting on additional information or feedback. sso

Comments

@shadycuz
Copy link

shadycuz commented May 7, 2024

Describe the bug

I have a python script that will work for some time, but eventually, it starts saying "Error when retrieving token from sso: Token has expired and refresh failed". The thing is, the token should still be valid. For example, I can go to the AWS CLI and run aws s3 ls and it will list the buckets for my default profile.

Expected Behavior

Well this code used to work, I'm not sure what changed external to break it. I might have updated boto3 or maybe the AWS CLI. But since the AWS CLI seems to work with my default profile, I would expect my script to work also.

Current Behavior

Here is my test code

session = boto3.Session()

log.debug(session)

log.debug(session.available_profiles)

# Checks that the credentials are set correctly
session.client("sts").get_caller_identity()

and the output:

debug: Session(region_name='us-west-2')
debug: ['default', 'developer-dev', 'development', 'network', 'backup', 'shared-services', 'test', 'qa', 'sandbox']
Error when retrieving token from sso: Token has expired and refresh failed

but if I run aws s3 ls from the CLI, it spits out the s3 buckets using my default profile. So the creds are still valid? or should be?

Reproduction Steps

I'm really not sure how to get it into this bad state. But it happened to me on linux and it happened to my other co-worker on windows.

Possible Solution

Well, if I go to the aws cli and I run aws sso login. Then the script starts working again? Strange. It seems like something is wrong in how it looks up default credential "chain". But I'm not sure.

Additional Information/Context

What my default profile looks like:

[default]
sso_session = aws
sso_account_id = xxxxxxx
sso_role_name = AdministratorAccess
region = us-west-2
output = json

[sso-session aws]
sso_region = us-west-2
sso_start_url = https://xxxxxxxx.awsapps.com/start
sso_registration_scopes = sso:account:access

SDK version used

1.28.85

Environment details (OS name and version, etc.)

WSL Ubuntu 22.04

@shadycuz shadycuz added bug This issue is a confirmed bug. needs-triage This issue or PR still needs to be triaged. labels May 7, 2024
@RyanFitzSimmonsAK RyanFitzSimmonsAK self-assigned this May 8, 2024
@RyanFitzSimmonsAK RyanFitzSimmonsAK added investigating This issue is being investigated and/or work is in progress to resolve the issue. sso credentials p3 This is a minor priority issue and removed needs-triage This issue or PR still needs to be triaged. labels May 8, 2024
@RyanFitzSimmonsAK
Copy link
Contributor

Hi @shadycuz, thanks for reaching out. Could you tell me a bit about how you are initially getting your Boto3 credentials? Do you know how long your script works before it fails to get credentials? I'd also recommend taking a look at documentation around configuring session duration.

For configuring access portal session duration, please refer to this documentation: https://docs.aws.amazon.com/singlesignon/latest/userguide/configure-user-session.html.

For configuring permission set session duration, you can refer to this documentation: https://docs.aws.amazon.com/singlesignon/latest/userguide/howtosessionduration.html.

Thanks!

@RyanFitzSimmonsAK RyanFitzSimmonsAK added response-requested Waiting on additional information or feedback. and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. labels May 10, 2024
Copy link

Greetings! It looks like this issue hasn’t been active in longer than five days. We encourage you to check if this is still an issue in the latest release. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or upvote with a reaction on the initial post to prevent automatic closure. If the issue is already closed, please feel free to open a new one.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a confirmed bug. closed-for-staleness credentials p3 This is a minor priority issue response-requested Waiting on additional information or feedback. sso
Projects
None yet
Development

No branches or pull requests

2 participants