我正在尝试为我的资源组定义 ARM 模板。最终,我尝试通过导航到门户中应用服务的 SSL 证书选项卡来复制必须手动执行的操作。
我已将 PFX 文件上传到我的 KeyVault 的“ secret ”选项卡。我已授予对全局 RM 服务主体的 Get 访问权限。
目前,这就是我的 Microsoft.Web/certificates
资源在模板中的样子。它只是被定义为资源组顶层的资源,而不是网站的子资源或类似的资源:
{
"type":"Microsoft.Web/certificates",
"name": "signingCredentials",
"location": "[parameters('region')]",
"apiVersion": "2015-08-01",
"properties": {
"keyVaultId": "<My KeyVault ID>",
"keyVaultSecretName": "<My Secret Name>"
}
}
当我尝试部署此模板时,我收到消息:
The parameter KeyVault Certificate has an invalid value
我无法找到有关此参数及其期望值的任何文档。我假设资源中的 properties
部分缺少它。到目前为止,我在该主题上发现的任何内容都仅引用了 keyVaultId
和 keyVaultSecretName
。
我做错了什么?我想要实现的目标是否可能实现?
最佳答案
问题似乎不是由我的模板引起的,而是与证书通过 UI 上传到 KeyVault 的方式有关。 This article为我提供了一个脚本,用于使用 powershell 将文件直接上传到 KeyVault。
$pfxFilePath = "F:\KeyVault\PrivateCertificate.pfx"
$pwd = "[2+)t^BgfYZ2C0WAu__gw["
$flag = [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable
$collection = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2Collection
$collection.Import($pfxFilePath, $pwd, $flag)
$pkcs12ContentType = [System.Security.Cryptography.X509Certificates.X509ContentType]::Pkcs12
$clearBytes = $collection.Export($pkcs12ContentType)
$fileContentEncoded = [System.Convert]::ToBase64String($clearBytes)
$secret = ConvertTo-SecureString -String $fileContentEncoded -AsPlainText –Force
$secretContentType = 'application/x-pkcs12'
Set-AzureKeyVaultSecret -VaultName akurmitestvault -Name keyVaultCert -SecretValue $Secret -ContentType $secretContentType # Change the Key Vault name and secret name
使用 Jambor 答案中的 Get-AzureKeyVault
脚本,我无法看到 UI 中上传的证书之间有任何差异。我什至将上传证书的内容类型从证书更改为application/x-pcks2,但它仍然不起作用。看起来这可能是 UI 中的错误,或者只是 powershell 脚本处理方式的差异。
关于azure - 当证书资源托管在 Key Vault 中时,如何在 ARM 模板中定义证书资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40290083/