工作负载身份联合允许 GKE on Azure 使用 Google 服务账号向 Azure 进行身份验证。向 Azure 进行身份验证的这个方法比旧版 AzureClient 身份验证方法更简单,后者要求您管理证书并手动将其上传到 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."
}
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-03。"],[],[],null,["# Create an Azure Active Directory application\n============================================\n\nIn this section, you create an\n[Azure Active Directory](https://azure.microsoft.com/en-us/services/active-directory/)\n(Azure AD) application and service principal objects. GKE on Azure\nuses these objects to store configuration information on Azure.\n\n1. To create the Azure AD application, run the following command:\n\n az ad app create --display-name \u003cvar translate=\"no\"\u003eAPPLICATION_NAME\u003c/var\u003e\n\n Replace \u003cvar translate=\"no\"\u003eAPPLICATION_NAME\u003c/var\u003e with a name for your\n application---for example, `anthos-clusters`.\n2. To save the application's ID to an environment variable for later use, run\n the following command:\n\n APPLICATION_ID=$(az ad app list --all \\\n --query \"[?displayName=='\u003cvar translate=\"no\"\u003eAPPLICATION_NAME\u003c/var\u003e'].appId\" \\\n --output tsv)\n\n Replace \u003cvar translate=\"no\"\u003eAPPLICATION_NAME\u003c/var\u003e with the name of your\n application.\n3. To create a service principal for the application, run the following command:\n\n az ad sp create --id \"${APPLICATION_ID}\"\n\nSet up Workload identity federation\n-----------------------------------\n\n\u003cbr /\u003e\n\n| **Note:** GKE on Azure provides two\n| methods of authenticating to Azure: workload identity federation\n| authentication and *AzureClient* authentication. We recommend that you use\n| the workload identity federation method described in this document, because\n| it's simpler and more secure.\n\n\u003cbr /\u003e\n\nWorkload identity federation allows GKE on Azure to authenticate to Azure\nusing a Google service account. This method of authenticating to Azure is\nsimpler than the legacy AzureClient authentication method, which requires\nyou to manage certificates and manually upload them to Azure Active Directory\n(AD).\n\nTo configure a federated identity credential on your Azure AD\napplication, run the following commands. Note that you can add up to twenty\ncredentials to each Azure AD application.\n\n1. Create a JSON file named `credential.json`.\n\n ```json\n {\n \"name\": \"CREDENTIAL_NAME\",\n \"issuer\": \"https://accounts.google.com\",\n \"subject\": \"service-PROJECT_NUMBER@gcp-sa-gkemulticloud.iam.gserviceaccount.com\",\n \"audiences\": [\"api://AzureADTokenExchange\"],\n \"description\": \"Allow GKE on Azure to authenticate to the Azure AD application using a Google service account.\"\n }\n ```\n - \u003cvar translate=\"no\"\u003eCREDENTIAL_NAME\u003c/var\u003e: the credential name.\n - \u003cvar translate=\"no\"\u003ePROJECT_NUMBER\u003c/var\u003e: the number of the Google Cloud project that hosts the cluster.\n2. Create a federated identity credential on the Azure AD application:\n\n az ad app federated-credential create --id \"${APPLICATION_ID}\" --parameters credential.json\n\nFor more details, see the Azure documentation\n[Azure AD workload identity federation with Google Cloud](https://blog.identitydigest.com/azuread-federate-gcp/).\n\nYou can also provision the Azure federated identity credential using Terraform.\nFor details, see [azuread_application_federated_identity_credential](https://registry.terraform.io/providers/hashicorp/azuread/latest/docs/resources/application_federated_identity_credential).\n\nWhat's next\n-----------\n\n- [Create Azure role assignments](/kubernetes-engine/multi-cloud/docs/azure/how-to/create-azure-role-assignments)"]]