Skip to content

Commit 7fedc6c

Browse files
authored
docs(firestore-bigquery-export): improve cross-project IAM docs (#2261)
1 parent fa8691d commit 7fedc6c

File tree

4 files changed

+37
-19
lines changed

4 files changed

+37
-19
lines changed

firestore-bigquery-export/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ feat - add basic materialized views support
44

55
fix - do not add/update clustering if an invalid clustering field is present.
66

7+
docs - improve cross-project IAM documentation
8+
79
## Version 0.1.56
810

911
feat - improve sync strategy by immediately writing to BQ, and using cloud tasks only as a last resort

firestore-bigquery-export/POSTINSTALL.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,30 @@ You can test out this extension right away!
44

55
1. Go to your [Cloud Firestore dashboard](https://console.firebase.google.com/project/${param:BIGQUERY_PROJECT_ID}/firestore/data) in the Firebase console.
66

7-
1. If it doesn't already exist, create the collection you specified during installation: `${param:COLLECTION_PATH}`
7+
2. If it doesn't already exist, create the collection you specified during installation: `${param:COLLECTION_PATH}`
88

9-
1. Create a document in the collection called `bigquery-mirror-test` that contains any fields with any values that you'd like.
9+
3. Create a document in the collection called `bigquery-mirror-test` that contains any fields with any values that you'd like.
1010

11-
1. Go to the [BigQuery web UI](https://console.cloud.google.com/bigquery?project=${param:BIGQUERY_PROJECT_ID}&p=${param:BIGQUERY_PROJECT_ID}&d=${param:DATASET_ID}) in the Google Cloud Platform console.
11+
4. Go to the [BigQuery web UI](https://console.cloud.google.com/bigquery?project=${param:BIGQUERY_PROJECT_ID}&p=${param:BIGQUERY_PROJECT_ID}&d=${param:DATASET_ID}) in the Google Cloud Platform console.
1212

13-
1. Query your **raw changelog table**, which should contain a single log of creating the `bigquery-mirror-test` document.
13+
5. Query your **raw changelog table**, which should contain a single log of creating the `bigquery-mirror-test` document.
1414

1515
```
1616
SELECT *
1717
FROM `${param:BIGQUERY_PROJECT_ID}.${param:DATASET_ID}.${param:TABLE_ID}_raw_changelog`
1818
```
1919
20-
1. Query your **latest view**, which should return the latest change event for the only document present -- `bigquery-mirror-test`.
20+
6. Query your **latest view**, which should return the latest change event for the only document present -- `bigquery-mirror-test`.
2121
2222
```
2323
SELECT *
2424
FROM `${param:BIGQUERY_PROJECT_ID}.${param:DATASET_ID}.${param:TABLE_ID}_raw_latest`
2525
```
2626
27-
1. Delete the `bigquery-mirror-test` document from [Cloud Firestore](https://console.firebase.google.com/project/${param:BIGQUERY_PROJECT_ID}/firestore/data).
27+
7. Delete the `bigquery-mirror-test` document from [Cloud Firestore](https://console.firebase.google.com/project/${param:BIGQUERY_PROJECT_ID}/firestore/data).
2828
The `bigquery-mirror-test` document will disappear from the **latest view** and a `DELETE` event will be added to the **raw changelog table**.
2929
30-
1. You can check the changelogs of a single document with this query:
30+
8. You can check the changelogs of a single document with this query:
3131
3232
```
3333
SELECT *
@@ -58,33 +58,39 @@ Enabling wildcard references will provide an additional STRING based column. The
5858
5959
By default, the extension exports data to BigQuery in the same project as your Firebase project. However, you can configure it to export to a BigQuery instance in a different Google Cloud project. To do this:
6060
61-
1. During installation, set the `BIGQUERY_PROJECT_ID` parameter to your target BigQuery project ID.
61+
1. During installation, set the `BIGQUERY_PROJECT_ID` parameter as your target BigQuery project ID.
6262
63-
2. After installation, you'll need to grant the extension's service account the necessary BigQuery permissions on the target project. You can use our provided scripts:
63+
2. Identify the service account on the source project associated with the extension. By default, it will be constructed as `ext-<extension-instance-id>@project-id.iam.gserviceaccount.com`. However, if the extension instance ID is too long, it may be truncated and 4 random characters appended to abide by service account length limits.
64+
65+
3. To find the exact service account, navigate to IAM & Admin -> IAM in the Google Cloud Platform Console. Look for the service account listed with "Name" as "Firebase Extensions <your extension instance ID> service account". The value in the "Principal" column will be the service account that needs permissions granted in the target project.
66+
67+
4. Grant the extension's service account the necessary BigQuery permissions on the target project. You can use our provided scripts:
6468
6569
**For Linux/Mac (Bash):**
6670
```bash
6771
curl -O https://raw.githubusercontent.com/firebase/extensions/master/firestore-bigquery-export/scripts/grant-crossproject-access.sh
6872
chmod +x grant-crossproject-access.sh
69-
./grant-crossproject-access.sh -f SOURCE_FIREBASE_PROJECT -b TARGET_BIGQUERY_PROJECT [-i EXTENSION_INSTANCE_ID]
73+
./grant-crossproject-access.sh -f SOURCE_FIREBASE_PROJECT -b TARGET_BIGQUERY_PROJECT [-i EXTENSION_INSTANCE_ID] [-s SERVICE_ACCOUNT]
7074
```
7175

7276
**For Windows (PowerShell):**
7377
```powershell
7478
Invoke-WebRequest -Uri "https://raw.githubusercontent.com/firebase/extensions/master/firestore-bigquery-export/scripts/grant-crossproject-access.ps1" -OutFile "grant-crossproject-access.ps1"
75-
.\grant-crossproject-access.ps1 -FirebaseProject SOURCE_FIREBASE_PROJECT -BigQueryProject TARGET_BIGQUERY_PROJECT [-ExtensionInstanceId EXTENSION_INSTANCE_ID]
79+
.\grant-crossproject-access.ps1 -FirebaseProject SOURCE_FIREBASE_PROJECT -BigQueryProject TARGET_BIGQUERY_PROJECT [-ExtensionInstanceId EXTENSION_INSTANCE_ID] [-ServiceAccount SERVICE_ACCOUNT]
7680
```
7781

7882
**Parameters:**
7983
For Bash script:
8084
- `-f`: Your Firebase (source) project ID
8185
- `-b`: Your target BigQuery project ID
8286
- `-i`: (Optional) Extension instance ID if different from default "firestore-bigquery-export"
87+
- `-s`: (Optional) Service account email. If not provided, it will be constructed using the extension instance ID
8388

8489
For PowerShell script:
8590
- `-FirebaseProject`: Your Firebase (source) project ID
8691
- `-BigQueryProject`: Your target BigQuery project ID
8792
- `-ExtensionInstanceId`: (Optional) Extension instance ID if different from default "firestore-bigquery-export"
93+
- `-ServiceAccount`: (Optional) Service account email. If not provided, it will be constructed using the extension instance ID
8894

8995
**Prerequisites:**
9096
- You must have the [gcloud CLI](https://cloud.google.com/sdk/docs/install) installed and configured

firestore-bigquery-export/scripts/grant-crossproject-access.ps1

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
# Help message
22
function Show-Help {
3-
Write-Host "Usage: .\grant-crossproject-access.ps1 -FirebaseProject <PROJECT_ID> -BigQueryProject <PROJECT_ID> [-ExtensionInstanceId <INSTANCE_ID>]"
3+
Write-Host "Usage: .\grant-crossproject-access.ps1 -FirebaseProject <PROJECT_ID> -BigQueryProject <PROJECT_ID> [-ExtensionInstanceId <INSTANCE_ID>] [-ServiceAccount <SERVICE_ACCOUNT>]"
44
Write-Host
55
Write-Host "Parameters:"
66
Write-Host " -FirebaseProject Firebase (source) project ID"
77
Write-Host " -BigQueryProject BigQuery project ID where dataset will be created"
88
Write-Host " -ExtensionInstanceId Extension instance ID (default: firestore-bigquery-export)"
9+
Write-Host " -ServiceAccount Service account email (optional, will be constructed if not provided)"
910
exit 1
1011
}
1112

@@ -18,11 +19,16 @@ param(
1819
[string]$BigQueryProject,
1920

2021
[Parameter(Mandatory=$false)]
21-
[string]$ExtensionInstanceId = "firestore-bigquery-export"
22+
[string]$ExtensionInstanceId = "firestore-bigquery-export",
23+
24+
[Parameter(Mandatory=$false)]
25+
[string]$ServiceAccount = ""
2226
)
2327

24-
# Construct service account email
25-
$ServiceAccount = "ext-${ExtensionInstanceId}@${FirebaseProject}.iam.gserviceaccount.com"
28+
# Construct service account email if not provided
29+
if (-not $ServiceAccount) {
30+
$ServiceAccount = "ext-${ExtensionInstanceId}@${FirebaseProject}.iam.gserviceaccount.com"
31+
}
2632

2733
Write-Host "Using service account: $ServiceAccount"
2834
Write-Host "Adding BigQuery permissions to $ServiceAccount on project: $BigQueryProject"

firestore-bigquery-export/scripts/grant-crossproject-access.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
# Help message
44
function show_help {
5-
echo "Usage: $0 -f FIREBASE_PROJECT -b BIGQUERY_PROJECT -i EXTENSION_INSTANCE_ID"
5+
echo "Usage: $0 -f FIREBASE_PROJECT -b BIGQUERY_PROJECT -i EXTENSION_INSTANCE_ID [-s SERVICE_ACCOUNT]"
66
echo
77
echo "Options:"
88
echo " -f Firebase (source) project ID"
99
echo " -b BigQuery project ID where dataset will be created"
1010
echo " -i Extension instance ID (default: firestore-bigquery-export)"
11+
echo " -s Service account email (optional, will be constructed if not provided)"
1112
echo " -h Show this help message"
1213
exit 1
1314
}
@@ -16,11 +17,12 @@ function show_help {
1617
EXT_INSTANCE_ID="firestore-bigquery-export"
1718

1819
# Parse command line arguments
19-
while getopts "f:b:i:h" opt; do
20+
while getopts "f:b:i:s:h" opt; do
2021
case $opt in
2122
f) FIREBASE_PROJECT="$OPTARG";;
2223
b) BIGQUERY_PROJECT="$OPTARG";;
2324
i) EXT_INSTANCE_ID="$OPTARG";;
25+
s) SERVICE_ACCOUNT="$OPTARG";;
2426
h) show_help;;
2527
?) show_help;;
2628
esac
@@ -32,8 +34,10 @@ if [ -z "$FIREBASE_PROJECT" ] || [ -z "$BIGQUERY_PROJECT" ]; then
3234
show_help
3335
fi
3436

35-
# Construct service account email
36-
SERVICE_ACCOUNT="ext-${EXT_INSTANCE_ID}@${FIREBASE_PROJECT}.iam.gserviceaccount.com"
37+
# Construct service account email if not provided
38+
if [ -z "$SERVICE_ACCOUNT" ]; then
39+
SERVICE_ACCOUNT="ext-${EXT_INSTANCE_ID}@${FIREBASE_PROJECT}.iam.gserviceaccount.com"
40+
fi
3741

3842
echo "Using service account: $SERVICE_ACCOUNT"
3943
echo "Adding BigQuery permissions to $SERVICE_ACCOUNT on project: $BIGQUERY_PROJECT"

0 commit comments

Comments
 (0)