使用 GCP 令牌、terraform 和 vault 創建項目時出現權限錯誤 (Permisson error creating project with GCP token, terraform and vault)


問題描述

使用 GCP 令牌、terraform 和 vault 創建項目時出現權限錯誤 (Permisson error creating project with GCP token, terraform and vault)

我想用 terraform 創建一個 GCP 項目,使用 vault 來獲取令牌。我已經配置了 GCP 機密引擎,我要求 terraform 中的 vault 獲取令牌;但是當我運行 terraform 來創建項目時,我收到一條錯誤消息:

Error 403: Service accounts cannot create projects without a parent., forbidden. If you received a 403 error, make sure you have the `roles/resourcemanager.projectCreator` permission
│ 
│   with module.gcp‑project.google_project.project,
│   on .terraform/modules/gcp‑project/main.tf line 6, in resource "google_project" "project":
│    6: resource "google_project" "project" {

我認為問題出在保險庫令牌的角色集綁定中,但我不知道我必須將哪個資源放入角色集中.

我嘗試使用 resourcemanager.projectCreator 角色;但它總是問我項目名稱。

我應該向所有組織授予權限嗎?因為如果我想創建新項目,如果我將一個存在的項目作為資源,我將無法創建另一個項目。

謝謝!!


參考解法

方法 1:

You must create a GCP Organization resource and ensure your Vault GCP roleset is created in a project that lives inside the org (e.g. an "admin" project).

When you create the project creator roleset using terraform you need to grant it a role that has resourcemanager.projects.create permission. You can create the binding against the whole org, or an individual folder within the org. For example:

resource "vault_gcp_secret_roleset" "default" {
  backend      = var.gcp_secret_backend
  roleset      = var.roleset_name
  project      = var.project
  secret_type  = var.secret_type
  token_scopes = ["https://www.googleapis.com/auth/cloud‑platform"]

  binding {
    resource = "//cloudresourcemanager.googleapis.com/folders/${var.folder_id}"

    roles = [
      "roles/resourcemanager.projectCreator",
      "roles/resourcemanager.projectMover",
      "roles/resourcemanager.projectDeleter",
    ]
  }
}

(by EMGMorgan Peat)

參考文件

  1. Permisson error creating project with GCP token, terraform and vault (CC BY‑SA 2.5/3.0/4.0)

#terraform #vault #google-cloud-platform






相關問題

如何在 terraform 中運行 kubectl apply 命令 (How To Run kubectl apply commands in terraform)

如何將生命週期規則發送到 terraform 中的 s3 模塊 (How to send lifecycle_rules to a s3 module in terraform)

將存儲桶策略附加到 s3 存儲桶時,Terraform 拋出存儲桶區域錯誤 (Terraform throwing bucket region error when attaching bucket policy to s3 bucket)

如何在 Terraform 中創建標量數組/列表? (How do you create scalar arrays/lists in Terraform?)

混合 Terraform 和無服務器框架 (Mixing Terraform and Serverless Framework)

我需要在 Fargate 中設置 aws_autoscaling_group 嗎? (Do I need to setup aws_autoscaling_group in fargate?)

Terraform:將變量列表傳遞給容器環境變量 (Terraform: pass variable list to container environment variables)

問題迭代“aws_wafv2_regex_pattern_set”terraform wafv2 (issue iteration over "aws_wafv2_regex_pattern_set" terraform wafv2)

Terraform 狀態 rm 命令 (Terraform state rm command)

如何使用 CMD 在 docker 容器中運行 terraform apply --auto-approve (How to run terraform apply --auto-approve in docker container using CMD)

使用 GCP 令牌、terraform 和 vault 創建項目時出現權限錯誤 (Permisson error creating project with GCP token, terraform and vault)

terraform.apply InvalidParameterException:以下提供的實例類型不存在:[m4.large] (terraform.apply InvalidParameterException: The following supplied instance types do not exist: [m4.large])







留言討論