【问题标题】:Make *.crt *.pem certificates available inside Azure App service running on docker container使 *.crt *.pem 证书在 docker 容器上运行的 Azure App 服务中可用
【发布时间】:2020-10-26 05:30:34
【问题描述】:

上下文

我正在使用 Azure 应用服务来运行应该使用 SSL 连接到 MongoDB 的 node.js 应用程序。使用 docker 容器部署的应用程序。 MongoDB服务器和node.js MongoDB客户端需要使用*.pem和*.crt证书。

问题

Azure Web 应用服务(TLS/SSL 设置)不允许我上传带有*.pem 和*.crt 文件扩展名的自签名证书。只允许*.pfx 扩展名。

如何使*.pem 或*.crt 文件在容器内可用?还有其他方法可以在 Azure 中使用 SSL 将 node.js 应用程序与 MongoDB 连接吗?

【问题讨论】:

  • 你有私钥吗?您是要在 webapp 层还是内部应用层绑定证书?
  • @Bevan 是的,我有私钥吗?抱歉,不明白您所说的 webapp/interna/cert 级别是什么意思。

标签: node.js mongodb azure docker ssl


【解决方案1】:

看到您拥有 provate 密钥,只需使用 openSSL 创建 PFX 文件。创建 PFX 文件后,您可以简单地上传到 Azure WebApp。更好的方法是上传到 Azure KeyVault,然后导入您的 WebApp/App 服务计划

我使用此命令准备我的证书以在 Azure 中使用

openssl pkcs12 -export -out PFXCertName -inkey PrivteKeyFile -in PEMCertificateFile -passout pass:PrivateKeyPassword

我为命令 shell 创建了这个小脚本来提示输入值。只需将其保存为.bat 并运行

@Echo off

set /P Cert=Enter Cert Name (Including Extension):
set /P CertKey=Enter Cert KEY Name (Including Extension):
set /P PFX=Enter New PFX Cert Name to Output (Including Extension):
set /P Password=Enter New PFX Password (Including Extension):

Echo Creating the PFX certificate

openssl pkcs12 -export -out %PFX% -inkey %CertKey% -in %Cert% -passout pass:"%Password%"

【讨论】:

  • MongoDB 服务器和 Node.JS 客户端之间的 SSL 连接能否使用 *.pfx 证书?来自文档 在文档中,他们使用 *.pem 证书 mongodb.github.io/node-mongodb-native/2.2/tutorials/connect/ssl 和 docs.mongodb.com/v3.4/tutorial/configure-ssl
  • 原始问题中对 Azure Web 应用服务的引用让我很困惑。我的回答允许您将 pfx 文件上传到 webapp(Azure 资源)。如果你想要容器中的文件,可以在构建过程中编辑 dockerfile 将证书文件复制到镜像中吗?
  • 是的,将证书放入映像是一种选择,但这并不安全。感谢您的帮助,贝文!
  • 如果要将证书绑定到映像中的应用程序,则证书需要成为映像的一部分。如果 azure webapp 资源是端点,您可以将证书上传到 webapp 并将它们绑定到门户中的主机名。
猜你喜欢
  • 1970-01-01
  • 2020-11-30
  • 2023-03-12
  • 2017-11-22
  • 1970-01-01
  • 2020-06-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多