如何使用 Azure Powershell 将私有公共证书上传到 Azure 应用服务。我知道 New-AzureRmWebApp SSLBindings,但我没有进行任何 SSL 绑定。
我们有使用 SSL 绑定的 Azure 应用服务。为此,我使用 New-AzureRmWebAppSSLBinding 上传证书。我确实为网络应用程序上的每个主机上传了一个证书。这很好用。
但我想将额外的私有和公共证书上传到此应用程序服务以进行 API 验证。我没有找到任何 azure powershell 命令来上传私有或公共证书。
Azure 门户允许上传私有证书及其密码或公共证书。不过我想使用 powershell 做同样的事情。门户 UI 还可以选择从密钥保管库导入证书。我确实可以将证书上传到密钥保管库,但没有 powershell 命令将其导入到 Azure 应用程序服务。
<a href="https://ibb.co/Kh7t5DL"><img src="https://i.ibb.co/fFt3X9n/Capture-Cert.jpg" alt="Capture-Cert" border="0"></a>
我已经阅读了这些文章,但它们都使用相同的命令。https://github.com/Azure/azure-powershell/issues/2108
如何使用 Powershell 将证书添加到 Azure RM 网站
New-AzureRmWebAppSSLBinding -ResourceGroupName $RGName -WebAppName $webAppName -CertificateFilePath $filePath -CertificatePassword $pass
如果我调用此方法,它会询问主机名。由于我已经为此主机名上传了具有 SSL 绑定的证书,因此我无法使用它。如果不提供主机名,此命令将失败。
好吧,终于我能够弄清楚并上传私人和公共证书。Azure 资源浏览器对于理解文件夹结构和证书位置确实很有帮助。
上传公共证书:这些是根据应用程序服务附加的。
$webApps = @{
"Dev_AppServicesGroup" = "DevUserService"
}
$certName = "chain-cert.cer"
$Path = "C:\Certs"
$fullpath = $path + '\' + $certname
$pwd = ConvertTo-SecureString -String 'anyPwd' -AsPlainText -Force
$cert = New-AzureRmApplicationGatewaySslCertificate -Name 'someCert' -CertificateFile $fullpath -Password $pwd
$apiVersion = '2018-02-01'
if($cert)
{
$PropertiesObject = @{
blob=$cert.Data;
publicCertificateLocation= "CurrentUserMy"
}
foreach($resourceGroup in $webApps.Keys)
{
$webAppName = $webApps.Item($resourceGroup)
$resource = Get-AzureRmWebApp -ResourceGroupName $resourceGroup -Name $webAppName
$resourceName = $resource.Name + "/"+$certName
New-AzureRmResource -Location $resource.Location -PropertyObject $PropertiesObject -ResourceGroupName $resource.ResourceGroup -ResourceType Microsoft.Web/sites/publicCertificates -ResourceName $resourceName -ApiVersion $apiVersion -Force
#Apply the cert to the deployment slots if any
$slots = Get-AzureRmResource -ResourceGroupName $resource.ResourceGroup -ResourceType Microsoft.Web/sites/slots -ResourceName $webAppName -ApiVersion $apiVersion
foreach($slot in $slots)
{
$resourceName = $slot.Name + "/"+$certName
New-AzureRmResource -Location $slot.Location -PropertyObject $PropertiesObject -ResourceGroupName $slot.ResourceGroupName -ResourceType Microsoft.Web/sites/slots/publicCertificates -ResourceName $resourceName -ApiVersion $apiVersion -Force
}
}
}
上传私有证书:这些内容按资源组上传,可供该组下的所有应用服务使用。
#Private certs needs to be uploaded to each resource group with app services
$resourceGroups = @("Dev_AppServicesGroup1", "Dev_AppServicesGroup2")
$certName = "event-store-user.p12"
$certPwd = "Your certificate password" #This is the private cert password
$Path = "C:\Certs"
$fullpath = $path + '\' + $certname
$pwd = ConvertTo-SecureString -String 'SomePwd' -AsPlainText -Force
$cert = New-AzureRmApplicationGatewaySslCertificate -Name someCert -CertificateFile $fullpath -Password $pwd
$apiVersion = '2018-02-01'
if($cert)
{
$PropertiesObject = @{
pfxBlob=$cert.Data;
password =$certPwd; #This is the private cert password
ResourceType = "Microsoft.Web/Certificates"
}
foreach($resourceGroup in $resourceGroups)
{
$resource = Get-AzureRmResourceGroup -Name $resourceGroup
New-AzureRmResource -ResourceName $certName -Location $resource.Location -PropertyObject $PropertiesObject -ResourceGroupName $resource.ResourceGroupName -ResourceType Microsoft.Web/certificates -ApiVersion $apiVersion -Force
}
}
就是这样。若要上传 SSL 证书并将其绑定到应用服务,可以使用命令“New-AzWebAppSSLBinding”。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)