gpt4 book ai didi

azure - Terraform azure keyVault SetSecret - 禁止访问被拒绝

转载 作者:行者123 更新时间:2023-12-02 22:59:02 24 4
gpt4 key购买 nike

我尝试提供一个 Terraform keyvault key ,定义访问策略,如下所示。但我遇到了权限问题。

 resource "azurerm_key_vault" "keyvault1" {
name = "${local.key_vault_one_name}"
location = "${local.location_name}"
resource_group_name = "${azurerm_resource_group.keyvault.name}"
enabled_for_disk_encryption = false
enabled_for_template_deployment = true
tenant_id = "${data.azurerm_client_config.current.tenant_id}"

sku {
name = "standard"
}

access_policy {
tenant_id = "${data.azurerm_client_config.current.tenant_id}"
object_id = "${data.azurerm_client_config.current.service_principal_object_id}"
application_id = "${data.azurerm_client_config.current.client_id}"

key_permissions = [
"get","list","update","create","import","delete","recover","backup","restore"
]

secret_permissions = [
"get","list","delete","recover","backup","restore","set"
]

certificate_permissions = [
"get","list","update","create","import","delete","recover","backup","restore", "deleteissuers", "getissuers", "listissuers", "managecontacts", "manageissuers", "setissuers"
]
}
}

# Create Key Vault Secrets
resource "azurerm_key_vault_secret" "test1" {
name = "db-username"
value = "bmipimadmin"
//vault_uri = "${azurerm_key_vault.keyvault1.vault_uri}"
key_vault_id = "${azurerm_key_vault.keyvault1.id}"
}

即使服务主体拥有使用 Key Vault 所需的所有访问权限,我在尝试 terraform apply 时也会收到以下错误。

发生 1 个错误: * azurerm_key_vault_secret.test1:发生 1 个错误: * azurerm_key_vault_secret.test1:keyvault.BaseClient#SetSecret:响应请求失败:StatusCode=403 -- 原始错误:autorest/azure:服务返回错误。 Status=403 Code="Forbidden"Message="访问被拒绝"InnerError={"code":"AccessDenied"}

最佳答案

我可以重现您的问题,但您在权限末尾缺少逗号 , 。在这种情况下,您只需在通过服务主体进行 terraform 应用时指定 tenant_idobject_id 即可。在此之前,应向服务主体授予有关 Azure key 保管库资源的 RBAC 角色(如贡献者角色)。查看更多详情here

例如,这对我有用,

  access_policy {
tenant_id = "${data.azurerm_client_config.current.tenant_id}"
object_id = "${data.azurerm_client_config.current.service_principal_object_id}"


key_permissions = [
"get","list","update","create","import","delete","recover","backup","restore",
]

secret_permissions = [
"get","list","delete","recover","backup","restore","set",
]

certificate_permissions = [
"get","list","update","create","import","delete","recover","backup","restore", "deleteissuers", "getissuers", "listissuers", "managecontacts", "manageissuers", "setissuers",
]
}

引用号:https://www.terraform.io/docs/providers/azurerm/r/key_vault.html#access_policy

关于azure - Terraform azure keyVault SetSecret - 禁止访问被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57111391/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com