Configure Secure CORS for Cloud Storage (Solution)

Configure Secure CORS for Cloud Storage (Solution)

Configure Secure CORS for Cloud Storage

experimentLabschedule10 minutesuniversal_currency_altNo costshow_chartIntroductory

infoThis lab may incorporate AI tools to support your learning.

Lab instructions and tasks

Google Cloud self-paced labs logo

Overview

  • Labs are timed and cannot be paused. The timer starts when you click Start Lab.

  • The included cloud terminal is preconfigured with the gcloud SDK.

  • Use the terminal to execute commands and then click Check my progress to verify your work.

Challenge scenario

Your company which is into scientific research utilizes a Google Cloud Storage bucket for public data dissemination. A research partner of yours needs to access this data within their web application http://example.com but faces cross-origin access errors.

Configure secure CORS on the created bucket, specifically permitting GET requests from (http://example.com), adhering to least privilege.

Click Check my progress to verify the objective.

Configure secure CORS on the created bucket.


Solution of Lab

curl -LO raw.githubusercontent.com/ePlus-DEV/storage/refs/heads/main/labs/configure-secure-cors-for-cloud-storage-solution/lab.sh
source lab.sh

Script Alternative

echo '[{"origin":["http://example.com"],"method":["GET"],"responseHeader":["Content-Type"],"maxAgeSeconds":3600}]' > cors.json
gcloud storage buckets update gs://$(gcloud config get-value project)-bucket --cors-file=cors.json