Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Nesta página, você encontra uma visão geral da autenticação de origem particular e instruções
para usá-la com o Cloud CDN.
A autenticação de origem particular dá ao Cloud CDN acesso de longo prazo a recursos de buckets particulares do Amazon S3 ou a outros armazenamentos de objetos compatíveis. O uso de
origens particulares impede que os clientes ignorem
o Cloud CDN e acessem a origem diretamente.
Esse recurso é compatível com o Cloud CDN com um balanceador de carga de aplicativo externo global ou um balanceador de carga de aplicativo clássico.
A autenticação de origem particular é voltada para a origem, enquanto os
URLs assinados
e os cookies assinados são voltados para o cliente. É
possível ativar ambos para o mesmo conteúdo. A autenticação de origem particular limita
o acesso não CDN às suas origens e conteúdo. URLs e cookies assinados controlam
quais usuários podem acessar o Cloud CDN.
Antes de começar
Crie uma chave de código de autenticação de mensagem baseada em hash (HMAC) para autenticar
solicitações e associá-la a uma conta de serviço. Anote a chave de acesso e a chave secreta.
Se o armazenamento de objetos espera um valor específico para o cabeçalho Host da solicitação
HTTP, verifique se ele está configurado no serviço de back-end. Se você não configurar um
cabeçalho de solicitação personalizado, um serviço de back-end preservará o cabeçalho Host usado pelo cliente
para se conectar ao balanceador de carga de aplicativo externo do Google Cloud.
Clique no nome da origem que você quer configurar. A origem precisa
ser do tipo Origem personalizada.
Na página Detalhes da origem, clique no botão Editar.
Para navegar até a seção Regras de host e caminho, clique em Próxima.
Para navegar até a seção Desempenho do cache, clique em Próxima.
Na seção Autenticação de origem particular, selecione
Autentique solicitações para a origem com o AWS Signature versão 4.
Em seguida, especifique as seguintes informações:
ID da chave: chave de acesso do bucket do Amazon S3 ou de outro armazenamento de objetos compatível.
Chave: a chave secreta usada para autenticar o acesso ao repositório de objetos.
Se você estiver usando um bucket particular do Cloud Storage, especifique a chave HMAC.
Versão da chave: um nome exclusivo para representar a versão da chave.
Região: a região em que o Object Storage está localizado, por
exemplo, us-east-1.
Clique em Concluído.
gcloud
Exporte a configuração de back-end da origem particular para um arquivo YAML usando o comando gcloud compute backend-services export:
Substitua DESTINATION pelo nome do arquivo YAML,
por exemplo, my-private-origin.yaml.
Para autenticar suas solicitações de back-end usando a chave HMAC,
especifique essas opções de configuração adicionais na
seção securitySettings de backendServices:
Para autenticar suas solicitações de back-end usando a chave HMAC, especifique essas
opções de configuração adicionais na seção securitySettings de
backendServices.
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices
PUT https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/BACKEND_SERVICE
Adicione o seguinte snippet ao corpo da solicitação JSON:
O nome do serviço é definido automaticamente como s3 para criar a assinatura.
Depois que essas configurações estiverem em vigor, o Cloud CDN vai gerar um
cabeçalho de autorização HTTP para todas as solicitações da origem.
Armazenar em cache respostas autenticadas de forma particular
Talvez você queira garantir que o conteúdo autenticado de forma particular seja armazenado em cache pelo
Cloud CDN.
Para fazer isso, defina o modo de cache
como Forçar cache de todo o conteúdo e especifique um TTL para que todo o conteúdo veiculado pela
origem seja armazenado em cache.
Como alternativa, se você não quiser forçar todo o conteúdo a ser armazenado em cache da mesma maneira,
mude o modo de cache para Usar a configuração de origem com base nos cabeçalhos Cache-Control
ou Armazenar em cache o conteúdo estático e verifique se o cabeçalho Cache-Control está
definido corretamente no conteúdo veiculado pela origem.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-11 UTC."],[[["\u003cp\u003ePrivate origin authentication enables Cloud CDN to securely access private Amazon S3 buckets or compatible object stores, preventing direct client access to the origin.\u003c/p\u003e\n"],["\u003cp\u003eThis feature is compatible with Cloud CDN using either a global external Application Load Balancer or a classic Application Load Balancer, and only supports the \u003ccode\u003eGET\u003c/code\u003e, \u003ccode\u003eHEAD\u003c/code\u003e, \u003ccode\u003eOPTIONS\u003c/code\u003e, and \u003ccode\u003eTRACE\u003c/code\u003e HTTP methods.\u003c/p\u003e\n"],["\u003cp\u003eConfiguration involves creating a hash-based message authentication code (HMAC) key, associating it with a service account, and configuring the backend service with the access key ID, access key, and region.\u003c/p\u003e\n"],["\u003cp\u003ePrivate origin authentication is origin-facing, contrasting with client-facing signed URLs and cookies, and it can be enabled alongside these other authentication options.\u003c/p\u003e\n"],["\u003cp\u003eTo ensure privately authenticated content is cached, you should set Cloud CDN's cache mode to "Force cache all content" or "Use origin setting based on Cache-Control headers", or "Cache static content" and verify the \u003ccode\u003eCache-Control\u003c/code\u003e header on the origin's content.\u003c/p\u003e\n"]]],[],null,["This page provides an overview of private origin authentication and instructions\nfor using it with Cloud CDN.\n\nPrivate origin authentication gives Cloud CDN long-term resource access\nto private Amazon S3 buckets or other compatible object stores. Using\nprivate origins prevents clients from bypassing\nCloud CDN and accessing your origin directly.\n\nThis feature is supported for Cloud CDN with either a\nglobal external Application Load Balancer or a classic Application Load Balancer.\n\nPrivate origin authentication is origin-facing, while\n[signed URLs](/cdn/docs/using-signed-urls)\nand [signed cookies](/cdn/docs/using-signed-cookies) are client-facing. You\ncan enable both for the same content. Private origin authentication limits\nnon-CDN access to your origins and content. Signed URLs and cookies control\nwhich users can access Cloud CDN.\n| **Note:** This feature supports only the `GET`, `HEAD`, `OPTIONS`, and `TRACE` HTTP methods.\n\nBefore you begin\n\n- Create a hash-based message authentication code (HMAC) key to authenticate\n requests and associate it with a service account. Make a note of the access\n key and secret.\n\n See [Accessing AWS using your AWS credentials: Programmatic Access](https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys) in AWS documentation.\n- [Configure a load balancer with the external backend](/load-balancing/docs/https/setting-up-https-external-backend-internet-neg#config-lb-external-backend).\n\n If your object store expects a particular value for the HTTP request's `Host`\n header, make sure that it is configured in the backend service. If you don't\n configure a custom request header, the backend service preserves the `Host`\n header that the client used to connect to the external Application Load Balancer.\n\n For configuration steps, see\n [Working with custom request headers](/load-balancing/docs/https/custom-headers#working-with-request).\n For a specific example, see\n [Configuring a load balancer with an external backend](/load-balancing/docs/https/setting-up-https-external-backend-internet-neg#config-lb-external-backend).\n- If necessary, update to the latest version of the Google Cloud CLI:\n\n ```\n gcloud components update\n ```\n\nConfigure authentication for private origins\n\nTo configure private origin authentication, use the following instructions: \n\nConsole\n\n1. In the Google Cloud console, go to the **Cloud CDN** page.\n\n [Go to Cloud CDN](https://console.cloud.google.com/networking/cdn/list)\n2. Click the name of the origin that you want to configure. The origin must\n be of the **Custom origin** type.\n\n3. On the **Origin details** page, click the **Edit** button.\n\n4. To navigate to the **Host and path rules** section, click **Next**.\n\n5. To navigate to the **Cache performance** section, click **Next**.\n\n6. In the **Private origin authentication** section, select\n **Authenticate requests to this origin with AWS Signature Version 4**.\n Then, specify the following information:\n\n - **Key ID**: access key for your Amazon S3 bucket or other compatible object store.\n - **Key**: the secret key used to authenticate to the object store. If you're using a private Cloud Storage bucket, specify the HMAC key.\n - **Key version**: a unique name to represent the key version.\n - **Region** : the region that your object store is located in---for example, `us-east-1`.\n7. Click **Done**.\n\ngcloud\n\n1. Export the backend configuration for your private origin into a\n YAML file by using the `gcloud compute backend-services export`\n command:\n\n ```\n gcloud compute backend-services export BACKEND_SERVICE_NAME \\\n [--destination=DESTINATION]\n ```\n\n Replace \u003cvar translate=\"no\"\u003eDESTINATION\u003c/var\u003e with the name of the YAML\n file---for example, `my-private-origin.yaml`.\n2. To authenticate your backend requests by using the HMAC key,\n specify these additional configuration options in the\n `securitySettings` section of `backendServices`:\n\n ```\n securitySettings:\n awsV4Authentication:\n accessKeyId: ACCESS_KEY_ID\n accessKey: ACCESS_KEY\n [accessKeyVersion: ACCESS_KEY_VERSION]\n originRegion: REGION\n …]\n ```\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eACCESS_KEY_ID\u003c/var\u003e: the HMAC access key ID\n - \u003cvar translate=\"no\"\u003eACCESS_KEY\u003c/var\u003e: the HMAC access key\n - \u003cvar translate=\"no\"\u003eACCESS_KEY_VERSION\u003c/var\u003e (optional): a unique name that you can set to represent the key version\n - \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e: a valid region for your storage provider. For Amazon S3, the value is not a Google Cloud region.\n\n The following snippet shows the contents of a sample\n `my-private-origin.yaml` file: \n\n name: shopping-cart-services\n backends:\n - description: cart-backend-1\n group: 'https://www.googleapis.com/compute/v1/projects/my-project-id/global/networkEndpointGroups/my-network-origin-group'\n securitySettings:\n awsV4Authentication:\n accessKeyId: AKIDEXAMPLE\n accessKey: c4afb1cc5771d871763a393e44b703571b55cc28424d1a5e86da6ed3c154a4b9\n accessKeyVersion: prod-access-key-v1.2\n originRegion: us-east-2\n\n3. To update your private origin, import the configuration to your\n backend service by using the\n `gcloud compute backend-services import` command:\n\n ```\n gcloud compute backend-services import BACKEND_SERVICE_NAME \\\n [--source=SOURCE]\n ```\n\n Replace \u003cvar translate=\"no\"\u003eSOURCE\u003c/var\u003e with the name of the YAML file.\n\nAPI\n\nTo authenticate your backend requests by using the HMAC key, specify these\nadditional configuration options in the `securitySettings` section of\n`backendServices`.\n\nUse the\n[`Method: backendServices.insert`](/compute/docs/reference/rest/v1/backendServices/insert) or\n[`Method: backendServices.update`](/compute/docs/reference/rest/v1/backendServices/update)\nAPI call. \n\n```\nPOST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices\nPUT https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/backendServices/BACKEND_SERVICE\n```\n\nAdd the following snippet to the JSON request body: \n\n```\nsecuritySettings: {\n awsV4Authentication: {\n accessKeyId: ACCESS_KEY_ID,\n accessKey: ACCESS_KEY,\n [accessKeyVersion: ACCESS_KEY_VERSION],\n originRegion: REGION\n }\n}\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003eACCESS_KEY_ID\u003c/var\u003e: the HMAC access key ID\n- \u003cvar translate=\"no\"\u003eACCESS_KEY\u003c/var\u003e: the HMAC access key\n- \u003cvar translate=\"no\"\u003eACCESS_KEY_VERSION\u003c/var\u003e (optional): a unique name that you can set to represent the key version\n- \u003cvar translate=\"no\"\u003eREGION\u003c/var\u003e: a valid region for your storage provider. For Amazon S3, the value is not a Google Cloud region.\n\nThe following snippet shows the contents of a sample\nJSON request body: \n\n```\nsecuritySettings: {\n awsV4Authentication: {\n accessKeyId: \"AKIDEXAMPLE\",\n accessKey: \"c4afb1cc5771d871763a393e44b703571b55cc28424d1a5e86da6ed3c154a4b9\",\n accessKeyVersion: \"prod-access-key-v1.2\",\n originRegion: \"us-east-2\"\n }\n}\n```\n\nThe service name is automatically set to `s3` for creating the signature.\nAfter these configurations are in place, Cloud CDN generates an\nHTTP Authorization header for all requests to your origin.\n\nCache privately authenticated responses\n\nYou might want to ensure that privately authenticated content is cached by\nCloud CDN.\n\nTo do this, set the [cache mode](/cdn/docs/using-cache-modes#cache-mode)\nto **Force cache all content** and specify a TTL, so that all content served from\nthe origin is cached.\n\nAlternatively, if you don't want to force all content to be cached the same way,\nchange the cache mode to **Use origin setting based on Cache-Control headers**\nor **Cache static content** and ensure that the `Cache-Control` header is\ncorrectly set on content served from your origin.\n\nWhat's next\n\n- [Web security best practices](/cdn/docs/web-security-best-practices)"]]