我在我的Azure订阅中有一个虚拟机,应该能够读取和写入同一订阅中的存储容器。
因此,我创建了一个RBAC角色,允许从存储容器中读取和写入。为了将角色分配给虚拟机,我启用了VM中的系统分配标识,并将rbac角色与容器的资源管理器ID作为范围分配给系统分配标识。
虚拟机启动后,我假设我可以在VM中执行一些
你的命令和环境中未提供凭据,我们将查询你的存储帐户的帐户密钥。
建议在命令中提供--connection-string、--account-key或--sas-token作为凭据。
如果你的登录账户被分配了必需的 RBAC 角色,请在命令中添加
了解有关存储中 RBAC 角色的更多信息,请访问https://learn.microsoft.com/en-us/azure/storage/common/storage-auth-aad-rbac-cli。
此外,设置相应的环境变量可以避免在命令中输入凭据。请使用 --help 获取有关环境变量使用情况的更多信息。
由于失败而跳过查询帐户密钥:请运行 'az login' 来设置帐户。
此存储帐户不允许公共访问。
请求标识:a3f2a5ce-301e-00a6-315b-931f48000000
时间:2021-08-17T11:30:31.2242111Z
错误代码:PublicAccessNotPermitted
错误:无
以下是我用来创建资源并分配角色的 Terraform 代码的部分内容:
执行 terraform plan 和 apply 无误,我在我的 Azure 门户中看到了系统分配给我的 VM 的标识。此标识已分配具有存储容器作用域的定义角色。
我进行了以下测试以检查权限:
- 创建具有定义的角色的服务主体 --> 使用此服务主体凭据从我的 VM 登录到 Azure,我可以列出容器中的 blob。 - 将 Contributor 角色分配给具有我的订阅作用域的系统分配的标识 --> 但错误仍然存在。
我的 Terraform 版本为:0.13.04 我的 Terraform 提供程序版本为:
初始化提供程序插件...
- 使用先前安装的 hashicorp/cloudinit v2.2.0 - terraform.io/builtin/terraform 内置于 Terraform - 使用先前安装的 hashicorp/azurerm v2.46.0 - 使用先前安装的 hashicorp/template v2.2
请问我错过了什么或做错了什么?非常感谢任何帮助。
谢谢,Christian
因此,我创建了一个RBAC角色,允许从存储容器中读取和写入。为了将角色分配给虚拟机,我启用了VM中的系统分配标识,并将rbac角色与容器的资源管理器ID作为范围分配给系统分配标识。
虚拟机启动后,我假设我可以在VM中执行一些
az storage blob...
命令,例如列出给定容器中的blob,但是该命令失败并显示身份验证问题。az storage blob list --account-name examplestorage --container-name example-container
你的命令和环境中未提供凭据,我们将查询你的存储帐户的帐户密钥。
建议在命令中提供--connection-string、--account-key或--sas-token作为凭据。
如果你的登录账户被分配了必需的 RBAC 角色,请在命令中添加
--auth-mode login
以使用 Azure Active Directory (Azure AD) 进行授权。了解有关存储中 RBAC 角色的更多信息,请访问https://learn.microsoft.com/en-us/azure/storage/common/storage-auth-aad-rbac-cli。
此外,设置相应的环境变量可以避免在命令中输入凭据。请使用 --help 获取有关环境变量使用情况的更多信息。
由于失败而跳过查询帐户密钥:请运行 'az login' 来设置帐户。
此存储帐户不允许公共访问。
请求标识:a3f2a5ce-301e-00a6-315b-931f48000000
时间:2021-08-17T11:30:31.2242111Z
错误代码:PublicAccessNotPermitted
错误:无
以下是我用来创建资源并分配角色的 Terraform 代码的部分内容:
resource azurerm_storage_account storage_account {
name = "examplestorage"
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 storage_container {
name = "example-container"
storage_account_name = azurerm_storage_account.storage_account.name
container_access_type = "private"
}
resource azurerm_role_definition storage_access_role {
name = "example-storage-access"
description = "Role granting permissions to access the blob container storage."
scope = data.azurerm_subscription.example.id
permissions {
actions = [
"Microsoft.Storage/storageAccounts/blobServices/containers/delete",
"Microsoft.Storage/storageAccounts/blobServices/containers/read",
"Microsoft.Storage/storageAccounts/blobServices/containers/write",
]
data_actions = [
"Microsoft.Storage/storageAccounts/blobServices/containers/blobs/delete",
"Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read",
"Microsoft.Storage/storageAccounts/blobServices/containers/blobs/write"
]
}
assignable_scopes = [
data.azurerm_subscription.example.id
]
}
resource azurerm_linux_virtual_machine example_instance {
name = "example-instance"
location = data.azurerm_resource_group.example.location
resource_group_name = data.azurerm_resource_group.example.name
size = "Standard_F2"
admin_username = "adminuser"
source_image_reference {
publisher = "Canonical"
offer = "UbuntuServer"
sku = "18.04-LTS"
version = "latest"
}
identity {
type = "SystemAssigned"
}
}
resource azurerm_role_assignment example_role_assignment {
scope = azurerm_storage_container.storage_container.resource_manager_id
role_definition_id = azurerm_role_definition.storage_access_role.id
principal_id = azurerm_linux_virtual_machine.example_instance.identity[0].principal_id
}
执行 terraform plan 和 apply 无误,我在我的 Azure 门户中看到了系统分配给我的 VM 的标识。此标识已分配具有存储容器作用域的定义角色。
我进行了以下测试以检查权限:
- 创建具有定义的角色的服务主体 --> 使用此服务主体凭据从我的 VM 登录到 Azure,我可以列出容器中的 blob。 - 将 Contributor 角色分配给具有我的订阅作用域的系统分配的标识 --> 但错误仍然存在。
我的 Terraform 版本为:0.13.04 我的 Terraform 提供程序版本为:
初始化提供程序插件...
- 使用先前安装的 hashicorp/cloudinit v2.2.0 - terraform.io/builtin/terraform 内置于 Terraform - 使用先前安装的 hashicorp/azurerm v2.46.0 - 使用先前安装的 hashicorp/template v2.2
请问我错过了什么或做错了什么?非常感谢任何帮助。
谢谢,Christian
az storage blob list --account-name examplestorage --container-name example-container --auth-mode login
。 - Gaurav Mantri