fuz*_*zzi 10 aws-api-gateway aws-security-group aws-load-balancer
理想情况下,我想锁定我的ALB,以便只能通过API网关访问它.
我已经研究过是否我可以API网关与入站规则联系起来 - 不过,我发现,API网关不能与IP地址或安全组关联.我也研究了面向内部的ALB,但由于VPC链接仅支持NLB,因此我无法使用它们.
任何帮助将不胜感激 - 我一直在寻找网关设置,但找不到此选项.
解决这个问题的最佳方法是什么,以便尽可能限制ALB?
在 API GW HTTP 集成方法的集成请求中注入自定义 HTTP 标头。使用静态值,如Amazon API Gateway API 请求和响应数据映射参考中所述。
“静态值”。STATIC_VALUE 是字符串文字,必须用一对单引号引起来。
与 AWS 文档的情况一样,我们是否应该使用“integration.request.header”会令人困惑。格式。如果在 AWS 控制台中进行设置,则无需键入“integration.request.header”。只需输入标题名称即可。确保标头值是单引号的
然而,当使用像CDK或CFN这样的工具时,我们需要使用“integration.request.header”。部分。
cdk_api_method: aws_apigateway.Method = cdk_api_resource.add_method(
http_method="post",
integration=aws_apigateway.HttpIntegration(
url=url,
http_method="post",
proxy=True,
options=aws_apigateway.IntegrationOptions(
request_parameters={
"integration.request.header.{}".format(HTTP_HEADER_X_VALIDATION_CLIENT_NAME): "'{}'".format(HTTP_HEADER_X_VALIDATION_CLIENT_VALUE)
}
)
)
)
Run Code Online (Sandbox Code Playgroud)
设置 WAF 以验证 HTTP 标头值并将 ALB 关联到 WAF ACL。
# https://github.com/aws-samples/wafv2-json-yaml-samples/blob/master/JSON/rule-001.json
aws_wafv2.CfnWebACL.RuleProperty(
name='header-x-validation-client',
action=aws_wafv2.CfnWebACL.RuleActionProperty(
allow={}
),
statement=aws_wafv2.CfnWebACL.StatementOneProperty(
byte_match_statement=aws_wafv2.CfnWebACL.ByteMatchStatementProperty(
field_to_match=aws_wafv2.CfnWebACL.FieldToMatchProperty(
single_header={
"Name": HTTP_HEADER_X_VALIDATION_CLIENT_NAME
}
),
positional_constraint="EXACTLY",
search_string=HTTP_HEADER_X_VALIDATION_CLIENT_VALUE,
text_transformations=[
aws_wafv2.CfnWebACL.TextTransformationProperty(
priority=0,
type="NONE"
)
]
)
),
visibility_config=aws_wafv2.CfnWebACL.VisibilityConfigProperty(
sampled_requests_enabled=True,
cloud_watch_metrics_enabled=True,
metric_name='waf-rule-header-x-validation-client'
),
priority=0
)
Run Code Online (Sandbox Code Playgroud)
API 网关没有静态 IP,并且 ALB 目前不提供除 Cognito 用户池之外的任何身份验证。因此,我想说,您最好的选择是在您建议时使用带有网络负载均衡器的 VPC 链接,并将请求通过 NLB 隧道传送到您的 ALB。
或者,您可以在 VPC 内使用 Lambda 调用 ALB,但这会慢很多,但对于小容量来说更便宜,因为您跳过了 NLB。
| 归档时间: |
|
| 查看次数: |
404 次 |
| 最近记录: |