Deploy the application to App Engine

Check my progress

/ 25

Restrict access with IAP

Check my progress

/ 25

Allow member to access application

Check my progress

/ 25

Access User Identity Information

Check my progress

/ 25

This lab may incorporate AI tools to support your learning.
This content is not yet optimized for mobile devices.
For the best experience, please visit us on a desktop computer using a link sent by email.

GSP946

Google Cloud self-paced labs

Overview

In the Zero Trust security model, no person, device, or network is inherently trusted. Granting access depends on numerous factors, including identity, device, location, and time of day. A primary use case for Zero Trust policy enforcement is providing secure access to web applications. These include HTTP/HTTPS-based applications hosted on Google Cloud or in on-premises data centers. Each web application can have its own access control for precise security and lower risk. Securing the web application doesn't require setting access control lists (ACLs). Instead, setting IP ranges allows for rapid onboarding without compromising security. Architecturally, the primary component that provides Zero Trust access is:

  • Identity-Aware Proxy (IAP): A policy enforcement engine for ensuring that every access request is authorized.

In this lab, you deploy a sample application to App Engine and enforce policies using Identity-Aware Proxy (IAP). You also obtain user identity information in the application protected by IAP.

What you'll learn

In this lab, you learn how to perform the following tasks:

  • Deploy a simple App Engine application using Python.
  • Enable Identity-Aware Proxy (IAP) to restrict access to the application.
  • Obtain user identity information from IAP in your application.

Prerequisites

Basic programming knowledge (Python).

Setup and requirements

Before you click the Start Lab button

Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources are made available to you.

This hands-on lab lets you do the lab activities in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials you use to sign in and access Google Cloud for the duration of the lab.

To complete this lab, you need:

  • Access to a standard internet browser (Chrome browser recommended).
Note: Use an Incognito (recommended) or private browser window to run this lab. This prevents conflicts between your personal account and the student account, which may cause extra charges incurred to your personal account.
  • Time to complete the lab—remember, once you start, you cannot pause a lab.
Note: Use only the student account for this lab. If you use a different Google Cloud account, you may incur charges to that account.

How to start your lab and sign in to the Google Cloud console

  1. Click the Start Lab button. If you need to pay for the lab, a dialog opens for you to select your payment method. On the right is the Lab setup and access panel with the following:

    • The Open Google Cloud console button
    • The temporary credentials (username and password) that you must use for this lab
    • Other information, if needed, to step through this lab

    Note that the lab timer is located near the top of the page, showing the remaining time.

  2. Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).

    The lab spins up resources, and then opens another tab that shows the Sign in page.

    Tip: Arrange the tabs in separate windows, side-by-side.

    Note: If you see the Choose an account dialog, click Use Another Account.
  3. If necessary, copy the Username below and paste it into the Sign in dialog.

    {{{user_0.username | "Username"}}}

    You can also find the Username in the Lab setup and access panel.

  4. Click Next.

  5. Copy the Password below and paste it into the Welcome dialog.

    {{{user_0.password | "Password"}}}

    You can also find the Password in the Lab setup and access panel.

  6. Click Next.

    Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges.
  7. Click through the subsequent pages:

    • Accept the terms and conditions.
    • Do not add recovery options or two-factor authentication (because this is a temporary account).
    • Do not sign up for free trials.

After a few moments, the Google Cloud console opens in this tab.

Note: To access Google Cloud products and services, click the Navigation menu or type the service or product name in the Search field. Navigation menu icon and Search field

Activate Cloud Shell

Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud. Cloud Shell provides command-line access to your Google Cloud resources.

  1. Click Activate Cloud Shell Activate Cloud Shell icon at the top of the Google Cloud console.

  2. Click through the following windows:

    • Continue through the Cloud Shell information window.
    • Authorize Cloud Shell to use your credentials to make Google Cloud API calls.

When you are connected, you are already authenticated, and the project is set to your Project_ID, . The output contains a line that declares the Project_ID for this session:

Your Cloud Platform project in this session is set to {{{project_0.project_id | "PROJECT_ID"}}}

gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.

  1. (Optional) You can list the active account name with this command:
gcloud auth list
  1. Click Authorize.

Output:

ACTIVE: * ACCOUNT: {{{user_0.username | "ACCOUNT"}}} To set the active account, run: $ gcloud config set account `ACCOUNT`
  1. (Optional) You can list the project ID with this command:
gcloud config list project

Output:

[core] project = {{{project_0.project_id | "PROJECT_ID"}}} Note: For full documentation of gcloud, in Google Cloud, refer to the gcloud CLI overview guide.

Scenario

