
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
Create default credentials
/ 20
Rolesets bindings
/ 20
Configure a roleset that generates service account keys
/ 30
Configure static accounts
/ 30
This lab was developed with our partner, Hashicorp. Your personal information may be shared with Hashicorp, the lab sponsor, if you have opted in to receive product updates, announcements, and offers in your Account Profile.
The Google Cloud Vault secrets engine dynamically generates Google Cloud service account keys and OAuth tokens based on IAM policies. This enables users to gain access to Google Cloud resources without needing to create or manage a dedicated service account. In this lab, you will learn about the Google Cloud secrets engine and how to dynamically provision OAuth2 authentication tokens and service account keys.
In this lab, you will:
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.
Press Enter to continue.
After installing Vault, verify the installation worked by checking that the Vault binary is available.
vault
command to verify the installation:You should see help output similar to the following:
Up to this point, you interacted with the "dev" server, which automatically unseals Vault, sets up in-memory storage, etc. Now that you know the basics of Vault, it is important to learn how to deploy Vault into a real environment. Vault is configured using HCL files. For a deeper dive into this topic covering all the ways to configure a Vault server, refer to the Configure Vault tutorial.
config.hcl
:Click Open Editor on the toolbar of your Cloud Shell window. If prompted, click Open in a new window.
Open the config.hcl
file and add the following code to it:
Within the configuration file, there are two primary configurations:
storage
- This is the physical backend that Vault uses for storage. Up to this point the dev server has used "inmem" (in memory), but the example above uses Integrated Storage (raft
), a much more production-ready backend.listener
- One or more listeners determine how Vault listens for API requests. The example above listens on localhost port 8200 without TLS. In your environment set VAULT_ADDR=http://127.0.0.1:8200
so the Vault client will connect without TLS.api_addr
- Specifies the address to advertise to route client requests.cluster_addr
- Indicates the address and port to be used for communication between the Vault nodes in a cluster.tls_disable = true
). In production, Vault should always use TLS to provide secure communication between clients and the Vault server. It requires a certificate file and key file on each Vault host.
On cloud console, click Open Terminal .
Create the ./vault/data
directory that the raft
storage backend uses:
-config
flag to point to the proper path where you saved the configuration above:disable_mlock
in Server Configuration.
Initialization is the process of configuring Vault. This only happens once when the server is started against a new backend that has never been used with Vault before. When running in HA mode, this happens once per cluster, not per server. During initialization, the encryption keys are generated, unseal keys are created, and the initial root token is created.
VAULT_ADDR
environment variable:vault operator init
. This is an unauthenticated request, but it only works on brand new Vaults without existing data:Your output should resemble the following:
Initialization outputs two incredibly important pieces of information: the unseal keys and the initial root token. This is the only time ever that all of this data is known by Vault, and also the only time that the unseal keys should ever be so close together.
For the purpose of this lab, save all of these keys somewhere, and continue. In a real deployment scenario, you would never save these keys together. Instead, you would likely use Vault's PGP and Keybase.io support to encrypt each of these keys with the users' PGP keys. This prevents one single person from having all the unseal keys. Please see the documentation on using PGP, GPG, and Keybase for more information.
Every initialized Vault server starts in the sealed state. From the configuration, Vault can access the physical storage, but it can't read any of it because it doesn't know how to decrypt it. The process of teaching Vault how to decrypt the data is known as unsealing the Vault.
Unsealing has to happen every time Vault starts. It can be done via the API and via the command line. To unseal the Vault, you must have the threshold number of unseal keys. In the output above, notice that the "key threshold" is 3. This means that to unseal the Vault, you need 3 of the 5 keys that were generated.
After pasting in a valid key and confirming, you see that Vault is still sealed, but progress is made. Vault knows it has 1 key out of 3. Due to the nature of the algorithm, Vault doesn't know if it has the correct key until the threshold is reached.
Also notice that the unseal process is stateful. You can go to another computer, use vault operator unseal
, and as long as it's pointing to the same server, that other computer can continue the unseal process. This is incredibly important to the design of the unseal process: multiple people with multiple keys are required to unseal the Vault. The Vault can be unsealed from multiple computers and the keys should never be together. A single malicious operator does not have enough keys to be malicious.
vault operator unseal
to complete unsealing the Vault. To unseal the vault you must use three different unseal keys, the same key repeated will not work. When the value for Sealed
changes to false
, the Vault is unsealed.Once you have supplied the threshold number of unseal keys, you should see output like this:
As a root user, you can reseal the Vault with vault operator seal
. A single operator is allowed to do this. This lets a single operator lock down the Vault in an emergency without consulting other operators. When the Vault is sealed again, it clears all of its state (including the encryption key) from memory. The Vault is secure and locked down from access.
In this section, you configured, initialized, and unsealed Vault. This is the basic knowledge necessary to deploy Vault into a real environment.
The Google Cloud Vault secrets engine dynamically generates Google Cloud service account keys and OAuth tokens based on IAM policies. This enables users to gain access to Google Cloud resources without needing to create or manage a dedicated service account.
The benefits of using this secrets engine to manage Google Cloud IAM service accounts are:
In this section, you will add the Google Cloud secrets engine and interact with it.
Most secrets engines must be configured in advance before they can perform their functions. These steps are usually completed by an operator or configuration management tool.
By default, the secrets engine will mount at the name of the engine. To enable the secrets engine at a different path, use the -path
argument.
In this section, you will create the default credentials that Vault will use to generate the service account keys and access tokens.
From the Navigation menu, go to IAM & Admin > Service Accounts.
Click the dots () next to the Qwiklabs User Service Account and select Manage keys.
Click Add Key > Create new key.
Leave the default type as JSON then click Create.
Click Save and then, click Close.
Your private key should be downloaded to your local machine.
Click Check my progress to verify the objective.
Click Choose Files and select the service account key that you just created and then, click Upload.
Run the following command to list the files in your home directory:
In this section you will supply the default credentials that Vault will use to generate the service account keys and access tokens, as well as TTL metadata for the leases Vault assigns to these secrets when generated.
path/to/creds.json
with the path to your private key file you uploaded:If your service account key file was correctly referenced, you should see the following output:
This config supplies default credentials that Vault will use to generate the service account keys and access tokens, as well as TTL metadata for the leases Vault assigns to these secrets when generated.
Roleset or static account bindings define a list of resources and the associated IAM roles on that resource. Bindings are used as the binding
argument when creating or updating a roleset or static account and are specified in the following format using HCL:
For example:
The top-level resource
block defines the resource or resource path for which IAM policy information will be bound. The resource path may be specified in a few different formats:
self_link
attribute of a resource in Google Cloud. This must include the resource nested in the parent project.The nested roles attribute is an array of strings names of Google Cloud IAM roles. The roles may be specified in the following formats:
In this section, you will create a bindings file that you will use to create a custom roleset.
bindings.hcl
:Navigate to code editor tab and if its not open then, click Open Editor on the toolbar of your Cloud Shell window.
Open the bindings.hcl
file and add the following code to it. Replace <my-bucket>
with your Project ID. Note that a Cloud Storage bucket was created upon lab startup and named with your Project ID:
A roleset consists of a Vault managed Google Cloud Service account along with a set of IAM bindings defined for that service account. The name of the service account is generated based on the time of creation or update. You should not depend on the name of the service account being fixed and should manage all IAM bindings for the service account through the bindings
parameter when creating or updating the roleset.
Each role set can generate one of two types of secrets: either access_token
for one-use OAuth access tokens or service_account_key
for long-lived service account keys. In this section, you will configure both of these rolesets and test out their capabilities.
<project-id>
with your Project ID:Click Check my progress to verify the objective.
After the secrets engine is configured and a user/machine has a Vault token with the proper permission, it can generate credentials. Depending on how the roleset was configured, you can generate OAuth2 tokens or service account keys. You will now generate OAuth2 access tokens.
To generate OAuth2 tokens, read from gcp/token/...
. The roleset must have been created as type access_token
.
This endpoint generates a non-renewable, non-revocable static OAuth2 access token with a lifetime of one hour, where token_ttl
is given in seconds and the expires_at_seconds
is the expiry time for the token, given as a Unix timestamp. The token value then can be used as a HTTP Authorization Bearer token in requests to Google Cloud APIs.
<OATH2_TOKEN>
with the token you retrieved from Vault and <BUCKET_NAME>
with the name of your storage bucket (your Project ID):Your output should resemble the following:
sample.txt
file from your storage bucket. Replace <OATH2_TOKEN>
with the token you retrieved from Vault and <BUCKET_NAME>
with the name of your storage bucket (your Project ID):Great! You successfully used the token OAuth2 token created by Vault to make a couple of API calls.
<project-id>
with your Project ID:If it ran successfully, you should see the following output:
To generate service account keys, read from gcp/key/...
. The roleset must have been created as type service_account_key
.
This endpoint generates a new Google Cloud IAM service account key associated with the roleset's service account. When the lease expires (or is revoked early), the Service Account key will be deleted.
There is a default limit of 10 keys per Service Account. For more information on this limit and recommended mitigation, please see the things to note section below.
Click Check my progress to verify the objective.
Static accounts are Google Cloud service accounts that are created outside of Vault and then provided to Vault to generate access tokens or keys. You can also use Vault to optionally manage IAM bindings for the service account.
From the Navigation menu, go to IAM & Admin > Service Accounts.
Copy the email address associated with the Qwiklabs User Service Account. It should resemble the following:
<service-account-email>
with the email you retrieved in the previous step:If it ran successfully, you should see the following output:
<service-account-email>
with the email you retrieved in the previous step:If it ran successfully, you should see the following output:
Click Check my progress to verify the objective.
In this lab, you learned how to deploy a non-dev Vault server, create bindings, configure rolesets for access tokens and service account keys, and add a static service account to Vault for the Google Cloud secrets engine.
Check out the following for more information on Vault:
...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 July 23, 2025
Lab Last Tested July 23, 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.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one