-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
AssumeRoleTokenProviderNotSetError when using assume_role with mfa enabled #10491
Comments
I can reproduce this issue exactly as described. I noticed there's a difference in behaviour between specifying the profile in an env var ( Specifying the profile in provider config still doesn't work though, and I can't see any indication in the trace logs that terraform is even trying to assume a role. The only error I get is:
|
Any update on this issue? I am having the exactly same problem. I think that using assume_role with MFA is probably the most common way of access control in big organizations. In my opinion, specifying profile should be enough for Terraform to recognize the use of assume_role with MFA since the configuration is already in ~/.aws/config and ~/.aws/credentials. |
As a workaround for anyone running into this when using aws-vault (maybe others?) it seems you can remove mfa_serial from the role profile while having it still in the base profile and it will work. So for example:
Note that the assumed_role does not have a mfa_serial option set. And then for your provider something like this should work:
One problem is this role doesn't seem to work with aws-vault now. To fix that you will likely want to make an assumed_role profile and an assumed_role_tf profile to support both. It almost seems like in this specific case if an error was not raised, this would simply work. |
To add (for
This way |
this does not work for me. Below is my ~/.aws/credentials file.
If I issue the terraform command I got this: terraform init --backend-config=backends/mb.tfbackend Initializing the backend... Error: No valid credential sources found for AWS Provider. Additionaly I had to issue
for another test I tried this An error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:iam::account_1:user/ai75169 is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::account_2:role/SuperAdmin |
This workaround works well but isn't flawless. When using VS Code with the Terraform plugin containing Terraform Language Server for example, the language server will perform Terraform commands in the background. While it doesn't output any error message, it tries to call |
I ran into a similar issue with the terraform language server, and I change the credential helper process line to something like this which will trigger a dialog box for the MFA prompt:
I do wish this configuration is more flexible because I do prefer TTY input in most other cases.
|
I'm on Ubuntu and I believe Anyway, this works for me but I'm not proud of it: credential_process=sh -c "if [ $(echo $(tty) | cut -c 1-5) = '/dev/' ]; then aws-vault exec base --json 2> $(tty); else return 0; fi" Works as before, minus |
without using aws-vault, I was able to make it work with The script would:
|
This still appears to be an issue - I have a fairly simple template but recently started using a role in the account and can now no longer deploy... |
I've encountered this issue too. Using workarounds always increases the complexity and should not be required. I think it's a common way to use 2FA when assuming a role. 😢 |
In our case, quick and dirty fix is:
Using > 4.0.0 we get It's frustrating that this doesn't work. |
Note, I finally read https://registry.terraform.io/providers/hashicorp/aws/latest/docs/guides/version-4-upgrade#changes-to-authentication and it gave me a pretty big clue. Removing the |
I use the following bash function to get around this issue:
This is based on this StackOverflow answer: https://stackoverflow.com/a/53199639. |
I use https://github.com/broamski/aws-mfa to get around this issue. I run this script below and then two "dynamic" profiles are created that will last 12 hours. This uses the main profile "mreeves" to fetch temporary creds for two profiles "mreeves-admin" and "mreeves-power" it saves to your ~/.aws/credentials file. See this PR to sceptre for how someone suggested they fix it so the boto session cache is respected: Sceptre/sceptre#674. There should be a way to "pre-auth" your creds, enter your mfa and then terraform would simply use boto session cache. That's how the aws cli works.
|
Hello, everyone. The issue #2420 also addresses the lack of support for MFA tokens in the AWS Provider. So that any future discussion will be in one place, I'm going to close this issue. See #2420 (comment) for the current status of the issue |
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. |
Community Note
Terraform Version
Terraform version: 0.12.10
Go runtime version: go1.13.1
provider.aws ~> 2.32.0
Affected Resource(s)
Terraform Configuration Files
env
~/.aws/config
Debug Output
https://gist.github.com/chrishowell/ddd169c24ba4f0fcaba70a3e2f624a5a
Panic Output
N/A
Expected Behavior
As of
terraform-provider-aws_v2.32.0
I believeassume_role
with mfa enabled should work.Actual Behavior
Error: error creating EC2 Metadata session: AssumeRoleTokenProviderNotSetError: assume role with MFA enabled, but AssumeRoleTokenProvider session option not set.
Steps to Reproduce
terraform plan
Important Factoids
Running locally on Mac OSX Catalina
Brew install of Terraform
No
~/.aws/configuration
file presentReferences
The text was updated successfully, but these errors were encountered: