我总是潜伏在这里,但最后我有一个问题,我真的无法回答或在任何地方在线找到。我发现人们在下载.pfx文件时遇到了麻烦,但是事实并非如此。
我正在尝试在Azure的应用程序网关中更新应用程序服务证书,以便我的SSL能够正常工作。问题是这样的:
我尝试通过Powershell,Azure CLI,旧Azure CLI下载它。但是a ...
**编辑:**我无法使其工作,并为相同的通配符域创建了一个全新的证书。而且-令人惊讶,令人惊讶-现在,Azure确实在密钥库中创建了用于此证书的新机密。问题仍然存在。当现有证书自动更新时,为什么不这样做呢???
这可能又很简单,但我看不到。你们当中有人知道如何解决这个问题吗?
谢谢!
添加了一些证明:
Screenshot: key vault secret date
记录脚本:
# Script for exporting pfx certificate from the Azure Cloud
#
# Type the following commands in PowerShell console to execute the script:
# > Powershell –ExecutionPolicy Bypass
# > .\copyasc.ps1
#
param (
[string]$appServiceCertificateName = "Cert_name",
[string]$azureLoginEmailId = "username@contoso.com"
)
$resourceGroupName = "RG_name"
$subscriptionId = "sub_id"
$exportFileName = "$appServiceCertificateName.pfx"
Login-AzureRmAccount
Set-AzureRmContext -SubscriptionId $subscriptionId
$ascResource = Get-AzureRmResource -ResourceName $appServiceCertificateName -ResourceGroupName $resourceGroupName -ResourceType "Microsoft.CertificateRegistration/certificateOrders" -ApiVersion "2015-08-01"
$keyVaultId = ""
$keyVaultSecretName = ""
$certificateProperties=Get-Member -InputObject $ascResource.Properties.certificates[0] -MemberType NoteProperty
$certificateName = $certificateProperties[0].Name
$keyVaultId = $ascResource.Properties.certificates[0].$certificateName.KeyVaultId
$keyVaultSecretName = $ascResource.Properties.certificates[0].$certificateName.KeyVaultSecretName
$keyVaultIdParts = $keyVaultId.Split("/")
$keyVaultName = $keyVaultIdParts[$keyVaultIdParts.Length - 1]
$keyVaultResourceGroupName = $keyVaultIdParts[$keyVaultIdParts.Length - 5]
Set-AzureRmKeyVaultAccessPolicy -ResourceGroupName $keyVaultResourceGroupName -VaultName $keyVaultName -UserPrincipalName $azureLoginEmailId -PermissionsToSecrets get
$secret = Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name $keyVaultSecretName
$pfxCertObject=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 -ArgumentList @([Convert]::FromBase64String($secret.SecretValueText),"", [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable)
$pfxPassword = -join ((65..90) + (97..122) + (48..57) | Get-Random -Count 50 | % {[char]$_})
$currentDirectory = (Get-Location -PSProvider FileSystem).ProviderPath
[Environment]::CurrentDirectory = (Get-Location -PSProvider FileSystem).ProviderPath
New-Item $currentDirectory\$exportFileName -ItemType file
[io.file]::WriteAllBytes(".\$exportFileName", $pfxCertObject.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12, $pfxPassword))
Write-Host "Created an App Service Certificate copy at: $currentDirectory\$exportFileName"
Write-Warning "For security reasons, do not store the PFX password. Use it directly from the console as required."
Write-Host "PFX password: $pfxPassword"
答案 0 :(得分:0)
根据我的测试,如果更新了机密,将会有多个版本。
能否请您仔细检查一下当前版本的到期日期是否正确?
在PowerShell中,您可以按照以下方式检查版本是否正确:
$secret = Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name $keyVaultSecretName
$secret.Version
$secret.Expires
如果以上两个均正确,则导出的pfx也应该正确。如果没有,您可以删除现有的pfx文件,然后重试。
答案 1 :(得分:0)
好吧...经过一些试验,我终于找到了解决方案。看来Azure本身没有足够的权限,这就是我解决的方法:
这使我认为,在密钥库访问策略中手动添加两个实体(应用程序)可能也已足够,但是解决方法是创建一个新的应用程序服务证书并删除(或使用)它之后。