Google Cloud Secret Manager: A Locked Vault for Passwords, Keys and Tokens
A beginner-friendly, book-style guide to Secret Manager, the Google Cloud service that stores sensitive values such as passwords, API keys and certificates, controls who can read them, records every access and helps you rotate them safely.
Imagine you run a hotel. Every room has a key, the safe in the office holds the master key, and the cash drawer has its own lock. You would never write the master key on a sticky note and leave it on the front desk, and you would never give every employee a copy. Instead you would keep keys in one locked cabinet, hand them out only to people who need them, and write down who took which key and when. Secret Manager is that locked cabinet for the sensitive values that software needs.
This guide assumes you know nothing about secrets management. Every new word is explained the first time it appears, with a simple comparison from daily life. By the end you will understand what a secret is, how Secret Manager stores and protects it, how applications read it safely, how to rotate and retire it, how to control cost, and how it differs from other security services.
1What Is Secret Manager and Why Does It Exist?
Secret Manager is a central, managed place to keep the sensitive values your applications need at run time.
What is a secret?
A secret is any piece of information that would cause harm if it fell into the wrong hands and that your software needs in order to work. Database passwords, API keys for payment or messaging providers, signing keys, access tokens, private certificates and encryption passphrases are all secrets. They are different from ordinary settings, such as a page title or a timeout, which can be public without harm.
The problem of scattered secrets
Without a proper place to keep them, secrets end up in the worst locations. Developers paste them into source code, where they are copied to every laptop and every backup. Teams put them in configuration files that are committed to version control. They place them in plain environment settings that appear in logs and error pages. They share them in chat messages and documents. Once a secret has spread this widely, nobody can say who has it, and changing it becomes a frightening project.
What the service does
Secret Manager is a fully managed service that stores secrets as text or binary data, encrypts them, and releases them only to identities that you authorize. Every secret has versions, so you can change a value without losing history. Every access can be recorded in audit logs. Applications fetch secrets when they need them, rather than carrying them around. It becomes the single source of truth for sensitive values in your Google Cloud environment.
A bank safe deposit room does not let customers wander in. A guard checks identity, opens only your box, and writes your visit in a logbook. Secret Manager is the safe deposit room, IAM is the guard and audit logs are the logbook.
Secret Manager is meant for small, sensitive values used by applications. It is not a general file store and not a place for large data, which belongs in storage services with their own encryption.
2Core Concepts in Plain English
Twelve words you will meet in every Secret Manager conversation.
Secret
The named container that holds a sensitive value over time. It carries settings such as labels, replication and rotation, but not the value itself.
Secret version
One actual stored value of a secret. Versions are immutable, meaning they cannot be edited, only added or retired.
Payload
The sensitive data inside a version, stored as text or as binary bytes.
Latest
A floating label that always points to the newest enabled version of a secret.
Version alias
A friendly custom name you attach to a version, such as stable, so applications can follow a name instead of a number.
Replication policy
The rule that decides in which locations the secret’s data is stored.
Rotation
Replacing a secret with a fresh value on purpose, so a leaked old value stops working.
Service account
The identity that an application uses when it asks Secret Manager for a value.
Least privilege
Giving each identity only the access it truly needs, and nothing more.
CMEK
Customer-managed encryption key. An optional setup where you control the encryption key that protects the secret data.
Audit log
A record of who did what to which resource and when.
Secret sprawl
The mess created when secrets are scattered across code, files, chats and machines with no central control.
Keep this list close. Each word returns with examples later, and the key idea to hold on to is this: the secret is the container, and the versions hold the values.
3Why Secrets Must Not Live in Code
The simplest security improvement most teams can make is to take secrets out of their code.
Source code is shared widely. It is copied to developer machines, stored in repositories, built into images, backed up and sometimes published by accident. A secret placed in code inherits all of this exposure, and it stays in the history of version control even after the line is deleted. Attackers know this and scan public and leaked repositories constantly for keys and passwords.
| Where the secret lives | Main risk | Better approach |
|---|---|---|
| Source code | Copied everywhere, stays in history | Fetch from Secret Manager at run time |
| Configuration files in a repository | Same exposure as code | Store only a reference to the secret name |
| Container images | Anyone who can pull the image can read it | Inject at deployment from Secret Manager |
| Plain environment variables on a machine | Appear in process listings, logs and crash dumps | Mount secrets as protected files, or restrict access carefully |
| Chat messages and documents | Uncontrolled copies and no audit trail | Share access, never values |
| Spreadsheets and notes | No access control or history | Use a managed vault |
flowchart LR
subgraph BAD["Without Secret Manager"]
C1["Code"] --- S1["Password inside"]
F1["Config file"] --- S2["Key inside"]
I1["Image"] --- S3["Token inside"]
end
subgraph GOOD["With Secret Manager"]
APP["Application"] -->|"Asks with its identity"| SM["Secret Manager"]
SM -->|"Releases the value if allowed"| APP
end
Writing your bank card PIN on the card itself means anyone who finds the card has the money. Keeping the PIN in your head, or in a vault, means finding the card is not enough.
A secret that has ever been committed to a repository, even a private one, should be treated as leaked. Rotate it. Deleting the line does not remove it from history or from other people’s copies.
4Architecture: Secrets, Versions and Locations
How the pieces are organized inside your project.
Inside a Google Cloud project you create secrets. Each secret has a name that is unique in the project, and settings such as labels and replication. Under each secret sit versions, numbered one, two, three and so on, each holding a payload. Applications almost always work with versions, not with the secret container. Access to a secret and to its versions is controlled with identity and access management.
flowchart TD
P["Google Cloud Project"] --> S1["Secret: database-password"]
P --> S2["Secret: payment-api-key"]
S1 --> V1["Version 1: disabled"]
S1 --> V2["Version 2: enabled"]
S1 --> V3["Version 3: enabled, latest"]
S2 --> V4["Version 1: enabled, latest"]
Immutable versions
A version can never be edited. To change a secret, you add a new version. This is a valuable safety feature. You always know exactly which value was in use at any time, you can roll back to a previous version, and a mistaken update never destroys the old value.
Regional and global thinking
Secret names are resources of the whole project, while the secret data is stored in regions that you choose, or that Google chooses for you. Newer regional secrets are created and accessed through regional endpoints, so that both the data and the requests stay in a chosen location. This matters for data residency rules and for latency.
A legal contract is never edited after signing. A new amended version is added, and the old one is kept on file. Secret versions work the same way, so there is always a clear record.
Name secrets by purpose and environment, such as a payments API key for production, and use labels to record owner and team. Clear names make permissions, audits and cleanup much easier.
5The Life of a Secret Version
A version moves through a small number of states, and each state has a meaning.
Enabled
The version can be read by authorized identities. This is the normal working state.
Disabled
The version still exists but cannot be read. A safe step to test whether anything still uses it before it is destroyed.
Scheduled for destruction
When delayed destruction is configured, a destroyed version is first disabled and kept recoverable for a set period.
Destroyed
The secret data is permanently removed and cannot be recovered. The record of the version remains, but the value is gone.
flowchart LR
A["Add version: Enabled"] --> B["Disable"]
B --> A
B --> C["Destroy requested"]
C -->|"Delay configured"| D["Scheduled for destruction"]
D -->|"Admin restores"| B
D -->|"Delay ends"| E["Destroyed"]
C -->|"No delay"| E
Disable first, destroy later
The safest way to retire a value is a staged one. First add the new version and move applications to it. Then disable the old version and watch for errors. If nothing breaks after an agreed period, destroy it. Because destroying is permanent by default, many teams turn on delayed destruction, which gives a recovery window in case a version turns out to be needed after all.
Add the new version
The new value becomes the latest version while the old one still works.
Move applications
Restart or redeploy so applications read the new value.
Disable the old version
Watch logs and alerts for anything that still depends on it.
Destroy after a safe period
Remove the old value for good, with delayed destruction as a safety net.
Before throwing away an old key, you put it in a drawer for a while to check that no door still needs it. Disabling is the drawer, destroying is the bin.
6Internal Working: Storing and Reading a Secret
Follow a secret from the moment you save it to the moment an application reads it.
sequenceDiagram
participant A as Administrator
participant SM as Secret Manager
participant K as Encryption Layer
participant App as Application
participant IAM as IAM
A->>SM: Create secret and add version
SM->>K: Encrypt payload
K-->>SM: Encrypted data stored
App->>SM: Access version using service account
SM->>IAM: Is this identity allowed?
IAM-->>SM: Yes
SM->>K: Decrypt payload
SM-->>App: Return payload over encrypted connection
SM->>SM: Write audit log entry
The value is submitted
An authorized person or automation adds a version, sending the value over an encrypted connection.
It is encrypted and stored
The payload is encrypted before being saved, using Google managed keys by default or your own keys if you choose.
It is replicated
Copies are stored in the locations set by the replication policy, for durability and availability.
An application asks for it
The application proves its identity, usually through the service account attached to its runtime.
Permission is checked
IAM confirms that this identity has the accessor role on that secret.
The value is returned and logged
The payload is decrypted and sent back, and the access can be written to audit logs.
You ask the vault clerk for a box. The clerk checks your badge, fetches the box from the back room, opens it for you and notes the time in the logbook. You never see the back room, and nobody else gets the box.
7Access Control with IAM
Decide exactly who can read, who can add values and who can manage.
Secret Manager uses Google Cloud identity and access management. Roles can be granted at the project level, which covers all secrets, or on a single secret, which is far safer. The most important idea is the separation between managing a secret and reading its value. A person who administers secrets does not automatically need to see their contents, and an application that reads a value does not need to change it.
| Role | What it allows | Typical holder |
|---|---|---|
| Secret Manager Secret Accessor | Read the payload of secret versions | Applications and runtimes that need the value |
| Secret Manager Secret Version Adder | Add new versions to existing secrets | Rotation jobs and deployment tools |
| Secret Manager Secret Version Manager | Add, enable, disable and destroy versions | Rotation automation and operators |
| Secret Manager Viewer | See secret metadata, not the values | Auditors and reviewers |
| Secret Manager Admin | Full control, including permissions | A very small platform or security team |
Grant on the secret
Give the accessor role on the specific secret, not on the whole project.
One identity per application
Use dedicated service accounts, so access can be traced and removed cleanly.
Separate reading from managing
Applications read. Automation adds versions. Humans seldom touch values at all.
Use conditions where helpful
IAM conditions can limit access by resource name or time, narrowing access further.
In a restaurant, the cook can open the kitchen stock room, the delivery driver can only drop items at the door, and the owner can change the locks. Nobody has all the powers just because it would be simpler.
Granting the accessor role on the whole project to a shared service account so that everything works. One compromised service then exposes every secret in the project. Grant per secret and per application.
8Replication, Locations and Resilience
Where your secret data is physically stored, and how it survives failures.
A secret that is stored in only one place is lost if that place fails, and an application that cannot read its database password cannot start. Replication stores copies in multiple locations so that secrets are durable and available. You choose a replication policy when you create a secret.
Automatic replication
Google chooses and manages the locations. The simplest option, suitable when you have no strict data location rules.
User-managed replication
You pick the exact regions where copies are stored. Needed for data residency rules, or to keep secrets close to the workloads that read them.
Regional secrets
Secrets created in a single chosen region and accessed through that region’s endpoint, keeping both data and requests inside the location.
flowchart TD
SEC["Secret: payment-api-key"] --> POL{"Replication policy"}
POL -->|"Automatic"| AUTO["Google chooses locations"]
POL -->|"User-managed"| UM["You choose regions"]
UM --> R1["Region A copy"]
UM --> R2["Region B copy"]
| Need | Suggested choice |
|---|---|
| No special rules, want simplicity | Automatic replication |
| Data must stay in a country or region | User-managed replication in permitted regions, or a regional secret |
| Workloads run in one region only | A regional secret or a replica in that region |
| Multi-region application needing high availability | Replicas in each region where it runs |
The replication policy of an existing secret cannot simply be flipped later. Decide with your residency and availability needs before creating secrets, especially for production.
9Encryption and Customer-Managed Keys
Secret data is always encrypted, and you can decide who holds the key.
By default, Secret Manager encrypts secret data at rest with keys managed by Google, and data in transit travels over encrypted connections. Some organizations must control the encryption key themselves, for example to satisfy a regulator or to be able to cut off access instantly. For these cases Secret Manager supports customer-managed encryption keys, using Cloud KMS. You create a key, grant the service permission to use it, and attach it to the secret. If the key is disabled or destroyed, the secret data becomes unreadable.
Advantages of customer-managed keys
- You control the key lifecycle and rotation
- You can revoke access by disabling the key
- Meets strict compliance requirements
- Key use is visible in audit logs
Disadvantages / Trade-offs
- More setup and more things to manage
- A mistake with the key can lock you out of your own secrets
- Key locations must match the secret’s replication locations
- Additional cost for key operations
A bank locks your box with its own key by default. With a customer-managed key, the box also needs a second key that only you hold. It adds control, but if you lose your key, the bank cannot open the box either.
Using a key in the wrong location. The key must be in a location that suits the secret’s replication policy, and a mismatch causes failures. Check the current documentation for the exact rules before enabling customer-managed keys.
10Rotation: Changing Secrets on a Schedule
A secret that never changes is a secret that is waiting to be stolen.
Rotation means replacing a secret with a fresh value regularly, so that a leaked or forgotten old value stops being useful. Rotation limits the damage window: if an attacker steals a password that expires in thirty days, their access ends. Many security standards require rotation for sensitive credentials.
What Secret Manager does, and what you do
Secret Manager can send a notification when a rotation is due. You attach a rotation schedule to the secret, with a period and the time of the next rotation, and configure Pub/Sub topics. At the scheduled time Secret Manager publishes a rotation message. It does not change the password in the target system itself. That part is yours: a small function or service listens for the message, creates a new credential in the database or provider, and adds it as a new version of the secret.
flowchart LR
SCH["Rotation schedule on the secret"] --> PS["Pub/Sub notification"]
PS --> FN["Rotation function or service"]
FN --> TGT["Create new credential in target system"]
FN --> NV["Add new secret version"]
NV --> APP["Applications read latest"]
FN --> OLD["Disable old version later"]
Schedule triggers
On the due date, Secret Manager publishes a rotation message to the configured topics.
Automation creates a new credential
A function sets a new password or key in the target system, such as a database.
New version is added
The function stores the new value as the latest secret version.
Applications pick it up
Applications read the new value on their next fetch or restart.
Old credential is retired
After a grace period, the old version is disabled and the old credential is removed from the target system.
Rotating the value in Secret Manager without changing it in the target system, or the reverse. Both must change together, with a short overlap in which both old and new values work, so no application is locked out mid-rotation.
Changing the locks of a building means cutting new keys, handing them to the right people, and only then collecting the old ones. If you take the old ones first, nobody can get in.
11Versions, Aliases and Pinning
Choosing which version an application reads is a design decision with real consequences.
When an application reads a secret, it names a version. There are three styles. It can ask for a specific number, such as version four, which never changes and is fully predictable. It can ask for latest, which always follows the newest enabled version. Or it can ask for an alias, such as stable, which you move between versions yourself. Each style has a place.
| Style | Behavior | Best for | Risk |
|---|---|---|---|
| Specific number | Always the same value | Controlled releases and reproducible deployments | Must update the number to rotate |
| Latest | Follows the newest enabled version | Automatic rotation with applications that re-read often | A bad new value reaches everyone at once |
| Alias | Points where you decide | Staged rollouts, such as testing a new value before promoting it | Needs discipline to keep aliases current |
Latest with automated rotation
A rotation job adds a version, and applications that fetch the latest value at start-up or periodically receive it without a redeploy.
Pinned version in production
Production reads version seven. A new value is tested in staging as version eight, and production is moved only after it passes.
Alias for staged promotion
A stable alias points to the version that production uses, and a candidate alias points to the new one, making rollout and rollback a single change.
A street sign that says current speed limit changes whenever the council decides. A sign that says speed limit fifty is fixed until someone replaces it. Latest is the first sign, a pinned version is the second.
Applications that fetch the latest version only at start-up will not see a rotation until they restart. Decide whether your applications should re-read secrets periodically, or whether a redeploy is part of your rotation process.
12Using Secrets from Google Cloud Workloads
How applications actually receive their secrets on different platforms.
Cloud Run and Cloud Run functions
Secrets can be exposed to a service as environment variables or as files mounted into the container, using the service’s identity to read them.
Google Kubernetes Engine
Secrets can be delivered through a driver that mounts them as files into pods, or through operators that sync them into the cluster, using workload identity instead of stored keys.
Compute Engine
Applications on a machine read secrets through client libraries or command line tools, authenticated by the machine’s service account.
Cloud Build and pipelines
Build steps can read secrets they need, such as credentials for publishing packages, without placing them in build files.
Workflows, Composer and Dataflow
Orchestrators and data pipelines fetch credentials for external systems at run time instead of storing them in job definitions.
Terraform and similar tools
Secrets can be created and referenced by name in infrastructure definitions, with the values supplied separately and never committed.
Environment variable or mounted file?
Both work, but they behave differently. Environment variables are simple and widely supported, but they are fixed when the instance starts, and they can show up in diagnostic output if handled carelessly. Mounted files can be refreshed, are less likely to leak in logs and are a good choice for certificates and larger values. For secrets that rotate while the application runs, a mounted file or an on-demand fetch is usually better.
flowchart TD
RUN["Cloud Run service with service account"] --> SM["Secret Manager"]
SM -->|"Value as environment variable at start"| ENV["Application process"]
SM -->|"Value as mounted file"| FILE["Application reads file when needed"]
Giving a courier a sealed envelope at the start of the trip is like an environment variable. Giving the courier a phone number to ask for the latest instructions at each stop is like fetching on demand. The second keeps up with changes.
13Avoiding Secrets Altogether
The best secret is the one that does not exist.
Before storing a secret, ask whether it is needed at all. Many secrets exist only because older systems used long-lived keys. Google Cloud offers ways to avoid them. Services running on Google Cloud can use attached service accounts, which obtain short-lived credentials automatically, so no key file is ever created. Workloads outside Google Cloud can use workload identity federation to exchange their own identity for temporary Google credentials. Databases can often use identity based login instead of passwords.
| Instead of storing | Consider |
|---|---|
| A service account key file | An attached service account or workload identity federation |
| A database password | Identity-based database authentication where supported |
| A shared admin password | Individual identities with limited roles |
| A long-lived token | Short-lived tokens issued on demand |
Still needs a secret
Third party API keys, signing keys for outside partners and credentials for systems that cannot use modern identity remain good fits for Secret Manager.
A hotel that issues a keycard valid only for your stay is safer than one that hands out permanent metal keys. Short-lived credentials are the keycards, and Secret Manager guards the metal keys that cannot be replaced yet.
Make Secret Manager your fallback, not your first choice. Use identity based access where it exists, and keep the vault for the secrets that truly must exist.
14Auditing, Logging and Monitoring
Knowing who touched a secret is as important as protecting it.
Secret Manager works with Cloud Audit Logs. Administrative actions, such as creating a secret, changing its permissions or destroying a version, are recorded. Data access events, such as reading a secret value, can be recorded as well, but data access logging may need to be enabled and can add log volume and cost. For sensitive secrets, enabling data access logs is usually worth it, because it lets you answer who read this value and when.
Who read this secret?
Data access logs show the identity, time and source of each read.
Who changed permissions?
Admin activity logs record changes to access policies.
Was a version destroyed?
Logs show destruction requests, and notifications can alert you to scheduled destruction.
Is something unusual happening?
Alerts on sudden spikes in reads, access from unexpected identities or failed attempts help detect abuse.
Enable data access logs for sensitive secrets
Turn on the right log types for Secret Manager in your audit configuration.
Route logs to a protected place
Send audit logs to a restricted bucket or dataset that administrators of the secrets cannot edit.
Create alerts
Alert on reads by unexpected identities, many failed attempts and secret deletions.
Review regularly
Check who has access, and remove access that is no longer needed.
A building with a keycard system records every door opening. If something goes missing, the record shows who entered the room and when. The record is only useful if somebody keeps it safe and reads it.
15Security Hardening and Network Controls
Several extra layers make a good vault much harder to abuse.
Least privilege
Per-secret roles, dedicated service accounts and no project-wide accessor roles.
VPC Service Controls
A perimeter that prevents secrets from being read from outside approved networks and projects, even by valid credentials.
Private access
Reach Secret Manager through private routes from networks without public internet access.
Customer-managed keys
Control over encryption keys where regulations require it.
Delayed destruction
A recovery window against accidental or malicious deletion of critical versions.
Organization policies
Rules set at the organization level, such as restricting where secrets may be stored.
Expiration
Secrets can be given an expiry time or lifespan, after which they are removed, which suits temporary credentials.
Separation of environments
Keep development, test and production secrets in different projects, with different people and rules.
A museum protects a famous painting with a guard, a glass case, cameras, an alarm and a locked room. No single measure is perfect, but together they make theft very hard.
Putting development and production secrets in the same project because it is convenient. Developers then have a path to production credentials. Separate projects make mistakes smaller and access reviews simpler.
16Understanding Cost and Pricing
Costs are small per secret, but they scale with the number of versions and the number of reads.
Secret Manager pricing has three main parts. Active secret versions are billed per version, per location, per month, while destroyed versions are free. Access operations, meaning reads of secret values, are billed per set of operations. Rotation notifications sent to Pub/Sub are billed per message. Management operations, such as creating secrets and versions, are not billed. A small free allowance exists. Exact rates and allowances change over time, so always use the official pricing page and calculator.
| Cost driver | Why it grows | How to control it |
|---|---|---|
| Active versions | Every rotation adds a version that stays active | Disable and destroy old versions after a grace period |
| Replica locations | Versions are billed for each location | Replicate only where needed |
| Access operations | Applications that read on every request | Read once, cache in memory for a short time and refresh periodically |
| Rotation notifications | Frequent schedules across many secrets | Rotate at sensible intervals matched to risk |
| Audit logging | Data access logs for busy secrets | Enable where valuable, and manage log retention |
A service that fetches the same secret on every incoming request can create millions of reads. Besides cost, it adds delay and may reach quotas. Cache the value in memory for a short period instead.
Cost should never be a reason to keep a secret in code. The price of a secret in Secret Manager is tiny compared with the cost of one leaked credential.
17Real-World and Industry Examples
Where a central vault quietly prevents breaches.
These are common patterns rather than named customer stories, because specific designs change over time.
Web applications and microservices
Each service stores its database credentials and third party API keys in Secret Manager, readable only by its own service account.
Payment and e-commerce platforms
Payment gateway keys and signing secrets are guarded with per-secret access, audit logs and scheduled rotation to meet card industry rules.
CI and CD pipelines
Build systems fetch publishing tokens and deployment credentials only during a job, instead of keeping them in pipeline files.
Data and analytics pipelines
Pipelines read credentials for external databases and software as a service tools at run time, with rotation handled centrally.
Financial services and healthcare
Regulated organizations use customer-managed keys, regional secrets, perimeter controls and detailed audit trails to prove who accessed what.
Machine learning and AI applications
Applications that call model providers and tools keep API keys in the vault, so keys do not appear in notebooks or code repositories.
Incident response
After a suspected leak, teams add a new version, move applications to it and destroy the old one, finishing a containment in minutes instead of days.
18Advantages, Disadvantages and Trade-offs
A managed vault removes a lot of risk and asks for discipline in return.
Advantages
- One central, managed place for secrets across your projects
- Fine-grained access control through IAM
- Immutable versions with easy rollback and a clear history
- Encryption by default, with optional customer-managed keys
- Audit logging and integration with Google Cloud services
- Low cost per secret, with no servers to operate
Disadvantages / Trade-offs
- Rotation notifications exist, but you build the rotation logic yourself
- Not designed for large values or general file storage
- Applications depend on the service being reachable when they fetch secrets
- Costs can grow with many versions and heavy read traffic
- Misconfigured IAM can expose secrets as easily as it protects them
- Tied to Google Cloud, so multi-cloud setups need extra design
A professional safe is far better than a drawer, but the safe does nothing if you leave it open or give the code to everyone. The tool is strong, and the habits around it decide the outcome.
19Design Patterns and Anti-patterns
Habits that keep secrets safe, and habits that quietly undo the protection.
Patterns that work
Strong teams give each application its own service account and grant it access to only its own secrets. They separate environments into projects. They fetch secrets at run time, cache them briefly and handle fetch failures gracefully. They automate rotation, and they keep a short, tested process for emergency replacement. They enable audit logs for sensitive secrets, and they prefer identity based access to stored keys wherever possible.
Problem
Secrets are fetched from Secret Manager and then written into logs, error messages or debug output.
Why It’s Harmful
The secret now lives in a place with far weaker protection and wider access, defeating the purpose of the vault.
Correct Approach
Never log secret values. Mask them in diagnostics, and review logging libraries that dump configuration objects.
Problem
One shared service account has the accessor role on every secret in the project.
Why It’s Harmful
A compromise of any one workload exposes all secrets, and the audit trail cannot tell workloads apart.
Correct Approach
Use a dedicated service account per workload, with access granted on only the secrets it needs.
Problem
Secrets are never rotated because it is risky and nobody owns the process.
Why It’s Harmful
Old values accumulate in ex-employees’ memories, old backups and past leaks, and a stolen value works forever.
Correct Approach
Assign an owner, automate rotation with overlap periods and practice the process before an emergency.
Problem
An application reads the secret from Secret Manager on every single request.
Why It’s Harmful
It adds delay to each request, creates a heavy and costly read load, and makes the application depend on the vault for every call.
Correct Approach
Fetch at start-up and refresh periodically, caching the value in memory with a short lifetime.
Problem
Non-secret settings, such as page titles and feature flags, are stored as secrets.
Why It’s Harmful
It clutters the vault, adds cost, makes real secrets harder to find and encourages broad access to the vault.
Correct Approach
Keep ordinary configuration in configuration services or files, and reserve the vault for values that need protection.
20Best Practices and Common Mistakes
A checklist to keep your secrets safe, tidy and manageable.
Take inventory first
Find where secrets live today, in code, files, images and pipelines, and plan the move to the vault.
Eliminate what you can
Replace key files and passwords with identity based access where possible.
Name and label consistently
Use clear names, environment markers and labels for owner and purpose.
Grant least privilege per secret
Accessor roles on single secrets, adder roles for automation, and few administrators.
Choose replication deliberately
Match locations to residency rules and workload regions before creating production secrets.
Automate rotation with overlap
Add new versions, move applications, and retire the old one after a grace period.
Log, alert and review
Enable audit logs for sensitive secrets, alert on odd access and review permissions often.
Plan for emergencies
Write and test a runbook for replacing a leaked secret quickly, including who does what.
Mistakes beginners make most often
The first is leaving old secrets in code and repository history. The second is granting broad project-level access. The third is logging secret values. The fourth is skipping rotation. The fifth is reading the secret on every request. The sixth is mixing environments in one project. The seventh is destroying a version without first disabling it, and finding out the hard way that something still used it.
Once a year, pretend a key has leaked and practice replacing it end to end. Teams that rehearse replace secrets in minutes, and teams that do not often take days.
21Secret Manager Compared with Other Services
Google Cloud has several services that touch on keys and sensitive data, and each has its own job.
| Service | What it stores or does | Use it for |
|---|---|---|
| Secret Manager | Sensitive values such as passwords, API keys and tokens | Values your application must read at run time |
| Cloud KMS | Encryption keys and cryptographic operations | Encrypting and signing data, without exposing the key |
| Certificate Manager | TLS certificates for load balancers and services | Managing and renewing public certificates |
| Configuration and parameter services | Ordinary, non-secret settings | Feature flags, endpoints and tuning values |
| Service account identity | Short-lived credentials for workloads | Authenticating to Google Cloud without stored keys |
| Cloud Storage with encryption | Files and large objects | Large or file-based data, not small secrets |
flowchart TD
Q1{"Is the value sensitive and small?"} -->|No| CFG["Use configuration or file storage"]
Q1 -->|Yes| Q2{"Can the workload use identity instead of a stored value?"}
Q2 -->|Yes| ID["Use service account or federation"]
Q2 -->|No| Q3{"Must you perform encryption or signing without seeing the key?"}
Q3 -->|Yes| KMS["Cloud KMS"]
Q3 -->|No| SM["Secret Manager"]
A key cutter makes keys, a locksmith turns the lock for you without handing over the key, and a key cabinet keeps spare keys safe. Cloud KMS is the locksmith, Secret Manager is the key cabinet, and identity based access is the keycard that replaces the key entirely.
KMS and Secret Manager together
The two services work well together. Secret Manager can use a key from Cloud KMS to encrypt secret data. An application might use KMS to encrypt a large piece of data, and store the small data key in Secret Manager. Each does what it does best.
22Frequently Asked Questions
It is Google Cloud’s managed service for storing, controlling access to, auditing and rotating sensitive values such as passwords, API keys and certificates.
A secret is the named container with its settings. A version holds one actual value. Versions are immutable, so changing a secret means adding a new version.
It runs with a service account that has the accessor role on that specific secret, and it requests the value at run time, either through a client library or through a platform feature that exposes the secret as an environment variable or a mounted file.
It can send a rotation notification on a schedule, but it does not change the credential in the target system for you. You provide the automation that creates the new credential and adds a new version.
It is a floating label that always points to the newest enabled version. You can also pin a specific number, or use a custom alias that you control.
By default, destruction is immediate and permanent. If delayed destruction is configured, the version is disabled and recoverable until the delay ends, and an administrator can restore it.
In the locations set by the replication policy. Automatic replication lets Google choose, user-managed replication lets you choose regions, and regional secrets keep data and requests in one chosen region.
Environment variables are simple but fixed at start and easier to leak through diagnostics. Mounted files can be refreshed and suit certificates and values that rotate. Choose according to your rotation needs.
Mainly by active secret versions per location and by access operations, with a small free allowance and free management operations. Rotation notifications are charged per message. Check the official pricing page for current rates.
No. Secret Manager stores values your application needs to read. Cloud KMS manages encryption keys and performs cryptographic operations without exposing the key. They can be used together.
It is meant for small sensitive values, and each version has a size limit, so check the current limit. Keep large files in storage services with encryption, and store only the key or password for them in Secret Manager.
Create the replacement credential in the target system, add it as a new secret version, move applications to it, disable and then destroy the old version, and review audit logs to understand the exposure.
23Summary and Key Takeaways
Secret Manager is Google Cloud’s managed vault for sensitive application values. Secrets hold immutable versions, access is controlled by IAM at the level of single secrets, data is encrypted and replicated to chosen locations, and activity can be audited. Applications read secrets at run time through their own identities, rotation is triggered by notifications and completed by your automation, and old versions are disabled before being destroyed. The best results come from removing secrets where identity can replace them, granting narrow access, rotating regularly, logging carefully and rehearsing how to respond when something leaks.
Key Takeaways
- Keep secrets out of code — store sensitive values in the vault and fetch them at run time with the application’s own identity.
- Secrets hold immutable versions — add, disable and destroy versions instead of editing values, and use latest, pinned numbers or aliases deliberately.
- Least privilege per secret — separate reading from managing, use dedicated service accounts and avoid project-wide access.
- Choose locations and keys on purpose — pick replication or regional secrets for residency, and customer-managed keys when rules demand control.
- Rotate with overlap — notifications start the process, your automation changes the target system, and old versions retire after a grace period.
- Prefer identity over stored keys — use attached service accounts and federation first, and keep the vault for secrets that must exist.
- Audit, cache and rehearse — log access to sensitive secrets, cache values briefly to control cost and delay, and practice replacing a leaked secret.