Skip to content

Commit

Permalink
Fix what's bound to which service account and add commentary
Browse files Browse the repository at this point in the history
  • Loading branch information
athornton committed Nov 16, 2023
1 parent 3c6aa10 commit e325dd1
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions environment/deployments/roundtable/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,22 @@ module "iam_admin" {
member = "gcp-${var.application_name}[email protected]"
}

# Service account for Git LFS read/write
resource "google_service_account" "git_lfs_rw_sa" {
account_id = "git-lfs-rw"
display_name = "Git LFS (RW)"
description = "Terraform-managed service account for Git LFS RW access"
project = module.project_factory.project_id
}

resource "google_service_account_iam_member" "git_lfs_rw_sa_wi" {
# Use Workload Identity to have the service run as the appropriate service
# account (bound to a Kubernetes service account)
resource "google_service_account_iam_binding" "git-lfs-rw-sa-wi" {
service_account_id = google_service_account.git_lfs_rw_sa.name
role = "roles/iam.workloadIdentityUser"
member = "serviceAccount:git-lfs-rw@${module.project_factory.project_id}.iam.gserviceaccount.com"
members = [
"serviceAccount:${module.project_factory.project_id}.svc.id.goog[giftless/git-lfs-rw]"
]
}

# The git-lfs service accounts must be granted the ability to generate
Expand All @@ -41,29 +46,32 @@ resource "google_service_account_iam_member" "git_lfs_rw_sa_wi" {
resource "google_service_account_iam_binding" "git-lfs-rw-gcs-binding" {
service_account_id = google_service_account.git_lfs_rw_sa.name
role = "roles/iam.serviceAccountTokenCreator"

members = [
"serviceAccount:git-lfs-rw@${module.project_factory.project_id}.iam.gserviceaccount.com"
]
}

# Service account for Git LFS read-only
resource "google_service_account" "git_lfs_ro_sa" {
account_id = "git-lfs-ro"
display_name = "Git LFS (RO)"
description = "Terraform-managed service account for Git LFS RO access"
project = module.project_factory.project_id
}

resource "google_service_account_iam_member" "git_lfs_ro_sa_wi" {
# See above, but for read-only account
resource "google_service_account_iam_binding" "git-lfs-ro-sa-wi" {
service_account_id = google_service_account.git_lfs_ro_sa.name
role = "roles/iam.workloadIdentityUser"
member = "serviceAccount:git-lfs-ro@${module.project_factory.project_id}.iam.gserviceaccount.com"
members = [
"serviceAccount:${module.project_factory.project_id}.svc.id.goog[giftless/git-lfs-ro]"
]
}

# See above, but for read-only account
resource "google_service_account_iam_binding" "git-lfs-ro-gcs-binding" {
service_account_id = google_service_account.git_lfs_ro_sa.name
role = "roles/iam.serviceAccountTokenCreator"

members = [
"serviceAccount:git-lfs-ro@${module.project_factory.project_id}.iam.gserviceaccount.com"
]
Expand Down

0 comments on commit e325dd1

Please sign in to comment.