重置 Azure 存储帐户/容器上的 IAM 权限

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

我们正在从本地共享迁移到 Azure 存储帐户。我们将使用 blob 存储。目前,有一些本地文件夹结构需要镜像到云端,并且每个文件夹都设置了访问权限。每次添加新文件夹时,自动脚本都会删除文件夹中的所有权限(以防有人在我们不知情的情况下添加了一些文件夹权限),并且在添加新文件夹后会再次重新创建已删除的权限。所以基本上访问权限重置已经完成。

我的问题是,如上所述的权限重置在 Azure 中有意义吗?或者,还有更好的方法?我将创建存储帐户/容器并使用 terraform 分配权限。我知道有从资源组/订阅等继承的权限,因此我们只想关注存储帐户/容器。目前,我们并不是唯一能够向订阅中的存储帐户分配权限的人,因此我们希望确保每次运行新文件夹创建时,分配的权限都是根据我们的最佳实践进行的。

谢谢你。

azure terraform azure-blob-storage
1个回答
0
投票

重置 Azure 存储帐户/容器上的 IAM 权限

我同意@KonTheCat他提供的见解。

为了确保 Terraform 中的要求是实现 Azure Blob 存储的 RBAC(基于角色的访问控制)更改的唯一方法,我们可以将 Terraform 配置为直接管理 RBAC 权限,并限制对 Azure 门户的访问或其他更改权限的方式。我们还将确保 Azure Policy 设置为仅审核模式,以避免与 Terraform 发生冲突。

我的地形配置:

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "vinay-rg"
  location = "East US"
}

resource "azurerm_storage_account" "example" {
  name                     = "msbvkstrageaccount"
  resource_group_name      = azurerm_resource_group.example.name
  location                 = azurerm_resource_group.example.location
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

resource "azurerm_storage_container" "example" {
  name                  = "vkcontainer"
  storage_account_name  = azurerm_storage_account.example.name
  container_access_type = "private"
}

variable "folders" {
  description = "List of folder names to be created"
  type        = list(string)
  default     = ["folder1", "folder2"]
}


# Null resource to reset permissions upon folder creation
resource "null_resource" "reset_permissions" {
  count = length(var.folders)

  triggers = {
    folder_created = timestamp()
  }

  depends_on = [azurerm_storage_container.example]

  provisioner "local-exec" {
    interpreter = ["Pwsh", "-Command"]
    command = <<-EOT
      # Resetting permissions for the folder
      az role assignment delete --role "Storage Blob Data Contributor" --scope "${azurerm_storage_container.example.id}" --output none
      az role assignment create --role "Storage Blob Data Contributor" --assignee "<Service_Principal_Object_ID>" --scope "${azurerm_storage_container.example.id}" --output none
    EOT
  }

  
}

# Create blobs representing folders
resource "azurerm_storage_blob" "folders" {
  count                 = length(var.folders)
  name                  = "${var.folders[count.index]}/test.txt"  # Simulate folders by naming blobs with "/"
  storage_account_name  = azurerm_storage_account.example.name
  storage_container_name= azurerm_storage_container.example.name
  type                  = "Block"
  source = "pathtosourcefile\\${var.folders[count.index]}/test.txt"  # Provide a valid source for the blobs
}

部署成功:

enter image description here

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.