You need to let a customer download one private file from Cloud Storage — without making the bucket public, without creating a Google account for them, and without the link working forever. Google Cloud signed URLs are the standard answer: a URL that embeds a cryptographic signature and an expiry time, granting temporary access to exactly one object. Anyone with the link can download it until it expires; nobody else can guess a working link.

This guide shows how to create Google Cloud signed URLs with gcloud and with a service account in code, and how to avoid the mistakes that turn a temporary link into a permanent hole. For bucket setup fundamentals, see our Cloud Storage bucket and permissions guide, and for public hosting, our static website on Cloud Storage guide.
Prerequisites
- A Google Cloud project with a Cloud Storage bucket and at least one object in it.
- The
gcloudCLI installed and authenticated, or a service account key for programmatic signing. - A service account with permission to read the object (
storage.objects.get) — the signer needs access to the object it signs for.
How Google Cloud Signed URLs Work
A signed URL is an ordinary object URL with three extra query parameters: an expiry timestamp, the signing account’s email, and a signature computed over the request details with the service account’s private key. Cloud Storage verifies the signature and the expiry on every request, then serves the object if both check out. No Google sign-in is required from the downloader, and no bucket policy changes are needed.
Two properties follow from this design. First, the URL grants access to exactly one object and one operation (typically a GET download); it is not a login and it does not grant bucket access. Second, anyone who obtains the URL can use it until it expires — signed URLs are bearer tokens, so treat them like passwords in transit: serve them over HTTPS, send them only to the intended recipient, and keep expiries short.
Creating Google Cloud Signed URLs with gcloud
The fastest way to create a signed URL is the gcloud storage sign-url command. It needs a service account key file, because signing requires the private key:
gcloud storage sign-url gs://my-bucket/reports/annual-report.pdf \
--duration=1h \
--private-key-file=/path/to/service-account-key.json
The --duration flag sets how long the URL works — here, one hour. The command prints the full URL, which you can hand to the recipient. A few details matter: the maximum duration for a V4 signed URL is 7 days, the key file must belong to a service account with read access to the object, and the object must exist at signing time, because the signature covers its exact path.
To create a signed URL for an upload instead of a download, use a PUT request. This lets a client upload directly to your bucket without receiving your credentials:
gcloud storage sign-url gs://my-bucket/uploads/report.pdf \
--http-verb=PUT \
--content-type=application/pdf \
--duration=30m \
--private-key-file=/path/to/service-account-key.json
For PUT URLs, the client must send exactly the content type and headers that were signed; a mismatch makes Cloud Storage reject the request with a signature error. Keep PUT URLs short-lived — 30 minutes is a good default for uploads.
Generating Google Cloud Signed URLs in Code
In applications, you generate signed URLs at request time, after checking that the user is allowed to access the file. With the Python client library, the code is short:
from google.cloud import storage
from datetime import timedelta
client = storage.Client()
bucket = client.bucket("my-bucket")
blob = bucket.blob("reports/annual-report.pdf")
url = blob.generate_signed_url(
version="v4",
expiration=timedelta(hours=1),
method="GET",
)
print(url)
When this code runs on Compute Engine, Cloud Run, or GKE with a service account attached, it can sign using IAM signBlob instead of a downloaded key file — which avoids storing a private key on disk entirely. That is the preferred production pattern: attach a least-privilege service account to the workload, grant it roles/iam.serviceAccountTokenCreator on itself if needed, and let the library sign through IAM.
Always generate the URL after authorization, never before. The typical flow is: user requests a file, your application checks ownership or subscription status, and only then generates a short-lived signed URL. Generating URLs for every file on page load, before any check, defeats the purpose.
Expiry, Rotation, and Security Best Practices
Choose expiries by use case, not by convenience. Downloads for a logged-in user: 15 minutes to 1 hour. Email links that may be opened later: a few hours at most, and regenerate on click if you can. Never use the 7-day maximum for user-facing downloads — a leaked link stays valid for a week, and there is no way to revoke a single signed URL short of rotating the service account key, which invalidates every URL that key signed.
Other practices that matter: keep buckets private and grant access only through signed URLs or IAM, never by flipping a bucket public for convenience. Log signed URL generation in your application so you can audit who received access to what. And do not put signed URLs in public pages, analytics parameters, or referrer-visible locations — a URL in a page that third parties can view is a URL that third parties can use.
Troubleshooting Google Cloud Signed URLs
“Signature does not match” on download. The signed request differs from what was signed — a different HTTP method, content type, or header. For downloads, check that nothing rewrites the URL (some proxies and email clients do). For uploads, send exactly the headers that were signed.
403 Forbidden despite a fresh URL. The signing service account lacks storage.objects.get on the object, or the object path in the URL does not match the signed path. Verify the service account’s IAM binding on the bucket and re-check the object name for typos and encoding differences.
URL expired immediately. Clock skew between the signer and Google’s servers, or a duration parsed as seconds instead of the intended unit. Check the system clock on the signing host and confirm the expiry value in the URL’s X-Goog-Expires parameter.
Signing fails on Compute Engine without a key file. The workload’s service account needs IAM signing permission. Grant roles/iam.serviceAccountTokenCreator and use the client library’s IAM signing path instead of a key file.
Conclusion
Google Cloud signed URLs give private objects a safe, temporary public face: one object, one operation, one expiry — no accounts, no bucket policy changes, no permanent exposure. Generate them after authorization, keep expiries short, prefer IAM signing over key files, and treat every URL as a bearer token. The complete reference, including V4 signing details and all options, is in the Cloud Storage signed URLs documentation. Used this way, signed URLs are one of the simplest secure sharing mechanisms in cloud storage — and one of the easiest to get right.