I am trying to migrate data from our firebase dev project to our firebase test project using the gcloud cli. To accomplish the task I have created the following script.
#!/bin/bash
SRC_PROJECT=$1
SRC_ACCOUNT="importexport@$SRC_PROJECT.iam.gserviceaccount.com"
SRC_CREDENTIALS=/home/$SRC_PROJECT.json
DEST_PROJECT=$2
DEST_ACCOUNT="importexport@$DEST_PROJECT.iam.gserviceaccount.com"
DEST_CREDENTIALS=/home/$DEST_PROJECT.json
GCLOUD_STORAGE=$3
echo "-------------------------------------------"
echo " Activate Service Account $SRC_PROJECT"
echo "-------------------------------------------"
gcloud --quiet config set project ${SRC_PROJECT}
gcloud beta auth activate-service-account ${SRC_ACCOUNT} --key-file=${SRC_CREDENTIALS}
echo "-------------------------------------------"
echo " Exporting $SRC_PROJECT"
echo "-------------------------------------------"
gcloud beta firestore export $GCLOUD_STORAGE > ./meta.txt
echo "-------------------------------------------"
echo " Activate Service Account $DEST_PROJECT"
echo "-------------------------------------------"
gcloud --quiet config set project ${DEST_PROJECT}
gcloud beta auth activate-service-account ${DEST_ACCOUNT} --key-file=${DEST_CREDENTIALS}
echo "-------------------------------------------"
echo "Importing $DEST_PROJECT $(grep -o 'gs://.*$' ./meta.txt)"
echo "-------------------------------------------"
gcloud beta firestore import $(grep -o 'gs://.*$' ./meta.txt)
This script assumes that you have credentials files located in /home that follow the naming convension of <project_id>.json. It further assumes that a service account has been created for both source project and dest project that follows the naming convention of importexport@<project_id>.iam.gserviceaccount.com.
Running the script is as simple as executing the following ...
%> ./migrate.sh dev-project-id test-project-id google-storage
I have ensured that the service accounts both have permissions for the same GCLOUD_STORAGE. And yet I am still getting the following error:
ERROR: (gcloud.beta.firestore.import) PERMISSION_DENIED: The caller does not have permission
Has anyone else tried to accomplish something similar? Any idea why I would still have a permission issue?
Here are the permissions I have assigned to both accounts and both accounts are added as members in each others storage.
- Cloud Datastore Import Export Admin
- Cloud Datastore Owner
- Cloud Filestore Editor
- Firebase Admin
- Owner
- Storage Admin