This page provides an overview of signed URLs when working with the V2 signing process, which is a mechanism for query string authentication for buckets and objects. Signed URLs provide a way to give time-limited read or write access to anyone in possession of the URL, regardless of whether they have a Google account.
Components of the string that requires signing
When creating a signed URL using a program, your program constructs a string that will be signed. This string should be defined in your program as:
StringToSign = HTTP_Verb + "\n" + Content_MD5 + "\n" + Content_Type + "\n" + Expires + "\n" + Canonicalized_Extension_Headers + Canonicalized_Resource
The components that make up this structure are described in the following table:
||Required. The HTTP verb to be used with the signed URL.
Note: The HTTP verb
||Optional. The MD5 digest value in Base64. If you provide this in the string, the client (usually a browser) must provide this HTTP header with this same value in its request.|
||As needed. If you provide a content-type, the client (browser) must provide this HTTP header set to the same value.|
||Required. This is the timestamp (represented as the number of seconds since the Unix Epoch of 00:00:00 UTC on January 1, 1970) when the signature expires. The server rejects any requests received after this timestamp, as well as any requests received after the key used to generate the signed URL is rotated. For security and for compatibility with the V4 signing process, you should set
||As needed. The server checks to make sure that the client provides matching values in requests using the signed URL. For information about how to create canonical headers for signing, see Canonical extension headers.|
||Required. The resource being addressed in the URL. For more details, see Canonical resources.|
Signing strings with the App Engine App Identity service
When creating a signed URL using a program, you can either sign the string from within your program, or else from within a Google App Engine application using the App Engine Identity service, which uses App Engine's service account credentials. For example, using the Python App Identity API, you can:
google.appengine.api.app_identity.sign_blob()to sign the bytes from your constructed string, providing the
Signatureyou need when assembling the signed URL.
google.appengine.api.app_identity.get_service_account_name()to retrieve a service account name, which is the
GoogleAccessIdyou need when assembling the signed URL.
The App Identity service rotates the private keys when it signs blobs. Signed URLs generated from the App Identity service are good for at least one hour, and are best used for short-lived access to resources.
Canonical extension headers
When creating a signed URL using a program, you construct the Canonical
Extension Headers portion of the message by concatenating all
extension (custom) headers that begin with
x-goog-. However, you cannot perform a simple
concatenation. Keep the following algorithm in mind as you create the headers:
Make all custom header names lowercase.
Sort all custom headers by header name using a lexicographical sort by code point value.
If present, remove the
x-goog-encryption-key-sha256headers. These headers contain sensitive information that must not be included in the string-to-sign; however, these headers must still be used in any requests that use the generated signed URL.
Eliminate duplicate header names by creating one header name with a comma-separated list of values. Be sure there is no whitespace between the values, and be sure that the order of the comma-separated list matches the order that the headers appear in your request. For more information, see RFC 7230 section 3.2.
Replace any folding whitespace or newlines (CRLF or LF) with a single space. For more information about folding whitespace, see RFC 7230, section 3.2.4.
Remove any whitespace around the colon that appears after the header name.
Append a newline "\n" (U+000A) to each custom header.
Concatenate all custom headers.
When creating a signed URL using a program, you construct the Canonicalized Resource portion of the message by concatenating the resource path (bucket and object and subresource) that the request is acting on. Keep the following in mind as you create the resource:
The canonical resource is everything that follows the host name. For example, if the Cloud Storage URL is
https://storage.googleapis.com/example-bucket/cat-pics/tabby.jpeg, then the canonical resource is
If the request is scoped to a subresource, such as
?cors, add this subresource, including the question mark, to the end of the string.
Be sure to copy the HTTP request path literally: that is, you should include all URL encoding (percent signs) in the string that you create. Also, be sure that you include only query string parameters that designate subresources (such as
cors). You should not include query string parameters such as