使* .crt * .pem证书在docker容器上运行的Azure App服务内可用

发布时间:2020-07-06 06:08

上下文

我正在使用Azure App服务运行应使用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连接吗?

回答1

看到您拥有证明密钥,只需使用openSSL即可创建PFX文件。创建完PFX文件后,您只需将其上传到Azure WebApp。更好的方法是将其上传到Azure KeyVault,然后导入到您的WebApp / App服务计划中

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

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

我为命令外壳创建了这个小脚本,以提示输入值。只需将其另存为.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%"