-
Notifications
You must be signed in to change notification settings - Fork 384
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(firestore-bigquery-export): provided bash/ps1 scripts for granti…
…ng cross-project access to the extension (#2241)
- Loading branch information
Showing
5 changed files
with
210 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
firestore-bigquery-export/scripts/grant-crossproject-access.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# Help message | ||
function Show-Help { | ||
Write-Host "Usage: .\grant-crossproject-access.ps1 -FirebaseProject <PROJECT_ID> -BigQueryProject <PROJECT_ID> [-ExtensionInstanceId <INSTANCE_ID>]" | ||
Write-Host | ||
Write-Host "Parameters:" | ||
Write-Host " -FirebaseProject Firebase (source) project ID" | ||
Write-Host " -BigQueryProject BigQuery project ID where dataset will be created" | ||
Write-Host " -ExtensionInstanceId Extension instance ID (default: firestore-bigquery-export)" | ||
exit 1 | ||
} | ||
|
||
# Parameters | ||
param( | ||
[Parameter(Mandatory=$true)] | ||
[string]$FirebaseProject, | ||
|
||
[Parameter(Mandatory=$true)] | ||
[string]$BigQueryProject, | ||
|
||
[Parameter(Mandatory=$false)] | ||
[string]$ExtensionInstanceId = "firestore-bigquery-export" | ||
) | ||
|
||
# Construct service account email | ||
$ServiceAccount = "ext-${ExtensionInstanceId}@${FirebaseProject}.iam.gserviceaccount.com" | ||
|
||
Write-Host "Using service account: $ServiceAccount" | ||
Write-Host "Adding BigQuery permissions to $ServiceAccount on project: $BigQueryProject" | ||
|
||
$confirmation = Read-Host "Continue? (y/N)" | ||
if ($confirmation -notmatch '^[yY]$') { | ||
exit 1 | ||
} | ||
|
||
# Grant bigquery.dataEditor role | ||
gcloud projects add-iam-policy-binding $BigQueryProject ` | ||
--member="serviceAccount:$ServiceAccount" ` | ||
--role="roles/bigquery.dataEditor" | ||
|
||
# Grant bigquery.dataOwner which includes dataset.create permission | ||
gcloud projects add-iam-policy-binding $BigQueryProject ` | ||
--member="serviceAccount:$ServiceAccount" ` | ||
--role="roles/bigquery.dataOwner" |
53 changes: 53 additions & 0 deletions
53
firestore-bigquery-export/scripts/grant-crossproject-access.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/bash | ||
|
||
# Help message | ||
function show_help { | ||
echo "Usage: $0 -f FIREBASE_PROJECT -b BIGQUERY_PROJECT -i EXTENSION_INSTANCE_ID" | ||
echo | ||
echo "Options:" | ||
echo " -f Firebase (source) project ID" | ||
echo " -b BigQuery project ID where dataset will be created" | ||
echo " -i Extension instance ID (default: firestore-bigquery-export)" | ||
echo " -h Show this help message" | ||
exit 1 | ||
} | ||
|
||
# Set default extension instance ID | ||
EXT_INSTANCE_ID="firestore-bigquery-export" | ||
|
||
# Parse command line arguments | ||
while getopts "f:b:i:h" opt; do | ||
case $opt in | ||
f) FIREBASE_PROJECT="$OPTARG";; | ||
b) BIGQUERY_PROJECT="$OPTARG";; | ||
i) EXT_INSTANCE_ID="$OPTARG";; | ||
h) show_help;; | ||
?) show_help;; | ||
esac | ||
done | ||
|
||
# Check if required arguments are provided | ||
if [ -z "$FIREBASE_PROJECT" ] || [ -z "$BIGQUERY_PROJECT" ]; then | ||
echo "Error: Both Firebase and BigQuery project IDs are required" | ||
show_help | ||
fi | ||
|
||
# Construct service account email | ||
SERVICE_ACCOUNT="ext-${EXT_INSTANCE_ID}@${FIREBASE_PROJECT}.iam.gserviceaccount.com" | ||
|
||
echo "Using service account: $SERVICE_ACCOUNT" | ||
echo "Adding BigQuery permissions to $SERVICE_ACCOUNT on project: $BIGQUERY_PROJECT" | ||
read -p "Continue? (y/N) " -n 1 -r | ||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then | ||
exit 1 | ||
fi | ||
|
||
# Grant bigquery.dataEditor role | ||
gcloud projects add-iam-policy-binding $BIGQUERY_PROJECT \ | ||
--member="serviceAccount:$SERVICE_ACCOUNT" \ | ||
--role="roles/bigquery.dataEditor" | ||
|
||
# Grant bigquery.dataOwner which includes dataset.create permission | ||
gcloud projects add-iam-policy-binding $BIGQUERY_PROJECT \ | ||
--member="serviceAccount:$SERVICE_ACCOUNT" \ | ||
--role="roles/bigquery.dataOwner" |