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

Release 4.2.0 changes authentication behaviour #23407

Closed
morfien101 opened this issue Feb 28, 2022 · 5 comments
Closed

Release 4.2.0 changes authentication behaviour #23407

morfien101 opened this issue Feb 28, 2022 · 5 comments
Assignees
Labels
authentication Pertains to authentication; to the provider itself of otherwise. provider Pertains to the provider itself, rather than any interaction with AWS.

Comments

@morfien101
Copy link

There appears to be a change in behaviour with the AWS Creds chain.

On version 3.74.0 the ENV vars are selected first and requests will us these values for the API calls.
In version 4.2.0 the EC2 Instance role appears to be selected first, in our case this causes authentication failures.

We found this with our Jenkins agents. We pass in credentials to the agent using the withCredentials function which will set the auth env vars AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY and AWS_SESSION_TOKEN. However we get a failure like this:

Error: operation error STS: AssumeRole, https response error StatusCode: 403, RequestID: 648d56a7-dc69-4126-9bae-80689030cc83, api error AccessDenied: User: arn:aws:sts::123:assumed-role/jenkins-agents-ec2/i-123abc is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::123:role/jenkins-role

This is not the case in 3.74.0

Maybe this change?
#23282

@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Feb 28, 2022
@ewbankkit ewbankkit added authentication Pertains to authentication; to the provider itself of otherwise. provider Pertains to the provider itself, rather than any interaction with AWS. labels Feb 28, 2022
@gdavison
Copy link
Contributor

Hi @morfien101, thanks for opening this issue. Version 4 of the AWS provider has changes to the authentication flow to bring it in line with the behaviour of the AWS CLI and the default behaviour of the AWS SDKs. For more information, see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/guides/version-4-upgrade#changes-to-authentication.

Most cases where we've seen this reported define both a profile in the provider configuration block and the credentials environment variables, i.e.

provider "aws" {
  profile = "example-profile"
}

If that is not the case, can you please share the details of your provider configuration block?

@gdavison gdavison added waiting-response Maintainers are waiting on response from community or contributor. and removed needs-triage Waiting for first response or review from a maintainer. labels Feb 28, 2022
@gdavison gdavison self-assigned this Feb 28, 2022
@morfien101
Copy link
Author

We do define the profile in the provider block as you stated.

Our use case is like so:
Dev on laptop has .aws/[config,credentails] with the profiles. This works fine.
On Jenkins server, the EC2 instance has an instance profile assigned to it that has basic abilities in it to allow the starting of the agents. Then the Jenkins config has credentials that are passed into the job which appear as the environment variables.
As stated in the original post, the env vars are ignored due to the presence of the Instance Profile.

@github-actions github-actions bot removed the waiting-response Maintainers are waiting on response from community or contributor. label Mar 1, 2022
@gdavison
Copy link
Contributor

gdavison commented Mar 2, 2022

Thank you for your response, @morfien101. This is expected behaviour starting with version 4.

Version 4 of the AWS provider has changes to the authentication flow to bring it in line with the behaviour of the AWS CLI and the default behaviour of the AWS SDKs. For more information, see https://registry.terraform.io/providers/hashicorp/aws/latest/docs/guides/version-4-upgrade#changes-to-authentication.

@gdavison gdavison closed this as completed Mar 2, 2022
@EdSforzati
Copy link

Hi @gdavison, since this is expected now, and the gospel spread far and wide in the past was "use the profile parameter in the provider blocks", is there a recommended new way to use this provider? I'm in the same boat as @morfien101 above.

I'm expecting a lot of people to be hit by this problem in the future, and think an official recommendation would perhaps be better than just shutting the door without any further discourse.

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
authentication Pertains to authentication; to the provider itself of otherwise. provider Pertains to the provider itself, rather than any interaction with AWS.
Projects
None yet
Development

No branches or pull requests

4 participants