Azure create servicePrincipal 结果“一个或多个属性包含无效值”

标签 azure azure-devops azure-active-directory azure-cli

我正在获取 token (我的 Gitlab 需要它作为我的运行者的环境变量) 通过我的计算机上的 Azure cli 像这样:

C:\Users\myuser>az ad sp create-for-rbac --name http://gitlab-runner-acr-service-principal --scopes /subscriptions/xxxxxxx-xxxxx-xxxx-xxxx-xxxxxx/resourceGroups/MyRegistryResourceGroup/providers/Microsoft.ContainerRegistry/registries/MyDockerImageRegistry --role acrpush --query password --output tsv

一直以来一切都很顺利(一年多了)。 产生的输出将是这样的:

“找到“xxxxx-xxxx-xxxx-xxxx-xxxxxxxxxx”的现有应用程序实例。我们将对其进行修补 在“/subscriptions/xxxxxxx-xxxxx-xxxx-xxxx-xxxxxx/resourceGroups/MyRegistryResourceGroup/providers/Microsoft.ContainerRegistry/registries/MyDockerImageRegistry”范围下创建角色分配

角色分配已存在。

b3253fac-267e-284f-9642-d4267a2620f8

我需要从输出中得到这样的标记。但是,几周前该命令停止获取 token 。 现在我收到以下消息:“一个或多个属性包含无效值。” 命令完全相同(就像一直以来一样)。我不明白为什么会发生这种情况,以及为什么我无法再获得 token 。

我没有在 azure-cli 中更改任何内容(我使用相同的版本),也没有通过 Azure Portal 执行任何操作,所以我不明白为什么它停止工作。。 我在 Google 上搜索过,看到了一些示例和建议,如何通过 Microsoft Graph API 解决类似问题(不完全像这样)。但我对 Microsoft Graph API 并不熟悉,所以请您帮助我如何通过 Azure CLI 使其工作。

我的问题是如何使 azure-cli 使用相同的命令获取 token ?我必须做什么才能让它再次工作?

编辑: 我添加了 --debug 标志,最后一部分是这样的:

