【问题标题】:Attribute mappings in configuring workload identity federation between GCP and GitHub在 GCP 和 GitHub 之间配置工作负载身份联合时的属性映射
【发布时间】:2022-10-17 17:37:40
【问题描述】:

鉴于那里的示例仍然太少并且文档相当晦涩,我正试图围绕这个新主题展开思考。

我正在尝试对this repo 进行逆向工程。

我想了解的是我们告知 GCP OIDC 令牌具有具体的属性(即来自特定组织/存储库/分支等)仅被接受为有效。

我注意到 iam 政策是defined,如下所示:

data "google_iam_policy" "wli_user_ghshr" {
  binding {
    role = "roles/iam.workloadIdentityUser"

    members = [
      "principalSet://iam.googleapis.com/projects/${data.google_project.project.number}/locations/global/workloadIdentityPools/gh-pool/attribute.full/${var.gh_repo}${var.gh_branch}",
    ]
  }
}

然后我看到身份池提供者也是declared 像这样

resource "google_iam_workload_identity_pool_provider" "provider" {
  provider                           = google-beta
  project                            = var.project_id
  workload_identity_pool_id          = google_iam_workload_identity_pool.gh_pool.workload_identity_pool_id
  workload_identity_pool_provider_id = "gh-provider"
  attribute_mapping                  = {
    "google.subject" = "assertion.sub"
    "attribute.full" = "assertion.repository+assertion.ref"
  }
  oidc {
    allowed_audiences = ["google-wlif"]
    issuer_uri        = "https://token.actions.githubusercontent.com"
  }
}

我的问题如下:

在 iam 政策声明中执行此行

"principalSet://iam.googleapis.com/projects/${data.google_project.project.number}/locations/global/workloadIdentityPools/gh-pool/attribute.full/${var.gh_repo}${var.gh_branch}",

必须与身份池提供者的attribute_mapping 字段中的属性映射对齐,即

  attribute_mapping                  = {
    "google.subject" = "assertion.sub"
    "attribute.full" = "assertion.repository+assertion.ref"
  }

即是attribute.full

"attribute.full" = "assertion.repository+assertion.ref"

体现在iam政策的principalSet的最后部分如下:

attribute.full/${var.gh_repo}${var.gh_branch}"

?

如果是这样,在attribute_mappinggoogle.subject字段中,assertion.sub的作用是什么? assertion.sub 的值必须是什么具体的?

如果是这样,这是在哪里说明/反映的?

【问题讨论】:

    标签: github google-cloud-platform github-actions openid-connect workload-identity


    【解决方案1】:

    在来自 repo 的特定示例中,仅使用了 attribute.full。所以你可以使用:

      attribute_mapping                  = {
        "google.subject" = "assertion.repository+assertion.ref"
      }
    

    并将服务账户的 IAM 策略更改为向身份授予 Workload Identity User 权限:

    principal://iam.googleapis.com/projects/${data.google_project.project.number}/locations/global/workloadIdentityPools/gh-pool/subject/${var.gh_repo}${var.gh_branch}
    

    希望这会有所帮助,我还制作了第二个视频来更详细地解释这一点:https://youtu.be/fa9jHNaG4SA

    【讨论】:

      【解决方案2】:

      c0d.eu,我尝试按照您的指示进行操作,但我仍然获得许可拒绝。你有什么更新吗?

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-11-11
        • 1970-01-01
        • 2021-10-24
        • 2021-05-08
        • 2020-02-25
        • 1970-01-01
        • 2021-09-01
        • 2017-08-15
        相关资源
        最近更新 更多