Status=403 Code="AuthorizationFailure" Message="该请求无权执行此操作"

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

我正在尝试运行一个部署存储容器的 terraform 部署。初始部署有效(由于尚未到位 IP 过滤),但随后失败。运行 terraform plan 时,我得到以下信息:

Error: retrieving Container "xxxx" (Account "xxxx" / Resource Group "xxx"): containers.Client#GetProperties: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="AuthorizationFailure" Message="This request is not authorized to perform this operation.\nRequestId:62a85c92-901e-0021-12de-816608000000\nTime:2022-06-17T00:11:56.2063816Z"

根据一些研究和调试,当存储容器没有将托管管道代理的 IP 列入白名单时,就会发生这种情况。

我修改了管道,以便检索代理的 IP 并将其添加为防火墙规则。然后我添加了不同时间的睡眠(最多 5 分钟)来尝试给规则生效的时间,但它从来没有起作用。

这是我的管道的片段:

          - task: AzureCLI@2
            inputs:
              azureSubscription: '$(azureSubscription)'
              scriptType: 'bash'
              scriptLocation: 'inlineScript'
              inlineScript: |
                 agentIP=$(curl -s https://api.ipify.org/)
                 az storage account network-rule add -g xxx --account-name xxx --ip-address $agentIP
                 sleep 300

在睡眠期间我已确认代理IP已添加到白名单中。白名单也是在与 terraform 计划相同的阶段完成的。

有人可以建议我哪里可能出错吗?

编辑

我更进一步,在管道中添加了一个步骤,将 DevOps 组织区域(114 个范围)中的所有 IP 地址列入白名单,但它仍然失败。

我的 Azure DevOps 管道代理获取的 IP 甚至不属于

az network list-service-tags --location australiaeast --query "values[?name == 'AzureCloud.australiaeast'].properties.addressPrefixes[]"

返回的范围的一部分
azure azure-devops terraform azure-pipelines azure-blob-storage
4个回答
7
投票

要解决错误“Status=403 Code=AuthorizationFailure Message=此请求无权执行此操作”尝试修改 Azure 门户中的设置,如下所示:

转到 Azure 门户 -> 存储帐户 -> 您从 terraform 创建的存储帐户 -> 网络

enter image description here

  • 启用“允许受信任的 Microsoft 服务访问此存储帐户”允许您访问存储帐户。
  • 确保拥有所需的权限,例如
    Contributor
    User Access Administrator
    角色 /
    Storage Blob Data  Owner
    角色。

如果问题仍然存在,请使用 Ansuman Bal 的类似 SO Thread 中的示例代码。


2
投票

我最终做的是在 DevOps 管道上启动构建时获取构建代理 IP(只需发起对 https://api.ipify.org?format=json 的调用即可获取构建代理 IP),然后使用 powershell/AzCli 将该 IP 添加到存储帐户上的网络规则列表(如果存在),然后还要确保将 IP 添加到 bicep/arm/terraform 中的网络规则中。看起来效果不错。


0
投票

取消注释/禁用所有身份验证参数,例如: use_azure_auth 和 storage_use_azureread


-3
投票

有同样的问题,解决方案是在创建存储帐户时将其添加到 terraform 中

  public_network_access_enabled = true
© www.soinside.com 2019 - 2024. All rights reserved.