@@ -79,6 +79,8 @@ readonly PROD_PROJECT_SERVICES=(
7979 containerregistry.googleapis.com
8080 # prod projects host binaries in GCS
8181 storage-component.googleapis.com
82+ # prod projects host containers in AR
83+ artifactregistry.googleapis.com
8284)
8385
8486readonly PROD_PROJECT_DISABLED_SERVICES=(
@@ -87,7 +89,9 @@ readonly PROD_PROJECT_DISABLED_SERVICES=(
8789)
8890
8991# Regions for prod GCR.
90- PROD_REGIONS=(us eu asia)
92+ GCR_PROD_REGIONS=(us eu asia)
93+ # Regions for prod AR.
94+ AR_PROD_REGIONS=(asia-east1 asia-south1 asia-northeast1 asia-northeast2 australia-southeast1 europe-north1 europe-southeast1 europe-west1 europe-west2 europe-west4 europe-west8 europe-west9 southamerica-west1 us-central1 us-east1 us-east4 us-east5 us-south1 us-west1 us-west2)
9195
9296# Minimum time we expect to keep prod GCS artifacts.
9397PROD_RETENTION=" 10y"
@@ -102,8 +106,8 @@ function ensure_prod_gcr() {
102106 fi
103107 local project=" ${1} "
104108
105- color 6 " Ensuring prod GCR for regions: ${PROD_REGIONS [*]} "
106- for region in " ${PROD_REGIONS [@]} " ; do
109+ color 6 " Ensuring prod GCR for regions: ${GCR_PROD_REGIONS [*]} "
110+ for region in " ${GCR_PROD_REGIONS [@]} " ; do
107111 local gcr_bucket=" gs://${region} .artifacts.${project} .appspot.com"
108112
109113 color 3 " region: ${region} "
@@ -121,6 +125,33 @@ function ensure_prod_gcr() {
121125 done 2>&1 | indent
122126}
123127
128+ # Make a prod AR repository and grant access to it.
129+ #
130+ # $1: The GCP project name (GCR names == project names)
131+ function ensure_prod_ar() {
132+ if [ $# != 1 ] || [ -z " $1 " ]; then
133+ echo " ensure_prod_ar(project) requires 1 argument" >&2
134+ return 1
135+ fi
136+ local project=" ${1} "
137+ local serviceaccount
138+
139+ color 6 " Ensuring prod AR registry for locations: ${AR_PROD_REGIONS[*]} "
140+ for region in " ${AR_PROD_REGIONS[@]} " ; do
141+
142+ color 3 " region: ${region} "
143+ color 6 " Ensuring an AR repo exists in location: ${region} for project: ${project} "
144+ ensure_ar_repo " ${project} " " ${region} "
145+
146+ color 6 " Ensuring GCR admins can admin AR in location: ${region} for project: ${project} "
147+ empower_ar_admins " ${project} " " ${region} "
148+
149+ color 6 " Empowering image promoter with roles/artifactregistry.repoAdmin in project: ${project} "
150+ serviceaccount=$( svc_acct_email " ${project} " " ${IMAGE_PROMOTER_SVCACCT} " )
151+ ensure_project_role_binding " ${project} " " serviceAccount:$serviceaccount " " artifactregistry.repoAdmin"
152+ done 2>&1 | indent
153+ }
154+
124155# Make a prod GCS bucket and grant access to it. We need whole buckets for
125156# this because we want to grant minimal permissions, but there's no concept of
126157# permissions on a "subdirectory" of a bucket. If we had a GCS promoter akin
@@ -175,7 +206,7 @@ function empower_group_to_fake_prod() {
175206 empower_group_as_viewer " ${project} " " ${group} "
176207
177208 color 6 " Empowering $group for GCR in $project "
178- for r in " ${PROD_REGIONS [@]} " ; do
209+ for r in " ${GCR_PROD_REGIONS [@]} " ; do
179210 color 3 " region $r "
180211 empower_group_to_write_gcr " ${group} " " ${project} " " ${r} "
181212 done
@@ -198,15 +229,18 @@ function ensure_all_prod_projects() {
198229 color 6 " Ensuring project exists: ${prj} "
199230 ensure_project " ${prj} "
200231
201- color 6 " Ensuring Services to host and analyze aritfacts : ${prj} "
232+ color 6 " Ensuring Services to host and analyze artifacts : ${prj} "
202233 ensure_services " ${prj} " " ${PROD_PROJECT_SERVICES[@]} " 2>&1 | indent
203234
204235 color 6 " Ensuring disabled services for prod project: ${prj} "
205236 ensure_disabled_services " ${prj} " " ${PROD_PROJECT_DISABLED_SERVICES[@]} " 2>&1 | indent
206237
207- color 6 " Ensuring the GCR repository : ${prj} "
238+ color 6 " Ensuring the GCR repositories : ${prj} "
208239 ensure_prod_gcr " ${prj} " 2>&1 | indent
209240
241+ color 6 " Ensuring the AR repositories: ${prj} "
242+ ensure_prod_ar " ${prj} " 2>&1 | indent
243+
210244 color 6 " Ensuring the GCS bucket: gs://${prj} "
211245 ensure_prod_gcs_bucket " ${prj} " " gs://${prj} " 2>&1 | indent
212246 done
@@ -289,7 +323,7 @@ function ensure_all_prod_special_cases() {
289323 # real $PRODBAK_PROJECT). We don't want this same power for the non-test
290324 # backup system, so a compromised promoter can't nuke backups.
291325 color 6 " Empowering backup-test-prod promoter to backup-test-prod GCR"
292- for r in " ${PROD_REGIONS [@]} " ; do
326+ for r in " ${GCR_PROD_REGIONS [@]} " ; do
293327 color 3 " region $r "
294328 empower_svcacct_to_write_gcr \
295329 " $( svc_acct_email " ${GCR_BACKUP_TEST_PRODBAK_PROJECT} " " ${IMAGE_PROMOTER_SVCACCT} " ) " \
0 commit comments