在 Batch 集區中啟用自動憑證輪替
您可以使用可自動更新的憑證來建立 Batch 集區。 若要這樣做,您的集區必須使用具有 Azure 金鑰保存庫 憑證存取權的使用者指派受控識別來建立。
建立使用者指派的身分識別
首先,在與 Batch 帳戶相同的租用戶中建立使用者指派的受控識別。 此受控識別無須位於相同資源群組,甚或位於相同訂用帳戶。
請務必記下 使用者指派受控識別的用戶端 標識碼。 您稍後需要此值。
建立您的憑證
接下來,您必須建立憑證,並將其新增至 Azure 金鑰保存庫。 如果您尚未建立金鑰保存庫,您必須先執行該動作。 如需指示,請參閱快速入門:使用 Azure 入口網站 從 Azure 金鑰保存庫 設定及擷取憑證。
建立憑證時,請務必將 [存留期動作類型] 設定為自動更新,並指定憑證應更新的天數。
建立憑證之後,請記下其 秘密標識符。 您稍後需要此值。
在 Azure 金鑰保存庫 中新增存取原則
在您的密鑰保存庫中,指派 金鑰保存庫 存取原則,以允許使用者指派的受控識別存取秘密和憑證。 如需詳細指示,請參閱使用 Azure 入口網站 指派 金鑰保存庫 存取原則。
使用使用者指派的受控識別建立 Batch 集區
使用 Batch .NET 管理連結庫,以受控識別建立 Batch 集區。 如需詳細資訊,請參閱 在 Batch 集區中設定受控識別。
提示
現有的集區無法使用 金鑰保存庫 VM 擴充功能更新。 您必須重新建立集區。
下列範例會使用 Batch Management REST API 來建立集區。 請務必針對 使用憑證的秘密標識碼observedCertificates
,以及的受控識別用戶端標識碼msiClientId
,並取代下列範例數據。
REST API URI
PUT https://management.azure.com/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://testkvwestus2s.vault.azure.net/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://testkvwestus2s.vault.azure.net/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#
疑難解答 金鑰保存庫 擴充功能
如果 金鑰保存庫 擴充功能設定不正確,計算節點可能處於可用狀態。 若要針對 金鑰保存庫 擴充功能失敗進行疑難解答,您可以暫時將 requireInitialSync 設定為 false 並重新部署您的集區,然後計算節點處於閑置狀態,您可以登入計算節點來檢查 KeyVault 擴充功能記錄是否有錯誤並修正設定問題。 如需詳細資訊,請流覽下列 金鑰保存庫 延伸模組文件連結。
下一步
- 了解 Azure 資源的受控識別。
- 了解如何使用客戶自控金鑰搭配使用者受控身分識別。