Guide Google Cloud Secret Manager — Secure and Encrypt Your Variables Quickly and Safely
2 min readJun 2, 2024
Google Cloud Secret Manager is a service provided by Google Cloud Platform (GCP) designed to securely store, manage, and access sensitive information known as secrets. These secrets can include sensitive data such as passwords, API keys, certificates, and other private information that should not be exposed publicly.
Key Features of Google Cloud Secret Manager
- Secure Storage: Secrets are securely stored within GCP, with encryption at rest using either Google-managed encryption keys or customer-managed keys.
- Access Control: Uses Google Cloud’s Identity and Access Management (IAM) to control who has access to secrets and what actions they can perform (read, write, manage).
- Secret Versioning: Allows the creation of multiple versions of a secret, making it easy to rotate keys and manage different versions.
How Google Cloud Secret Manager Works
- Creating Secrets: Secrets can be created via the Google Cloud Console, gcloud CLI, or the Secret Manager APIs. A secret is defined with a unique name and can have multiple versions.
- Accessing Secrets: Secrets can be accessed through the same interfaces (console, CLI, API). Applications that need the secrets can read specific versions of the secrets.
- Managing Versions: Each time a secret is created or updated, a new version is created. You can mark specific versions as “enabled,” “disabled,” or “destroyed.”
- Access Control: Use IAM policies to define who can access or manage the secrets. This ensures that only authorized individuals and services can interact with the secrets.
Creating a Secret and Configurations:
# Create a secret with an automatic replication policy without creating any
$ gcloud secrets create my-guide-secret
# Create secret with an automatic replication policy and data from a file
$ gcloud secrets create my-guide-secret --data-file=/tmp/secret
# Create secret in region 'us-central1'
$ gcloud secrets create my-guide-secret --data-file=/tmp/secret \
--replication-policy=user-managed --locations=us-central1
# Create secret in 'us-central1' and 'us-east1' with the value "s3cr3t"
$ printf "p4sw0rD" | gcloud secrets create my-guide-secret --data-file=- \
--replication-policy=user-managed \
--locations=us-central1,us-east1
# View secret 'my-guide-secret'
gcloud secrets versions access latest --secret="my-guide-secret"
# Configuring IAM for the Secret
gcloud secrets add-iam-policy-binding my-guide-secret \
--member="user:example@example.com" \
--role="roles/secretmanager.secretAccessor"
Common Use Cases
- Database Credentials Management: Storing database credentials and allowing only authorized applications to access them.
- API Key Rotation: Facilitating the regular rotation of API keys without service interruption.
- Microservices Security: In microservices environments, each service can securely access its secrets in a centralized manner.