在 Batch 集區中啟用自動憑證輪替

您可以使用可自動更新的憑證來建立 Batch 集區。 若要這樣做,您的集區必須使用具有 Azure 金鑰保存庫 中憑證存取權的使用者指派受控識別來建立。

建立使用者指派的身分識別

首先,在與 Batch 帳戶相同的租用戶中建立使用者指派的受控識別。 此受控識別不需要位於相同的資源群組中,甚至不需要在相同的訂用帳戶中。

請務必記下使用者指派的受控識別的用戶端識別碼。 您後續會用到此值。

此螢幕快照顯示 Azure 入口網站 中使用者指派受控識別的用戶端標識碼。

建立您的憑證

接下來,您必須建立憑證,並將其新增至 Azure 金鑰保存庫。 如果您尚未建立金鑰保存庫,您必須先執行該動作。 如要取得說明,請參閱快速入門:從 Azure Key Vault 使用 Azure 入口網站設定與擷取憑證。

建立憑證時,請務必將 [存留期動作類型] 設定為自動更新,並指定憑證應更新的天數。

Azure 入口網站 中憑證建立畫面的螢幕快照。

當您建立憑證之後,請記下其秘密識別碼。 您後續會用到此值。

顯示憑證秘密標識碼的螢幕快照。

在 Azure Key Vault 中新增存取原則

在您的金鑰保存庫中,指派一個允許您的使用者指派受控識別存取機密和憑證的金鑰保存庫存取原則。 如需詳細說明,請參閱使用 Azure 入口網站指派 金鑰保存庫 存取原則。

使用使用者指派的受控識別建立 Batch 集區

使用 Batch .NET 管理程式庫,建立具有受控識別的 Batch 集區。 如需詳細資訊,請參閱在 Batch 集區中設定受控識別。

提示

現有的集區無法使用 金鑰保存庫 VM 擴充功能更新。 重現你的泳池。

下列範例會使用 Batch 管理 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/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/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/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/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 延伸模組記錄是否有錯誤並修正設定問題。 如需詳細資訊,請瀏覽下列 金鑰保存庫 延伸模組文件連結。

下一步