You build a minimal web application with App Engine. You then explore ways to use Identity-Aware Proxy to restrict access to the application and provide user identity information to it. Your app:

  • Displays a welcome page.
  • Accesses user identity information provided by IAP.

Task 1. Deploy the application and protect it using IAP

The application is an App Engine standard environment application written in Python 3.8 that displays a "Hello, World" welcome page. In this task, you deploy and test the application, and then restrict access to it using IAP.

  • In Cloud Shell, run the following commands to download the code needed for this lab from GitHub and change to the code folder:
git clone https://github.com/googlecodelabs/user-authentication-with-iap.git cd user-authentication-with-iap

Review the application code

  • Run the following command to change from the main project folder to the 1-HelloWorld folder:
cd 1-HelloWorld

The application code is in the main.py file. It uses the Flask web framework to respond to web requests with the contents of a template. That template file is in templates/index.html, and for this step, it contains only plain HTML. A second template file contains a skeletal example privacy policy in templates/privacy.html.

There are two other files: requirements.txt lists all the non-default Python libraries the application uses, and app.yaml tells Google Cloud that this is a Python 3.8 App Engine application.

You can list each file in Cloud Shell using the cat command:

cat main.py

You can also open the Cloud Shell Editor by clicking Edit (Edit icon) in the Cloud Shell toolbar to examine the code.

You don't need to change any files for this step.

Deploy the application to App Engine

In this subtask, you deploy the application to the App Engine standard environment for Python.

Note: An App Engine application has already been created for you in the region, so you don't need to create one.
  1. In the Cloud Shell Editor, open the app.yaml file in the 1-HelloWorld folder.

  2. Update the Python runtime version and add automatic_scaling with max_instances: 1 so that deployments stay within the project's App Engine max instances quota:

runtime: python311 automatic_scaling: max_instances: 1
  1. Run the following command to set your project ID:
gcloud config set project {{{project_0.project_id | "PROJECT_ID"}}}
  1. Run the following command to deploy the application:
gcloud app deploy
  1. If prompted to continue, type Y and press ENTER.
Note: You might also be asked to authorize the call to deploy the App Engine app. If so, click Authorize. Note: If an error appears, then rerun the command.

In a few minutes, the deployment finishes, and a message indicates that you can view your application.

  1. To view your application, run the following command:
gcloud app browse
  1. Copy the output URL because you use it as input for the form in the next steps.
Note: Because this is the first time you run this app, it takes a few seconds to appear while a cloud instance starts. You should see output similar to the following image, and access is not yet restricted.

IAP example application in a browser displaying the text 'This is step 1 of the User Authentication with IAP codelab'

Click Check my progress to verify the objective. Deploy the application to App Engine

Restrict access with IAP

  1. In the Google Cloud console, on the Navigation menu (Navigation menu icon), click View all products > Security > Identity-Aware Proxy.

The Identity-Aware Proxy API is already enabled for you, so you don't need to click Enable API.

  1. To configure your project's OAuth consent screen, on the Navigation menu, click APIs & Services > OAuth consent screen.

  2. On the OAuth Overview page, click Get Started.

  3. For App name, type IAP Example

  4. For User support email, select .

  5. For Audience Type, select Internal.

  6. Click Next.

  7. Under Contact Information, type

  8. Click Next.

  9. Under Finish, select the Accept terms and conditions checkbox.

  10. Click Create.

  11. Return to the first browser tab, and then in Cloud Shell, run the following command:

export AUTH_DOMAIN=$(gcloud config get-value project).uc.r.appspot.com
  1. To view the populated value, run the following command:
echo $AUTH_DOMAIN
  1. On the OAuth Overview page, click Create Auth Client.

  2. For Application type, select Web Application.

  3. Under Authorized redirect URIs, click Add URL.

  4. Paste the URL from the Cloud Shell command output.

  5. Click Create.

  6. In the remaining tab, on the Navigation menu, click View all products > Security > Identity-Aware Proxy.

You might need to refresh the page.

  1. In the App Engine app row, click the toggle in the IAP column to turn on IAP for the application that you deployed.

HTTPS Resources tab showing the IAP toggle switched on for the App Engine app

  1. To open the application, press and hold CTRL (or COMMAND on macOS), and then click the URL of the App Engine application on the Identity-Aware Proxy page.

  2. Sign in with the student account listed in the sign-in form.

Google sign-in dialog displaying the student account

A page appears stating that you don't have access to the application.

Access denied notification displaying "You don't have access"

You've successfully protected your app with IAP, but you haven't yet told IAP which accounts to allow.

Click Check my progress to verify the objective. Restrict access with IAP

