Wenn Sie Ihre Compute Engine-Instanz noch nicht eingerichtet haben, lesen Sie die vollständige Schritt-für-Schritt-Anleitung unter IAP für Compute Engine einrichten.
IAP verwendet einen von Google verwalteten OAuth-Client, um Nutzer zu authentifizieren.
Nur Nutzer innerhalb der Organisation können auf die IAP-kompatible App zugreifen. Wenn Sie Nutzern außerhalb Ihrer Organisation Zugriff gewähren möchten, lesen Sie den Hilfeartikel IAP für externe Anwendungen aktivieren.
Sie können IAP für einen Compute Engine-Back-End-Dienst oder eine Compute Engine-Weiterleitungsregel aktivieren.
Wenn Sie IAP für einen Compute Engine-Back-End-Dienst aktivieren, wird nur dieser Back-End-Dienst durch IAP geschützt. Wenn Sie IAP für eine Compute Engine-Weiterleitungsregel aktivieren, werden alle Compute Engine-Instanzen hinter der Weiterleitungsregel durch IAP geschützt.
IAP für eine Weiterleitungsregel aktivieren
Sie können IAP für eine Weiterleitungsregel mithilfe des Frameworks für Autorisierungsrichtlinien für Load Balancer aktivieren.
gcloud
Führen Sie den folgenden Befehl aus, um eine policy.yaml-Datei vorzubereiten.
$ cat << EOF > policy.yamlaction:CUSTOMdescription:authz policy with Cloud IAPname:AUTHZ_POLICY_NAMEcustomProvider:cloudIap:{}target:loadBalancingScheme:EXTERNAL_MANAGEDresources:-https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/forwardingRules/FORWARDING_RULE_IDEOF
Führen Sie den folgenden Befehl aus, um IAP für eine Weiterleitungsregel zu aktivieren.
IAP für einen Compute Engine-Back-End-Dienst aktivieren
Sie können IAP für einen Compute Engine-Back-End-Dienst über diesen Back-End-Dienst aktivieren.
Console
Der von Google verwaltete OAuth-Client ist nicht verfügbar, wenn Sie IAP über die Google Cloud -Konsole aktivieren.
Wenn Sie den OAuth-Zustimmungsbildschirm Ihres Projekts noch nicht konfiguriert haben, werden Sie dazu aufgefordert. Eine Anleitung dazu finden Sie unter OAuth-Zustimmungsbildschirm einrichten.
Wenn Sie GKE-Cluster der Version 1.24 oder höher verwenden, können Sie IAP und GKE mit der Kubernetes Gateway API konfigurieren. Führen Sie dazu die folgenden Schritte aus und folgen Sie dann der Anleitung unter IAP konfigurieren.
Konfigurieren Sie BackendConfig nicht.
Wählen Sie das Projekt aus, das Sie mit IAP sichern möchten.
Klicken Sie das Kästchen neben der Ressource an, für die Sie Zugriff gewähren möchten.
Wenn keine Ressource angezeigt wird, prüfen Sie, ob die Ressource erstellt wurde und der BackendConfig-Compute Engine-Ingress-Controller synchronisiert ist.
Führen Sie den folgenden gcloud-Befehl aus, um zu prüfen, ob der Backend-Dienst verfügbar ist:
gcloud compute backend-services list
Klicken Sie im rechten Bereich auf Hauptkonto hinzufügen.
Fügen Sie im daraufhin angezeigten Dialogfeld Hauptkonten hinzufügen die E-Mail-Adressen von Nutzergruppen oder einzelnen Nutzern hinzu, denen Sie für das Projekt die Rolle Nutzer von IAP-gesicherten Web-Apps zuweisen möchten.
Folgende Hauptkonten können diese Rolle haben:
Google-Konto: nutzer@gmail.com
Google Group: admins@googlegroups.com
Dienstkonto: server@beispiel.gserviceaccount.com
Google Workspace-Domain: beispiel.de
Fügen Sie unbedingt ein Google-Konto hinzu, auf das Sie zugreifen können.
Wählen Sie in der Drop-down-Liste Rollen den Eintrag Cloud IAP > Nutzer von IAP-gesicherten Web-Apps aus.
Klicken Sie auf Speichern.
IAP aktivieren
Suchen Sie auf der Seite Identity-Aware Proxy unter APPLICATIONS (ANWENDUNGEN) nach dem Load Balancer, über den instance group bereitgestellt wird, auf die Sie den Zugriff beschränken möchten. Verwenden Sie den Schieberegler in der Spalte IAP, um IAP für eine Ressource zu aktivieren.
So aktivieren Sie IAP:
Sie benötigen die Berechtigungen compute.backendServices.update, clientauthconfig.clients.create und clientauthconfig.clients.getWithSecret. Diese Berechtigungen erhalten Sie über Rollen wie "Projektbearbeiter". Weitere Informationen finden Sie unter Zugriff auf durch IAP gesicherte Ressourcen verwalten.
Klicken Sie im angezeigten Fenster IAP aktivieren auf Aktivieren, um zu bestätigen, dass die Ressource durch IAP gesichert werden soll. Nachdem Sie IAP aktiviert haben, sind für alle Verbindungen zu Ihrem Load-Balancer Anmeldedaten erforderlich.
Zugriff erhalten nur Konten mit der Rolle Nutzer von IAP-gesicherten Web-Apps für das Projekt.
gcloud
Bevor Sie Ihr Projekt und IAP einrichten, benötigen Sie eine aktuelle Version der gcloud CLI. Eine Anleitung zur Installation der gcloud CLI finden Sie unter gcloud CLI installieren.
Führen Sie zum Authentifizieren den folgenden Befehl über die Google Cloud CLI aus.
gcloud auth login
Folgen Sie der angezeigten URL, um sich anzumelden.
Kopieren Sie, nachdem Sie sich angemeldet haben, den angezeigten Bestätigungscode und fügen Sie ihn in die Befehlszeile ein.
Führen Sie den folgenden Befehl aus, um das Projekt anzugeben, das die Ressource enthält, die Sie mit IAP schützen möchten.
gcloud config set project PROJECT_ID
Führen Sie zum Aktivieren von IAP entweder den Befehl für die globale oder die regionale Ebene aus.
[[["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-09-03 (UTC)."],[[["\u003cp\u003eThis guide outlines the process of securing Compute Engine instances using Identity-Aware Proxy (IAP), which involves enabling IAP on either a backend service or a forwarding rule.\u003c/p\u003e\n"],["\u003cp\u003eTo enable IAP, you'll need a Google Cloud project with billing enabled, a load balancer serving Compute Engine instances, a registered domain name, and code to verify user identity.\u003c/p\u003e\n"],["\u003cp\u003eIAP utilizes a Google-managed OAuth client for user authentication, primarily allowing access to users within the organization, but can be configured for external users.\u003c/p\u003e\n"],["\u003cp\u003eIAP can be enabled on a Compute Engine forwarding rule using load balancer authorization policies, or directly on a backend service using the console, gcloud CLI, or API.\u003c/p\u003e\n"],["\u003cp\u003eOnce enabled, access to IAP-protected resources is managed by assigning the "IAP-Secured Web App User" role to specific Google accounts, groups, service accounts, or Google Workspace domains.\u003c/p\u003e\n"]]],[],null,["# Enable IAP for Compute Engine\n\nThis page explains how to secure a Compute Engine instance with\n[Identity-Aware Proxy (IAP)](/iap/docs/concepts-overview).\n\nBefore you begin\n----------------\n\nTo enable IAP for Compute Engine, you need the\nfollowing:\n\n- A Google Cloud console project with billing enabled.\n- A group of one or more Compute Engine instances, served by a load balancer.\n - Learn about [Setting up an external HTTPS load balancer](/load-balancing/docs/https/setting-up-https).\n - Learn about [setting up an internal HTTP load balancer](/load-balancing/docs/l7-internal/setting-up-l7-internal).\n- A domain name registered to the address of your load balancer.\n- Application code to verify that all requests have an identity.\n - Learn about [Getting the user's identity](/iap/docs/identity-howto).\n\nIf you don't have your Compute Engine instance set up already, see\n[Setting up IAP for Compute Engine](/iap/docs/tutorial-gce)\nfor a complete walkthrough.\n\nIAP uses a Google-managed OAuth client to authenticate users.\nOnly users within the organization can access the IAP-enabled\napplication. If you want to allow access to users outside of your organization,\nsee [Enable IAP for external applications](/iap/docs/custom-oauth-configuration).\n| **Note:** The ability to authenticate users with a Google-managed OAuth client is available in [Preview](/products#product-launch-stages).\n\nYou can enable IAP on a Compute Engine\n[backend service](/load-balancing/docs/backend-service) or on a\nCompute Engine [forwarding rule](/load-balancing/docs/forwarding-rule-concepts).\nWhen you enable IAP on a Compute Engine backend service,\nonly that backend service is protected by IAP. When you enable\nIAP on a Compute Engine forwarding rule, all of the\nCompute Engine instances behind the forwarding rule are protected by\nIAP.\n\nEnable IAP on a forwarding rule\n-------------------------------\n\nYou can enable IAP on a forwarding rule by using the\nload balancer [authorization policies](/load-balancing/docs/auth-policy/auth-policy-overview)\nframework. \n\n### gcloud\n\n1. Run the following command to prepare a `policy.yaml` file.\n\n $ cat \u003c\u003c EOF \u003e policy.yaml\n action: CUSTOM\n description: authz policy with Cloud IAP\n name: \u003cvar translate=\"no\"\u003e\u003cspan class=\"devsite-syntax-l devsite-syntax-l-Scalar devsite-syntax-l-Scalar-Plain\"\u003eAUTHZ_POLICY_NAME\u003c/span\u003e\u003c/var\u003e\n customProvider:\n cloudIap: {}\n target:\n loadBalancingScheme: EXTERNAL_MANAGED\n resources:\n - https://www.googleapis.com/compute/v1/projects/\u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e/regions/\u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e/forwardingRules/\u003cvar translate=\"no\"\u003eFORWARDING_RULE_ID\u003c/var\u003e\n EOF\n\n1. Run the following command to enable IAP on a forwarding rule.\n\n```\ngcloud beta network-security authz-policies import AUTHZ_POLICY_NAME \\\n--source=policy.yaml \\\n--location=LOCATION \\\n--project=PROJECT_ID\n```\n\nReplace the following:\n\n- \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: The Google Cloud project ID.\n- \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: The region that the resource is located in.\n- \u003cvar translate=\"no\"\u003eFORWARDING_RULE_ID\u003c/var\u003e: The ID of the forwarding rule resource.\n- \u003cvar translate=\"no\"\u003eAUTHZ_POLICY_NAME\u003c/var\u003e: The name of the authorization policy.\n\n### API\n\n1. Run the following command to prepare a `policy.json` file. \n\n ```\n cat \u003c\u003c EOF \u003e policy.json\n {\n \"name\": \"AUTHZ_POLICY_NAME\",\n \"target\": {\n \"loadBalancingScheme\": \"INTERNAL_MANAGED\",\n \"resources\": [\n \"https://www.googleapis.com/compute/v1/projects/PROJECT_ID/regions/LOCATION/forwardingRules/FORWARDING_RULE_ID\"\n ],\n },\n \"action\": \"CUSTOM\",\n \"httpRules\": [],\n \"customProvider\": {\n \"cloudIap\": {}\n }\n }\n EOF\n ```\n2. Run the following command to enable IAP on a forwarding rule.\n\n ```\n curl -X PATCH \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"Accept: application/json\" \\\n -H \"Content-Type: application/json\" \\\n -d @policy.json \\\n \"https://networksecurity.googleapis.com/v1beta1/projects/PROJECT_ID/locations/LOCATION/authzPolicies\"\n ```\n\n \u003cbr /\u003e\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e: The Google Cloud project ID.\n - \u003cvar translate=\"no\"\u003eLOCATION\u003c/var\u003e: The region that the resource is located in.\n - \u003cvar translate=\"no\"\u003eFORWARDING_RULE_ID\u003c/var\u003e: The ID of the forwarding rule resource.\n - \u003cvar translate=\"no\"\u003eAUTHZ_POLICY_NAME\u003c/var\u003e: The name of the authorization policy.\n\nAfter you enable IAP on a forwarding rule, you can\n[apply permissions to resources](/iap/docs/auth-policies#apply_permissions_to_resources).\n\nEnable IAP on a Compute Engine backend service\n----------------------------------------------\n\nYou can enable IAP on a Compute Engine backend service\nthrough that backend service. \n\n### console\n\nThe Google-managed OAuth client is not available when enabling IAP using the Google Cloud console.\n\nIf you haven't configured your project's OAuth consent screen, you'll be\nprompted to do so. To configure your OAuth consent screen, see\n[Setting up your OAuth consent screen](https://support.google.com/cloud/answer/10311615).\n\nIf you are running GKE clusters version 1.24 or later, you can configure\nIAP and GKE by using the Kubernetes Gateway API. To do so, complete\nthe following steps and then follow the instructions in\n[Configure IAP](/kubernetes-engine/docs/how-to/configure-gateway-resources#configure_iap).\nDo not configure `BackendConfig`.\n\n### Setting up IAP access\n\n1. Go to the [Identity-Aware Proxy page](https://console.cloud.google.com/security/iap). \n [Go to the Identity-Aware Proxy page](https://console.cloud.google.com/security/iap)\n2. Select the project you want to secure with IAP.\n3. Select the checkbox next to the resource you want to grant access to.\n\n If you don't see a resource, ensure that the resource is created and that\n the BackendConfig Compute Engine ingress controller is synced.\n\n To verify that the backend service is available, run the following\n gcloud command:\n `gcloud compute backend-services list`\n4. On the right side panel, click **Add principal**.\n5. In the **Add principals** dialog that appears, enter the email addresses of groups or individuals who should have the **IAP-secured Web App User** role for the project.\n\n The following kinds of principals can have this role:\n - **Google Account**: user@gmail.com\n - **Google Group**: admins@googlegroups.com\n - **Service account**: server@example.gserviceaccount.com\n - **Google Workspace domain**: example.com\n\n Make sure to add a Google Account that you have access to.\n6. Select **Cloud IAP \\\u003e IAP-secured Web App User** from the **Roles** drop-down list.\n7. Click **Save**.\n\n### Turning on IAP\n\n1. On the **Identity-Aware Proxy** page, under **APPLICATIONS** , find the load balancer that serves the instance group you want to restrict access to. To turn on IAP for a resource, toggle the on/off switch in the **IAP** column. \n To enable IAP:\n - At least one protocol in the load balancer frontend configuration must be HTTPS. Learn about [setting up\n a load balancer](/iap/docs/load-balancer-howto).\n - You need the `compute.backendServices.update`, `clientauthconfig.clients.create`, and `clientauthconfig.clients.getWithSecret` permissions. These permissions are granted by roles, such as the Project Editor role. To learn more, see [Managing access to IAP-secured resources](/iap/docs/managing-access#turning_on_and_off).\n2. In the **Turn on IAP** window that appears, click **Turn On** to confirm that you want IAP to secure your resource. After you turn on IAP, it requires login credentials for all connections to your load balancer. Only accounts with the **IAP-Secured Web App User** role on the project will be given access.\n\n### gcloud\n\nBefore you set up your project and IAP, you need an up-to-date version of the\ngcloud CLI. For instructions on how to install the gcloud CLI,\nsee [Install the gcloud CLI](/sdk/downloads).\n\n1. To authenticate, use the Google Cloud CLI and run the following command. \n\n gcloud auth login\n\n2. To sign in, follow the URL that appears.\n3. After you sign in, copy the verification code that appears and paste it in the command line.\n4. Run the following command to specify the project that contains the resource that you want to protect with IAP. \n\n gcloud config set project \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e\n\n5. To enable IAP, run either the globally or regionally scoped command. \n\n Global scope \n\n gcloud compute backend-services update \u003cvar translate=\"no\"\u003eBACKEND_SERVICE_NAME\u003c/var\u003e --global --iap=enabled\n\n Regional scope \n\n gcloud compute backend-services update \u003cvar translate=\"no\"\u003eBACKEND_SERVICE_NAME\u003c/var\u003e --region \u003cvar translate=\"no\"\u003eREGION_NAME\u003c/var\u003e --iap=enabled\n\nAfter you enable IAP, you can use the gcloud CLI to modify\nthe IAP access policy using the IAM role\n`roles/iap.httpsResourceAccessor`. Learn more about\n[managing roles and permissions](/iam/docs/granting-changing-revoking-access).\n\n### API\n\n1. Run the following command to prepare a `settings.json` file.\n\n ```\n cat \u003c\u003c EOF \u003e settings.json\n {\n \"iap\":\n {\n \"enabled\":true\n }\n }\n EOF\n ```\n\n \u003cbr /\u003e\n\n2. Run the following command to enable IAP.\n\n ```\n curl -X PATCH \\\n -H \"Authorization: Bearer $(gcloud auth print-access-token)\" \\\n -H \"Accept: application/json\" \\\n -H \"Content-Type: application/json\" \\\n -d @settings.json \\\n \"https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/REGION/backendServices/BACKEND_SERVICE_NAME\"\n ```\n\n \u003cbr /\u003e\n\nAfter you enable IAP, you can use the Google Cloud CLI to modify the\nIAP access policy using the IAM role\n`roles/iap.httpsResourceAccessor`. Learn more about\n[managing roles and permissions](/iam/docs/granting-changing-revoking-access)."]]