Skip to content

Commit 179ca6c

Browse files
Add required permission to service account (#82)
Given that we're using service account, which is required to get OAuth tokens needed for Code Assist, we have switched from "Direct Workload Identity Federation" to "Workload Identity Federation through a Service Account". For this reason, we need to add the right permissions to the service account. In future work, we'll remove the direct permissions in WIF. Co-authored-by: Lee Hagood James <leehagoodjames@google.com>
1 parent f420b50 commit 179ca6c

1 file changed

Lines changed: 31 additions & 2 deletions

File tree

scripts/setup_workload_identity.sh

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ WIF_POOL_ID=$(gcloud iam workload-identity-pools describe "${POOL_NAME}" \
235235
--location="${GOOGLE_CLOUD_LOCATION}" \
236236
--format="value(name)")
237237

238-
# Step 2: Create Workload Identity Provider
238+
# Step 3: Create Workload Identity Provider
239239
print_header "Step 2: Creating Workload Identity Provider"
240240
ATTRIBUTE_CONDITION="assertion.repository_owner == '${REPO_OWNER}'"
241241

@@ -257,7 +257,7 @@ else
257257
print_success "Workload Identity Provider already exists"
258258
fi
259259

260-
# Step 3: Grant required permissions to the Workload Identity Pool
260+
# Step 4: Grant required permissions to the Workload Identity Pool
261261
print_header "Step 3: Granting required permissions to Workload Identity Pool"
262262
PRINCIPAL_SET="principalSet://iam.googleapis.com/${WIF_POOL_ID}/attribute.repository/${GITHUB_REPO}"
263263

@@ -316,11 +316,40 @@ gcloud projects add-iam-policy-binding "${GOOGLE_CLOUD_PROJECT}" \
316316

317317
# Allow the service account to generate an access tokens
318318
print_info "Granting 'Service Account Token Creator' role to Service Account..."
319+
319320
gcloud projects add-iam-policy-binding "${GOOGLE_CLOUD_PROJECT}" \
320321
--role="roles/iam.serviceAccountTokenCreator" \
321322
--member="serviceAccount:${SERVICE_ACCOUNT_EMAIL}" \
322323
--condition=None
323324

325+
# Grant logging permissions to the service account
326+
print_info "Granting 'Logging Writer' role to Service Account..."
327+
gcloud projects add-iam-policy-binding "${GOOGLE_CLOUD_PROJECT}" \
328+
--role="roles/logging.logWriter" \
329+
--member="serviceAccount:${SERVICE_ACCOUNT_EMAIL}" \
330+
--condition=None
331+
332+
# Grant monitoring permissions to the service account
333+
print_info "Granting 'Monitoring Editor' role to Service Account..."
334+
gcloud projects add-iam-policy-binding "${GOOGLE_CLOUD_PROJECT}" \
335+
--role="roles/monitoring.editor" \
336+
--member="serviceAccount:${SERVICE_ACCOUNT_EMAIL}" \
337+
--condition=None
338+
339+
# Grant tracing permissions to the service account
340+
print_info "Granting 'Cloud Trace Agent' role to Service Account..."
341+
gcloud projects add-iam-policy-binding "${GOOGLE_CLOUD_PROJECT}" \
342+
--role="roles/cloudtrace.agent" \
343+
--member="serviceAccount:${SERVICE_ACCOUNT_EMAIL}" \
344+
--condition=None
345+
346+
# Grant Vertex AI permissions to the service account
347+
print_info "Granting 'Vertex AI User' role to Service Account..."
348+
gcloud projects add-iam-policy-binding "${GOOGLE_CLOUD_PROJECT}" \
349+
--role="roles/aiplatform.user" \
350+
--member="serviceAccount:${SERVICE_ACCOUNT_EMAIL}" \
351+
--condition=None
352+
324353
# Allow the Workload Identity Pool to impersonate the Service Account
325354
print_info "Allowing GitHub Actions from '${GITHUB_REPO}' to impersonate the Service Account..."
326355
gcloud iam service-accounts add-iam-policy-binding "${SERVICE_ACCOUNT_EMAIL}" \

0 commit comments

Comments
 (0)