代码之家  ›  专栏  ›  技术社区  ›  mark

terraform是否可以使用服务主体凭据而不是访问密钥向azure存储容器进行身份验证?

  •  0
  • mark  · 技术社区  · 2 年前

    我有一个服务主体,它是某个存储容器中的数据Blob贡献者。我检查了,可以使用Azure CLI在该容器中上传/下载/删除Blob --auth-mode login 参数,而不传递访问密钥。

    然而,当我跑步时 terraform init 对于针对相同存储容器的相同服务主体,我得到的是:

    Initializing the backend...
    ╷
    │ Error: Failed to get existing workspaces: Error retrieving keys for Storage Account "app541certfremotebackend": storage.AccountsClient#ListKeys: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="AuthorizationFailed" Message="The client '53bfcd5f-0906-4043-bda0-84cacf6ce9d0' with object id '53bfcd5f-0906-4043-bda0-84cacf6ce9d0' does not have authorization to perform action 'Microsoft.Storage/storageAccounts/listKeys/action' over scope '/subscriptions/4...d/resourceGroups/a...2/providers/Microsoft.Storage/storageAccounts/a...d' or the scope is invalid. If access was recently granted, please refresh your credentials."
    │
    │
    ╵
    

    使用访问密钥需要我们授予服务主体一个包含操作的角色 Microsoft.Storage/storageAccounts/listKeys/action 。最接近的内置角色是 Reader And Data Access

    我真的不喜欢它,因为有了访问密钥,就不可能访问存储帐户中的所有存储容器了吗?

    是否可以通过利用RBAC使其在没有访问密钥的情况下工作?

    0 回复  |  直到 2 年前
        1
  •  0
  •   mark    2 年前

    是的,这是经典的RTF M时刻。根据 https://developer.hashicorp.com/terraform/language/settings/backends/azurerm 我可以设置 use_azuread_auth = true 在后端配置中。

    我测试了它,它真的很管用。