-
Notifications
You must be signed in to change notification settings - Fork 36
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 provider/backend skip_metadata_api_check required to use aws credentials file native role_arn #7
Comments
Wonder if these are related? Alot of the logic in this module looks similar to that in the session module of aws-sdk-go aws/aws-sdk-go#2528 We're running on ECS and can't assumerole via config file, have been chasing things down all over the place. |
I have a slightly different use case - running TF in EKS pod that uses IAM attached to Service Account as described here https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html The long story short, I get
Then I have
Terraform picking up EKS node instance profile instead of everything defined in
For my particular use case, AWS metadata IP should be anyway iptabled out so not accessible by EKS pods, I just haven't got there yet. Still this is a bug worth fixing - I can imagine there might be use cases these workarounds does not apply. Such as using |
Thanks @etherops this was exactly the issue we were having (#17 (comment)) and we were successfully able to fix it with your "workaround". Not sure what that functionality should do or why its even required, as you can handle any case directly via the profile configuration. Ideally we keep "profile lookup functionality" the same as the SDK so there are no caveats. |
@llibicpep your workaround is exactly what I needed as it works on older version of terraform. I'm using terraform 0.11.11 and have an instance profile tied to an EC2 instance. However, I have ~/.aws/credentials with the following [default] but terraform ALWAYS loads the chain with the instance metadata even with the skip_metadata_api_check set to true. |
I'm attempting to run Atlantis (or terraform plan at all) on ECS and this has completely stopped us from being able to. Due to the use cases of our other automation and our developer access roles etc. we can't hardcode the role arn directly in the provider, so we're relying on it picking up that information from the standard AWS environment variables and config etc. I have this in the aws config
Provider looks like this
I've got AWS_PROFILE=myrole set and I have verified that the ECS task role has permissions to assume the role and I have set the environment variable The permission errors I get from terraform plan show that it's attempting to use the task execution role and not the role that it should be assuming. These workarounds did not work for ECS tasks:
Looking for more ideas for workarounds, or maybe getting that pull request in with the fix please! 🙏 |
The fix for this has been merged and will release with v0.5.0 of this library, for inclusion with Terraform CLI (S3 Backend) v0.13.0-rc1 and Terraform AWS Provider v3.0.0. Thanks to @nkupton for the implementation and patience. 👍 |
@katharosada we had to set "skip_metadata_api_check = true" on the backend config as well so that the correct profile was used when accessing the state bucket.
|
The aws-sdk-go v1.15.54 (and thereby terraform 12) now supports using the aws credentials file native format role_arn, as such:
(note
Ec2InstanceMetadata
used for example, but bug is not limited to that credential_source)However, attempting to use the following provider/s3 config backend...
results in the following error...
Error trace:
I discovered, as did another user here: hashicorp/terraform-provider-aws#5018 (comment), that setting
skip_metadata_api_check
is a workaround.I further discovered, essentially why, this is.
After some tracing, I discovered that the reason is the logic above. During the so called metadataapicheck... the code not only checks the API, but adds the metadata creds to the auth provider chain!
Subsequently, then, on 229, if you haven't hard coded the
role_arn
into the terraform config, the awsauth.go code will return and not attempt to add anything else to the auth chain. This causes any subsequent AWS calls (for both the s3 backend or provider) to use the ec2 role creds retrieved from the ec2instancemetadata API, and it will sadly then not follow any role_arn instructions in the shared credentials file :-(Why the workaround works
So by setting
skip_metadata_api_check
= true in the terrraform config, we can now basically trick the SDK into doing what it does best, instead of using the ec2 instance role creds that were set during the "check" on line 214.Expected Behavior
Expected behavior would be that if you specify
role_arn
in your aws credentials file, that by default terraform will use that, and not use the ec2 machine role that it gets from the ec2instanemetadata api.The text was updated successfully, but these errors were encountered: