Skip to content

Commit 642deeb

Browse files
fix: remove unused service and redundant IAM bindings in workload identity setup script (#481)
The original fix for #444 dated in January is incomplete. This change removes an unused Google internal service `cloudcode-pa.googleapis.com` for users in the setup script for Workload Identity Federation. It also removes redundant IAM bindings on the Workload Identity Pool's principal in Step 4. These IAM bindings are added in Step 5 on a connected service account to the Workload Identity Pool, different from its principal. GitHub Actions "impersonates" this connected service account, which has access to Google Cloud resources and services. Lastly, it updates the description to correctly reflect the content of the shell script. I have published this [codelab](https://codelabs.developers.google.com/gemini-cli/gemini-cli-security-review#0) that teaches about this setup. Signed-off-by: Tianzi Cai <tianzi@google.com>
1 parent b0c9501 commit 642deeb

File tree

1 file changed

+7
-35
lines changed

1 file changed

+7
-35
lines changed

scripts/setup_workload_identity.sh

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
# limitations under the License.
1616

1717
# Universal Direct Workload Identity Federation Setup Script for GitHub Actions
18-
# This script sets up Google Cloud Direct Workload Identity Federation for any GitHub repository
19-
# to work with the google-github-actions/auth action.
18+
# The original script sets up Google Cloud Direct Workload Identity Federation for
19+
# any GitHub repositorty to work with the google-github-actions/auth action.
2020
#
21-
# Uses Direct WIF (preferred): No intermediate service accounts, direct authentication to GCP resources.
21+
# It has been modified for Gemini CLI, which requires a special WIF setup
22+
# setup through a Service Account.
23+
2224

2325
set -e
2426

@@ -221,9 +223,7 @@ required_apis=(
221223
)
222224
# Separately enable the internal-only Cloud Code API, ignoring errors
223225
# for public users who may not have access.
224-
gcloud services enable "cloudcode-pa.googleapis.com" --project="${GOOGLE_CLOUD_PROJECT}" || true
225226
gcloud services enable "${required_apis[@]}" --project="${GOOGLE_CLOUD_PROJECT}"
226-
gcloud services enable "cloudcode-pa.googleapis.com" --project="${GOOGLE_CLOUD_PROJECT}" || true
227227
print_success "APIs enabled successfully."
228228

229229
# Step 2: Create Workload Identity Pool
@@ -319,38 +319,10 @@ else
319319
fi
320320

321321
# Step 4: Grant required permissions to the Workload Identity Pool
322-
print_header "Step 4: Granting required permissions to Workload Identity Pool"
322+
print_header "(Skipped) Step 4: Granting required permissions to Workload Identity Pool"
323323
PRINCIPAL_SET="principalSet://iam.googleapis.com/${WIF_POOL_ID}/attribute.repository/${GITHUB_REPO}"
324324

325-
print_info "Granting required permissions directly to the Workload Identity Pool..."
326-
327-
# Observability permissions
328-
print_info "Granting logging permissions..."
329-
gcloud projects add-iam-policy-binding "${GOOGLE_CLOUD_PROJECT}" \
330-
--role="roles/logging.logWriter" \
331-
--member="${PRINCIPAL_SET}" \
332-
--condition=None
333-
334-
print_info "Granting monitoring permissions..."
335-
gcloud projects add-iam-policy-binding "${GOOGLE_CLOUD_PROJECT}" \
336-
--role="roles/monitoring.metricWriter" \
337-
--member="${PRINCIPAL_SET}" \
338-
--condition=None
339-
340-
print_info "Granting tracing permissions..."
341-
gcloud projects add-iam-policy-binding "${GOOGLE_CLOUD_PROJECT}" \
342-
--role="roles/cloudtrace.agent" \
343-
--member="${PRINCIPAL_SET}" \
344-
--condition=None
345-
346-
# Model inference permissions
347-
print_info "Granting vertex permissions..."
348-
gcloud projects add-iam-policy-binding "${GOOGLE_CLOUD_PROJECT}" \
349-
--role="roles/aiplatform.user" \
350-
--member="${PRINCIPAL_SET}" \
351-
--condition=None
352-
353-
print_success "Required permissions granted to Workload Identity Pool"
325+
print_info "(Skipped) Granting required permissions directly to the Workload Identity Pool..."
354326

355327
# Step 5: Create and Configure Service Account for Gemini CLI
356328
print_header "Step 5: Create and Configure Service Account for Gemini CLI"

0 commit comments

Comments
 (0)