gpt4 book ai didi

尝试角色分配时,Azure DevOps 管道 terraform 错误 - 403

转载 作者:行者123 更新时间:2023-12-03 00:55:34 26 4
gpt4 key购买 nike

我正在尝试为通过 terraform 创建的系统分配托管标识部署 aks 集群和角色分配,但收到 403 响应

azurerm_role_assignment.acrpull_role: Creating...

│ Error: authorization.RoleAssignmentsClient#Create: Failure responding to request: StatusCode=403 -- Original Error: autorest/azure: Service returned an error. Status=403 Code="AuthorizationFailed" Message="The client '626eac40-c9dd-44cc-a528-3c3d3e069e85' with object id '626eac40-c9dd-44cc-a528-3c3d3e069e85' does not have authorization to perform action 'Microsoft.Authorization/roleAssignments/write' over scope '/subscriptions/7b73e02c-dbff-4eb7-9d73-e73a2a17e818/resourceGroups/myaks-rg/providers/Microsoft.ContainerRegistry/registries/aksmattcloudgurutest/providers/Microsoft.Authorization/roleAssignments/c144ad6d-946f-1898-635e-0d0d27ca2f1c' or the scope is invalid. If access was recently granted, please refresh your credentials."

│ with azurerm_role_assignment.acrpull_role,
│ on main.tf line 53, in resource "azurerm_role_assignment" "acrpull_role":
│ 53: resource "azurerm_role_assignment" "acrpull_role" {


这仅发生在 Azure Devops Pipeline 中。我的管道如下所示...

trigger:
- main

pool:
vmImage: ubuntu-latest

steps:

- task: TerraformInstaller@0
inputs:
terraformVersion: '1.0.7'

- task: TerraformCLI@0
inputs:
command: 'init'
workingDirectory: '$(System.DefaultWorkingDirectory)/Shared/Pipeline/Cluster'
backendType: 'azurerm'
backendServiceArm: 'Matt Local Service Connection'
ensureBackend: true
backendAzureRmResourceGroupName: 'tfstate'
backendAzureRmResourceGroupLocation: 'UK South'
backendAzureRmStorageAccountName: 'tfstateq7nqv'
backendAzureRmContainerName: 'tfstate'
backendAzureRmKey: 'terraform.tfstate'
allowTelemetryCollection: true

- task: TerraformCLI@0
inputs:
command: 'plan'
workingDirectory: '$(System.DefaultWorkingDirectory)/Shared/Pipeline/Cluster'
environmentServiceName: 'Matt Local Service Connection'
allowTelemetryCollection: true

- task: TerraformCLI@0
inputs:
command: 'validate'
workingDirectory: '$(System.DefaultWorkingDirectory)/Shared/Pipeline/Cluster'
allowTelemetryCollection: true

- task: TerraformCLI@0
inputs:
command: 'apply'
workingDirectory: '$(System.DefaultWorkingDirectory)/Shared/Pipeline/Cluster'
environmentServiceName: 'Matt Local Service Connection'
allowTelemetryCollection: false

我正在使用这里的 terraform 任务 - https://marketplace.visualstudio.com/items?itemName=charleszipp.azure-pipelines-tasks-terraform

这是我的地形文件

terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "=2.46.0"
}
}
}

provider "azurerm" {
features {}
}

resource "azurerm_resource_group" "TerraformCluster" {
name = "terraform-cluster"
location = "UK South"
}

resource "azurerm_kubernetes_cluster" "TerraformClusterAKS" {
name = "terraform-cluster-aks1"
location = azurerm_resource_group.TerraformCluster.location
resource_group_name = azurerm_resource_group.TerraformCluster.name
dns_prefix = "terraform-cluster-aks1"

network_profile {
network_plugin = "azure"
}

default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_D2_v2"
}

identity {
type = "SystemAssigned"
}

tags = {
Environment = "Production"
}
}

data "azurerm_container_registry" "this" {
depends_on = [
azurerm_kubernetes_cluster.TerraformClusterAKS
]
provider = azurerm
name = "aksmattcloudgurutest"
resource_group_name = "myaks-rg"
}

resource "azurerm_role_assignment" "acrpull_role" {
scope = data.azurerm_container_registry.this.id
role_definition_name = "AcrPull"
principal_id = azurerm_kubernetes_cluster.TerraformClusterAKS.identity[0].principal_id
}

我哪里出错了?

最佳答案

需要为 AAD 中与您的 ADO 服务连接(“Matt 本地服务连接”)关联的服务主体分配资源范围内的所有者角色或以上角色(具体取决于您还将在哪里分配权限)。您可以阅读有关各种角色的详细信息 here两个最常用的角色是所有者和贡献者,主要区别在于所有者允许管理角色分配。

作为这项工作的一部分,您还应该熟悉 principle of least privilege (如果您还不知道的话)。在这种情况下它将如何应用;如果服务主体只需要资源级别的所有者,那么不要将其分配为资源组或订阅级别的所有者,因为这样更方便,您可以随时更新范围,但要撤消任何损害要困难得多(假设是恶意或缺乏经验的参与者)在被利用后过度宽松的角色分配。

关于尝试角色分配时,Azure DevOps 管道 terraform 错误 - 403,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69829349/

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