【问题标题】:Retrieving SSL certificate from Azure key vault to Azure app service将 SSL 证书从 Azure 密钥保管库检索到 Azure 应用服务
【发布时间】:2020-05-07 00:07:34
【问题描述】:

我在 Azure keyvault 中有一个 SSL 证书。我需要通过 powershell 将此证书安装到 Azure 应用服务。

【问题讨论】:

标签: azure powershell ssl-certificate azure-web-app-service azure-keyvault


【解决方案1】:

关于这个问题,我们可以从 Azure 密钥库下载 SSL 证书作为 pfx 文件,然后使用 pfx 文件为 Azure Web 应用程序配置 SSL

详细步骤如下。

  1. Download SSL certificate from Azure key vault。请注意,在运行以下命令之前,请为密钥保管库中的帐户配置访问策略
Connect-AzAccount
$cert=Get-AzKeyVaultSecret -VaultName "your key vault name" -Name ""
$password="Password0123!"
$certBytes = [System.Convert]::FromBase64String($cert.SecretValueText)
$certCollection = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2Collection
$certCollection.Import($certBytes,$null,[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$protectedCertificateBytes = $certCollection.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12, $password)
$pfxPath = "E:\mycert.pfx"
[System.IO.File]::WriteAllBytes($pfxPath, $protectedCertificateBytes)
  1. 配置 SSl
New-AzWebAppSSLBinding -WebAppName $webappname -ResourceGroupName $webappname -Name $fqdn `
-CertificateFilePath $pfxPath -CertificatePassword $pfxPassword -SslState SniEnabled

【讨论】:

  • 我试过这个脚本。但是在 AzWebAppSSLBinding 中,如果我直接传递密码,它会显示 New-AzWebAppSSLBinding:操作返回无效状态代码“NotFound”。但是如果我将它作为安全字符串传递,它会抛出网络密码不正确。但我通过门户手动尝试,我可以上传它而不会出现任何错误
  • @Learner 请将 -Debug 参数附加到 New-AzWebAppSSLBinding 以获取详细的错误消息。
  • 谢谢伙计。其实那是我的误会。现在工作正常
  • @Learner 既然你的问题已经解决了,可以请accept the answer吗?它可能会帮助更多有类似问题的人
猜你喜欢
  • 1970-01-01
  • 2021-08-25
  • 1970-01-01
  • 2019-07-15
  • 2020-10-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-07-31
相关资源
最近更新 更多