Azure下载旧证书,同时应用程序服务证书已续订并颁发
我总是躲在这里,但最后我有一个问题,我真的无法回答,也无法在网上找到任何地方。我发现人们在下载.pfx文件时遇到问题,但这里的情况并非如此 我正在尝试更新Azure中我的应用程序网关中的应用程序服务证书,以便SSL继续工作。问题是:Azure下载旧证书,同时应用程序服务证书已续订并颁发,azure,powershell,certificate,pfx,renewal,Azure,Powershell,Certificate,Pfx,Renewal,我总是躲在这里,但最后我有一个问题,我真的无法回答,也无法在网上找到任何地方。我发现人们在下载.pfx文件时遇到问题,但这里的情况并非如此 我正在尝试更新Azure中我的应用程序网关中的应用程序服务证书,以便SSL继续工作。问题是: 起初我有一个权限问题,但现在我可以使用 证书已在Azure中设置为自动续订(Azure说它的有效期至10月20日;这是正确的,它刚刚被续订和颁发) 但下载后。。。我注意到证书上的日期仍然定在10月19日 到目前为止,我不知道为什么,因为这种方法去年确实有效。。。我
- 起初我有一个权限问题,但现在我可以使用
- 证书已在Azure中设置为自动续订(Azure说它的有效期至10月20日;这是正确的,它刚刚被续订和颁发)
- 但下载后。。。我注意到证书上的日期仍然定在10月19日李>
- 到目前为止,我不知道为什么,因为这种方法去年确实有效。。。我只想下载新的.pfx并上传到我的应用网关
# 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"
根据我的测试,如果一个秘密被更新,将会有多个版本
如果上述两项都正确,那么输出的pfx也应该正确。如果没有,您可以删除现有的pfx文件并重试 好吧。。。经过一些试验,我终于找到了解决办法。Azure本身似乎没有足够的权限,我就是这样解决的:
这让我想到,在密钥保管库访问策略中手动添加这两个实体(应用程序)可能也就足够了,但解决方法是创建一个新的应用程序服务证书,然后删除(或使用)它。非常感谢您关注这一点。我刚刚检查了一下,我确实看到了一些差异。这就是我发现的:1:应用服务证书本身声明它的到期日是2020年10月。(当我在Azure中检查通配符证书时可以看到这一点。)2:但是,当我进入密钥库时,日期是2019年10月。(应用服务证书->出口证书->显示保险库状态。)所以我想我的问题是。。。为什么证书本身显示2020,而密钥库机密显示2019;它还出口哪些产品?这不是应该自动更新吗?附言:我可以看到我2018年的版本是旧版本。我不明白的是为什么没有新版本;我是说。。。我有它的自动更新,它应该更新的秘密,就我所知。我添加了2个截图。。。一个来自证书本身,一个来自“当前”版本。我尝试在密钥库中手动添加一个秘密,但当我尝试使用上述脚本下载它时,它会引发base64异常。所以我不能再下载旧的pfx了,因为它现在使用的是新的、坏的、机密的,因为这是保险库中的“当前版本”。
$secret = Get-AzureKeyVaultSecret -VaultName $keyVaultName -Name $keyVaultSecretName
$secret.Version
$secret.Expires