amazon-web-services - 无法设置到私有 AWS API 网关 API 的 SSH 隧道
问题描述
我有一个私有 AWS API Gateway REST API,这意味着它只能在我的 VPC 中访问。我有一个在 VPC 中运行的堡垒 SSH 实例,这意味着我可以执行以下操作:
ssh -J ec2-user@<bastion> ec2-user@<ip of EC2 instance within my VPC>
从那个实例我可以然后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>
此命令返回正常,但是当我尝试执行时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
并正常调用它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>
或者,如果您的堡垒配置为允许,您可以将ssh
其用作 SOCKS5 代理并通过堡垒代理您的请求。
在一个 shell 会话中启动代理
ssh -D 8888 ec2-user@<bastion>
然后在另一个shell中,使用它
export HTTPS_PROXY=socks5://localhost:8888
curl https://<api-id>.execute-api.eu-west-1.amazonaws.com/dev/<my endpoint>
推荐阅读
- jpeg2000 - JPEG2000 文件结构
- javascript - 如何在 React 中显示进度值
- dialogflow-es - 通过实现文本将参数传递给对话流
- javascript - How to get reference of parent view with respect window
- python - 错误:参数 -s/--source 是必需的
- python - Pandas:为变量的每个不同值查找最后一个非空值
- html - 使用 Internet Explorer 的 Html Google Fonts 字体在希伯来语中不起作用(适用于 Chrome 和 Firefox)
- node.js - 如何通过 Bale Bot 发送照片消息?
- c++ - 在 Google 测试中,我可以从构造函数中调用 GetParam() 吗?
- perl - 使用 LWP::Simple 时的状态 403