我想通过Azure DevOps任务为我的应用服务上传.pfx证书。请问有人可以帮我学习如何通过ARM模板上传证书吗?
$(<mySecureFile>.secureFilePath)或$(Agent.TempDirectory)
来引用它。查看这里获取有关预定义变量的更多信息。certificateBase64Content
中。查看这里了解有关变量的更多信息。$secName = “<certificateName>.pfx
$tempDirectory = $env:AGENT_TEMPDIRECTORY
$pfxFilePath = Join-Path $tempDirectory $secName
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$flag = [System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]::Exportable
$cert.Import($pfxFilePath, "$(certificatePassword)", $flag)
$bin = $cert.RawData
$base64Value = [System.Convert]::ToBase64String($bin)
Write-Host "##vso[task.setvariable variable=certificateBase64Content;]$base64Value"
4、创建一个 KeyVault 并授予 Microsoft.Web 资源提供程序访问 KeyVault 的权限,以获取存储在 KeyVault 中的证书。
请查看博客 "创建具有所需设置的KeyVault" 部分,获取 ARM 模板示例。
5、将证书存储在上一步中创建的 KeyVault 中。
请查看博客 在 KeyVault 中存储证书 部分,获取 ARM 模板示例。
6、参考博客“将证书部署到 Web 应用”的最后一步骤,部署您的证书。
提示:
在上述博客中,ARM 模板中定义的参数被 Azure 资源组部署任务中的参数覆盖。您可以在Azure资源组部署任务的模板设置下进行配置。
附加:
如果您不想使用 KeyVault,则可以省略上述第 4 步和第 5 步。在证书被转换并存储在上述第 3 步中自定义的变量中后,您可以直接上传证书。您需要用自定义变量 certificateBase64Content
替换 parameters('certificatePfxBase64')
。
"variables": {
"certificateName": "[concat(parameters('certificatePrefixName'), uniqueString(resourceGroup().id))]"
},
"resources": [
{
"apiVersion": "2015-08-01",
"name": "[variables('certificateName')]",
"type": "Microsoft.Web/certificates",
"location": "[resourceGroup().location]",
"properties": {
"pfxBlob": "[parameters('certificatePfxBase64')]",
"password": "[parameters('certificatePfxPassword')]"
},
"tags": {
"displayName": "Certificate"
}
}
]