建立 Azure Active Directory 應用程式
在本節中,您將建立 Azure Active Directory (Azure AD) 應用程式和服務主體物件。Azure 上的 GKE 會使用這些物件,在 Azure 上儲存設定資訊。
- 如要建立 Azure AD 應用程式,請執行下列指令: - az ad app create --display-name APPLICATION_NAME- 將 - APPLICATION_NAME替換為應用程式的名稱,例如- anthos-clusters。
- 如要將應用程式 ID 儲存至環境變數以供後續使用,請執行下列指令: - APPLICATION_ID=$(az ad app list --all \ --query "[?displayName=='APPLICATION_NAME'].appId" \ --output tsv)- 將 - APPLICATION_NAME換成您的應用程式名稱。
- 如要為應用程式建立服務主體,請執行下列指令: - az ad sp create --id "${APPLICATION_ID}"
設定 Workload Identity 聯盟
工作負載身分聯盟可讓 Azure 上的 GKE 使用 Google 服務帳戶向 Azure 進行驗證。相較於舊版 AzureClient 驗證方法,這種 Azure 驗證方法較為簡單,不需要管理憑證,也不必手動將憑證上傳至 Azure Active Directory (AD)。
如要在 Azure AD 應用程式中設定同盟身分憑證,請執行下列指令。請注意,每個 Azure AD 應用程式最多可新增 20 個憑證。
- 建立名為 - credential.json的 JSON 檔案。- { "name": "CREDENTIAL_NAME", "issuer": "https://accounts.google.com", "subject": "service-PROJECT_NUMBER@gcp-sa-gkemulticloud.iam.gserviceaccount.com", "audiences": ["api://AzureADTokenExchange"], "description": "Allow GKE on Azure to authenticate to the Azure AD application using a Google service account." }- CREDENTIAL_NAME:憑證名稱。
- PROJECT_NUMBER:代管叢集的 Google Cloud 專案編號。
 
- 在 Azure AD 應用程式中建立同盟身分憑證: - az ad app federated-credential create --id "${APPLICATION_ID}" --parameters credential.json
詳情請參閱 Azure 說明文件「Azure AD workload identity federation with Google Cloud」。
您也可以使用 Terraform 佈建 Azure 聯盟身分憑證。詳情請參閱 azuread_application_federated_identity_credential。