I am trying to wrap my head around this new topic, given that there are still too few examples out there and the documentation is rather obscure.
I am trying to reverse engineer this repo.
What I want to understand is the way we inform GCP that OIDC tokens having specific attributes (i.e coming from specific orgs/repos/branches etc) are only accepted as valid.
I notice that the iam policy is defined as follows:
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}",
]
}
}
then I see that the identity pool provider is also declared like this
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"
}
}
My question is the following:
does this line in the iam policy declaration
"principalSet://iam.googleapis.com/projects/${data.google_project.project.number}/locations/global/workloadIdentityPools/gh-pool/attribute.full/${var.gh_repo}${var.gh_branch}",
must be aligned with the attribute mapping in the identity pool provider's attribute_mapping
field, i.e
attribute_mapping = {
"google.subject" = "assertion.sub"
"attribute.full" = "assertion.repository+assertion.ref"
}
i.e. is the attribute.full
"attribute.full" = "assertion.repository+assertion.ref"
is reflected in the last part of the principalSet
of the iam policy as follows:
attribute.full/${var.gh_repo}${var.gh_branch}"
?
If so, in the attribute_mapping
google.subject
field, what's the role of assertion.sub
? Does the value of the assertion.sub
has to be something specific?
If so, where is this stated / reflected?