LoginSignup
3
1

More than 3 years have passed since last update.

Firestoreでimportする際、権限エラーでハマった

Posted at

経緯

Firestoreのデータを別のプロジェクトに移すため、下記を参考に作業したがimportコマンドで権限エラーが出てハマった。そのときの対処メモ。

データのエクスポートとインポート
https://firebase.google.com/docs/firestore/manage-data/export-import?hl=ja

Cloud Firestore の import / export やってみた
https://qiita.com/star__hoshi/items/b500e6350f2ff8e991db

事象

gcloudコマンドでimportを打つとこんな感じのエラーが出る。
([BUCKET_NAME],[EXPORT_PREFIX],[firestore-projectid]は読み替えてください)

C:\Program Files (x86)\Google\Cloud SDK>gcloud firestore import gs://[BUCKET_NAME]/[EXPORT_PREFIX]/
ERROR: (gcloud.firestore.import) PERMISSION_DENIED: Service account does not have access to Google Cloud Storage file: [BUCKET_NAME]/[EXPORT_PREFIX]/[EXPORT_PREFIX].overall_export_metadata. See https://cloud.google.com/datastore/docs/export-import-entities#permissions for a list of permissions needed. Error details: [firebase-projectid]@appspot.gserviceaccount.com does not have storage.buckets.get access to the Google Cloud Storage bucket.

対処

こちらに書いてあるとおり、移行先の[firebase-projectid]に権限付与が必要でした。

プロジェクト間でデータを移動する
https://firebase.google.com/docs/firestore/manage-data/move-data?hl=ja#give_the_destination_project_access_to_your_data_files

gsutil iam ch serviceAccount:[firebase-projectid]@appspot.gserviceaccount.com:admin gs://[SOURCE_BUCKET]

このコマンド実行後にimportを打つとデータ移行できました。
最初からこの記事を見ていれば問題なかったですね。。

コマンド例

パラメータが下記の場合。

  • [firebase-projectid]:firebase-test
  • [SOURCE_BUCKET]:gcpstrage-test
gsutil iam ch serviceAccount:firebase-test@appspot.gserviceaccount.com:admin gs://gcpstrage-test

その他

Firebaseプロジェクトを有料プランに移行する、FirebaseプロジェクトとGCP Strage Bucketのリージョンは一致させる、作業用アカウントにも権限つけるなど注意することが色々あり、予想以上に大変でした。。

3
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
1