Skip to content
This repository has been archived by the owner on Dec 17, 2023. It is now read-only.

Manage sensitive information to Google Cloud Secret Manager

tpAtalas edited this page Mar 25, 2023 · 2 revisions

Secret Manager allows you to store, manage, and access secrets as binary blobs or text strings. With the appropriate permissions, you can view the contents of the secret.

More Info: Secret Manager conceptual overview

Table of Contents

How to create Secret Manager and add secret value to Secret Manager

  1. Go to your project
  2. Create a secret to Secret Manager
# gcloud secrets create [secret_name] --replication-policy="automatic"
gcloud secrets create example-secrets --replication-policy="automatic"
  1. Add a secret value with file

the file must contain the value only

# gcloud secrets versions add [secret_name] --data-file=[file_name]
gcloud secrets versions add example-secrets --data-file=secret-mongodb-uri

How to update secret during deployment to Google Cloud Run

# you may run this command while deploying
# --update-secrets ENVIRONMENT_VARIABLE_NAME=SECRET_NAME:VERSION
gcloud run deploy \
  --update-secrets MONGODB_URI=example-secrets:latest

How to delete the Secret from Secret Manager

  1. Check the current secret
gcloud secrets list
  1. Delete the secret
# gcloud secrets delete SECRET_NAME
gcloud secrets delete example-secret