简体   繁体   English

API 网关 - ALB:主机名/IP 与证书的替代名称不匹配

[英]API Gateway - ALB: Hostname/IP doesn't match certificate's altnames

My setup currently looks like:我的设置目前看起来像:

API Gateway --- ALB --- ECS Cluster --- NodeJS Applications
             |    
             -- Lambda

I also have a custom domain name set on API Gateway (UPDATE: I used the default API gateway link and got the same problem, I don't think this is a custom domain issue)我也在 API Gateway 上设置了自定义域名(更新:我使用了默认的 API 网关链接并遇到了同样的问题,我认为这不是自定义域问题)

When 1 service in ECS cluster calls another service via API gateway, I get当 ECS 集群中的 1 个服务通过 API 网关调用另一个服务时,我得到

Hostname/IP doesn't match certificate's altnames: "Host: someid.ap-southeast-1.elb.amazonaws.com. is not in the cert's altnames: DNS:*.execute-api.ap-southeast-1.amazonaws.com"主机名/IP 与证书的替代名称不匹配:“主机:someid.ap-southeast-1.elb.amazonaws.com。不在证书的替代名称中:DNS:*.execute-api.ap-southeast-1.amazonaws。 com”

Why is this?为什么是这样?

UPDATE更新

I notice when I start a local server that calls the API gateway I get a similar error:我注意到当我启动一个调用 API 网关的本地服务器时,我收到了类似的错误:

{
    "error": "Hostname/IP doesn't match certificate's altnames: \"Host: localhost. is not in the cert's altnames: DNS:*.execute-api.ap-southeast-1.amazonaws.com\""
}

And if I try to disable the HTTPS check:如果我尝试禁用 HTTPS 检查:

const response = await axios({
  method: req.method,
  url,
  baseURL,
  params: req.params,
  query: req.query,
  data: body || req.body,
  headers: req.headers,
  httpsAgent: new https.Agent({
   : false // <<=== HERE!
  })
})

I get this instead ...我得到了这个......

{
    "message": "Forbidden"
}

When I call the underlying API gateway URL directly on Postman it works ... somehow it reminds me of CORS, where the server seems to be blocking my server either localhost or ECS/ELB from accessing my API gateway?当我直接在 Postman 上调用底层 API 网关 URL 时,它工作......不知何故,它让我想起了 CORS,服务器似乎阻止了我的服务器本地主机或 ECS/ELB 访问我的 API 网关?


It maybe quite confusing so a summary of what I tried:这可能很令人困惑,所以总结一下我的尝试:

  • In the existing setup, services inside ECS may call another via API gateway.在现有设置中,ECS 内部的服务可以通过 API 网关调用另一个服务。 When that happens it fails because of the HTTPS error当发生这种情况时,它会因为 HTTPS 错误而失败
  • To resolve it, I set rejectUnauthorized: false , but API gateway returns HTTP 403为了解决它,我设置了rejectUnauthorized: false ,但 API 网关返回 HTTP 403
  • When running on localhost, the error is similar在本地主机上运行时,错误类似
  • I tried calling ELB instead of API gateway, it works ...我尝试调用 ELB 而不是 API 网关,它有效......

There are various workarounds, which introduce security implications, instead of providing a proper solution.有多种变通方法会引入安全隐患,而不是提供适当的解决方案。 in order to fix it, you need to add a CNAME entry for someid.ap-southeast-1.elb.amazonaws.com.为了修复它,您需要为someid.ap-southeast-1.elb.amazonaws.com.添加一个CNAME条目someid.ap-southeast-1.elb.amazonaws.com. to the DNS (this entry might already exists) and also to one SSL certificate, alike it is being described in the AWS documentation for Adding an Alternate Domain Name .到 DNS(此条目可能已经存在)以及一个 SSL 证书,就像 AWS 文档中关于添加备用域名的描述一样。 this can be done with the CloudFront console & ACM .这可以通过CloudFront控制台和ACM来完成。 the point is, that with the current certificate, that alternate (internal !!) host-name will never match the certificate, which only can cover a single IP - therefore it's much more of an infrastructural problem, than it would be a code problem.关键是,对于当前证书,该备用(内部!!)主机名永远不会与证书匹配,该证书只能覆盖单个 IP - 因此它更像是一个基础设施问题,而不是一个代码问题.

When reviewing it once again... instead of extending the SSL certificate of the public-facing interface - a better solution might be to use a separate SSL certificate, for the communication in between the API Gateway and the ALB, according to this guide ;再次查看它时......而不是扩展面向公众的接口的 SSL 证书 - 根据本指南,更好的解决方案可能是使用单独的 SSL 证书,用于 API 网关和 ALB 之间的通信; even self-signed is possible in this case, because the certificate would never been accessed by any external client.在这种情况下,甚至可以进行自签名,因为任何外部客户端都不会访问该证书。

Concerning that HTTP403 the docs read:关于HTTP403文档内容如下:

You configured an AWS WAF web access control list (web ACL) to monitor requests to your Application Load Balancer and it blocked a request.您配置了一个 AWS WAF Web 访问控制列表 (Web ACL) 来监控对您的 Application Load Balancer 的请求,并且它阻止了一个请求。

I hope this helps setting up end-to-end encryption, while only the one public-facing interface of the API gateway needs a CA certificate, for whatever internal communication, self-signed should suffice.我希望这有助于设置端到端加密,而只有 API 网关的一个面向公众的接口需要 CA 证书,对于任何内部通信,自签名就足够了。

Thisarticle is about the difference in between ELB and ALB - while it might be worth a consideration, if indeed the most suitable load-balancer for the given scenario had been chosen.这篇文章是关于ELBALB之间的区别 - 虽然它可能值得考虑,如果确实为给定场景选择了最合适的负载均衡器。 in case no content-based routing is required, cutting down on useless complexity might be helpful.如果不需要基于内容的路由,减少无用的复杂性可能会有所帮助。 this would eliminate the need to define the routing rules ...which you should also review once, in case sticking to ALB .这将消除定义路由规则的需要......你也应该检查一次,以防坚持ALB I mean, the questions only shows the basic scenario and some code which fails, but not the routing rules.我的意思是,这些问题只显示了基本场景和一些失败的代码,而不是路由规则。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 遇到主机名/ IP与Heroku上的证书的altname不匹配 - Encountering Hostname/IP doesn't match certificate's altnames on Heroku 错误:主机名/ IP与证书的altnames不匹配: - Error: Hostname/IP doesn't match certificate's altnames: Node.js 主机名/IP 与证书的替代名称不匹配 - Node.js Hostname/IP doesn't match certificate's altnames Node.js SOAP请求主机名/ IP甚至与rejectUnauthorized都不匹配证书的替代名称:false - Node.js SOAP request Hostname/IP doesn't match certificate's altnames even with rejectUnauthorized: false NPM没有安装包。主机名/ IP地址与证书的altnames不匹配: - NPM not installing package. Hostname/IP address doesn't match certificate's altnames: 主机名/ IP与证书的备用名称不匹配[Meteor JS电子邮件] - Hostname/IP doesn't match certificate's altnames [Meteor JS Email] Nodejs Axios 错误:主机名/IP 与证书的别名不匹配:“主机:(URL)。不在证书的别名中:DNS:*.sa-east-1.es.amazonaws.com” - Nodejs Axios Error: Hostname/IP doesn't match certificate's altnames: "Host: (URL). is not in the cert's altnames: DNS:*.sa-east-1.es.amazonaws.com" 如何修复“主机名/IP 与证书的替代名称不匹配” - How to fix 'Hostname/IP does not match certificate's altnames' 主机名/ IP与证书的altname不匹配 - Hostname / IP doesn't match certificate's altname 获取 MongooseServerSelectionError:主机名/IP 与证书的替代名称不匹配:IP:xxx.xx.xx.xx 不在证书列表中: - Getting MongooseServerSelectionError: Hostname/IP does not match certificate's altnames: IP: xxx.xx.xx.xx is not in the cert's list:
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM