Restez organisé à l'aide des collections
Enregistrez et classez les contenus selon vos préférences.
Authentifier les utilisateurs avec un compte Google
Cette page explique comment déployer une application d'environnement standard ou flexible App Engine et la sécuriser avec Identity-Aware Proxy (IAP). Ce guide de démarrage rapide inclut un exemple de code pour une application Web d'environnement standard App Engine qui permet de valider le nom d'un utilisateur connecté. Dans ce guide, nous faisons appel à Cloud Shell pour cloner et déployer l'exemple d'application. Vous pouvez suivre ce guide de démarrage rapide afin d'activer IAP pour votre propre application d'environnement standard ou flexible App Engine.
Si vous prévoyez de diffuser des ressources à partir d'un réseau de diffusion de contenu (CDN), consultez le guide des bonnes pratiques pour obtenir des informations importantes.
Lorsqu'une application App Engine se compose de plusieurs services, il est possible de configurer différentes autorisations IAP sur les différents services, y compris de rendre uniquement certains services accessibles au public tout en protégeant les autres.
Pour obtenir des instructions détaillées sur cette tâche directement dans la console Google Cloud , cliquez sur Visite guidée :
Sign in to your Google Cloud account. If you're new to
Google Cloud,
create an account to evaluate how our products perform in
real-world scenarios. New customers also get $300 in free credits to
run, test, and deploy workloads.
In the Google Cloud console, on the project selector page,
select or create a Google Cloud project.
Pour activer IAP pour App Engine, vous devez disposer des éléments suivants :
Un projet de la console Google Cloud avec la facturation activée.
Si votre instance App Engine n'est pas déjà configurée, consultez la page Déployer App Engine pour obtenir une présentation complète.
IAP utilise un client OAuth géré par Google pour authentifier les utilisateurs.
Seuls les utilisateurs de l'organisation peuvent accéder à l'application compatible avec les achats via l'application.
Si vous souhaitez autoriser l'accès à des utilisateurs extérieurs à votre organisation, consultez Activer IAP pour les applications externes.
Activer IAP
Console
Le client OAuth géré par Google n'est pas disponible lorsque vous activez IAP à l'aide de la console Google Cloud .
🌐 Démarrage rapide: authentifier les utilisateurs avec des comptes Google | Identity-Aware Proxy | Google CloudFichier d'inclusion dynamique - cloud.google.com
Si vous n'avez pas configuré l'écran d'autorisation OAuth de votre projet, vous êtes invité à le faire. Pour configurer votre écran d'autorisation OAuth, consultez la section Configurer l'écran de consentement OAuth.
Sélectionnez le projet que vous souhaitez sécuriser avec IAP.
Cochez la case située à côté de la ressource à laquelle vous souhaitez accorder l'accès.
Dans le panneau de droite, cliquez sur Ajouter un compte principal.
Dans la boîte de dialogue Ajouter des comptes principaux qui s'affiche, ajoutez les adresses e-mail des groupes ou des personnes auxquels vous souhaitez accorder le rôle Utilisateur de l'application Web sécurisée par IAP dans le cadre du projet.
Les types de comptes principaux suivants peuvent disposer de ce rôle:
Compte Google : user@gmail.com
Groupe Google : admins@googlegroups.com
Compte de service: server@example.gserviceaccount.com
Domaine Google Workspace : example.com
Veillez à ajouter un compte Google auquel vous avez accès.
Sélectionnez Cloud IAP > Utilisateur de l'application Web sécurisée par IAP dans la liste déroulante Rôles.
Cliquez sur Enregistrer.
Activer IAP
Sur la page Identity-Aware Proxy, sous APPLICATIONS (APPLICATIONS), recherchez l'application à laquelle vous souhaitez restreindre l'accès. Pour activer IAP pour une ressource,
appuyez sur le bouton Activé/Désactivé dans la colonne IAP.
Dans la fenêtre Activer IAP qui s'affiche, cliquez sur Activer pour confirmer que vous souhaitez qu'IAP sécurise votre ressource. Une fois IAP activé, des identifiants de connexion sont requis pour toutes les connexions à votre équilibreur de charge.
Seuls les comptes disposant du rôle Utilisateur de l'application Web sécurisée par IAP sur le projet y ont accès.
gcloud
Avant de configurer votre projet et votre IAP, vous devez disposer d'une version à jour de la gcloud CLI. Pour savoir comment installer la CLI gcloud, consultez Installer la CLI gcloud.
Pour vous authentifier, utilisez la Google Cloud CLI et exécutez la commande suivante.
gcloud auth login
Cliquez sur l'URL qui s'affiche, puis connectez-vous.
Une fois la connexion effectuée, copiez le code de validation qui s'affiche et collez-le dans la ligne de commande.
Exécutez la commande suivante pour spécifier le projet contenant les applications que vous souhaitez protéger avec IAP.
gcloud config set project PROJECT_ID
Pour activer les achats intégrés, exécutez la commande suivante.
gcloud iap web enable --resource-type=app-engine --versions=version
Ajoutez au projet les comptes principaux qui doivent disposer du rôle "Utilisateur de l'application Web sécurisée par IAP".
Remplacez PRINCIPAL_IDENTIFIER par les principaux nécessaires. Il peut s'agir d'un type de domaine, de groupe, de serviceAccount ou d'utilisateur. Par exemple, user:myemail@example.com.
Une fois que vous avez activé IAP, vous pouvez modifier la stratégie d'accès IAP à l'aide du rôle IAM roles/iap.httpsResourceAccessor via la gcloud CLI. Découvrez comment gérer les rôles et les autorisations.
API
Exécutez la commande suivante pour préparer un fichier settings.json.
Une fois que vous avez activé IAP, vous pouvez modifier la stratégie d'accès IAP à l'aide du rôle IAM roles/iap.httpsResourceAccessor via la Google Cloud CLI. Découvrez comment gérer les rôles et les autorisations.
Tester l'authentification des utilisateurs
Accédez à l'URL de l'application à partir d'un compte Google que vous avez ajouté à IAP avec le rôle Utilisateur de l'application Web sécurisée par IAP, comme décrit ci-dessus. Vous devez disposer d'un accès illimité à l'application.
Ouvrez une fenêtre de navigation privée dans Chrome pour accéder à l'application, puis connectez-vous lorsque vous y êtes invité. Si vous tentez d'accéder à l'application au moyen d'un compte non autorisé avec le rôle Utilisateur de l'application Web sécurisée par IAP, un message s'affiche indiquant que vous ne disposeez pas de l'accès.
Sauf indication contraire, le contenu de cette page est régi par une licence Creative Commons Attribution 4.0, et les échantillons de code sont régis par une licence Apache 2.0. Pour en savoir plus, consultez les Règles du site Google Developers. Java est une marque déposée d'Oracle et/ou de ses sociétés affiliées.
Dernière mise à jour le 2025/08/18 (UTC).
[[["Facile à comprendre","easyToUnderstand","thumb-up"],["J'ai pu résoudre mon problème","solvedMyProblem","thumb-up"],["Autre","otherUp","thumb-up"]],[["Difficile à comprendre","hardToUnderstand","thumb-down"],["Informations ou exemple de code incorrects","incorrectInformationOrSampleCode","thumb-down"],["Il n'y a pas l'information/les exemples dont j'ai besoin","missingTheInformationSamplesINeed","thumb-down"],["Problème de traduction","translationIssue","thumb-down"],["Autre","otherDown","thumb-down"]],["Dernière mise à jour le 2025/08/18 (UTC)."],[[["\u003cp\u003eThis guide explains how to secure App Engine applications using Identity-Aware Proxy (IAP), allowing authentication through Google Accounts.\u003c/p\u003e\n"],["\u003cp\u003eYou can enable IAP for both App Engine standard and flexible environments, securing them with user login credentials.\u003c/p\u003e\n"],["\u003cp\u003eIAP access can be configured to be granted to specific Google Accounts, Google Groups, service accounts, or Google Workspace domains, with the IAP-secured Web App User role.\u003c/p\u003e\n"],["\u003cp\u003eMultiple services within an App Engine application can have different IAP permissions, allowing some to be publicly accessible while others are protected.\u003c/p\u003e\n"],["\u003cp\u003eEnabling IAP can be accomplished through the Google Cloud console, the gcloud CLI, or by using an API, and it is essential to configure the OAuth consent screen.\u003c/p\u003e\n"]]],[],null,["# Quickstart: Authenticate users with Google Accounts\n\nAuthenticate users with Google Accounts\n=======================================\n\nThis page walks you through deploying an App Engine standard or flexible\nenvironment application and securing it with [Identity-Aware Proxy\n(IAP)](/iap/docs/concepts-overview). The quickstart includes\nsample code for an App Engine standard environment web app that\nverifies a logged-in user's\nname. This quickstart uses Cloud Shell to clone and deploy the sample\napplication. You can use this quickstart to enable IAP for\nyour own App Engine standard environment or\nApp Engine flexible environment app.\n\nIf you plan to serve resources from a content delivery network (CDN), see the [best practices guide](/iap/docs/concepts-best-practices#caching)\nfor important information.\n\nWhen an App Engine application consists of multiple services, it is\npossible to configure different IAP permissions on the\ndifferent services, including making only some of the services\n[publicly-accessible](https://cloud.google.com/iap/docs/managing-access#public_access) while keeping the others protected.\n\n*** ** * ** ***\n\nTo follow step-by-step guidance for this task directly in the\nGoogle Cloud console, click **Guide me**:\n\n[Guide me](https://console.cloud.google.com/freetrial?redirectPath=/?tutorial=context_aware_access_secure_web_app)\n\n*** ** * ** ***\n\nBefore you begin\n----------------\n\n- Sign in to your Google Cloud account. If you're new to Google Cloud, [create an account](https://console.cloud.google.com/freetrial) to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\n- In the Google Cloud console, on the project selector page,\n select or create a Google Cloud project.\n\n | **Note**: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.\n\n [Go to project selector](https://console.cloud.google.com/projectselector2/home/dashboard)\n-\n [Verify that billing is enabled for your Google Cloud project](/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project).\n\nBefore you begin\n----------------\n\nTo enable IAP for App Engine, you need the\nfollowing:\n\n- A Google Cloud console project with billing enabled.\n\nIf you don't have your App Engine instance set up already, see\n[Deploying App Engine](/build/docs/deploying-builds/deploy-appengine)\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 application.\nIf you want to allow access to users outside of your organization, see [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\nEnabling IAP\n------------\n\n### Console\n\nThe Google-managed OAuth client is not available when enabling IAP using the Google Cloud console.\n\n\nDynamic include file\n\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\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.\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 application you want to restrict access to. To turn on IAP for a resource, toggle the on/off switch in the **IAP** column. \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\u003cbr /\u003e\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, see [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. Click the URL that appears and sign in.\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 applications 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 the following command. \n\n gcloud iap web enable --resource-type=app-engine --versions=\u003cvar translate=\"no\"\u003eversion\u003c/var\u003e\n\n6. Add principals who should have the IAP-secured Web App user role to the project. \n\n gcloud projects add-iam-policy-binding \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e \\\n --member=\u003cvar translate=\"no\"\u003ePRINCIPAL_IDENTIFIER\u003c/var\u003e \\\n --role=roles/iap.httpsResourceAccessor\n\n - Replace \u003cvar translate=\"no\"\u003ePROJECT_ID\u003c/var\u003e with your project ID.\n - Replace \u003cvar translate=\"no\"\u003ePRINCIPAL_IDENTIFIER\u003c/var\u003e with the necessary principals. This can be a type of domain, group, serviceAccount, or user. For example, `user:myemail@example.com`.\n\nAfter you enable IAP, you can use the gcloud 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).\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://appengine.googleapis.com/v1/apps/PROJECT_ID?updateMask=iap\"\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).\n| **Note:** When a App Engine application consists of multiple services, in order to make some services publicly-accessible and keep others restricted, enable IAP on the entire application, then grant the **IAP-secured Web App User** role to \\`allUsers\\` or \\`allAuthenticatedUsers\\` on the services that should be publicly-accessible.\n| **Role-based access:** If you're a project owner, you may think that you get automatic access to the app. That is not the case as only accounts with the **IAP-secured Web App User** role on this project will be given access. Imagine you're in corporate IT implementing IAP access to the HR payroll system. In most scenarios, only the staff on the Payroll team should have access to the app. This is one of the reasons why role-based access is more secure. The owner (or editor, etc.) of a project can manage all aspects of the project but doesn't automatically get app access.\n\nTest user authentication\n------------------------\n\n1. Access the app URL from a Google account that you added to\n IAP with the **IAP-secured Web App User** role\n as described above. You should have unrestricted access to the app.\n\n2. Use an incognito window in Chrome to access the app and sign in when\n prompted. If you try to access the app with an account that isn't authorized\n with the **IAP-secured Web App User** role, you'll see a message\n saying that you don't have access.\n\nWhat's next\n-----------\n\n- Learn about [Getting the user's identity](/iap/docs/identity-howto) and develop your own [App Engine](/appengine) app."]]