Azure托管服务身份:12次后未能获取令牌

时间:2019-01-22 08:30:17

标签: azure-active-directory azure-container-registry azure-msi

我有一个具有系统分配的托管服务标识的VM。我授予它从Azure容器注册表中提取图像的权限。 I followed this tutorial

我昨天工作很好。但是当要提取新图像时,它说要重新认证。这是失败的地方。当我执行以下任一操作时,出现错误,说明令牌获取失败。

我做错什么了吗?

  

az登录-身份

     

az acr登录-名称MYREGISTRY

MSI: Failed to acquire tokens after 12 times
Traceback (most recent call last):
  File "/opt/az/lib/python3.6/site-packages/knack/cli.py", line 206, in invoke
    cmd_result = self.invocation.execute(args)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 328, in execute
    raise ex
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 386, in _run_jobs_serially
    results.append(self._run_job(expanded_arg, cmd_copy))
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 379, in _run_job
    six.reraise(*sys.exc_info())
  File "/opt/az/lib/python3.6/site-packages/six.py", line 693, in reraise
    raise value
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 356, in _run_job
    result = cmd_copy(params)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 171, in __call__
    return self.handler(*args, **kwargs)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 441, in default_command_handler
    return op(**command_args)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/command_modules/profile/custom.py", line 111, in login
    return profile.find_subscriptions_in_vm_with_msi(username)
  File "/opt/az/lib/python3.6/site-packages/azure/cli/core/_profile.py", line 297, in find_subscriptions_in_vm_with_msi
    msi_creds = MSIAuthentication(resource=resource)
  File "/opt/az/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 576, in __init__
    self.set_token()
  File "/opt/az/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 584, in set_token
    token_entry = self._vm_msi.get_token(self.resource)
  File "/opt/az/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 632, in get_token
    token_entry = self._retrieve_token_from_imds_with_retry(resource)
  File "/opt/az/lib/python3.6/site-packages/msrestazure/azure_active_directory.py", line 674, in _retrieve_token_from_imds_with_retry
    raise TimeoutError('MSI: Failed to acquire tokens after {} times'.format(max_retry))
TimeoutError: MSI: Failed to acquire tokens after 12 times

2 个答案:

答案 0 :(得分:0)

有一种解释,说明您遵循文档进行操作。

  1. az vm identity assign -g myResourceGroup -n myDockerVM

此CLI命令表示您启用了VM系统MSI。参见az vm identity

  1. az role assignment create --assignee '0a6b28fd-*********' --scope '/subscriptions/{subscription-id}/resourceGroups/{your-resource-group}/providers/Microsoft.ContainerRegistry/registries/{acr-name}' --role reader

此CLI命令意味着您为VM Reader分配了使用VM系统MSI访问ACR的权限。

  1. az login --identity

此CLI命令表示您使用VM的系统分配的身份登录。权限取决于VM的受让人。这样您就可以在具有VM许可的情况下运行CLI命令。

  1. az acr login --name ManiTempRegistry

此CLI命令表示您使用当前用户登录ACR。在此问题中,这意味着您使用具有读取器权限的VM系统MSI登录ACR。

以上所有步骤均已完成,然后您就可以从ACR中以读取器的形式提取docker映像了。令牌存储在文件~/.docker/config.json中。文件将显示如下:

enter image description here

因此,如果令牌未过期,则无需再次登录。因此,您可以检查令牌是否正确。您还有其他问题可以给我留言。

答案 1 :(得分:0)

接受的答案对我不起作用,但是停止然后重新启动VM再次解决了该问题。提醒您重新启动无效。必须先停止然后再从Azure Web界面启动,即VM的重新分配和重新分配。看起来像Azure VM分配中的故障。