-
Notifications
You must be signed in to change notification settings - Fork 4k
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
feat(apigateway): resource policy configuration for private API #32719
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #32719 +/- ##
=======================================
Coverage 80.92% 80.92%
=======================================
Files 236 236
Lines 14253 14253
Branches 2490 2490
=======================================
Hits 11534 11534
Misses 2434 2434
Partials 285 285
Flags with carried forward coverage won't be shown. Click here to find out more.
|
@go-to-k Thank you very much!! This is exactly the kind of situation where lazy is useful… I’m sad that I didn’t think of it😭 I'll update my code including the function name. |
We might reflect the following in the integ test:
this.api.grantInvokeFromVpcEndpointsOnly([vpcEndpoint1, vpcEndpoint2]);
this.api.grantInvokeFromVpcEndpointsOnly([vpcEndpoint3]);
this.api.grantInvokeFromVpcEndpointsOnly([vpcEndpoint3]); I tried the above integ test in my environment and it seemed to work. "Policy": {
"Statement": [
{
"Action": "execute-api:Invoke",
"Condition": {
"StringNotEquals": {
"aws:SourceVpce": {
"Fn::Join": [
"",
[
{
"Ref": "VpcVpcEndpoint1E6998B88"
},
",",
{
"Ref": "VpcVpcEndpoint2469C3DB9"
},
",",
{
"Ref": "VpcVpcEndpoint33172AEA2"
}
]
]
}
}
},
"Effect": "Deny",
"Principal": {
"AWS": "*"
},
"Resource": "execute-api:/*"
},
{
"Action": "execute-api:Invoke",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Resource": "execute-api:/*"
}
],
"Version": "2012-10-17"
} |
This could be covered by unit tests only instead of an integ test... Anyway, we'll need to cover these in unit tests. |
Nice, this is what I was considering too. Thanks for suggesting it! |
In the above example, string is passed to StringNotEquals, but thinking about it, should this have been an array. Please consider the above as just an example.
Sorry, I haven't actually deployed it, I've only tried it up to synthesis. If something doesn't work, let me know. |
Thank you! As you said, I wasn’t sure if the array handling would work, so I’m currently fixing the integ test and verifying it. |
FYI const endpoints = Lazy.list({
produce: () => {
return Array.from(this._allowedVpcEndpoints).map(endpoint => endpoint.vpcEndpointId);
},
}); "Statement": [
{
"Action": "execute-api:Invoke",
"Condition": {
"StringNotEquals": {
"aws:SourceVpce": [
{
"Ref": "VpcVpcEndpoint1E6998B88"
},
{
"Ref": "VpcVpcEndpoint2469C3DB9"
},
{
"Ref": "VpcVpcEndpoint33172AEA2"
}
]
}
},
"Effect": "Deny",
"Principal": {
"AWS": "*"
},
"Resource": "execute-api:/*"
},
{
"Action": "execute-api:Invoke",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Resource": "execute-api:/*"
}
], |
@go-to-k Thank you for your nice suggestion! I've used |
Nice work! LGTM! But already approved :) |
@GavinZZ I've resolved all problems. Could you please confirm again? |
Thank you so much!! LGTM. |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
AWS CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork). |
Comments on closed issues and PRs are hard for our team to see. |
Issue # (if applicable)
Closes #31660.
Reason for this change
The same PR is closed during maintainer's review. (#31692)
To create a Private API Gateway, we need to attach a resource policy that allows access only from specific Interface VPC Endpoints, as shown below.
This is a bit troublesome.
Description of changes
IRestApi.addToResourcePolicy()
addToResourcePolicy()
at RestApi, SpecApi, and imported RestApi classRestApiBase.grantInvokeToVpcEndpoint()
In the
grantInvokeToVpcEndpoint
method, it was necessary to set a resource policy, and since a policy already existed in RestApiProps, I implemented it so that both can be used simultaneously.Describe any new or updated permissions being added
Add 2 functions which modify resource policies.
Description of how you validated changes
Add both unit and integ tests.
Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license