Skip to content

Instantly share code, notes, and snippets.

@Intelrunner
Created August 19, 2024 16:30
Show Gist options
  • Save Intelrunner/020dd81cd27a7389254d2512306355e0 to your computer and use it in GitHub Desktop.
Save Intelrunner/020dd81cd27a7389254d2512306355e0 to your computer and use it in GitHub Desktop.
To provide $USER view access to your BQ Admin Project ($PROJECT_ID) for reviewing Recommendation Engine reccs. View Only.
# Ensure these environment variables are set before running the script:
# export PROJECT_ID=<your-project-id>
# export USER_EMAIL=<user-email>
# export EXPIRATION_DATE=<expiration-date> # Format: YYYY-MM-DD
# Creates the custom role for BigQuery Reservations Viewer
gcloud iam roles create bigqueryReservationsViewer \
--project="$PROJECT_ID" \
--title="BigQuery Reservations Viewer" \
--permissions="bigquery.reservations.list,bigquery.reservationAssignments.list,bigquery.capacityCommitments.list" \
--stage="GA"
# Assigns the custom role to the specified user
gcloud projects add-iam-policy-binding "$PROJECT_ID" \
--member="user:$USER_EMAIL" \
--role="projects/$PROJECT_ID/roles/bigqueryReservationsViewer" \
--condition="expression=request.time < timestamp('$EXPIRATION_DATET23:59:00Z'), title='Temporary Access', description='Access expires on $EXPIRATION_DATE'"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment