Authentifizierung des privaten Ursprungs konfigurieren
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Auf dieser Seite finden Sie eine Übersicht über die Authentifizierung mit privatem Ursprung und eine Anleitung für die Verwendung mit Cloud CDN.
Die Authentifizierung über einen privaten Ursprung ermöglicht Cloud CDN langfristigen Ressourcenzugriff auf private Amazon S3-Buckets oder andere kompatible Objektspeicher. Wenn Sie private Ursprünge verwenden, können Clients Cloud CDN nicht umgehen und nicht direkt auf Ihren Ursprung zugreifen.
Diese Funktion wird für Cloud CDN mit einem globalen externen Application Load Balancer oder einem klassischen Application Load Balancer unterstützt.
Die Authentifizierung des privaten Ursprungs ist ursprünglich gerichtet, während signierte URLs und signierte Cookies clientseitig sind. Sie können beide für dieselben Inhalte aktivieren. Die Authentifizierung des privaten Ursprungs schränkt den Zugriff auf Ihre Ursprünge und Inhalte ein, der nicht über das CDN erfolgt. Mit signierten URLs und Cookies wird festgelegt, welche Nutzer auf Cloud CDN zugreifen können.
Hinweise
Erstellen Sie einen HMAC-Schlüssel (Hash-based Message Authentication Code), um Anfragen zu authentifizieren, und verknüpfen Sie ihn mit einem Dienstkonto. Notieren Sie sich den Zugriffsschlüssel und das Secret.
Wenn Ihr Objektspeicher für den Host-Header der HTTP-Anfrage einen bestimmten Wert erwartet, muss dieser im Back-End-Dienst konfiguriert sein. Wenn Sie keinen benutzerdefinierten Anfrageheader konfigurieren, behält der Backend-Dienst den Host-Header bei, den der Client für die Verbindung mit dem externen Application Load Balancer verwendet hat.
Klicken Sie auf den Namen der Quelle, die Sie konfigurieren möchten. Der Ursprung muss vom Typ Benutzerdefinierter Ursprung sein.
Klicken Sie auf der Seite Details zum Ursprung auf die Schaltfläche Bearbeiten.
Klicken Sie auf Weiter, um zum Abschnitt Host- und Pfadregeln zu gelangen.
Klicken Sie auf Weiter, um zum Abschnitt Cache-Leistung zu gelangen.
Wählen Sie im Abschnitt Authentifizierung des privaten Ursprungs die Option Anfragen an diesen Ursprung mit AWS Signature Version 4 authentifizieren aus.
Geben Sie dann die folgenden Informationen an:
Schlüssel-ID: Zugriffsschlüssel für Ihren Amazon S3-Bucket oder einen anderen kompatiblen Objektspeicher.
Key: Der geheime Schlüssel, der zur Authentifizierung beim Objektspeicher verwendet wird.
Wenn Sie einen privaten Cloud Storage-Bucket verwenden, geben Sie den HMAC-Schlüssel an.
Schlüsselversion: Ein eindeutiger Name für die Schlüsselversion.
Region: Die Region, in der sich Ihr Objektspeicher befindet, z. B. us-east-1.
Klicken Sie auf Fertig.
gcloud
Exportieren Sie die Backendkonfiguration für Ihren privaten Ursprung mit dem Befehl gcloud compute backend-services export in eine YAML-Datei:
Ersetzen Sie DESTINATION durch den Namen der YAML-Datei, z. B. my-private-origin.yaml.
Wenn du deine Backend-Anfragen mit dem HMAC-Schlüssel authentifizieren möchtest, gib die folgenden zusätzlichen Konfigurationsoptionen im Abschnitt securitySettings von backendServices an:
Wenn Sie Ihren privaten Ursprung aktualisieren möchten, importieren Sie die Konfiguration mit dem Befehl gcloud compute backend-services import in Ihren Backend-Dienst:
Ersetzen Sie SOURCE durch den Namen der YAML-Datei.
API
Wenn du deine Backendanfragen mit dem HMAC-Schlüssel authentifizieren möchtest, gib die folgenden zusätzlichen Konfigurationsoptionen im Abschnitt securitySettings von backendServices an.
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
Fügen Sie dem JSON-Anfragetext folgendes Snippet hinzu:
Der Dienstname wird beim Erstellen der Signatur automatisch auf s3 festgelegt.
Nachdem diese Konfigurationen eingerichtet sind, generiert Cloud CDN einen HTTP-Autorisierungsheader für alle Anfragen an Ihren Ursprung.
Antworten mit privater Authentifizierung im Cache speichern
Sie können dafür sorgen, dass privat authentifizierte Inhalte von Cloud CDN im Cache gespeichert werden.
Legen Sie dazu den Cache-Modus auf Alle Inhalte im Cache speichern fest und geben Sie eine TTL an, damit alle vom Ursprung bereitgestellten Inhalte im Cache gespeichert werden.
Wenn Sie nicht möchten, dass alle Inhalte auf dieselbe Weise im Cache gespeichert werden, können Sie den Cache-Modus auch in Auf Cache-Control-Headern basierende Ursprungsserver-Einstellungen verwenden oder Statische Inhalte im Cache speichern ändern. Achten Sie dabei darauf, dass der Cache-Control-Header für Inhalte, die von Ihrem Ursprung bereitgestellt werden, richtig festgelegt ist.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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)"]]