The Digital "VIP Ticket" for Your Private Content.
Cloud CDN is great for delivering public content like logos and style sheets. But what about content that should only be seen by specific, authenticated users? For example:
If you put this content in a public Cloud Storage bucket, anyone with the link can access it. Signed URLs are the solution to this problem.
Think of your private content as a VIP concert. A normal URL is like an address to the venue—anyone who has it can show up.
A **Signed URL** is like a special, non-transferable VIP ticket. It has three key properties:
The Core Idea: A Signed URL is a special, temporary URL that grants a user time-limited access to a private resource. It's generated on-the-fly by your application and "signed" with a secret key that only you and Google know.
Using Signed URLs involves two distinct phases: first, your application must generate the URL, and second, the user's browser uses it to access the content.
The user never signs the URL themselves. They access your web application, which verifies they are logged in and have permission to see the content. If they do, your application server generates the special URL.
The user's browser then uses this special, long URL to request the content. Google's Edge Cache intercepts the request and performs a series of checks.
| Term | What It Means |
|---|---|
| Signed URL | A URL with extra query parameters for an expiration time and a cryptographic signature that grants temporary access. |
| Origin | Your source server (e.g., a private Cloud Storage bucket) that holds the actual content. |
| Signed URL Key | A secret, random string of text that you generate. Your application uses this key to create the signature. You must keep this key private. |
| Signature | The unique, tamper-proof "holographic seal" attached to the URL, created using your secret key. |
This process requires you to have an existing Global External Application Load Balancer with Cloud CDN already enabled on its backend service.
First, we need to generate the secret key. This command creates a new, random key and saves it to a file on your local machine.
CRITICAL: Treat this key file like a password or a private SSH key. It must be stored securely and made available to your application server. Do not commit it to a public source code repository.
# Create a file to store the new key
head -c 16 /dev/urandom | base64 | tr -d '+/=' > cdn-key-file.txt
# Now, create the key within Cloud Armor using that file.
gcloud compute security-policies signed-url-keys create my-cdn-key \
--key-name=my-key-name \
--key-file=cdn-key-file.txt \
--project=my-gcp-project-12345
Now, you must "tell" your backend that it should expect and validate URLs signed with this specific key.
# This command updates your backend service to use the new key
gcloud compute backend-services update my-cdn-backend-service \
--signed-url-cache-max-age=3600 \
--signed-url-key-name=my-key-name \
--global
In a real application, your server-side code (in Python, Go, Node.js, etc.) would perform this step. However, for testing purposes, `gcloud` provides a handy command to simulate this process.
The URL you use here should be the public-facing URL of your load balancer, not the private address of your origin.
# This command simulates what your application server would do
gcloud compute sign-url \
"https://www.example.com/videos/private/course101.mp4" \
--key-name=my-key-name \
--key-file=cdn-key-file.txt \
--expires-in=10m
The command will output a very long URL containing `Expires`, `KeyName`, and `Signature` parameters. This is your temporary VIP ticket.