JHH*_*JHH 3 amazon-web-services ssh-tunnel amazon-vpc aws-api-gateway
我有一个私有的 AWS API Gateway REST API,这意味着它只能在我的 VPC 中访问。我有一个在 VPC 中运行的堡垒 SSH 实例,这意味着我可以执行以下操作:
ssh -J ec2-user@<bastion> ec2-user@<ip of EC2 instance within my VPC>
Run Code Online (Sandbox Code Playgroud)
从那个实例我可以然后curl我的 API 使用https://<api-id>.execute-api.eu-west-1.amazonaws.com/dev/<my endpoint>URL。
现在,对于本地测试,我想将此实例隧道传输到本地端口,所以我尝试
ssh -J ec2-user@<bastion> -L 8888:<api-id>.execute-api.eu-west-1.amazonaws.com:443 ec2-user@<ip of EC2 instance within my VPC>
Run Code Online (Sandbox Code Playgroud)
此命令返回正常,但是当我尝试执行时curl localhost:8888/dev/<my endpoint>,我首先收到证书错误,这是很自然的,但是当我尝试使用curl -k localhost:8888/dev/<my endpoint>忽略证书时,我只会收到来自 AWS 的 403 Forbidden 响应。对于这些请求,我的 REST API 访问日志中根本没有任何内容。
403 是否与我忽略 TLS 证书或其他原因有关?是否有可能建立这样的隧道?不幸的是,似乎不可能对 API 网关 REST API:s 使用纯 HTTP,否则我更喜欢这种类型的东西。
API Gateway 要求主机标头与 API 端点 URL 匹配。将主机名添加到您的/etc/hosts
<api-id>.execute-api.eu-west-1.amazonaws.com 127.0.0.1
Run Code Online (Sandbox Code Playgroud)
并正常调用它 curl https://<api-id>.execute-api.eu-west-1.amazonaws.com:8888/dev/<my endpoint>
或使用 curl 的--resolve标志
curl \
--resolve <api-id>.execute-api.eu-west-1.amazonaws.com:443:localhost:8888 \
localhost:8888/dev/<my endpoint>
Run Code Online (Sandbox Code Playgroud)
或者,如果您的堡垒配置为允许它,您可以将其ssh用作 SOCKS5 代理并通过堡垒代理您的请求。
在一个 shell 会话中启动代理
ssh -D 8888 ec2-user@<bastion>
Run Code Online (Sandbox Code Playgroud)
然后在另一个shell中,使用它
export HTTPS_PROXY=socks5://localhost:8888
curl https://<api-id>.execute-api.eu-west-1.amazonaws.com/dev/<my endpoint>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
668 次 |
| 最近记录: |