系统图示: 在亚马逊的话中(https://aws.amazon.com/api-gateway/faqs/):“代理请求到后端操作也需要在Internet上公开访问”。这迫使我将ELB公开(面向Internet),而不是内部。然后,我需要一种方法来确保仅 API Gateway 能够在VPC之外访问ELB。
我的第一个想法是在API Gatway中使用客户端证书,但ELB似乎不支持它。
任何想法都将不胜感激!
从推广的方式来看,这似乎是API网关技术中一个巨大的缺失部分。如果不能调用VPC内部面向服务器,它将严重限制其作为互联网访问身份验证前门的实用性。 Azure的API管理支持此功能 - 它可以接受来自互联网的请求并直接调用您的虚拟网络,否则该网络将被防火墙隔离。 在AWS下唯一似乎可行的方法是使用Lambdas,这增加了相当大的复杂性,特别是如果您需要支持各种二进制协议。
看起来现在已经添加了这种支持。没有测试过,可能会有所不同:
string ApiGatewayPassthroughHeader = context.HttpContext.Request.Headers["ApiGatewayPassthroughHeader"];
if (ApiGatewayPassthroughHeader != Environment.GetEnvironmentVariable("ApiGatewayPassthroughHeader"))
{
throw new error;
}
"x-amazon-apigateway-integration": {
"type": "http_proxy",
"uri": "https://${stageVariables.url}/path/to/resource",
"httpMethod": "post",
"requestParameters": {
"integration.request.header.ApiGatewayPassthroughHeader": "${ApiGatewayPassthroughHeader}"
}
},
services:
example:
environment:
- ApiGatewayPassthroughHeader=9708cc2d-2d42-example-8526-4586b1bcc74d
在构建时,我们从设置文件中获取密钥,并将其替换到swagger.json文件中。这样,我们就可以轮换设置文件中的密钥,API网关会更新以使用应用程序正在查找的密钥。
https://aws.amazon.com/de/blogs/aws/built-in-authentication-in-alb/
为了通过私有链接将请求路由到ALB,ALB应该是内部的。在我的设置中,完全可以正常工作,无需在其前面放置NLB。
路由应该如下:
$default / GET(或POST或您想要使用的任何其他方法) 集成应附加到所有路径$default和GET / POST / ANY等
目前没有办法将API Gateway放在私有ELB的前面,所以您是正确的,它必须面向Internet。我能想到的最好的解决方法是将ELB置于TCP通过模式,并在ELB后面的终端主机上终止客户端证书。