-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Addition of implicit partition support #1417
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1417 +/- ##
=======================================
Coverage 95.39% 95.39%
=======================================
Files 29 29
Lines 5565 5565
Branches 707 707
=======================================
Hits 5309 5309
Misses 179 179
Partials 77 77 Continue to review full report at Codecov.
|
Thanks for the pull request! This is a fairly large change so it's taking some time to go through it but just wanted to give an update that I am looking at it. |
Thanks for taking the time to look! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, thanks for the pull request, I think this is really well done and it looks good to me.
I like that we're using the endpoints.json file from botocore so we'll automatically support any partitions in the endpoints.json file.
The only thing I'm a little hesitant on is using the EndpointResolver directly. While using the botocore loaders should be fine (it's a publicly documented API in botocore), the EndpointResolver isn't a public API (on a botocore session it's registered as an "internal component"). While it's not as ideal in terms of code duplication, I think it might be worth using the loaders directly to load up the endpoints.json file and have a separate implementation just for chalice to use.
I can put together a patch that shows what I had in mind, but overall I think it would be a fairly small change. Let me know what you think.
Thanks again for the pull request.
I had this exact debate internally on whether or not to duplicate the code from Did you envision pulling the entire |
Yeah, fortunately that module is pretty self-contained so there shouldn't be any issues vendoring that file. There's also some additional logic that builds on top of the endpoint resolver that botocore uses ( If you want to take a crack at this, feel free. |
Sounds good, I can make the updates and push the changes to the PR. Do you have a preference on where the vendored |
If we're going to be pulling in the file in its entirety it might make sense to start a |
Codecov Report
|
Okay, I took a crack at it earlier this morning and had the file collocated with the other chalice code. I'll move the contents to the requested location but issues will occur with the code being unaltered due to the
Since it's a donated package would it be amenable to add an exemption for this file? |
@jamesls I moved around the vendored package to the location that you specified and added some exceptions to the CI tooling so that the vendored module would no longer trip up code validation. |
Ok sounds good. Thanks for updating. Would you mind rebasing off of the latest master? I also don't mind if you want to consolidate your commits as well. |
7525788
to
5538039
Compare
Happy to rebase off master again, just saw the conflicts this morning and I'll consolidate the commits as well. |
69dba34
to
5f4412c
Compare
@jamesls the commit has been rebased and collapsed down to a single action. Thanks again for all your help and interaction. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for all your work on this, I think this is looking pretty good.
When I try this out in the cn-north-1
region, I'm getting this error when it tries to call CreateRole for the app created from chalice new-project
:
2020-06-12 12:09:56,994 botocore.endpoint [DEBUG] Sending http request: <AWSPreparedRequest stream_output=False, method=POST, url=https://iam.cn-north-1.amazonaws.com.cn/, headers={'Content-Type': b'application/x-www-form-urlencoded; charset=utf-8', 'User-Agent': b'aws-chalice/1.14.1 Python/3.7.3 Darwin/18.7.0 exec-env/AWS_Lambda aws-chalice/1.14.1 Botocore/1.12.253', 'X-Amz-Date': b'20200612T160956Z', 'Authorization': b'', 'Content-Length': '333'}>
2020-06-12 12:09:56,995 urllib3.util.retry [DEBUG] Converted retries value: False -> Retry(total=False, connect=None, read=None, redirect=0, status=None)
2020-06-12 12:09:57,291 urllib3.connectionpool [DEBUG] https://iam.cn-north-1.amazonaws.com.cn:443 "POST / HTTP/1.1" 400 339
2020-06-12 12:09:57,292 botocore.parsers [DEBUG] Response headers: {'x-amzn-RequestId': '', 'Content-Type': 'text/xml', 'Content-Length': '339', 'Date': 'Fri, 12 Jun 2020 16:09:56 GMT', 'Connection': 'close'}
2020-06-12 12:09:57,292 botocore.parsers [DEBUG] Response body:
b'<ErrorResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/">\n <Error>\n <Type>Sender</Type>\n <Code>MalformedPolicyDocument</Code>\n <Message>Invalid principal in policy: "SERVICE":"lambda.amazonaws.com.cn"</Message>\n </Error>\n <RequestId>7d25ff0d-d960-48b2-b2eb-07cebadc39c6</RequestId>\n</ErrorResponse>\n'
2020-06-12 12:09:57,293 botocore.hooks [DEBUG] Event needs-retry.iam.CreateRole: calling handler <botocore.retryhandler.RetryHandler object at 0x10543c2e8>
2020-06-12 12:09:57,293 botocore.retryhandler [DEBUG] No retry needed.
2020-06-12 12:09:57,293 botocore.hooks [DEBUG] Event after-call.iam.CreateRole: calling handler <function json_decode_policies at 0x104356598>
botocore.errorfactory.MalformedPolicyDocumentException: An error occurred (MalformedPolicyDocument) when calling the CreateRole operation: Invalid principal in policy: "SERVICE":"lambda.amazonaws.com.cn"
Are you seeing this as well?
Seems like the CDK ran into similar issues (aws/aws-cdk#3491) |
So for the case of IAM policy we'd need to implement a similar implementation to aws-cdk/packages/@aws-cdk/region-info/lib/default.ts It's unfortunate that the assumption about dnsuffix being a |
Digging deeper into other changes done to that |
Yeah that's unfortunate that they don't consistently use DNS suffix. Sounds like mirroring what CDK's region-info package does is our best option. |
The deployer and planner changes are relatively simple since they'll have access to the session information via the intrinsic functions that have already been established in this PR. What do we do about the CFN and Terraform deployments though? When we were utilizing |
What if we pass in some sort of |
Would it make sense to pass the |
Preferably agnostic to the deployment environment because it's more flexible for users, and there's less possibility for things to go wrong (e.g. different regions between package vs. deploying your cfn stack). I think as a min bar we should preserve the existing behavior of being agnostic to region when we're in the aws partition (people could be relying on that). While possible, I don't think it's likely someone would package in aws-cn but then try to deploy in an aws partition. I would be ok with a tradeoff that if you want to package for a non-aws partition, we'll use your currently configured region to look at that info. In terms of implementation, could we look up the configured region before calling the packagers and, if not in the aws partition, fill in the |
Sounds good, I believe this would require the |
@jamesls I've done the work to port the For The packager on the other hand definitely needs access to the profile information. This already exists in the Since the class TemplateGenerator(object):
def __init__(self, config):
# type: (Config) -> None
self._config = config
self._session = Session(profile=self._config.profile)
def _service_principal(self, service_name):
client = self._session.create_client(service_name)
region = client.meta.region_name
dns_suffix = regioninfo.endpoint_dns_suffix(service_name, region)
return regioninfo.service_principal(service_name, region, dns_suffix) This would require the migration of the region utility methods back out of the Thoughts? |
Is this proposal in lieu of or in addition to the
Or add it to the |
@jamesls thanks for the pseudo code, it gave me the kick in the right direction. I was concerned with the modification of the method signatures and repeated object passing to the _methods internal to the different generators. I should have the necessary changes ready shortly so that we can put this issue to 🛌 . |
86a54f3
to
17492ef
Compare
@jamesls I've implemented the changes for the |
Changes needed after rebasing from the latest on master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the delay, the changes look good to me. I rebased and had to make a few changes to work with the latest master branch. Thanks for all your work on this!
@jamesls My pleasure, I'm sure/know that there are some functional pieces still missing but I believe it's a good start. The next big challenge is supporting role/policy generation for the non-standard partitions. Thank you for allowing me to contribute. |
Issue #, if available: #792
Description of changes:
This PR contains the code changes necessary for implicitly supporting partitions as requested by issue #792 and the details of its comments.
botocore
EndpointResolver
based on service and region (also from an existing ARN)parse_arn
to return thedns_suffix
for the ARN.interrogate_profile
has been added whereparse_arn
is unable to be utilized in the deployment plan.AWS::Partition
andAWS::URLSuffix
have been used to fill in all the necessary characteristics for the resources that would need to be modified.partition
anddns_suffix
attributes fromdata "aws_partition" "chalice" {}
have been used in the templates to populate the necessary policies and resource definitions.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.