Azure KeyVault:如何检索现有服务主体的 clientId、clientSecret 和 tenantId?

Azure KeyVault: how to retrieve clientId, clientSecret and the tenantId for an existing Service Principal?

我组织中的云工程师设置了 Azure KeyVault 和服务主体。我知道这个 Service Principal 的 ID,但我还需要 clientIdclientSecrettenantId.

The documentation 显示当您使用 Azure CLI 创建服务主体时,这些变量会向您公开,但在我的例子中,已经有一个。我没有创建新证书的凭据,坦率地说,我不需要。

那么,如何检索与现有服务委托人关联的 clientIdclientSecrettenantId

您可以使用如下 CLI 命令获取服务主体的 Client IdTenant Id

az ad sp list --query "[].{id:appId, tenant:appOwnerTenantId}"

您甚至可以获得更多服务主体的值 - 请参阅 ServicePrincipalInner class。

此外,如评论中所述,您无法检索其他人创建的 Client Secret。你将不得不 reset 它:

az ad sp credential reset --name APP_ID