在 Batch 池中启用自动证书轮换
可以使用可自动续订的证书创建 Batch 池。 为此,必须使用有权访问 Azure 密钥保管库中证书的用户分配的托管标识创建池。
首先,在与 Batch 帐户相同的租户中创建用户分配的托管标识。 此托管标识无需位于同一资源组中,甚至不需要位于同一订阅中。
确保记下用户分配的托管标识的“客户端 ID”。 稍后需要用到此值。
接下来,需要创建证书并将其添加到 Azure 密钥保管库。 如果尚未创建密钥保管库,则需要先执行此操作。 有关说明,请参阅快速入门:使用 Azure 门户在 Azure 密钥保管库中设置和检索证书。
创建证书时,请确保将“生存期操作类型”设置为自动续订,并指定证书应在多少天后续订。
创建证书后,记下其“机密标识符”。 稍后需要用到此值。
在密钥保管库中,分配密钥保管库访问策略,以允许使用用户分配的托管标识访问机密和证书。 有关详细说明,请参阅使用 Azure 门户分配密钥保管库访问策略。
使用 Batch .NET 管理库创建包含托管标识的 Batch 池。 有关详细信息,请参阅在 Batch 池中配置托管标识。
提示
无法使用密钥保管库 VM 扩展更新现有池。 你需要重新创建池。
以下示例使用 Batch Management REST API 来创建池。 请确保 observedCertificates
使用证书的“机密标识符”,msiClientId
使用托管标识的“客户端 ID”,并替换下面的示例数据。
REST API URI
PUT https://management.chinacloudapi.cn/subscriptions/<subscriptionid>/resourceGroups/<resourcegroupName>/providers/Microsoft.Batch/batchAccounts/<batchaccountname>/pools/<poolname>?api-version=2021-01-01
Linux 节点的请求正文
{
"name": "test2",
"type": "Microsoft.Batch/batchAccounts/pools",
"properties": {
"vmSize": "STANDARD_DS2_V2",
"taskSchedulingPolicy": {
"nodeFillType": "Pack"
},
"deploymentConfiguration": {
"virtualMachineConfiguration": {
"imageReference": {
"publisher": "canonical",
"offer": "ubuntuserver",
"sku": "20.04-lts",
"version": "latest"
},
"nodeAgentSkuId": "batch.node.ubuntu 20.04",
"extensions": [
{
"name": "KVExtensions",
"type": "KeyVaultForLinux",
"publisher": "Microsoft.Azure.KeyVault",
"typeHandlerVersion": "3.0",
"autoUpgradeMinorVersion": true,
"settings": {
"secretsManagementSettings": {
"pollingIntervalInS": "300",
"certificateStoreLocation": "/var/lib/waagent/Microsoft.Azure.KeyVault",
"requireInitialSync": true,
"observedCertificates": [
"https://testkvchinanorth2s.vault.azure.cn/secrets/authcertforumatesting/8f5f3f491afd48cb99286ba2aacd39af"
]
},
"authenticationSettings": {
"msiEndpoint": "http://169.254.169.254/metadata/identity",
"msiClientId": "b9f6dd56-d2d6-4967-99d7-8062d56fd84c"
}
}
}
]
}
},
"scaleSettings": {
"fixedScale": {
"targetDedicatedNodes": 1,
"resizeTimeout": "PT15M"
}
}
},
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/042998e4-36dc-4b7d-8ce3-a7a2c4877d33/resourceGroups/ACR/providers/Microsoft.ManagedIdentity/userAssignedIdentities/testumaforpools": {}
}
}
}
Windows 节点的请求正文
{
"name": "test2",
"type": "Microsoft.Batch/batchAccounts/pools",
"properties": {
"vmSize": "STANDARD_DS2_V2",
"taskSchedulingPolicy": {
"nodeFillType": "Pack"
},
"deploymentConfiguration": {
"virtualMachineConfiguration": {
"imageReference": {
"publisher": "microsoftwindowsserver",
"offer": "windowsserver",
"sku": "2022-datacenter",
"version": "latest"
},
"nodeAgentSkuId": "batch.node.windows amd64",
"extensions": [
{
"name": "KVExtensions",
"type": "KeyVaultForWindows",
"publisher": "Microsoft.Azure.KeyVault",
"typeHandlerVersion": "3.0",
"autoUpgradeMinorVersion": true,
"settings": {
"secretsManagementSettings": {
"pollingIntervalInS": "300",
"requireInitialSync": true,
"observedCertificates": [
{
"url": "https://testkvchinanorth2s.vault.azure.cn/secrets/authcertforumatesting/8f5f3f491afd48cb99286ba2aacd39af",
"certificateStoreLocation": "LocalMachine",
"keyExportable": true
}
]
},
"authenticationSettings": {
"msiEndpoint": "http://169.254.169.254/metadata/identity",
"msiClientId": "b9f6dd56-d2d6-4967-99d7-8062d56fd84c"
}
},
}
]
}
},
"scaleSettings": {
"fixedScale": {
"targetDedicatedNodes": 1,
"resizeTimeout": "PT15M"
}
},
},
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"/subscriptions/042998e4-36dc-4b7d-8ce3-a7a2c4877d33/resourceGroups/ACR/providers/Microsoft.ManagedIdentity/userAssignedIdentities/testumaforpools": {}
}
}
}
要确认已成功部署证书,请登录到计算节点。 应该会看到与下面类似的输出:
root@74773db5fe1b42ab9a4b6cf679d929da000000:/var/lib/waagent/Microsoft.Azure.KeyVault.KeyVaultForLinux-1.0.1363.13/status# cat 1.status
[{"status":{"code":0,"formattedMessage":{"lang":"en","message":"Successfully started Key Vault extension service. 2021-03-03T23:12:23Z"},"operation":"Service start.","status":"success"},"timestampUTC":"2021-03-03T23:12:23Z","version":"1.0"}]root@74773db5fe1b42ab9a4b6cf679d929da000000:/var/lib/waagent/Microsoft.Azure.KeyVault.KeyVaultForLinux-1.0.1363.13/status#
如果 Key Vault 扩展配置错误,则计算节点可能处于可用状态。 要排查密钥保管库扩展失败问题,可以暂时将 requireInitialSync 设置为 false 并重新部署池,然后在计算节点处于空闲状态时,可以登录到计算节点来检查密钥保管库扩展日志是否存在错误并修复配置问题。 有关详细信息,请访问以下密钥保管库扩展文档链接。
- 详细了解 Azure 资源托管标识。