Skip to content

[GCP] 將 Google Cloud Storage 改為公開存取的 bucket

Published: at 12:28 PM (2 min read)

Table of Contents

Open Table of Contents

描述

預設在建立 bucket 時,預設權限為僅限自己存取,因此你分享的連結只有自己能存取,因此你可能會遇到分享連結給其他人,卻無法存取的情況,若想要讓所有人都能公開存取,則要調整對應的權限設定

1️⃣ 將整個 bucket 設定為公開存取

  1. 建立 bucket 時,取消勾選 Enforce public access prevention on this bucket prevent-public-access
  2. 確定 bucket 的 Permissions 設定有正確的 Public access 設定 public-access
  3. 點擊 bucket 列表右方的 ... 按鈕,選擇 Edit access edit-access
  4. 點擊 Add principal add-principal
  5. New principals 欄位輸入 allUsersRole 欄位選擇 Storage Object Viewer add-principal-1
  6. 點擊 SaveAllow public access 按鈕 save-changes
  7. 在 bucket 列表中,你會看到預期的 Public access 設定 public-access-1
  8. 完成設定,現在你在 bucket 中的檔案連結可以公開存取給所有使用者 🎉

2️⃣ 僅開放特定檔案公開存取

  1. 建立 bucket 時,取消勾選 Enforce public access prevention on this bucket prevent-public-access
  2. 建立 bucket 時,Access control 的權限選擇 Fine-grained prevent-public-access
  3. 確定 bucket 的 Permissions 設定有正確的 Public access 設定 public-access
  4. 確定 bucket 的 Permissions 設定有正確的 Public access 設定 public-access public-access
  5. 點擊特定檔案的 Edit access edit-access
  6. 點擊 Add entry,並新增 allUsersPublic read 權限 add-entry
  7. 在檔案列表中,你會看到預期的 Public access 設定 public-access-2
  8. 完成設定,現在這個檔案的連結可以公開存取給所有使用者 🎉

參考資料


Next Post
[GCP] 如何設定 Google Cloud Storage 的自訂網域