What is IAM?
Google Cloud offers Cloud Identity and Access Management (IAM), which lets you manage access control by defining who (identity) has what access (role) for which resource.
In IAM, permission to access a resource isn't granted directly to the end user. Instead, permissions are grouped into roles, and roles are granted to authenticated principals. (In the past, IAM often referred to principals as members. Some APIs still use this term.)
Identities
In Cloud IAM, you grant access to principals. Principals can be of the following types:
Google Account
Service account
Google group
Google Workspace account
Cloud Identity domain
All authenticated users
All users
Learn more about these identity types from the Concepts related to identity Guide.
In this lab, you use Google accounts, service accounts, and Cloud Identity domain groups.
Roles
A role is a collection of permissions. You cannot assign a permission to the user directly; instead you grant them a role. When you grant a role to a user, you grant them all the permissions that the role contains.
Overview
This lab looks at three common areas to understand with regards to IAM and gcloud:
the configuration of the gcloud environment
the use of multiple gcloud configurations
the use of services accounts
In this lab you use the gcloud CLI tool to set up and configure command features of Cloud Identity and Access Management (IAM).
What you'll learn
In this lab, you do the following:
Review IAM and using the gcloud client
Create and switch between multiple IAM configurations
Identify and assign correct IAM permissions
Create and use a service account
Starting environment
You start with two user accounts and two projects;
user1 is the "owner" of both projects
user2 is the "viewer" of only the first project.
There is a Linux virtual machine (vm) running in the first project.
You can run:
$ gcloud config set account `ACCOUNT`
to switch accounts if necessary.
Your credentials may be visible to others with access to this
virtual machine. Are you sure you want to authenticate with
your personal account?
Do you want to continue (Y/n)? Y
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=32555940559.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Fsdk.cloud.google.com%2Fauthcode.html&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fsqlservice.login+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&state=dY4JfRm3mhdf7HDgbEoWpIwfsS1AFS&prompt=consent&access_type=offline&code_challenge=woUOXswqaJT5TmpGs11XKtcCEcVCbPM9eSvTplVjM_o&code_challenge_method=S256
Enter authorization code: 4/0AZEOvhVrKbPSDmowePe1BKnU8Li-prGyiQBtkzzzWJMAd8b5Kf3wQboQbjAhqhdZaKpDIw
You are now logged in as [student-04-6234289191d9@qwiklabs.net].
Your current project is [qwiklabs-gcp-01-2f669a123a64]. You can change this setting by running:
$ gcloud config set project PROJECT_ID
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config list
[core]
account = student-04-6234289191d9@qwiklabs.net
disable_usage_reporting = True
project = qwiklabs-gcp-01-2f669a123a64
Your active configuration is: [default]
[student-04-6234289191d9@centos-clean ~]$ gcloud config set compute/regions us-west1
ERROR: (gcloud.config.set) Section [compute] has no property [regions].
[student-04-6234289191d9@centos-clean ~]$ gcloud config set compute/region us-west1
Updated property [compute/region].
[student-04-6234289191d9@centos-clean ~]$ gcloud config list
[compute]
region = us-west1
[core]
account = student-04-6234289191d9@qwiklabs.net
disable_usage_reporting = True
project = qwiklabs-gcp-01-2f669a123a64
Your active configuration is: [default]
[student-04-6234289191d9@centos-clean ~]$ gcloud config set compute/zone us-west1-a
Updated property [compute/zone].
[student-04-6234289191d9@centos-clean ~]$ gcloud config list
[compute]
region = us-west1
zone = us-west1-a
[core]
account = student-04-6234289191d9@qwiklabs.net
disable_usage_reporting = True
project = qwiklabs-gcp-01-2f669a123a64
Your active configuration is: [default]
[student-04-6234289191d9@centos-clean ~]$ gcloud config list zone
ERROR: (gcloud.config.list) Section [core] has no property [zone].
[student-04-6234289191d9@centos-clean ~]$ gcloud config list project
[core]
project = qwiklabs-gcp-01-2f669a123a64
Your active configuration is: [default]
[student-04-6234289191d9@centos-clean ~]$ gcloud config list region
ERROR: (gcloud.config.list) Section [core] has no property [region].
[student-04-6234289191d9@centos-clean ~]$ gcloud config list account
[core]
account = student-04-6234289191d9@qwiklabs.net
Your active configuration is: [default]
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud compute instances create lab-1 --zone us-west1-a --machine-type=e2-standard-2
Created [https://www.googleapis.com/compute/v1/projects/qwiklabs-gcp-01-2f669a123a64/zones/us-west1-a/instances/lab-1].
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
lab-1 us-west1-a e2-standard-2 10.138.0.3 35.197.89.11 RUNNING
[student-04-6234289191d9@centos-clean ~]$ gcloud config list
[compute]
region = us-west1
zone = us-west1-a
[core]
account = student-04-6234289191d9@qwiklabs.net
disable_usage_reporting = True
project = qwiklabs-gcp-01-2f669a123a64
Your active configuration is: [default]
[student-04-6234289191d9@centos-clean ~]$ gcloud compute zones list
NAME REGION STATUS NEXT_MAINTENANCE TURNDOWN_DATE
us-east1-b us-east1 UP
us-west3-b us-west3 UP
us-west3-c us-west3 UP
us-west4-a us-west4 UP
us-west4-b us-west4 UP
us-west4-c us-west4 UP
[student-04-6234289191d9@centos-clean ~]$ gcloud config list zones
ERROR: (gcloud.config.list) Section [core] has no property [zones].
[student-04-6234289191d9@centos-clean ~]$ gcloud config list
[compute]
region = us-west1
zone = us-west1-a
[core]
account = student-04-6234289191d9@qwiklabs.net
disable_usage_reporting = True
project = qwiklabs-gcp-01-2f669a123a64
Your active configuration is: [default]
[student-04-6234289191d9@centos-clean ~]$ gcloud config set compute/zone us-west1-b
Updated property [compute/zone].
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config list
[compute]
region = us-west1
zone = us-west1-b
[core]
account = student-04-6234289191d9@qwiklabs.net
disable_usage_reporting = True
project = qwiklabs-gcp-01-2f669a123a64
Your active configuration is: [default]
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ cat ~/.config/gcloud/configurations/config_default
[core]
account = student-04-6234289191d9@qwiklabs.net
[compute]
region = us-west1
zone = us-west1-b
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud init --no-launch-browser
Welcome! This command will take you through the configuration of gcloud.
Settings from your current configuration [default] are:
compute:
region: us-west1
zone: us-west1-b
core:
account: student-04-6234289191d9@qwiklabs.net
disable_usage_reporting: 'True'
project: qwiklabs-gcp-01-2f669a123a64
Pick configuration to use:
[1] Re-initialize this configuration [default] with new settings
[2] Create a new configuration
Please enter your numeric choice: 2
Enter configuration name. Names start with a lower case letter and contain only lower case letters a-z, digits
0-9, and hyphens '-': user2
Your current configuration has been set to: [user2]
You can skip diagnostics next time by using the following flag:
gcloud init --skip-diagnostics
Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).
Choose the account you would like to use to perform operations for this configuration:
[1] 96240167141-compute@developer.gserviceaccount.com
[2] student-04-6234289191d9@qwiklabs.net
[3] Log in with a new account
Please enter your numeric choice: 3
You are running on a Google Compute Engine virtual machine.
It is recommended that you use service accounts for authentication.
You can run:
$ gcloud config set account `ACCOUNT`
to switch accounts if necessary.
Your credentials may be visible to others with access to this
virtual machine. Are you sure you want to authenticate with
your personal account?
Do you want to continue (Y/n)? Y
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=32555940559.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Fsdk.cloud.google.com%2Fauthcode.html&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fsqlservice.login+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&state=gtlxDq0NvdMAFrnIXDgtAh8C0TopqO&prompt=consent&access_type=offline&code_challenge=ZBemYpx4BlVynDQT7cQLB9cHljUVdPwbVHS4DJ9LPeA&code_challenge_method=S256
Enter authorization code: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=32555940559.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Fsdk.cloud.google.com%2Fauthcode.html&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fsqlservice.login+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&state=gtlxDq0NvdMAFrnIXDgtAh8C0TopqO&prompt=consent&access_type=offline&code_challenge=ZBemYpx4BlVynDQT7cQLB9cHljU
ERROR: gcloud crashed (InvalidGrantError): (invalid_grant) Malformed auth code.
If you would like to report this issue, please run the following command:
gcloud feedback
To check gcloud for common problems, please run the following command:
gcloud info --run-diagnostics
[student-04-6234289191d9@centos-clean ~]$ gcloud init --no-launch-browser
Welcome! This command will take you through the configuration of gcloud.
Settings from your current configuration [user2] are:
core:
account: 96240167141-compute@developer.gserviceaccount.com
disable_usage_reporting: 'True'
project: qwiklabs-gcp-01-2f669a123a64
Pick configuration to use:
[1] Re-initialize this configuration [user2] with new settings
[2] Create a new configuration
[3] Switch to and re-initialize existing configuration: [default]
Please enter your numeric choice: 3
Your current configuration has been set to: [default]
You can skip diagnostics next time by using the following flag:
gcloud init --skip-diagnostics
Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).
Choose the account you would like to use to perform operations for this configuration:
[1] 96240167141-compute@developer.gserviceaccount.com
[2] student-04-6234289191d9@qwiklabs.net
[3] Log in with a new account
Please enter your numeric choice: ^C
Command killed by keyboard interrupt
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud init --no-launch-browser
Welcome! This command will take you through the configuration of gcloud.
Settings from your current configuration [default] are:
compute:
region: us-west1
zone: us-west1-b
core:
account: student-04-6234289191d9@qwiklabs.net
disable_usage_reporting: 'True'
project: qwiklabs-gcp-01-2f669a123a64
Pick configuration to use:
[1] Re-initialize this configuration [default] with new settings
[2] Create a new configuration
[3] Switch to and re-initialize existing configuration: [user2]
Please enter your numeric choice: 2
Enter configuration name. Names start with a lower case letter and contain only lower case letters a-z, digits
0-9, and hyphens '-': user2
ERROR: (gcloud.init) Cannot create configuration [user2], it already exists.
[student-04-6234289191d9@centos-clean ~]$ gcloud init --no-launch-browser
Welcome! This command will take you through the configuration of gcloud.
Settings from your current configuration [default] are:
compute:
region: us-west1
zone: us-west1-b
core:
account: student-04-6234289191d9@qwiklabs.net
disable_usage_reporting: 'True'
project: qwiklabs-gcp-01-2f669a123a64
Pick configuration to use:
[1] Re-initialize this configuration [default] with new settings
[2] Create a new configuration
[3] Switch to and re-initialize existing configuration: [user2]
Please enter your numeric choice: 3
Your current configuration has been set to: [user2]
You can skip diagnostics next time by using the following flag:
gcloud init --skip-diagnostics
Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).
Choose the account you would like to use to perform operations for this configuration:
[1] 96240167141-compute@developer.gserviceaccount.com
[2] student-04-6234289191d9@qwiklabs.net
[3] Log in with a new account
Please enter your numeric choice: 3
You are running on a Google Compute Engine virtual machine.
It is recommended that you use service accounts for authentication.
You can run:
$ gcloud config set account `ACCOUNT`
to switch accounts if necessary.
Your credentials may be visible to others with access to this
virtual machine. Are you sure you want to authenticate with
your personal account?
Do you want to continue (Y/n)? Y
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=32555940559.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Fsdk.cloud.google.com%2Fauthcode.html&scope=openid+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcloud-platform+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fappengine.admin+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fsqlservice.login+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcompute+https%3A%2F%2Fwww.googleapis.com%2Fauth%2Faccounts.reauth&state=xT3TGNy8SDdU8gVsRpd2FdQYBo6yDO&prompt=consent&access_type=offline&code_challenge=d9bwXXCn_9ZKUZMjGvU5dNP05DhAHT_isrp0yKQC5ig&code_challenge_method=S256
Enter authorization code: 4/0AZEOvhUTiOMUx2CoEb5QEZUhhjprxzx3fsiucf9MiGw8ocazBSAL6BqzDczXjdb5mVdbAA
You are logged in as: [student-01-2053c649e0fc@qwiklabs.net].
Pick cloud project to use:
[1] qwiklabs-gcp-01-2f669a123a64
[2] qwiklabs-resources
[3] Enter a project ID
[4] Create a new project
Please enter numeric choice or text value (must exactly match list item): 1
Your current project has been set to: [qwiklabs-gcp-01-2f669a123a64].
Your project default Compute Engine zone has been set to [us-west1-a].
You can change it by running [gcloud config set compute/zone NAME].
Your project default Compute Engine region has been set to [us-west1].
You can change it by running [gcloud config set compute/region NAME].
Created a default .boto configuration file at [/home/student-04-6234289191d9/.boto]. See this file and
[https://cloud.google.com/storage/docs/gsutil/commands/config] for more
information about configuring Google Cloud Storage.
Your Google Cloud SDK is configured and ready to use!
* Commands that require authentication will use student-01-2053c649e0fc@qwiklabs.net by default
* Commands will reference project `qwiklabs-gcp-01-2f669a123a64` by default
* Compute Engine commands will use region `us-west1` by default
* Compute Engine commands will use zone `us-west1-a` by default
Run `gcloud help config` to learn how to change individual settings
This gcloud configuration is called [user2]. You can create additional configurations if you work with multiple accounts and/or projects.
Run `gcloud topic configurations` to learn more.
Some things to try next:
* Run `gcloud --help` to see the Cloud Platform services you can interact with. And run `gcloud help COMMAND` to get help on any gcloud command.
* Run `gcloud topic --help` to learn about advanced features of the SDK like arg files and output formatting
* Run `gcloud cheat-sheet` to see a roster of go-to `gcloud` commands.
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud compute instance list
ERROR: (gcloud.compute) Invalid choice: 'instance'.
Maybe you meant:
gcloud compute instance-groups list-instances
gcloud compute instances list
gcloud compute instance-groups list
gcloud compute instance-groups managed instance-configs list
gcloud compute instance-templates list
gcloud compute target-instances list
gcloud compute instances os-inventory list-instances
gcloud compute instance-groups managed list-instances
gcloud compute instance-groups unmanaged list-instances
gcloud compute instances add-access-config
To search the help text of gcloud commands, run:
gcloud help -- SEARCH_TERMS
[student-04-6234289191d9@centos-clean ~]$ gcloud confi glist
ERROR: (gcloud) Invalid choice: 'confi'.
Maybe you meant:
gcloud config
To search the help text of gcloud commands, run:
gcloud help -- SEARCH_TERMS
[student-04-6234289191d9@centos-clean ~]$ gcloud configlist
ERROR: (gcloud) Invalid choice: 'configlist'.
Maybe you meant:
gcloud config get
gcloud config list
gcloud config set
gcloud config unset
To search the help text of gcloud commands, run:
gcloud help -- SEARCH_TERMS
[student-04-6234289191d9@centos-clean ~]$ gcloud config list
[compute]
region = us-west1
zone = us-west1-a
[core]
account = student-01-2053c649e0fc@qwiklabs.net
disable_usage_reporting = True
project = qwiklabs-gcp-01-2f669a123a64
Your active configuration is: [user2]
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
centos-clean us-west1-a e2-medium 10.138.0.2 34.127.54.190 RUNNING
lab-1 us-west1-a e2-standard-2 10.138.0.3 35.197.89.11 RUNNING
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud compute instances create lab-2 --machine-type=e2-standard-2
ERROR: (gcloud.compute.instances.create) Could not fetch resource:
- Required 'compute.instances.create' permission for 'projects/qwiklabs-gcp-01-2f669a123a64/zones/us-west1-a/instances/lab-2'
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations activate default
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud iam roles list | grep "name:"
name: roles/accessapproval.approver
name: roles/accessapproval.configEditor
name: roles/actions.Admin
name: roles/actions.Viewer
name: roles/advisorynotifications.viewer
- compute.zoneOperations.get
- compute.zoneOperations.list
- compute.zones.get
- compute.zones.list
- resourcemanager.projects.get
- resourcemanager.projects.list
- serviceusage.quotas.get
- serviceusage.services.get
- serviceusage.services.list
name: roles/compute.instanceAdmin
stage: GA
title: Compute Instance Admin (beta)
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations activate user2
Activated [user2].
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations
ERROR: (gcloud.config.configurations) Command name argument expected.
Available commands for gcloud config configurations:
activate Activates an existing named configuration.
create Creates a new named configuration.
delete Deletes a named configuration.
describe Describes a named configuration by listing its
properties.
list Lists existing named configurations.
rename Renames a named configuration.
For detailed information on this command and its flags, run:
gcloud config configurations --help
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations list
NAME IS_ACTIVE ACCOUNT PROJECT COMPUTE_DEFAULT_ZONE COMPUTE_DEFAULT_REGION
default False student-04-6234289191d9@qwiklabs.net us-west1-b us-west1
user2 True student-01-2053c649e0fc@qwiklabs.net qwiklabs-gcp-01-2f669a123a64 us-west1-a us-west1
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config list
[compute]
region = us-west1
zone = us-west1-a
[core]
account = student-01-2053c649e0fc@qwiklabs.net
disable_usage_reporting = True
project = qwiklabs-gcp-01-2f669a123a64
Your active configuration is: [user2]
[student-04-6234289191d9@centos-clean ~]$ qwiklabs-gcp-02-7ffb63561000
-bash: qwiklabs-gcp-02-7ffb63561000: command not found
[student-04-6234289191d9@centos-clean ~]$ qwiklabs-gcp-01-2f669a123a64
-bash: qwiklabs-gcp-01-2f669a123a64: command not found
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations activate user1
ERROR: (gcloud.config.configurations.activate) Cannot activate configuration [user1], it does not exist.
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations activate user2
Activated [user2].
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config list
[compute]
region = us-west1
zone = us-west1-a
[core]
account = student-01-2053c649e0fc@qwiklabs.net
disable_usage_reporting = True
project = qwiklabs-gcp-01-2f669a123a64
Your active configuration is: [user2]
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations list
NAME IS_ACTIVE ACCOUNT PROJECT COMPUTE_DEFAULT_ZONE COMPUTE_DEFAULT_REGION
default False student-04-6234289191d9@qwiklabs.net us-west1-b us-west1
user2 True student-01-2053c649e0fc@qwiklabs.net qwiklabs-gcp-01-2f669a123a64 us-west1-a us-west1
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud compute instances create lab-2 --machine-type=e2-standard-2
ERROR: (gcloud.compute.instances.create) Could not fetch resource:
- Required 'compute.instances.create' permission for 'projects/qwiklabs-gcp-01-2f669a123a64/zones/us-west1-a/instances/lab-2'
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ id
uid=733073824(student-04-6234289191d9) gid=1000(google-sudoers) groups=1000(google-sudoers),39(video) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
[student-04-6234289191d9@centos-clean ~]$ cat ~/.config/gcloud/configurations/config_default
[core]
account = student-04-6234289191d9@qwiklabs.net
[compute]
region = us-west1
zone = us-west1-b
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ echo "export PROJECTID2=qwiklabs-gcp-02-7ffb63561000" >> ~/.bashrc
[student-04-6234289191d9@centos-clean ~]$ cat ~/.bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
export PROJECTID2=qwiklabs-gcp-02-7ffb63561000
[student-04-6234289191d9@centos-clean ~]$ . ~/.bashrc
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config list
[compute]
region = us-west1
zone = us-west1-a
[core]
account = student-01-2053c649e0fc@qwiklabs.net
disable_usage_reporting = True
project = qwiklabs-gcp-01-2f669a123a64
Your active configuration is: [user2]
[student-04-6234289191d9@centos-clean ~]$ gcloud config set project $PROJECTID2
WARNING: You do not appear to have access to project [qwiklabs-gcp-02-7ffb63561000] or it does not exist.
Are you sure you wish to set property [core/project] to qwiklabs-gcp-02-7ffb63561000?
Do you want to continue (Y/n)? N
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations activate default
Activated [default].
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations list
NAME IS_ACTIVE ACCOUNT PROJECT COMPUTE_DEFAULT_ZONE COMPUTE_DEFAULT_REGION
default True student-04-6234289191d9@qwiklabs.net us-west1-b us-west1
user2 False student-01-2053c649e0fc@qwiklabs.net qwiklabs-gcp-01-2f669a123a64 us-west1-a us-west1
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ sudo yum -y install epel-release
Loaded plugins: fastestmirror
Determining fastest mirrors
epel/x86_64/metalink | 28 kB 00:00:00
* base: mirror.web-ster.com
[student-04-6234289191d9@centos-clean ~]$ sudo yum -y install jq
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.web-ster.com
Complete!
[student-04-6234289191d9@centos-clean ~]$ echo "export USERID2=student-01-2053c649e0fc@qwiklabs.net" >> ~/.bashrc
[student-04-6234289191d9@centos-clean ~]$ cat ~/.bashrc
# .bashrc
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
fi
# Uncomment the following line if you don't like systemctl's auto-paging feature:
# export SYSTEMD_PAGER=
# User specific aliases and functions
export PROJECTID2=qwiklabs-gcp-02-7ffb63561000
export USERID2=student-01-2053c649e0fc@qwiklabs.net
[student-04-6234289191d9@centos-clean ~]$ . ~/.bashrc
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud projects add-iam-policy-binding $PROJECTID2 --member user:$USERID2 --role=roles/viewer
Updated IAM policy for project [qwiklabs-gcp-02-7ffb63561000].
bindings:
- members:
- serviceAccount:qwiklabs-gcp-02-7ffb63561000@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
role: roles/bigquery.admin
- members:
- serviceAccount:295933315945@cloudbuild.gserviceaccount.com
role: roles/cloudbuild.builds.builder
- members:
- serviceAccount:service-295933315945@gcp-sa-cloudbuild.iam.gserviceaccount.com
role: roles/cloudbuild.serviceAgent
- members:
- serviceAccount:service-295933315945@compute-system.iam.gserviceaccount.com
role: roles/compute.serviceAgent
- members:
- serviceAccount:service-295933315945@container-engine-robot.iam.gserviceaccount.com
role: roles/container.serviceAgent
- members:
- serviceAccount:295933315945-compute@developer.gserviceaccount.com
- serviceAccount:295933315945@cloudservices.gserviceaccount.com
role: roles/editor
- members:
- user:student-04-6234289191d9@qwiklabs.net
role: roles/iam.serviceAccountAdmin
- members:
- serviceAccount:admiral@qwiklabs-services-prod.iam.gserviceaccount.com
- serviceAccount:qwiklabs-gcp-02-7ffb63561000@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
- user:student-04-6234289191d9@qwiklabs.net
role: roles/owner
- members:
- user:student-04-6234289191d9@qwiklabs.net
role: roles/resourcemanager.projectIamAdmin
- members:
- serviceAccount:qwiklabs-gcp-02-7ffb63561000@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
role: roles/storage.admin
- members:
- user:student-01-2053c649e0fc@qwiklabs.net
- user:student-04-6234289191d9@qwiklabs.net
role: roles/viewer
etag: BwYByx85k8c=
version: 1
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations list
NAME IS_ACTIVE ACCOUNT PROJECT COMPUTE_DEFAULT_ZONE COMPUTE_DEFAULT_REGION
default True student-04-6234289191d9@qwiklabs.net us-west1-b us-west1
user2 False student-01-2053c649e0fc@qwiklabs.net qwiklabs-gcp-01-2f669a123a64 us-west1-a us-west1
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations activate user2
Activated [user2].
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations list
NAME IS_ACTIVE ACCOUNT PROJECT COMPUTE_DEFAULT_ZONE COMPUTE_DEFAULT_REGION
default False student-04-6234289191d9@qwiklabs.net us-west1-b us-west1
user2 True student-01-2053c649e0fc@qwiklabs.net qwiklabs-gcp-01-2f669a123a64 us-west1-a us-west1
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config list
[compute]
region = us-west1
zone = us-west1-a
[core]
account = student-01-2053c649e0fc@qwiklabs.net
disable_usage_reporting = True
project = qwiklabs-gcp-01-2f669a123a64
Your active configuration is: [user2]
[student-04-6234289191d9@centos-clean ~]$ gcloud config set project $PROJECTID2
Updated property [core/project].
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config list
[compute]
region = us-west1
zone = us-west1-a
[core]
account = student-01-2053c649e0fc@qwiklabs.net
disable_usage_reporting = True
project = qwiklabs-gcp-02-7ffb63561000
Your active configuration is: [user2]
[student-04-6234289191d9@centos-clean ~]$ echo $PROJECTID2
qwiklabs-gcp-02-7ffb63561000
[student-04-6234289191d9@centos-clean ~]$ gcloud compute instances list
Listed 0 items.
[student-04-6234289191d9@centos-clean ~]$ gcloud compute instances create lab-2 --machine-type=e2-standard-2
ERROR: (gcloud.compute.instances.create) Could not fetch resource:
- Required 'compute.instances.create' permission for 'projects/qwiklabs-gcp-02-7ffb63561000/zones/us-west1-a/instances/lab-2'
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations list
NAME IS_ACTIVE ACCOUNT PROJECT COMPUTE_DEFAULT_ZONE COMPUTE_DEFAULT_REGION
default False student-04-6234289191d9@qwiklabs.net us-west1-b us-west1
user2 True student-01-2053c649e0fc@qwiklabs.net qwiklabs-gcp-02-7ffb63561000 us-west1-a us-west1
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations activate default
Activated [default].
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations list
NAME IS_ACTIVE ACCOUNT PROJECT COMPUTE_DEFAULT_ZONE COMPUTE_DEFAULT_REGION
default True student-04-6234289191d9@qwiklabs.net us-west1-b us-west1
user2 False student-01-2053c649e0fc@qwiklabs.net qwiklabs-gcp-02-7ffb63561000 us-west1-a us-west1
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud iam roles create devops --project $PROJECTID2 --permissions "compute.instances.create,compute.instances.delete,compute.instances.start,compute.instances.stop,compute.instances.update,compute.disks.create,compute.subnetworks.use,compute.subnetworks.useExternalIp,compute.instances.setMetadata,compute.instances.setServiceAccount"
Created role [devops].
etag: BwYByy6i1rA=
includedPermissions:
- compute.disks.create
- compute.instances.create
- compute.instances.delete
- compute.instances.setMetadata
- compute.instances.setServiceAccount
- compute.instances.start
- compute.instances.stop
- compute.instances.update
- compute.subnetworks.use
- compute.subnetworks.useExternalIp
name: projects/qwiklabs-gcp-02-7ffb63561000/roles/devops
stage: ALPHA
title: devops
[student-04-6234289191d9@centos-clean ~]$ gcloud iam roles list | grep devops
[student-04-6234289191d9@centos-clean ~]$ gcloud iam roles list | more
---
description: Ability to view or act on access approval requests and view configuration
etag: AA==
name: roles/accessapproval.approver
stage: GA
title: Access Approval Approver
---
description: Ability to update the Access Approval configuration
etag: AA==
name: roles/accessapproval.configEditor
stage: GA
title: Access Approval Config Editor
---
description: Ability to invalidate existing approved approval requests
etag: AA==
name: roles/accessapproval.invalidator
stage: GA
title: Access Approval Invalidator
---
description: Ability to view access approval requests and configuration
etag: AA==
name: roles/accessapproval.viewer
stage: GA
title: Access Approval Viewer
---
description: Create, edit, and change Cloud access bindings.
etag: AA==
name: roles/accesscontextmanager.gcpAccessAdmin
stage: GA
title: Cloud Access Binding Admin
---
description: Read access to Cloud access bindings.
etag: AA==
name: roles/accesscontextmanager.gcpAccessReader
stage: GA
title: Cloud Access Binding Reader
---
description: Full access to policies, access levels, access zones and authorized orgs
[student-04-6234289191d9@centos-clean ~]$ gcloud iam roles list | grep "name:" | grep devops
[student-04-6234289191d9@centos-clean ~]$ gcloud projects add-iam-policy-binding $PROJECTID2 --member user:$USERID2 --role=roles/iam.serviceAccountUser
Updated IAM policy for project [qwiklabs-gcp-02-7ffb63561000].
bindings:
- members:
- serviceAccount:qwiklabs-gcp-02-7ffb63561000@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
role: roles/bigquery.admin
- members:
- serviceAccount:295933315945@cloudbuild.gserviceaccount.com
role: roles/cloudbuild.builds.builder
- members:
- serviceAccount:service-295933315945@gcp-sa-cloudbuild.iam.gserviceaccount.com
role: roles/cloudbuild.serviceAgent
- members:
- serviceAccount:service-295933315945@compute-system.iam.gserviceaccount.com
role: roles/compute.serviceAgent
- members:
- serviceAccount:service-295933315945@container-engine-robot.iam.gserviceaccount.com
role: roles/container.serviceAgent
- members:
- serviceAccount:295933315945-compute@developer.gserviceaccount.com
- serviceAccount:295933315945@cloudservices.gserviceaccount.com
role: roles/editor
- members:
- user:student-04-6234289191d9@qwiklabs.net
role: roles/iam.serviceAccountAdmin
- members:
- user:student-01-2053c649e0fc@qwiklabs.net
role: roles/iam.serviceAccountUser
- members:
- serviceAccount:admiral@qwiklabs-services-prod.iam.gserviceaccount.com
- serviceAccount:qwiklabs-gcp-02-7ffb63561000@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
- user:student-04-6234289191d9@qwiklabs.net
role: roles/owner
- members:
- user:student-04-6234289191d9@qwiklabs.net
role: roles/resourcemanager.projectIamAdmin
- members:
- serviceAccount:qwiklabs-gcp-02-7ffb63561000@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
role: roles/storage.admin
- members:
- user:student-01-2053c649e0fc@qwiklabs.net
- user:student-04-6234289191d9@qwiklabs.net
role: roles/viewer
etag: BwYByzuIIdY=
version: 1
[student-04-6234289191d9@centos-clean ~]$ gcloud projects add-iam-policy-binding $PROJECTID2 --member user:$USERID2 --role=projects/$PROJECTID2/roles/devops
Updated IAM policy for project [qwiklabs-gcp-02-7ffb63561000].
bindings:
- members:
- user:student-01-2053c649e0fc@qwiklabs.net
role: projects/qwiklabs-gcp-02-7ffb63561000/roles/devops
- members:
- serviceAccount:qwiklabs-gcp-02-7ffb63561000@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
role: roles/bigquery.admin
- members:
- serviceAccount:295933315945@cloudbuild.gserviceaccount.com
role: roles/cloudbuild.builds.builder
- members:
- serviceAccount:service-295933315945@gcp-sa-cloudbuild.iam.gserviceaccount.com
role: roles/cloudbuild.serviceAgent
- members:
- serviceAccount:service-295933315945@compute-system.iam.gserviceaccount.com
role: roles/compute.serviceAgent
- members:
- serviceAccount:service-295933315945@container-engine-robot.iam.gserviceaccount.com
role: roles/container.serviceAgent
- members:
- serviceAccount:295933315945-compute@developer.gserviceaccount.com
- serviceAccount:295933315945@cloudservices.gserviceaccount.com
role: roles/editor
- members:
- user:student-04-6234289191d9@qwiklabs.net
role: roles/iam.serviceAccountAdmin
- members:
- user:student-01-2053c649e0fc@qwiklabs.net
role: roles/iam.serviceAccountUser
- members:
- serviceAccount:admiral@qwiklabs-services-prod.iam.gserviceaccount.com
- serviceAccount:qwiklabs-gcp-02-7ffb63561000@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
- user:student-04-6234289191d9@qwiklabs.net
role: roles/owner
- members:
- user:student-04-6234289191d9@qwiklabs.net
role: roles/resourcemanager.projectIamAdmin
- members:
- serviceAccount:qwiklabs-gcp-02-7ffb63561000@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
role: roles/storage.admin
- members:
- user:student-01-2053c649e0fc@qwiklabs.net
- user:student-04-6234289191d9@qwiklabs.net
role: roles/viewer
etag: BwYByz02VDM=
version: 1
[student-04-6234289191d9@centos-clean ~]$ history
1 gcloud --version
2 gcloud auth login
3 gcloud config list
4 gcloud config set compute/regions us-west1
5 gcloud config set compute/region us-west1
6 gcloud config list
7 gcloud config set compute/zone us-west1-a
8 gcloud config list
9 gcloud config list zone
10 gcloud config list project
11 gcloud config list region
12 gcloud config list account
13 gcloud compute instances create lab-1 --zone us-west1-a --machine-type=e2-standard-2
14 gcloud config list
15 gcloud compute zones list
16 gcloud config list zones
17 gcloud config list
18 gcloud config set compute/zone us-west1-b
19 gcloud config list
20 cat ~/.config/gcloud/configurations/config_default
21 gcloud init --no-launch-browser
22 gcloud compute instance list
23 gcloud confi glist
24 gcloud configlist
25 gcloud config list
26 gcloud compute instances list
27 gcloud compute instances create lab-2 --machine-type=e2-standard-2
28 gcloud config configuration activate default
29 gcloud config configurations activate default
30 history
31 gcloud iam roles list
32 gcloud iam roles list | grep "name:"
33 gcloud iam roles describe roles/compute.instanceAdmin
34 gcloud config configurations activate user2
35 gcloud config configurations
36 gcloud config configurations list
37 gcloud config list
38 qwiklabs-gcp-02-7ffb63561000
39 qwiklabs-gcp-01-2f669a123a64
40 gcloud config configurations activate user1
41 gcloud config configurations activate user2
42 gcloud config list
43 gcloud config configurations list
44 gcloud compute instances create lab-2 --machine-type=e2-standard-2
45 id
46 cat ~/.config/gcloud/configurations/config_default
47 echo "export PROJECTID2=qwiklabs-gcp-02-7ffb63561000" >> ~/.bashrc
48 cat ~/.bashrc
49 . ~/.bashrc
50 gcloud config list
51 gcloud config set project $PROJECTID2
52 gcloud config configurations activate default
53 gcloud config configurations list
54 sudo yum -y install epel-release
55 sudo yum -y install jq
56 echo "export USERID2=student-01-2053c649e0fc@qwiklabs.net" >> ~/.bashrc
57 cat ~/.bashrc
58 . ~/.bashrc
59 gcloud projects add-iam-policy-binding $PROJECTID2 --member user:$USERID2 --role=roles/viewer
60 gcloud config configurations list
61 gcloud config configurations activate user2
62 gcloud config configurations list
63 gcloud config list
64 gcloud config set project $PROJECTID2
65 gcloud config list
66 echo $PROJECTID2
67 gcloud compute instances list
68 gcloud compute instances create lab-2 --machine-type=e2-standard-2
69 gcloud config configurations list
70 gcloud config configurations activate default
71 gcloud config configurations list
72 gcloud iam roles create devops --project $PROJECTID2 --permissions
73 gcloud iam roles create devops --project $PROJECTID2 --permissions "compute.instances.create,compute.instances.delete,compute.instances.start,compute.instances.stop,compute.instances.update,compute.disks.create,compute.subnetworks.use,compute.subnetworks.useExternalIp,compute.instances.setMetadata,compute.instances.setServiceAccount"
74 gcloud iam roles list | grep devops
75 gcloud iam roles list | more
76 gcloud iam roles list | grep "name:" | grep devops
77 gcloud iam roles
78 gcloud projects add-iam-policy-binding $PROJECTID2 --member user:$USERID2 --role=roles/iam.serviceAccountUser
79 gcloud projects add-iam-policy-binding $PROJECTID2 --member user:$USERID2 --role=projects/$PROJECTID2/roles/devops
80 history
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations list
NAME IS_ACTIVE ACCOUNT PROJECT COMPUTE_DEFAULT_ZONE COMPUTE_DEFAULT_REGION
default True student-04-6234289191d9@qwiklabs.net us-west1-b us-west1
user2 False student-01-2053c649e0fc@qwiklabs.net qwiklabs-gcp-02-7ffb63561000 us-west1-a us-west1
[student-04-6234289191d9@centos-clean ~]$ gcloud iam roles list | grep devops
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations activate user2
Activated [user2].
[student-04-6234289191d9@centos-clean ~]$ gcloud compute instances create lab-2 --machine-type=e2-standard-2
Created [https://www.googleapis.com/compute/v1/projects/qwiklabs-gcp-02-7ffb63561000/zones/us-west1-a/instances/lab-2].
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
lab-2 us-west1-a e2-standard-2 10.138.0.2 34.105.80.208 RUNNING
[student-04-6234289191d9@centos-clean ~]$ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
lab-2 us-west1-a e2-standard-2 10.138.0.2 34.105.80.208 RUNNING
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations list
NAME IS_ACTIVE ACCOUNT PROJECT COMPUTE_DEFAULT_ZONE COMPUTE_DEFAULT_REGION
default False student-04-6234289191d9@qwiklabs.net us-west1-b us-west1
user2 True student-01-2053c649e0fc@qwiklabs.net qwiklabs-gcp-02-7ffb63561000 us-west1-a us-west1
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations activate default
Activated [default].
[student-04-6234289191d9@centos-clean ~]$ gcloud config configurations list
NAME IS_ACTIVE ACCOUNT PROJECT COMPUTE_DEFAULT_ZONE COMPUTE_DEFAULT_REGION
default True student-04-6234289191d9@qwiklabs.net us-west1-b us-west1
user2 False student-01-2053c649e0fc@qwiklabs.net qwiklabs-gcp-02-7ffb63561000 us-west1-a us-west1
[student-04-6234289191d9@centos-clean ~]$ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
centos-clean us-west1-a e2-medium 10.138.0.2 34.127.54.190 RUNNING
lab-1 us-west1-a e2-standard-2 10.138.0.3 35.197.89.11 RUNNING
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config list
[compute]
region = us-west1
zone = us-west1-b
[core]
account = student-04-6234289191d9@qwiklabs.net
disable_usage_reporting = True
project = qwiklabs-gcp-01-2f669a123a64
Your active configuration is: [default]
[student-04-6234289191d9@centos-clean ~]$ gcloud config set project $PROJECTID2
Updated property [core/project].
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud config list
[compute]
region = us-west1
zone = us-west1-b
[core]
account = student-04-6234289191d9@qwiklabs.net
disable_usage_reporting = True
project = qwiklabs-gcp-02-7ffb63561000
Your active configuration is: [default]
[student-04-6234289191d9@centos-clean ~]$
Task 5. Using a service account
You have seen how to authenticate and use gcloud to access Google Cloud services with roles. Now you'll look at a typical approach.
You have an application that uses the Application Programming Interfaces (APIs) to read and write to Cloud Storage buckets. You don't want to have to authenticate every time you launch a new server, that would be both painful and not in the spirit of using the cloud! So, you use service accounts.
A service account is a special Google account that belongs to your application or a virtual machine (VM) instead of to an individual end user. Your application uses the service account to call the Google API of a service so that the users aren't directly involved.
Learn more about service accounts from the Service accounts Guide.
Now you create a service account, use that service account with a compute instance, then test that the service account allows the access you need.
Create a service account
[student-04-6234289191d9@centos-clean ~]$ gcloud iam service-accounts create devops --display-name devops
Created service account [devops].
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud iam service-accounts list
DISPLAY NAME EMAIL DISABLED
devops devops@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com False
Qwiklabs User Service Account qwiklabs-gcp-02-7ffb63561000@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com False
Compute Engine default service account 295933315945-compute@developer.gserviceaccount.com False
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud iam service-accounts list --filter "displayName=devops"
DISPLAY NAME EMAIL DISABLED
devops devops@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com False
[student-04-6234289191d9@centos-clean ~]$ SA=$(gcloud iam service-accounts list --format="value(email)" --filter "displayName=devops")
[student-04-6234289191d9@centos-clean ~]$ echo $SA
devops@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud projects add-iam-policy-binding $PROJECTID2 --member serviceAccount:$SA --role=roles/iam.serviceAccountUser
Updated IAM policy for project [qwiklabs-gcp-02-7ffb63561000].
bindings:
- members:
- user:student-01-2053c649e0fc@qwiklabs.net
role: projects/qwiklabs-gcp-02-7ffb63561000/roles/devops
- members:
- serviceAccount:qwiklabs-gcp-02-7ffb63561000@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
role: roles/bigquery.admin
- members:
- serviceAccount:295933315945@cloudbuild.gserviceaccount.com
role: roles/cloudbuild.builds.builder
- members:
- serviceAccount:service-295933315945@gcp-sa-cloudbuild.iam.gserviceaccount.com
role: roles/cloudbuild.serviceAgent
- members:
- serviceAccount:service-295933315945@compute-system.iam.gserviceaccount.com
role: roles/compute.serviceAgent
- members:
- serviceAccount:service-295933315945@container-engine-robot.iam.gserviceaccount.com
role: roles/container.serviceAgent
- members:
- serviceAccount:295933315945-compute@developer.gserviceaccount.com
- serviceAccount:295933315945@cloudservices.gserviceaccount.com
role: roles/editor
- members:
- user:student-04-6234289191d9@qwiklabs.net
role: roles/iam.serviceAccountAdmin
- members:
- serviceAccount:devops@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
- user:student-01-2053c649e0fc@qwiklabs.net
role: roles/iam.serviceAccountUser
- members:
- serviceAccount:admiral@qwiklabs-services-prod.iam.gserviceaccount.com
- serviceAccount:qwiklabs-gcp-02-7ffb63561000@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
- user:student-04-6234289191d9@qwiklabs.net
role: roles/owner
- members:
- user:student-04-6234289191d9@qwiklabs.net
role: roles/resourcemanager.projectIamAdmin
- members:
- serviceAccount:qwiklabs-gcp-02-7ffb63561000@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
role: roles/storage.admin
- members:
- user:student-01-2053c649e0fc@qwiklabs.net
- user:student-04-6234289191d9@qwiklabs.net
role: roles/viewer
etag: BwYBy2F-0Xc=
version: 1
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud projects add-iam-policy-binding $PROJECTID2 --member serviceAccount:$SA --role=roles/compute.instanceAdmin
Updated IAM policy for project [qwiklabs-gcp-02-7ffb63561000].
bindings:
- members:
- user:student-01-2053c649e0fc@qwiklabs.net
role: projects/qwiklabs-gcp-02-7ffb63561000/roles/devops
- members:
- serviceAccount:qwiklabs-gcp-02-7ffb63561000@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
role: roles/bigquery.admin
- members:
- serviceAccount:295933315945@cloudbuild.gserviceaccount.com
role: roles/cloudbuild.builds.builder
- members:
- serviceAccount:service-295933315945@gcp-sa-cloudbuild.iam.gserviceaccount.com
role: roles/cloudbuild.serviceAgent
- members:
- serviceAccount:devops@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
role: roles/compute.instanceAdmin
- members:
- serviceAccount:service-295933315945@compute-system.iam.gserviceaccount.com
role: roles/compute.serviceAgent
- members:
- serviceAccount:service-295933315945@container-engine-robot.iam.gserviceaccount.com
role: roles/container.serviceAgent
- members:
- serviceAccount:295933315945-compute@developer.gserviceaccount.com
- serviceAccount:295933315945@cloudservices.gserviceaccount.com
role: roles/editor
- members:
- user:student-04-6234289191d9@qwiklabs.net
role: roles/iam.serviceAccountAdmin
- members:
- serviceAccount:devops@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
- user:student-01-2053c649e0fc@qwiklabs.net
role: roles/iam.serviceAccountUser
- members:
- serviceAccount:admiral@qwiklabs-services-prod.iam.gserviceaccount.com
- serviceAccount:qwiklabs-gcp-02-7ffb63561000@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
- user:student-04-6234289191d9@qwiklabs.net
role: roles/owner
- members:
- user:student-04-6234289191d9@qwiklabs.net
role: roles/resourcemanager.projectIamAdmin
- members:
- serviceAccount:qwiklabs-gcp-02-7ffb63561000@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
role: roles/storage.admin
- members:
- user:student-01-2053c649e0fc@qwiklabs.net
- user:student-04-6234289191d9@qwiklabs.net
role: roles/viewer
etag: BwYBy2TgJb0=
version: 1
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud compute instances create lab-3 --machine-type=e2-standard-2 --service-account $SA --scopes "https://www.googleapis.com/auth/compute"
Created [https://www.googleapis.com/compute/v1/projects/qwiklabs-gcp-02-7ffb63561000/zones/us-west1-b/instances/lab-3].
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
lab-3 us-west1-b e2-standard-2 10.138.0.3 34.82.235.65 RUNNING
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$
[student-04-6234289191d9@centos-clean ~]$ gcloud compute ssh lab-3
WARNING: The private SSH key file for gcloud does not exist.
WARNING: The public SSH key file for gcloud does not exist.
WARNING: You do not have an SSH key for gcloud.
WARNING: SSH keygen will be executed to generate a key.
This tool needs to create the directory [/home/student-04-6234289191d9/.ssh] before being able to generate SSH keys.
Do you want to continue (Y/n)? Y
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/student-04-6234289191d9/.ssh/google_compute_engine.
Your public key has been saved in /home/student-04-6234289191d9/.ssh/google_compute_engine.pub.
The key fingerprint is:
SHA256:4M9ZndBiNoqNNQf0a7A3+MFCH/E/2iFw5oWZLY9UMmY student-04-6234289191d9@centos-clean
The key's randomart image is:
+---[RSA 2048]----+
| .o . E . |
| o * O |
| . = @ @ o |
| . B % & B |
| + S X * = |
| o B o + o |
| + . . . |
| |
| |
+----[SHA256]-----+
Warning: Permanently added 'compute.4968332160125261736' (ECDSA) to the list of known hosts.
Linux lab-3 5.10.0-23-cloud-amd64 #1 SMP Debian 5.10.179-1 (2023-05-12) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Creating directory '/home/student-04-6234289191d9'.
student-04-6234289191d9@lab-3:~$
student-04-6234289191d9@lab-3:~$
student-04-6234289191d9@lab-3:~$ gcloud config list
[core]
account = devops@qwiklabs-gcp-02-7ffb63561000.iam.gserviceaccount.com
disable_usage_reporting = True
project = qwiklabs-gcp-02-7ffb63561000
Your active configuration is: [default]
student-04-6234289191d9@lab-3:~$ gcloud compute instances create lab-4 --machine-type=e2-standard-2
Did you mean zone [us-west1-b] for instance: [lab-4] (Y/n)? Y
Created [https://www.googleapis.com/compute/v1/projects/qwiklabs-gcp-02-7ffb63561000/zones/us-west1-b/instances/lab-4].
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
lab-4 us-west1-b e2-standard-2 10.138.0.4 104.199.125.101 RUNNING
student-04-6234289191d9@lab-3:~$ gcloud compute instances list
NAME ZONE MACHINE_TYPE PREEMPTIBLE INTERNAL_IP EXTERNAL_IP STATUS
lab-2 us-west1-a e2-standard-2 10.138.0.2 34.105.80.208 RUNNING
lab-3 us-west1-b e2-standard-2 10.138.0.3 34.82.235.65 RUNNING
lab-4 us-west1-b e2-standard-2 10.138.0.4 104.199.125.101 RUNNING
student-04-6234289191d9@lab-3:~$
student-04-6234289191d9@lab-3:~$ history
1 gcloud config list
2 gcloud compute instances create lab-4 --machine-type=e2-standard-2
3 gcloud compute instances list
4 history
student-04-6234289191d9@lab-3:~$
student-04-6234289191d9@lab-3:~$
student-04-6234289191d9@lab-3:~$ exit
logout
Connection to 34.82.235.65 closed.
[student-04-6234289191d9@centos-clean ~]$ history
1 gcloud --version
2 gcloud auth login
3 gcloud config list
4 gcloud config set compute/regions us-west1
5 gcloud config set compute/region us-west1
6 gcloud config list
7 gcloud config set compute/zone us-west1-a
8 gcloud config list
9 gcloud config list zone
10 gcloud config list project
11 gcloud config list region
12 gcloud config list account
13 gcloud compute instances create lab-1 --zone us-west1-a --machine-type=e2-standard-2
14 gcloud config list
15 gcloud compute zones list
16 gcloud config list zones
17 gcloud config list
18 gcloud config set compute/zone us-west1-b
19 gcloud config list
20 cat ~/.config/gcloud/configurations/config_default
21 gcloud init --no-launch-browser
22 gcloud compute instance list
23 gcloud confi glist
24 gcloud configlist
25 gcloud config list
26 gcloud compute instances list
27 gcloud compute instances create lab-2 --machine-type=e2-standard-2
28 gcloud config configuration activate default
29 gcloud config configurations activate default
30 history
31 gcloud iam roles list
32 gcloud iam roles list | grep "name:"
33 gcloud iam roles describe roles/compute.instanceAdmin
34 gcloud config configurations activate user2
35 gcloud config configurations
36 gcloud config configurations list
37 gcloud config list
38 qwiklabs-gcp-02-7ffb63561000
39 qwiklabs-gcp-01-2f669a123a64
40 gcloud config configurations activate user1
41 gcloud config configurations activate user2
42 gcloud config list
43 gcloud config configurations list
44 gcloud compute instances create lab-2 --machine-type=e2-standard-2
45 id
46 cat ~/.config/gcloud/configurations/config_default
47 echo "export PROJECTID2=qwiklabs-gcp-02-7ffb63561000" >> ~/.bashrc
48 cat ~/.bashrc
49 . ~/.bashrc
50 gcloud config list
51 gcloud config set project $PROJECTID2
52 gcloud config configurations activate default
53 gcloud config configurations list
54 sudo yum -y install epel-release
55 sudo yum -y install jq
56 echo "export USERID2=student-01-2053c649e0fc@qwiklabs.net" >> ~/.bashrc
57 cat ~/.bashrc
58 . ~/.bashrc
59 gcloud projects add-iam-policy-binding $PROJECTID2 --member user:$USERID2 --role=roles/viewer
60 gcloud config configurations list
61 gcloud config configurations activate user2
62 gcloud config configurations list
63 gcloud config list
64 gcloud config set project $PROJECTID2
65 gcloud config list
66 echo $PROJECTID2
67 gcloud compute instances list
68 gcloud compute instances create lab-2 --machine-type=e2-standard-2
69 gcloud config configurations list
70 gcloud config configurations activate default
71 gcloud config configurations list
72 gcloud iam roles create devops --project $PROJECTID2 --permissions
73 gcloud iam roles create devops --project $PROJECTID2 --permissions "compute.instances.create,compute.instances.delete,compute.instances.start,compute.instances.stop,compute.instances.update,compute.disks.create,compute.subnetworks.use,compute.subnetworks.useExternalIp,compute.instances.setMetadata,compute.instances.setServiceAccount"
74 gcloud iam roles list | grep devops
75 gcloud iam roles list | more
76 gcloud iam roles list | grep "name:" | grep devops
77 gcloud iam roles
78 gcloud projects add-iam-policy-binding $PROJECTID2 --member user:$USERID2 --role=roles/iam.serviceAccountUser
79 gcloud projects add-iam-policy-binding $PROJECTID2 --member user:$USERID2 --role=projects/$PROJECTID2/roles/devops
80 history
81 gcloud config configurations list
82 gcloud iam roles list | grep devops
83 gcloud config configurations activate user2
84 gcloud compute instances create lab-2 --machine-type=e2-standard-2
85 gcloud compute instances list
86 gcloud config configurations list
87 gcloud config configurations activate default
88 gcloud config configurations list
89 gcloud compute instances list
90 gcloud config list
91 gcloud config set project $PROJECTID2
92 gcloud config list
93 gcloud iam service-accounts create devops --display-name devops
94 gcloud iam service-accounts list
95 gcloud iam service-accounts list --filter "displayName=devops"
96 SA=$(gcloud iam service-accounts list --format="value(email)" --filter "displayName=devops")
97 echo $SA
98 gcloud projects add-iam-policy-binding $PROJECTID2 --member serviceAccount:$SA --role=roles/iam.serviceAccountUser
99 gcloud projects add-iam-policy-binding $PROJECTID2 --member serviceAccount:$SA --role=roles/compute.instanceAdmin
100 gcloud compute instances create lab-3 --machine-type=e2-standard-2 --service-account $SA --scopes "https://www.googleapis.com/auth/compute"
101 gcloud compute ssh lab-3
102 history
[student-04-6234289191d9@centos-clean ~]$