我在 Azure 中创建了启用 RBAC 的服务主体,以使用环境变量在我的操作系统中配置 Key Vault 访问。创建服务主体时,Azure CLI 会响应服务主体详细信息,其中包含
clientSecret
值。创建命令:
az ad sp create-for-rbac -n <http://my-name> --sdk-auth
我想知道稍后是否可以以及如何请求
clientSecret
。当我使用
az ad sp show --id <my-service-principal-uuid>
或
az ad sp credential list --id <my-service-principal-uuid>
响应信息中没有
clientSecret
。
除了创建时之外,还有什么方法可以检索
clientSecret
吗?
创建后无法检索。您能做的最好的事情就是重置它,此时您将看到新值:
PS C:\> az ad sp credential reset --name foo
{
"appId": "...",
"name": "foo",
"password": "...",
"tenant": "..."
}
这意味着无论您在何处使用凭据,都需要手动更新该凭据,例如在 Azure DevOps 中,如果您使用该特定服务主体创建了 Azure RM 服务连接。
你可以像下面这样
SPA_SP_APP_ID=$(az ad sp create-for-rbac --name $AKS_SP_NAME --skip-assignment --query appId)
SPA_SP_SECRET=$(az ad sp credential reset --name $SPA_SP_APP_ID --query "password")
编辑
正如 Moss 上面提到的,一旦创建就无法检索。
如果您想让客户端密钥在 Azure 门户 > Entra ID (Active Directory) > 应用程序注册 > sp-name > 证书和密钥 > 客户端密钥中可见
那么你需要使用这个命令
az ad app credential reset --id ${CLIENT_ID}
az ad sp
命令会产生不同的秘密。
az ad app credential list --id ${CLIENT_ID}
az ad sp credential list --id ${CLIENT_ID}