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_PROFILE is ignored when AWS_ROLE_ARN is set #8883

Open
Slevy35 opened this issue Aug 26, 2024 · 6 comments
Open

AWS_PROFILE is ignored when AWS_ROLE_ARN is set #8883

Slevy35 opened this issue Aug 26, 2024 · 6 comments
Assignees
Labels
bug This issue is a bug. configuration p2 This is a standard priority issue

Comments

@Slevy35
Copy link

Slevy35 commented Aug 26, 2024

Describe the bug

when using the environment variable AWS_PROFILE, if the AWS_ROLE_ARN env exists the profile env is ignored.
but when using the --profile the new profile is used.

Expected Behavior

AWS_PROFILE should not get override

Current Behavior

AWS_PROFILE env is ignored if AWS_ROLE_ARN is set

Reproduction Steps

run aws configure

aws configure set --profile <NEW_PROFILE> web_identity_token_file /var/run/secrets/eks.amazonaws.com/serviceaccount/token
aws configure set --profile <NEW_PROFILE> ****
aws configure set --profile <NEW_PROFILE> region cn-north-1

run aws sts get-caller-identity

root:/# env |  grep -i aws
AWS_DEFAULT_REGION=us-east-1
AWS_REGION=us-east-1
AWS_ROLE_ARN=<CURRENT_ROLE_ARN>
AWS_WEB_IDENTITY_TOKEN_FILE=/var/run/secrets/eks.amazonaws.com/serviceaccount/token
AWS_STS_REGIONAL_ENDPOINTS=regional
root:/# AWS_PROFILE=<NEW_PROFILE> aws sts get-caller-identity --region cn-north-1

An error occurred (InvalidClientTokenId) when calling the GetCallerIdentity operation: The security token included in the request is invalid
root:/# unset AWS_ROLE_ARN
root:/# AWS_PROFILE=<NEW_PROFILE> aws sts get-caller-identity --region cn-north-1
{
    "UserId": "***",
    "Account": "***",
    "Arn": "arn:aws-cn:sts::****:assumed-role/****"
}

Possible Solution

No response

Additional Information/Context

No response

CLI version used

aws-cli/2.17.33 Python/3.11.9 Linux/5.10.219-208.866.amzn2.x86_64 exe/x86_64.debian.11

Environment details (OS name and version, etc.)

docker image python:3.11-slim-bullseye

@Slevy35 Slevy35 added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Aug 26, 2024
@tim-finnigan tim-finnigan self-assigned this Aug 27, 2024
@tim-finnigan tim-finnigan added the investigating This issue is being investigated and/or work is in progress to resolve the issue. label Aug 27, 2024
@tim-finnigan
Copy link
Contributor

Thanks for reaching out. I'm not able to reproduce this, when I set AWS_PROFILE and AWS_ROLE_ARN, then AWS_PROFILE is getting used, which is expected based on the configuration and credentials precedence documentation.

Also the documentation for assuming a role with web identity notes for environment variables AWS_ROLE_ARN and AWS_WEB_IDENTITY_TOKEN_FILE:

These environment variables currently apply only to the assume role with web identity provider. They don't apply to the general assume role provider configuration.

For further investigation, could you provide your debug logs (with any sensitive info redacted) by adding --debug to the command?)

@tim-finnigan tim-finnigan added configuration response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. p2 This is a standard priority issue and removed investigating This issue is being investigated and/or work is in progress to resolve the issue. needs-triage This issue or PR still needs to be triaged. labels Aug 27, 2024
Copy link

github-actions bot commented Sep 6, 2024

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 the closing-soon This issue will automatically close in 4 days unless further comments are made. label Sep 6, 2024
@eternaltyro
Copy link

I face this issue when I use aws sso login.

➜  .aws git:(main) ✗ aws --version
aws-cli/2.17.45 Python/3.11.9 Linux/6.10.7-arch1-1 docker/x86_64.amzn.2
$ cat ~/.aws/config
[default]
sso_session = workstation
sso_account_id = 012312312312
sso_role_name = AdministratorAccess
region = us-west-1
output = json
s3 =
    use_dualstack_endpoint = true

[profile client1]
region = ap-south-1
sso_session = client1
sso_account_id = 045645645645
sso_role_name = AdministratorAccess

[sso-session workstation]
sso_start_url = https://d-123123123.awsapps.com/start
sso_region = eu-west-1
sso_registration_scopes = sso:account:access

[sso-session client1]
sso_start_url = https://d-456456456.awsapps.com/start
sso_region = ap-south-1
sso_registration_scopes = sso:account:access

Setting AWS_PROFILE envvar does nothing. I'm having to explicitly provide --profile switch for it to work.

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Sep 6, 2024
@tim-finnigan tim-finnigan added the response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. label Sep 12, 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 the closing-soon This issue will automatically close in 4 days unless further comments are made. label Sep 16, 2024
@eternaltyro
Copy link

Issue persists in version 2.17.52

@github-actions github-actions bot removed closing-soon This issue will automatically close in 4 days unless further comments are made. response-requested Waiting on additional info and feedback. Will move to "closing-soon" in 7 days. labels Sep 17, 2024
@tim-finnigan
Copy link
Contributor

If you add --debug to your command, then you should see the order in which the CLI is looking for credentials, which is documented here: https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html. Can you share your logs (with any sensitive info redacted) for further investigation? I'm not sure that what you're describing is directly related to the original issue here, or if either case is reproducible.

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. configuration p2 This is a standard priority issue
Projects
None yet
Development

No branches or pull requests

4 participants
@eternaltyro @Slevy35 @tim-finnigan and others