Learn how to create and manage secrets using Cloud Code's Secret Manager integration.
To follow step-by-step guidance for this task directly in the Cloud Shell Editor, click Guide me:
In the Google Cloud console, go to the project selector page.
Select or create a Google Cloud project.
Roles required to select or create a project
roles/resourcemanager.projectCreator), which contains the
resourcemanager.projects.create permission. Learn how to grant
roles.
Use Cloud Shell Editor as your environment for creating your Cloud Run service and secret. The editor comes preloaded with the tools needed for cloud development.
To create your service:
In the Cloud Code status bar, click the active project name.

In the Quick Pick menu that appears, select click New Application, and then click Cloud Run Application.
From the list of Cloud Run samples, select Python (Flask): Cloud Run.
Select a folder for your sample and then click Create New Application.
After Cloud Shell Editor loads your service in a new workspace, view its files in
the
Secret Manager allows you to securely store, manage, and access secrets as binary blobs or text strings. Additionally, it manages your secrets, meaning you don't have to deal with virtual machines or operating services.
To create a secret with Cloud Code's Secret Manager integration:
In the Secret Manager - Create Secret tab that appears, enter the following in the Name field:
my-secret
In the Secret Value field, enter:
Hello secret!
Click Create Secret and a message that your secret was successfully created appears.
Secrets are great for storing configuration information such as database passwords, API keys, or TLS certificates needed by an application at runtime.
To add a secret to your code:
Open the
This opens a Google Cloud API Detail tab with Secret Manager API as the heading.
In the Install Client Library section, click the Python tab and
click play_arrow Run in terminal.
This installs the google-cloud-secret-manager client library.
Open
google-cloud-secret-manager==VERSION_NUMBER
You can find the version number in the console after you run the
installation in the previous step. For example, the console might show:
Successfully installed google-cloud-secret-manager-2.23.1
Your changes are automatically saved.
To get the latest value of your secret, open
def access_secret_version(secret_version_id):
"""Return the value of a secret's version"""
from google.cloud import secretmanager
# Create the Secret Manager client.
client = secretmanager.SecretManagerServiceClient()
# Access the secret version.
response = client.access_secret_version(name=secret_version_id)
# Return the decoded payload.
return response.payload.data.decode('UTF-8')
To call the access_secret_version function, replace the
message = access_secret_version("<SECRET_VERSION_ID>")
If you still have the Secret Manager - Create Secret tab open, file_copy Copy the ID.
To get the ID of a secret version at any time, navigate to
To add the version ID, replace the placeholder
<SECRET_VERSION_ID>
To test your new secret, run your Cloud Run service locally on the Cloud Run emulator.
When running the configuration for the first time, this process can take up
to 5 minutes. The
After your app is built, launch your app by clicking the localhost link that
appears in your
Cloud Code's Secret Manager view gives you a quick look at your project's secrets, with actions for managing them.
Note that you can't edit a secret version. To update a secret's value, you must create a new version.
The value of a secret is stored in a secret version. A secret can have many versions. This is helpful in situations where a secret changes. Updating a secret with a new version means you don't have to update your code.
latest.
Secret versions are enabled by default after creation, meaning they can be accessed. A disabled secret is inaccessible, but you can always restore access to it at any time.
To disable a secret version:
When you destroy a secret version, it can't be accessed. Destroying a secret version is permanent.
To delete just the cluster you created for this quickstart:
To delete your project (and associated resources, including any clusters):
Go to the Projects page in the Google Cloud console:
Select the project that you created for this quickstart and then click Delete.
Type the project ID to confirm and then click Shut down.
This shuts down the project and schedules it for deletion.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-06-11 UTC.