-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Change auth_helpers GetAccountID to first try using caller-identity for the AccountID #5060
Conversation
It looks like |
Hi @potto007 👋 Thanks for submitting this! Introducing additional API calls per resource can be fairly detrimental to the operation of the provider. It can cause additional failure scenarios and is inefficient in large infrastructures. If there is a bug with As @ewbankkit mentioned though, directly using available ARN attributes for resources is a more preferred solution rather than attempting to derive the ARN using values from the provider initialization process. Its likely this came to be because those attributes did not exist during the original resource implementation. Do you have the time to switch their implementation of ARN handling? Thanks! |
Hi @ewbankkit, @bflad - thanks for looking at this. I was looking at doing it that way, but have a related PR I will be submitting for elasticache. In the case of elasticache, there is no way to get the ARN for a cache cluster. I agree that it is cleaner to use a known value rather than trying to derive it. Would you prefer if I pull out the helper function and submit it with that PR? I have run across other AWS resources that still require the ARN for tagging, like Lambda - but haven't done the due-diligence to discover whether they have the same limitation as elasticache. |
@bflad Yes, I have the time. I'm doing the refactor now. I had some half-written code from last night that did what @ewbankkit is talking about, I just need to polish it up and apply it to each resource_aws_db*.go file. |
If you're referring to the |
@bflad - I easily changed the various Read functions for aws/resource_aws_db_*.go using the ARNs from known resources. However, the Update functions are not guaranteed to have that information available, due to the fact that tags can be the only change required, meaning none of the requestUpdate / HasChange branches will be followed within a given Update function. So, returning to the question of how the accountID should be defined... I was wondering if you knew of cases where aws-provider would expect Profile's AccountID rather than the assumed-role's AccountID? It's quite simple to add logic into GetAccountID to check, and use, the AccountID from config.AssumeRoleARN. However, I'm inclined to access config.AssumeRoleARN from the tagging locations if there is the remote chance of side-effects. Thoughts? |
Assuming that
Great question. 😄 I am willing to go out on a limb and say its probably not expected to want the account ID of the source account when assuming a cross-account role. Otherwise, the account ID can be retrieved by creating a provider that does not assume the cross-account role. As far as I know, the behavior of the provider strictly handles the target account (e.g. managing the target account resources, retrieving the target account information from data sources, etc.) in every case except for this one apparently. I think its most valid to update the provider |
74911b7
to
b8cbeee
Compare
Thanks for giving me your thoughts on this, @bflad. Given your last statement, I think the simplest fix turns out to be the best fix. I reverted everything else I did, and simply moved the "try caller identity" block of code to be first in aws/auth_helpers GetAccountID. I have a test build in progress on our CI, and will run it through some of my failure states. |
Yep, this fixed both my RDS tagging issues and my elasticache tagging issues. Would be interesting to see if it fixes the other issues you've identified. |
Hi again, @potto007 👋 After thinking about this some more, I have some reservations about changing the ordering of handlers in this logic, which could potentially have some negative impact on folks if they using certain configurations. For example, this change could start generating Instead of changing any API call ordering, I made an attempt at shortcutting this logic completely if the information is available beforehand: #5177 Can you see if that will work in your environment? It won't help if |
@bflad that makes sense to me. I was a little nervous about how the order change might impact things. I'll had your PR into a test build over the weekend and see how it works in our environment. |
@potto007 fantastic, you are awesome. Please reach out if you need help with anything. Sorry this issue is so nuanced and thank you for everything you have done so far! |
This PR should have been superseded by #5177, released in version 1.31.0 of the AWS provider, which uses two methods to try and shortcut the account ID lookup before it reaches this logic:
Given credentials validation is the default, is recommended for most environments, and provides the same functional behavior of this PR, I'm going to close this one as the underlying problem should be resolved. If its not, we can certainly revisit this. Thanks again for your thoughts and work on this! |
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 feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Fixes #1189 and #5064
Changes proposed in this pull request:
Add helper function to aws/auth_helpers.go called GetCallerID. Unlike the GetAccountID function at the top of auth_helpers, GetCallerID prefers AccountID from the sts:get-caller-identity API call. That call should work in all cases where access permissions allow, but falls back to use accountID referenced by the AWSClient interface.
In locations where ARN in created by concatenation, AccountID is changed to use the GetCallerID helper function described in Change 1. This change occurs in each Read and Update function that touches RDS tags.