...
adal-python : 91386626-a42a-4d22-ba63-d22961220cec - CacheDriver:Returning token from cache lookup, AccessTokenId: b'OKDsXwBiy7YUjkUuLqUbDVL+mTGi19P9914i8J3knnQ=', RefreshTokenId: b'PSu7XWGVFXFQLMQ3GBtTxj5DsNQt8ZhkjjFKegqQXZQ='
msrest.http_logger : Request URL: 'https://graph.windows.net/478d151e-37db-4a62-833b-4b989ce41c1c/applications?api-version=1.6'
msrest.http_logger : Request method: 'POST'
msrest.http_logger : Request headers:
msrest.http_logger :     'Accept': 'application/json'
msrest.http_logger :     'Content-Type': 'application/json; charset=utf-8'
msrest.http_logger :     'accept-language': 'en-US'
msrest.http_logger :     'Content-Length': '461'
msrest.http_logger :     'User-Agent': 'python/3.6.6 (Windows-10-10.0.19041-SP0) msrest/0.6.11 msrest_azure/0.6.3 azure-graphrbac/0.60.0 Azure-SDK-For-Python AZURECLI/2.3.1 (MSI)'
msrest.http_logger : Request body:
msrest.http_logger : {"availableToOtherTenants": false, "homepage": "https://gitlab-runner-acr-service-principal", "passwordCredentials": [{"startDate": "2020-09-28T12:15:30.026043Z", "endDate": "2021-09-28T12:15:30.026043Z", "keyId": "yyyyyyyy-yyyyyy-yyyyy-yyyyyyyyyyyyy", "value": "a9827bf6-a5a9-4922-bcbb-a28b2da7e04a", "customKeyIdentifier": "//5yAGIAYQBjAA=="}], "displayName": "gitlab-runner-acr-service-principal", "identifierUris": ["0884ae2d-515f-4efd-a069-595a63f1efee"]}
msrest.universal_http : Configuring redirects: allow=True, max=30
msrest.universal_http : Configuring request: timeout=100, verify=True, cert=None
msrest.universal_http : Configuring proxies: ''
msrest.universal_http : Evaluate proxies against ENV settings: True
urllib3.connectionpool : Starting new HTTPS connection (1): graph.windows.net:443
urllib3.connectionpool : Starting new HTTPS connection (1): graph.windows.net:443
urllib3.connectionpool : https://graph.windows.net:443 "POST /478d151e-37db-4a62-833b-4b989ce41c1c/applications?api-version=1.6 HTTP/1.1" 400 207
msrest.http_logger : Response status: 400
msrest.http_logger : Response headers:
msrest.http_logger :     'Cache-Control': 'no-cache'
msrest.http_logger :     'Pragma': 'no-cache'
msrest.http_logger :     'Content-Type': 'application/json; odata=minimalmetadata; streaming=true; charset=utf-8'
msrest.http_logger :     'Expires': '-1'
msrest.http_logger :     'ocp-aad-diagnostics-server-name': '9G9RnY9XiO+FpbH/eqhH2G8NOqXAfe/lEzfJH1kKGEc='
msrest.http_logger :     'request-id': '52133c1e-9e42-469b-8c84-4515b617e940'
msrest.http_logger :     'client-request-id': '4c129b1e-0184-11eb-afc2-6c0b84e25a98'
msrest.http_logger :     'x-ms-dirapi-data-contract-version': '1.6'
msrest.http_logger :     'ocp-aad-session-key': 'jR7Y9XU-WaZ2W5zpUmKDjXHgDJVYFGevEDu2emGYhyAezbIgh6y-7mPn_sxsfC5cymSICphmRbGOSdfu8X6gkKEXEFWdmBJeEoF6K0Pg4jaueLN1YMv9vIp1bRpIZOBbYVZOY-WKV-iebCkrTkC9xHYpXpZFML197SdsPJezGAWKEeFcwiwm4eESzkYPSjhLR1pmKMIme0EfM0CaVC58PA.IbhRdEvnM_6KoyQFkZu5OKeMILXYKaK6j7XdpDbfKlE'
msrest.http_logger :     'Duration': '3577050'
msrest.http_logger :     'x-ms-resource-unit': '1'
msrest.http_logger :     'DataServiceVersion': '3.0;'
msrest.http_logger :     'X-AspNet-Version': '4.0.30319'
msrest.http_logger :     'X-Powered-By': 'ASP.NET'
msrest.http_logger :     'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
msrest.http_logger :     'Access-Control-Allow-Origin': '*'
msrest.http_logger :     'Date': 'Mon, 28 Sep 2020 12:15:30 GMT'
msrest.http_logger :     'Content-Length': '207'
msrest.http_logger : Response content:
msrest.http_logger : {"odata.error":{"code":"Request_BadRequest","message":{"lang":"en","value":"One or more properties contains invalid values."},"requestId":"52133c1e-9e42-469b-8c84-4515b617e940","date":"2020-09-28T12:15:30"}}
msrest.exceptions : One or more properties contains invalid values.
cli.azure.cli.core.util : One or more properties contains invalid values.
One or more properties contains invalid values.

最佳答案

对我来说,这是因为这个名字已经存在。在您的情况下--name http://gitlab-runner-acr-service-principal

也许 CLI 过去会返回现有的(如果已经存在),但现在会抛出错误。

无论如何,我通过在创建 SP 之前检查 SP 是否已存在来修复该错误。

编辑

删除现有的并重新创建它后,CLI 开始返回现有的而不是抛出错误。我建议删除现有的来解决此问题。

史蒂夫

关于Azure create servicePrincipal 结果“一个或多个属性包含无效值”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64100034/

相关文章:

azure 网络作业 "The job is missing basic auth fields"

Azure Redis 缓存作为数据存储?

Azure 媒体服务直播/点播

python-3.x - Azure DevOps 的客户端凭据流程

angular - 在 Azure Active Directory 上启用 CORS

Azure 环境分离

azure - 在 Azure Devops 中,如何创建分支策略以要求在合并 PR 之前解析链接的工作项?

azure-devops - Azure DevOps : Build 1 Project in a Multi-Project Solution

azure - 为什么 'Azure Kubernetes Service RBAC Reader' 角色允许部署写入

azure - user_impersonation 范围 - 为什么?