Applying Signed URLs to Cloud Storage Objects

30 minutes
  • 3 Learning Objectives

About this Hands-on Lab

By default, the contents of Cloud Storage buckets are not publicly available. You can, however, make an object or an entire bucket viewable by all. But sometimes neither of these approaches – totally blocking or totally allowing access – is the right one. Google Cloud offers a method for providing limited access to one or more individuals for a specified time: the signed URL. Anyone using the signed URL can access a secure bucket object for the predetermined period, regardless of whether they are in your organization or even have a Google account. In this hands-on lab, we’ll set up a bucket with an object that is not publicly available and then create the necessary structure – a service account with a private key – required to generate the signed URL.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a Cloud Storage Bucket and Copy the File to It
  1. Activate the Cloud Shell.
  2. When it spins up, create the necessary bucket.
    gsutil mb -c regional -l us-east1 gs://[BUCKET_NAME]

    (Note: The bucket name must be unique.)

  3. Clone the GitHub repository:
    git clone
  4. Change directory to the content-gcpro-security-engineer/signed-url-lab folder:
    cd content-gcpro-security-engineer/signed-url-lab
  5. Copy the file to the bucket:
    gsutil cp restricted-logo.png gs://[BUCKET_NAME]
Create a Service Account and Key
  1. In the Cloud Shell, run the following code to establish a variable:
  2. Create a service account with the proper permissions:
    gcloud iam service-accounts create la-service-account –display-name "LA Service Account"
    gcloud projects add-iam-policy-binding ${PROJECT_ID} –member serviceAccount:la-service-account@${PROJECT_ID} –role roles/viewer
  3. Create a JSON key for authentication:
    gcloud iam service-accounts keys create key.json –iam-account la-service-account@${PROJECT_ID}
Generate a Signed URL
  1. In the Cloud Shell, install the openssl headers for Debian GNU/Linux

    sudo apt-get install build-essential libssl-dev libffi-dev 
    python3-dev cargo
  2. In the Cloud Shell, install the required library:
    sudo -H pip3 install --upgrade pip        
    sudo pip3 install pyopenssl
  3. Generate the signed URL:
    gsutil signurl -d 10m key.json gs://[BUCKET_NAME]/restricted-logo.png
  4. Test the URL by clicking the generated link.

Additional Resources

Your team is working with a number of outside contractors who will need to have limited access to materials stored in Cloud Storage buckets. You’ve been asked to lay the groundwork for signed URLs to be made available to them.

You’ll need to complete the following steps to accomplish your task:

  1. Make a Cloud Storage bucket.
  2. Copy the file to the bucket.
  3. Create a service account and private key.
  4. Generate a signed URL.
  5. Test the signed URL.

Note: When installing pyopenssl, use: sudo -H pip3 install --upgrade pip sudo pip3 install pyopenssl

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?