
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Deploy the application to App Engine
/ 25
Restrict access with IAP
/ 25
Allow member to access application
/ 25
Access User Identity Information
/ 25
The Zero Trust security model is where no person, device, or network is inherently trusted. Granting access is based on numerous factors including but not limited to: identity, device, location, and time of day. One of the primary use cases for Zero-Trust policy enforcement is to provide secure access to web applications, like HTTP/HTTPS-based applications that are hosted on Google Cloud or 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 to provide zero-trust access is:
In this lab, you will deploy a sample application to App Engine and enforcing policies using Identity-Aware Proxy (IAP). You will also obtain user identity information in the application protected by IAP.
Basic programming language knowledge (Python)
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:
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 left is the Lab Details pane with the following:
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.
If necessary, copy the Username below and paste it into the Sign in dialog.
You can also find the Username in the Lab Details pane.
Click Next.
Copy the Password below and paste it into the Welcome dialog.
You can also find the Password in the Lab Details pane.
Click Next.
Click through the subsequent pages:
After a few moments, the Google Cloud console opens in this tab.
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.
Click Activate Cloud Shell at the top of the Google Cloud console.
Click through the following windows:
When you are connected, you are already authenticated, and the project is set to your Project_ID,
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
You're building a minimal web application with Google App Engine, then exploring various ways to use Identity-Aware Proxy to restrict access to the application and provide user identity information to it. Your app will:
The application is an App Engine Standard application written in Python 3.8 that simply displays a "Hello, World" welcome page. You will deploy and test it, then restrict access to it using IAP.
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 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 Platform that this is a Python 3.8 App Engine application.
You can list each file in Cloud Shell using the cat
command:
You can also open the Cloud Shell Code Editor by clicking Edit () at the top right-hand side of the Cloud Shell window, and examine the code using the editor once it loads.
You do not need to change any files for this step.
Now deploy the app to the App Engine Standard environment for Python 3.8.
If you are asked if you want to continue, enter Y for yes.
app.yaml
file in 1-HelloWorld
folder. And update the runtime python version.If asked to continue, enter Y
and press Enter.
In a few minutes the deploy should complete and you will see a message that you can view your application with the following command:
Click Check my progress to verify the objective.
Since this is the first time you have enabled an authentication option for this project, you will see a message that you must configure your OAuth consent screen before you can use IAP.
Click on the Configure Consent Screen button. A new tab will open to configure the consent screen.
Select the Internal radio option and then click Create.
Go back to the first browser tab and run the following command in Cloud Shell:
You will use the output of the commands as input for the form on the OAuth Consent tab.
IAP Example
+
button and enter the output from the last step.student-lab@qwiklabs.net
(You must press Enter after entering this value.)Click the Save and Continue button at the bottom of the page.
In the Scopes step of the OAuth workflow, leave everything blank and click the Save and Continue button.
Click the Back to Dashboard button on the last step.
You can close the workflow browser tab after returning to the dashboard.
You may need to refresh the page if required.
Navigate to the application by holding down the Ctrl/Command key and selecting the URL of the App Engine application in the IAP console.
Sign in with the student user listed in the login form.
You will be shown a screen that informs you that you do not have access to the application.
You have successfully protected your app with IAP, but you have not yet told IAP which accounts to allow through.
Click Check my progress to verify the objective.
Return to the Identity-Aware Proxy page of the console by going to Navigation Menu > Security > Identity Aware Proxy.
Select the checkbox next to App Engine app, and see the sidebar at the right of the page and click Add Principal.
Copy the Username
from the lab console on the top left of the lab and enter it into the New principals input box.
Set its role to Cloud IAP > IAP-secured Web App User.
Click Check my progress to verify the objective.
However, you may still see the "You don't have access" page since IAP may not recheck your authorization due to a login cookie being stored.
In that case, do the following steps:
You will see a new Sign in with Google screen, with your account already showing.
These steps cause IAP to recheck your access and you should now see your application's home screen.
Once an app is protected with IAP, it can use the identity information that IAP provides in the web request headers it passes through. In this step, the application will get the logged-in user's email address and a persistent unique user ID assigned by the Google Identity Service to that user. That data will be displayed to the user in the welcome page.
app.yaml
file in 2-HelloUser
folder and update the runtime python version:Enter Y
if asked to continue.
When the deployment is ready, enter the following command:
If a new tab does not open on your browser, copy the displayed link and open it in a new tab. You should see a page similar to the following:
Click Check my progress to verify the objective.
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.
cat main.py
to view the contents of the main.py
file.There are two lines in main.py
that get the IAP-provided identity data:
The X-Goog-Authenticated-User-
headers are provided by IAP, and the names are case-insensitive, so they could be given in all lower or all upper case if preferred. The render_template
statement now includes those values so they can be displayed:
The index.html
template can display those values by enclosing the names in doubled curly braces:
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.
You have learned how to use Identity Aware Proxy (IAP) to secure HTTP(s) applications deployed to Google Cloud.
...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 January 31, 2025
Lab last tested January 31, 2025
Copyright 2025 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.
此内容目前不可用
一旦可用,我们会通过电子邮件告知您
太好了!
一旦可用,我们会通过电子邮件告知您
One lab at a time
Confirm to end all existing labs and start this one