-
Notifications
You must be signed in to change notification settings - Fork 0
/
register_wif.bash
52 lines (39 loc) · 1.79 KB
/
register_wif.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# follow https://github.com/google-github-actions/auth#setting-up-workload-identity-federation
# else run the below script after changing the top 3 variables
# replace with your project ID
export PROJECT_ID="realm-asgard"
# replace with your repo name you are creation deployment action on
export REPO="jenish-jain/bean_counter"
export SERVICE_ACCOUNT_ID="cloud-function-deployer"
# Roles required by SA #
# Cloud Functions Developer
# Cloud Functions Service Agent
# Secret Manager Secret Accessor
# Service Account Token Creator
# Service Account User
# Storage Admin
# Workload Identity User
gcloud iam service-accounts create "${SERVICE_ACCOUNT_ID}" \
--project "${PROJECT_ID}"
gcloud iam workload-identity-pools create "github-actions-pool" \
--project="${PROJECT_ID}" \
--location="global" \
--display-name="Github actions pool"
WPID=$(gcloud iam workload-identity-pools providers describe "github-actions" \
--project="${PROJECT_ID}" \
--location="global" \
--workload-identity-pool="github-actions-pool" \
--format="value(name)")
export WORKLOAD_IDENTITY_POOL_ID=$WPID
gcloud iam workload-identity-pools providers create-oidc "github-actions" \
--project="${PROJECT_ID}" \
--location="global" \
--workload-identity-pool="github-actions-pool" \
--display-name="Github actions provider" \
--attribute-mapping="google.subject=assertion.sub,attribute.actor=assertion.actor,attribute.repository=assertion.repository" \
--issuer-uri="https://token.actions.githubusercontent.com"
gcloud iam service-accounts add-iam-policy-binding "${SERVICE_ACCOUNT_ID}@${PROJECT_ID}.iam.gserviceaccount.com" \
--project="${PROJECT_ID}" \
--role="roles/iam.workloadIdentityUser" \
--member="principalSet://iam.googleapis.com/${WORKLOAD_IDENTITY_POOL_ID}/attribute.repository/${REPO}"