[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-27。"],[],[],null,["# Use signed requests\n\nTo create a signed request, compose a string that includes parameters that\ndescribe the content that you want to protect and the expiration time of the\nsigned value. You then include the composed string in your request.\nMedia CDN then verifies that your signed request is valid before\nacting upon it.\n\n### Signed request requirements\n\nSigned requests must meet the following requirements:\n\n- Have a `GET`, `HEAD`, or `OPTIONS` HTTP method. Other methods are not\n supported.\n\n- Have an expiration time set in the future. Due to potential clock\n synchronization differences, as well as client network conditions (for\n example, disconnects and retries), we recommend setting timestamps no\n less than one minute into the future, or no less than the length of the\n video stream, whichever is greater.\n\n- Have a signature that can be verified by a key or secret in an\n `EdgeCacheKeyset`.\n\nYou cannot sign other HTTP methods, such as `POST`, `PUT`, or `DELETE` requests.\nIf you need to issue signed URLs for user-facing uploads, see the\n[Cloud Storage documentation for signed URLs](/storage/docs/access-control/signed-urls).\n\nConfigure signed requests\n-------------------------\n\nThe following sections detail how to configure, sign, and validate signed\nrequests.\n\n### Generate keys\n\n[Create the keys](/media-cdn/docs/create-keys) that Media CDN uses to sign\nrequests.\n\n### Create a keyset\n\n[Create the keyset](/media-cdn/docs/create-keyset) that Media CDN uses\nfor signed requests.\n\n### Require signed requests\n\nTo allow only signed requests to access a resource, you can attach a\nlist of keys to a route and set the `signedRequestMode` to one of the following:\n\n- `REQUIRE_SIGNATURES` for signed requests not using tokens.\n\n- `REQUIRE_TOKENS` for signed requests using tokens.\n\nEnabling signed requests on a route enforces that all requests are signed or\npresent a token. Requests without a valid signature (such as an invalid key\nname, expired signature or token, mismatched signature, and so on), fail.\n\nAn `EdgeCacheKeyset` can contain multiple keys to allow for key\nrotation. Valid requests signed with any listed key are accepted, and keys\nare tried in order. For more information about key rotation, see [Rotate\nsecrets](/media-cdn/docs/rotate-secrets).\n\nWhen the `signedRequestMode` is set to `REQUIRE_SIGNATURES` or `REQUIRE_TOKENS`,\nMedia CDN validates both cache hits and misses. This includes all\nrequests to the origin.\n\nFollowing is an example of a Media CDN configuration that\nenforces signed requests on a given PathMatcher (route): \n\n```\ngcloud edge-cache services describe prod-media-service\n```\nOutput: \n\n```yaml\n...\n routeAction:\n cdnPolicy:\n cacheMode: CACHE_ALL_STATIC\n signedRequestMode: REQUIRE_SIGNATURES\n signedRequestKeyset: prod-vod-keyset\n```\n\nFor information on creating tokens for signed requests, see [Generate\ntokens](/media-cdn/docs/generate-tokens).\n\nTo disable request signing, you can set the `signedRequestMode` to `DISABLED`\nand delete the reference to the `signedRequestKeyset`.\n\n### Validate requests at the origin\n\nWhen a route is configured with a signing mode of `REQUIRE_SIGNATURES`,\nMedia CDN validates that every matching request has a valid\nsignature. The lack of a signature is treated as an invalid signature for these\nroutes.\n\nTo prevent cases where signing is misconfigured, and where a user\nattempts to access your origin directly, we recommend that you\nvalidate that requests are signed at the origin as well. A *defense in depth*\napproach to content protection helps prevent unauthorized access and download\nof your licensed and paid content.\n\nFor URL-based signing methods, where the signature is part of the query\nparameters or embedded as a URL path component, the signature and related\nparameters are removed from the URL before the request is sent to the\norigin. This prevents the signature from causing routing issues when the\norigin is handling the request. To validate these requests, you can inspect the\n`x-client-request-url` request header, which includes the original (signed)\nclient request URL prior to the removal of the signed components.\n| **Note:** If you are using Cloud Storage and have removed the `allUsers` (public access) permission, Cloud Storage rejects unauthenticated, public access to content on your behalf.\n\nTo validate requests at the origin, use the same validation code as part of\nyour request signing endpoints, which also helps mitigate key mismatch and\nissues due to key rotation.\n\n### Rotate keys\n\nAs a best practice, [rotate or update the secrets](/media-cdn/docs/rotate-secrets) used by\nMedia CDN regularly. We recommend rotating keys every 30 to 60\ndays, but it isn't strictly required.\n\nWhat's next\n-----------\n\n- To read more about how to enable and access Media CDN\n logs, including how to filter and query across your logs, see\n [Logging](/media-cdn/docs/logging).\n\n- To configure Media CDN and a\n private Cloud Storage bucket, see\n [Origin connectivity and shielding](/media-cdn/docs/origins)."]]