Checkpoints
Create the blue server
/ 15
Create the green server
/ 15
Install Nginx and customize the welcome page
/ 30
Create the tagged firewall rule
/ 15
Create a test-vm
/ 10
Create a Network-admin service account
/ 15
VPC Networks - Controlling Access
GSP213
Overview
In this lab, you create two nginx web servers and control external HTTP access to the web servers using tagged firewall rules. Then, you explore IAM roles and service accounts.
Objectives
In this lab, you learn how to perform the following tasks:
-
Create an nginx web server
-
Create tagged firewall rules
-
Create a service account with IAM roles
-
Explore permissions for the Network Admin and Security Admin roles
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 will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that 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).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud Console
-
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
- The Open Google Console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Console. 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. -
If necessary, copy the Username from the Lab Details panel and paste it into the Sign in dialog. Click Next.
-
Copy the Password from the Lab Details panel and paste it into the Welcome dialog. Click Next.
Important: You must use the credentials from the left panel. Do not use your Google Cloud Skills Boost credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
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 Cloud Console opens in this tab.
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.
- Click Activate Cloud Shell
at the top of the Google Cloud console.
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:
gcloud
is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
-
(Optional) You can list the active account name with this command:
-
Click Authorize.
-
Your output should now look like this:
Output:
-
(Optional) You can list the project ID with this command:
Output:
Example output:
gcloud
, in Google Cloud, refer to the gcloud CLI overview guide.
Task 1. Create the web servers
Create two web servers (blue and green) in the default VPC network. Then, install nginx on the webservers and modify the welcome page to distinguish the servers.
Create the blue server
Create the blue server with a network tag.
- In the Console, navigate to Navigation menu (
) > Compute Engine > VM instances.
-
Click Create Instance.
-
Set the following values, leave all other values at their defaults:
Property Value (type value or select option as specified) Name blue Region us-central1 (Iowa) Zone us-central1-a For more information on available regions and zones, in the Google Cloud Compute Engine Region and Zone guide, see the Available regions and zones section of the Compute Engine Guides.
-
Click NETWORKING, DISKS, SECURITY, MANAGEMENT, SOLE-TENANCY.
-
Click Networking.
-
For Network tags, type web-server.
-
Click Create.
Test Completed Task
Click Check my progress to verify your performed task. If you have completed the task successfully you will be granted an assessment score.
Create the green server
Create the green server without a network tag.
-
Still in the Console, in the VM instances dialog, click Create instance.
-
Set the following values, leave all other values at their defaults:
Property Value (type value or select option as specified) Name green Region us-central1 (Iowa) Zone us-central1-a -
Click Create.
Test Completed Task
Click Check my progress to verify your performed task. If you have completed the task successfully you will be granted an assessment score.
Install nginx and customize the welcome page
Install nginx on both VM instances and modify the welcome page to distinguish the servers.
-
Still in the VM instances dialog, for blue, click SSH to launch a terminal and connect.
-
In the SSH terminal to blue, run the following command to install nginx:
-
Open the welcome page in the nano editor:
-
Replace the
<h1>Welcome to nginx!</h1>
line with<h1>Welcome to the blue server!</h1>
. -
Press CTRL+o, ENTER, CTRL+x.
-
Verify the change:
The output should contain the following:
-
Close the SSH terminal to blue:
Repeat the same steps for the green server:
-
For green, click SSH to launch a terminal and connect.
-
Install nginx:
-
Open the welcome page in the nano editor:
-
Replace the
<h1>Welcome to nginx!</h1>
line with<h1>Welcome to the green server!</h1>
. -
Press CTRL+o, ENTER, CTRL+x.
-
Verify the change:
The output should contain the following:
-
Close the SSH terminal to green:
Test Completed Task
Click Check my progress to verify your performed task. If you have completed the task successfully you will be granted an assessment score.
Task 2. Create the firewall rule
Create the tagged firewall rule and test HTTP connectivity.
Create the tagged firewall rule
Create a firewall rule that applies to VM instances with the web-server network tag.
- In the Console, navigate to Navigation menu (
) > VPC network > Firewall.
- Notice the default-allow-internal firewall rule.
-
Click Create Firewall Rule.
-
Set the following values, leave all other values at their defaults and click Create:
Property Value (type value or select option as specified) Name allow-http-web-server Network default Targets Specified target tags Target tags web-server Source filter IPv4 Ranges Source IPv4 ranges 0.0.0.0/0 Protocols and ports Specified protocols and ports, and then check tcp, type: 80; and check Other protocols, type: icmp.
-
Click Create.
Test Completed Task
Click Check my progress to verify your performed task. If you have completed the task successfully you will be granted an assessment score.
Create a test-vm
Create a test-vm instance using the Cloud Shell command line.
-
Create a test-vm instance, in the us-central1-a zone:
The output should look like this:
Test Completed Task
Click Check my progress to verify your performed task. If you have completed the task successfully you will be granted an assessment score.
Test HTTP connectivity
From test-vm curl
the internal and external IP addresses of blue and green.
-
In the Console, navigate to Navigation menu (
) > Compute Engine > VM instances.
-
Note the internal and external IP addresses of blue and green.
-
For test-vm, click SSH to launch a terminal and connect.
-
To test HTTP connectivity to blue's internal IP, run the following command, replacing blue's internal IP:
-
To test HTTP connectivity to green's internal IP, run the following command, replacing green's internal IP:
You should see the Welcome to the green server!
header.
-
To test HTTP connectivity to blue's external IP, run the following command, replacing blue's external IP:
You should see the Welcome to the blue server!
header.
-
To test HTTP connectivity to green's external IP, run the following command, replacing green's external IP:
- Press CTRL+c to stop the HTTP request.
You can verify the same behavior from your browser by opening a new tab and navigating to http://[External IP of server]
.
Task 3. Explore the Network and Security Admin roles
Cloud IAM lets you authorize who can take action on specific resources, giving you full control and visibility to manage cloud resources centrally. The following roles are used in conjunction with single-project networking to independently control administrative access to each VPC Network:
- Network Admin: Permissions to create, modify, and delete networking resources, except for firewall rules and SSL certificates.
- Security Admin: Permissions to create, modify, and delete firewall rules and SSL certificates.
Explore these roles by applying them to a service account, which is a special Google account that belongs to your VM instance, instead of to an individual end user. Rather than creating a new user, you will authorize test-vm to use the service account to demonstrate the permissions of the Network Admin and Security Admin roles.
Verify current permissions
Currently, test-vm uses the Compute Engine default service account, which is enabled on all instances created by Cloud Shell command-line and the Cloud Console.
Try to list or delete the available firewall rules from test-vm.
-
Return to the SSH terminal of the test-vm instance.
-
Try to list the available firewall rules:
The output should look like this:
-
Try to delete the allow-http-web-server firewall rule:
- Enter Y, if asked to continue.
The output should look like this:
Create a service account
Create a service account and apply the Network Admin role.
-
In the Console, navigate to Navigation menu (
) > IAM & admin > Service Accounts.
-
Notice the Compute Engine default service account.
-
Click Create service account.
-
Set the Service account name to Network-admin and click CREATE AND CONTINUE.
-
For Select a role, select Compute Engine > Compute Network Admin and click CONTINUE then click DONE.
-
After creating the service account 'Network-admin', click on the three dots at the right corner and click Manage Key in the dropdown, then click on Add Key and select Create new key from the dropdown. Click Create to download your JSON output.
-
Click Close.
A JSON key file download to your local computer. Find this key file, you will upload it into the VM in a later step.
-
Rename the JSON key file on your local machine to credentials.json
Test Completed Task
Click Check my progress to verify your performed task. If you have completed the task successfully you will be granted an assessment score.
Authorize test-vm and verify permissions
Authorize test-vm to use the Network-admin service account.
-
Return to the SSH terminal of the test-vm instance.
-
To upload credentials.json through the SSH VM terminal, click on the Upload file icon in the upper-right corner.
-
Select credentials.json and upload it.
-
Click Close in the File Transfer window.
Note: If prompted, click Retry on the Connection via Cloud Identity-Aware Proxy Failed dialog and re-upload the file. -
Authorize the VM with the credentials you just uploaded:
-
Try to list the available firewall rules:
The output should look like this:
This should work!
-
Try to delete the allow-http-web-server firewall rule:
- Enter Y, if asked to continue.
The output should look like this:
Update service account and verify permissions
Update the Network-admin service account by providing it the Security Admin role.
-
In the Console, navigate to Navigation menu (
) > IAM & admin > IAM.
-
Find the Network-admin account. Focus on the Name column to identify this account.
-
Click on the pencil icon for the Network-admin account.
-
Change Role to Compute Engine > Compute Security Admin.
-
Click Save.
-
Return to the SSH terminal of the test-vm instance.
-
Try to list the available firewall rules:
The output should look like this:
This should work!
-
Try to delete the allow-http-web-server firewall rule:
- Enter Y, if asked to continue.
The output should look like this:
This should work!
Verify the deletion of the firewall rule
Verify that you can no longer HTTP access the external IP of the blue server, because you deleted the allow-http-web-server firewall rule.
-
Return to the SSH terminal of the test-vm instance.
-
To test HTTP connectivity to blue's external IP, run the following command, replacing blue's external IP:
- Press CTRL+c to stop the HTTP request.
Congratulations!
In this lab, you created two nginx web servers and controlled external HTTP access using a tagged firewall rule. Then, you created a service account with first the Network Admin role and then the Security Admin role to explore the different permissions of these roles.
If your company has a security team that manages firewalls and SSL certificates and a networking team that manages the rest of the networking resources, then grant the security team the Security Admin role and the networking team the Network Admin role.
Next steps / Learn more
For information on the basic concepts of Google Cloud Identity and Access Management, see Google Cloud Identity and Access Management Overview
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 November 2, 2022
Lab Last Tested June 15, 2022
Copyright 2023 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.