-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub_actions.bash
More file actions
44 lines (37 loc) · 1.93 KB
/
github_actions.bash
File metadata and controls
44 lines (37 loc) · 1.93 KB
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
# Set variables
export PROJECT_ID="your-project-id"
export POOL_NAME="github-actions-pool"
export PROVIDER_NAME="github-provider"
export SERVICE_ACCOUNT_NAME="github-actions-dbt"
export REPO="your-github-org/your-repo-name"
# Create service account (yes, you need one but only for WIF)
gcloud iam service-accounts create ${SERVICE_ACCOUNT_NAME} \
--display-name="GitHub Actions DBT"
# Grant necessary roles
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
--member="serviceAccount:${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com" \
--role="roles/bigquery.dataEditor"
gcloud projects add-iam-policy-binding ${PROJECT_ID} \
--member="serviceAccount:${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com" \
--role="roles/bigquery.jobUser"
# Create Workload Identity Pool
gcloud iam workload-identity-pools create ${POOL_NAME} \
--location="global" \
--display-name="GitHub Actions Pool"
# Create Workload Identity Provider
gcloud iam workload-identity-pools providers create-oidc ${PROVIDER_NAME} \
--location="global" \
--workload-identity-pool=${POOL_NAME} \
--issuer-uri="https://token.actions.githubusercontent.com" \
--attribute-mapping="google.subject=assertion.sub,attribute.repository=assertion.repository,attribute.actor=assertion.actor" \
--attribute-condition="assertion.repository=='${REPO}'"
# Allow GitHub Actions to impersonate the service account
gcloud iam service-accounts add-iam-policy-binding \
${SERVICE_ACCOUNT_NAME}@${PROJECT_ID}.iam.gserviceaccount.com \
--role="roles/iam.workloadIdentityUser" \
--member="principalSet://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/${POOL_NAME}/attribute.repository/${REPO}"
# Get the provider name for GitHub secrets
gcloud iam workload-identity-pools providers describe ${PROVIDER_NAME} \
--location="global" \
--workload-identity-pool=${POOL_NAME} \
--format="value(name)"