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

Harcoded ARNS Bad: There are more partitions than standard. #53936

Closed
wants to merge 11 commits into from

Conversation

thenoid
Copy link

@thenoid thenoid commented Jul 20, 2019

What does this PR do?

All throughout the boto salt code are hard coded strings starting with:
'arn:aws:'. This means this code will only ever support the standard partition.

There are at least 4 'known' partitions in the world:

  • standard - aws
  • govcloud - aws-us-gov
  • chinacloud - aws-cn
  • D-O-Dcloud - ???

Limting salt's ability to be an enterprise grade tool to 1/4 partitions.

Additionally throughout the code are queries to 'ec2.get_user' and other services to return the accountID. Which leads to chicken and the egg scenarios and granting additional permissions beyond what is needed to function

Thankfully AWS provides the sts endpoint which allows you to ask the philosophical questions of 'who am i?', 'where am i?', but saddly not 'are you my mother?'.

This MR implements a 'boto_sts' module so that we can get introspective and patches the boto_iam module to make use of it. There are close to a hundred additional hardcoded strings to be fixed, but for now this solves our use cases.

https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html

What issues does this PR fix or reference?

Salt's ability to support partitions beyond standard.
Having to grant additional permissions when managing other services.

Previous Behavior

Attempting manage any resource in any partition other than standard would result in failure. In addition in the standard partition, you had to grant the IAM/LAMBDA module access to EC2 api endpoints....even if it wasn't managing EC2

New Behavior

You can now create IAM/LAMBDA resources in non-standard partitions. Also no longer have to grant superfluous permissions.

Tests written?

No

Commits signed with GPG?

No

Please review Salt's Contributing Guide for best practices.

See GitHub's page on GPG signing for more information about signing commits with GPG.

Rocky Olsen added 3 commits July 19, 2019 14:51
All throughout the boto salt code are hard coded strings starting with:
'arn:aws:'.  This means this code will only ever support the standard partition.

There are at least 4 'known' partitions in the world:
* standard - aws
* govcloud - aws-us-gov
* chinacloud - aws-cn
* D-O-Dcloud - ???

Limting salt's ability to be an enterprise grade tool to 1/4.

Additionally throughout the code are queries to 'get_user' and other services to
return the accountID. Which leads to chicken and the egg scenarios as well as
granting additional permissions.

Thankfully AWS provides the `sts` endpoint which allows you to ask the
philosophical questions of 'who am i?', 'where am i?', but saddly not 'are you my
mother?'.

This MR implements a 'boto_sts' module so that we can get introspective and
patches the boto_iam/lambda module to make use of it.  There are close to a hundred
additional hardcoded strings to be fixed, but for now this solves our use cases.

https://docs.aws.amazon.com/general/latest/gr/aws-arns-and-namespaces.html
@ghost
Copy link

ghost commented Jul 20, 2019

@thenoid, thanks for your PR! By analyzing the history of the files in this pull request, we identified @ryan-lane and @tkwilliams to be potential reviewers.

Copy link
Contributor

@tkwilliams tkwilliams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the generalization of the ARN strings -- good catch! :)

WRT the IAM->STS changes, I distinctly recall TRYING to go this route before (in fact the URL to that boto3 function call is still red, showing "recently visited", in my google search results); but IIRC, it behaved unreliably in different situations. Note that the boto modules all support a variety of bind methods: IAM instance creds, STS creds, key-pair, etc. I don't remember exactly which, but the STS call failed with one or the other of these. Please do verify all the possible auth methods before merge (hopefully updating the test cases appropriately).

I've not used the get_partition function, and it looks useful, but the same concerns would be there WRT whether these structures are actually populated in all authentication scenarios. Please do verify, and create test-cases if possible.

Also, on a stupidly pedantic note, the comments still mention get_user even though you're using get_caller_identity :)

PS, grabbing the info from the FAILURE return data if it gets an error back?!? GENIUS!!

@thenoid
Copy link
Author

thenoid commented Jul 23, 2019

So we have been using this code in production for over a year now, using all those authentication schemes you mentioned, with 0 issues. the get_caller_identity function is there explicitly for asking who am I, which is nice because it doesn't require authorization, just authentication, to access.

Thanks for the comments catch - looking at the CI failures guess I need to become adept at writing salt tests.

@dwoz
Copy link
Contributor

dwoz commented Dec 2, 2019

@fattybenji This needs to be re-opened against the master branch and link to this PR. We are no longer accepting PRs to 2017.7.x. Sorry for the confusion.

@dwoz dwoz closed this Dec 2, 2019
@thenoid
Copy link
Author

thenoid commented Dec 3, 2019

@dwoz @Ch3LL This PR sat for 5 months, passing tests, unmerged and now you are asking me to do MORE work to fix bugs in your product. This is how you kill a community.

@Ch3LL
Copy link
Contributor

Ch3LL commented Dec 3, 2019

@thenoid we apologize for the delay. We have been doing a lot of planning to change our release and branch strategy to increase our release velocity, which unfortunately required taking a delay. All of the details of these changes are in this SEP here saltstack/salt-enhancement-proposals#20

I'm more than willing to help you port this to the master branch as well just let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants