[英]Can't connect to remote endpoint using self-signed cert from Web Api core app on Docker
When I try to connect to a remote endpoint from my dockerized web api core app, I'm getting the following error: System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
System.Net.Http.HttpRequestException: The SSL connection could not be established, see inner exception. ---> System.Security.Authentication.AuthenticationException: The remote certificate is invalid according to the validation procedure.
在 Docker 之外运行相同的应用程序时,它按预期工作。 我认为问题在于我们的组织使用自签名证书。 完整的链已加载到我的本地计算机上,但我无法将其安装在 Docker 上,因此 web api 应用程序将识别它。
After loading the certs in my Dockerfile (see details below), I am able to connect to the remote site with openssl and curl successfully from my Dockerfile:
RUN openssl s_client -connect REMOTE.ENDPOINT:443 -servername REMOTE.ENDPOINT -verify_hostname REMOTE.ENDPOINT
...snip...
Verification: OK
...snip...
RUN curl --verbose https://REMOTE.ENDPOINT
...snip...
SSL certificate verify ok.
请注意,这些 openssl 和 curl 调用是我的 Dockerfile 中的最后一件事,所以我希望一切都可以为我的应用程序设置好查看和使用证书。
这是我如何将自签名证书添加到 Dockerfile 中的 docker 图像中
ADD localEc.crt /usr/local/share/ca-certificates/localEc.crt
RUN chmod 644 /usr/local/share/ca-certificates/localEc.crt && update-ca-certificates
当应用程序运行时,我已验证我的证书不在/etc/ssl/certs/ca-certificates.crt
中,并且我的证书文件不在/etc/ssl/certs
中。 虽然我认为没有必要,但我尝试将证书直接复制到图像中:
COPY --from=build /etc/ssl/certs/ /etc/ssl/certs/
COPY ["/etc/ssl/certs", "/etc/ssl/certs"]
我错过了什么?
我知道我可以覆盖 ssl 验证过程以允许此证书,但我宁愿修复根本问题(并避免由解决方法<g>
引起的所有讨论)。
我终于弄明白了。 我不完全理解分阶段的 docker 构建过程是如何工作的。 似乎在调试时,Visual Studio 只使用了 dockerfile 的第一阶段,而我在最后阶段添加了证书。 本文阐明了 Docker 构建过程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.