Allow members to access the application

  1. To return to the Identity-Aware Proxy page, on the Navigation menu, click View all products > Security > Identity-Aware Proxy.

  2. Select the checkbox next to App Engine app.

  3. In the info panel, click Add Principal.

App Engine app panel showing the Show inherited permissions toggle and Add Member button

  1. Copy the Username from the lab details panel.

  2. For New principals, paste the copied username.

  3. Select the Cloud IAP > IAP-secured Web App User role.

Filter drop-down menu showing Quick access, By product or service, and Roles categories

  1. Click Save.

The "Policy Updated" message appears.

Click Check my progress to verify the objective. Allow member to access application

Verify access is restored

  • Return to your App Engine application and reload the page.

You should now see your web app because you already signed in with an authorized user.

However, you might still see the "You don't have access" page because IAP might not recheck your authorization due to a stored login cookie.

In that case, complete the following steps:

  1. In your web browser, open the application's home page URL with /_gcp_iap/clear_login_cookie appended to the end (for example, https://iap-example-999999.appspot.com/_gcp_iap/clear_login_cookie).
Note: Use the URL from the App Engine application that you deployed earlier in the lab. The preceding URL is an example.

A new Sign in with Google screen appears with your account already listed.

Note: Do not click the account!
  1. Click Use another account.

  2. Re-enter your credentials.

These steps cause IAP to recheck your access, and you should now see your application's home screen.

Task 2. Access user identity information

After an app is protected with IAP, it can use the identity information that IAP provides in the web request headers. In this task, the application retrieves the signed-in user's email address and a persistent unique user ID assigned by Google Identity Service. It then displays that data on the welcome page.

  1. In Cloud Shell, run the following command:
cd ~/user-authentication-with-iap/2-HelloUser
  1. In the Cloud Shell Editor, open the app.yaml file in the 2-HelloUser folder.

  2. Update the Python runtime version and add automatic_scaling with max_instances: 1:

runtime: python311 automatic_scaling: max_instances: 1
  1. Run the following command to deploy the application to App Engine:
gcloud app deploy Note: You might be asked to authorize the call to deploy the application.
  1. If prompted to continue, type Y and press ENTER.

  2. When the deployment is ready, run the following command:

gcloud app browse

If a new tab doesn't open in your browser, then copy the displayed link and open it in a new tab. You should see a page similar to the following:

IAP Hello User page

Note: You might need to wait a few minutes for the new version of your application to replace the previous version. Refresh the page if needed to see a page similar to the preceding image.

Click Check my progress to verify the objective. Access User Identity Information

Examine the application files

The 2-HelloUser folder contains the same set of files as in the 1-HelloWorld folder, but two of the files have been changed: main.py and templates/index.html. The program has been changed to retrieve the user information that IAP provides in request headers, and the template now displays that data.

  • Run the following command to view the contents of the main.py file:
cat main.py

There are two lines in main.py that get the IAP-provided identity data:

user_email = request.headers.get('X-Goog-Authenticated-User-Email') user_id = request.headers.get('X-Goog-Authenticated-User-ID')

The X-Goog-Authenticated-User- headers are provided by IAP, and the names are case-insensitive, so they can be in all lowercase or all uppercase if preferred. The render_template statement now includes those values so they can be displayed:

page = render_template('index.html', email=user_email, id=user_id)

The index.html template can display those values by enclosing the names in double curly braces:

Hello, {{ email }}! Your persistent ID is {{ id }}.

The provided data is prefixed with accounts.google.com:, showing where the information came from. Your application can remove everything up to and including the colon to get the raw values if desired.

Congratulations!

You have learned how to use Identity-Aware Proxy (IAP) to secure HTTP(S) applications deployed to Google Cloud.

Google Cloud training and certification

...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.

Manual Last Updated on November 20, 2026

Lab last tested November 20, 2026

Copyright 2026 Google LLC. All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.

Before you begin

  1. Labs create a Google Cloud project and resources for a fixed time
  2. Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
  3. On the top left of your screen, click Start lab to begin

Use private browsing

  1. Copy the provided Username and Password for the lab
  2. Click Open console in private mode

Sign in to the Console

  1. Sign in using your lab credentials. Using other credentials might cause errors or incur charges.
  2. Accept the terms, and skip the recovery resource page
  3. Don't click End lab unless you've finished the lab or want to restart it, as it will clear your work and remove the project

This content is not currently available

We can notify you via email when it becomes available

Great!

We can contact you via email if it becomes available

One lab at a time

Confirm to end all existing labs and start this one

Use private browsing to run the lab

Using an Incognito or private browser window is the best way to run this lab. This prevents any conflicts between your personal account and the Student account, which may cause extra charges incurred to your personal account.