获取服务主体的 AZURE_CREDENTIALS

问题描述 投票:0回答:3

我已经创建了我的服务主体。

使用 GitHub,我需要完成以下所有参数。我的问题是我们在哪里以及如何找到每一个?

AZURE_CREDENTIALS :
{
  "clientId": "XXX",
  "clientSecret": "XXX",
  "subscriptionId": "XXX",
  "tenantId": "XXX",
  "activeDirectoryEndpointUrl": "XXX",
  "resourceManagerEndpointUrl": "XXX",
  "activeDirectoryGraphResourceId": "XXX",
  "sqlManagementEndpointUrl": "XXX",
  "galleryEndpointUrl": "XXX",
  "managementEndpointUrl": "XXX"
}

我已经在文档中看到,我们可以使用 CLI Azure 为新的主体服务生成 JSON 文件:

az ad sp create-for-rbac `
         --name "myApp" --role contributor `
         --scopes /subscriptions/8baa642d-5109-4f1c-b935-401e5b215078/resourceGroups/rg-ai-recommender `
         --sdk-auth

但我想使用现有的服务主体。

azure github-actions credentials
3个回答
3
投票

您可以多次运行该命令。

如果再次运行它,将会出现一条消息,内容如下:

az ad sp create-for-rbac --name TestPrincipal --role Contributor --sdk-auth
Found an existing application instance of "[existingId]". We will patch it
Creating 'Contributor' role assignment under scope '/subscriptions/[guid]'
  Role assignment already exists.

The output includes credentials that you must protect. Be sure that you do not include these credentials in your code or check the credentials into your source control. For more information, see https://aka.ms/azadsp-cli
'name' property in the output is deprecated and will be removed in the future. Use 'appId' instead.
{
  "clientId": "[existingId]",
  "clientSecret": "[aNewSecret]",
  "subscriptionId": "[subscriptionid]",
  // all the other properties
}

当然,这将使您在其他存储库中使用的凭据无效,因此您也应该更新这些凭据。

恢复秘密是不可能的,因为它是秘密。

这样您就可以在多个存储库中使用相同的服务主体。


请记住,为不同的服务/部署创建新的服务主体可能是一种更安全的策略,因此您可以尽可能细化角色分配。但这不是你的问题。


2
投票

服务主体分为三种类型:

  • 申请
  • 托管身份
  • 遗产

您可以使用 Azure 门户中的企业应用程序边栏选项卡来列出和管理租户中的服务主体。您可以查看服务主体的权限、用户同意的权限、哪些用户已同意、登录信息等等。

转到 Azure 门户,打开 Azure Active Directory,然后单击管理下的企业应用程序菜单项。

在那里,找到服务主体的注册,并找到相应的信息。

要为服务主体创建新的 clientSecret,请在“应用程序注册”中找到相应的注册,然后打开“管理”下的“证书和机密”菜单。从那里,您可以创建一个新的秘密。您无法查看现有机密的值。


0
投票

clientId:

是服务原理的applicationId,如果您进入概述中的服务原理页面,您应该会看到该id。

clientSecret:

当您在服务原理中创建秘密时会显示秘密值,它仅在创建时显示。如果您不知道秘密,只需创建一个新的

subscriptionId:

如果您转到 github 将连接到的应用程序,您应该能够看到订阅 ID。

tenantId:

Azure Active Directory 应用程序(服务原则的父应用程序)租户 ID 显示在概述中 从这个页面我得到了所有的URL

https://github.com/Azure/azure-cli/issues/22297

"activeDirectoryEndpointUrl": "https://login.microsoftonline.com", "resourceManagerEndpointUrl": "https://management.azure.com/", "activeDirectoryGraphResourceId": "https://graph.windows.net/", "sqlManagementEndpointUrl": "https://management.core.windows.net:8443/", "galleryEndpointUrl": "https://gallery.azure.com/", "managementEndpointUrl": "https://management.core.windows.net/"

© www.soinside.com 2019 - 2024. All rights reserved.