0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Cloud Storageで既存オブジェクトを上書きするときは削除権限も必要

Posted at

発生した問題

以下のようなコードで file.save() を実行した際、ファイルが既に存在する場合にエラーになっていた。

const content = "Hello, World!";
const storage = new Storage(storageOptions);
const bucket = storage.bucket("my-bucket");
const file = bucket.file("path/to/my-file.txt");
await file.save(Buffer.from(content, "utf-8"), {
  contentType: "text/plain",
});

原因

Cloud Storage に適用される IAM 権限  |  Google Cloud Documentation を確認すると以下の記述があった。

注: 既存のオブジェクトを置換するには、storage.objects.create と storage.objects.delete の両方の権限が必要です。

どうやら上書きは、「削除」→「作成」のような考え方らしく、createとdelete両方の権限が必要とのこと。
ちなみにupdate権限は存在しない。

結論

既存オブジェクトの置換には storage.objects.createstorage.objects.delete 両方必要。

該当のサービスアカウントに storage.objects.delete を追加したところ解決した。

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?