Google Cloud Secret Manager: A Locked Vault for Passwords, Keys and Tokens

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.

Simple Analogy

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.

Versions
every change creates a new immutable version, with history kept
IAM
fine-grained control over who can read or change each secret
Audit
activity can be recorded for investigation and compliance
i
Good to Know

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.

Term 1

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.

Term 2

Secret version

One actual stored value of a secret. Versions are immutable, meaning they cannot be edited, only added or retired.

Term 3

Payload

The sensitive data inside a version, stored as text or as binary bytes.

Term 4

Latest

A floating label that always points to the newest enabled version of a secret.

Term 5

Version alias

A friendly custom name you attach to a version, such as stable, so applications can follow a name instead of a number.

Term 6

Replication policy

The rule that decides in which locations the secret’s data is stored.

Term 7

Rotation

Replacing a secret with a fresh value on purpose, so a leaked old value stops working.

Term 8

Service account

The identity that an application uses when it asks Secret Manager for a value.

Term 9

Least privilege

Giving each identity only the access it truly needs, and nothing more.

Term 10

CMEK

Customer-managed encryption key. An optional setup where you control the encryption key that protects the secret data.

Term 11

Audit log

A record of who did what to which resource and when.

Term 12

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 livesMain riskBetter approach
Source codeCopied everywhere, stays in historyFetch from Secret Manager at run time
Configuration files in a repositorySame exposure as codeStore only a reference to the secret name
Container imagesAnyone who can pull the image can read itInject at deployment from Secret Manager
Plain environment variables on a machineAppear in process listings, logs and crash dumpsMount secrets as protected files, or restrict access carefully
Chat messages and documentsUncontrolled copies and no audit trailShare access, never values
Spreadsheets and notesNo access control or historyUse 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
        
FIG 1 — Secrets scattered everywhere, compared with secrets held in one vault
Simple Analogy

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.

!
Hard Truth

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"]
        
FIG 2 — Secrets hold versions, and versions hold the values

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.

Simple Analogy

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.

i
Tip

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.

State 1

Enabled

The version can be read by authorized identities. This is the normal working state.

State 2

Disabled

The version still exists but cannot be read. A safe step to test whether anything still uses it before it is destroyed.

State 3

Scheduled for destruction

When delayed destruction is configured, a destroyed version is first disabled and kept recoverable for a set period.

State 4

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
        
FIG 3 — The states a secret version can pass through

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.

1

Add the new version

The new value becomes the latest version while the old one still works.

2

Move applications

Restart or redeploy so applications read the new value.

3

Disable the old version

Watch logs and alerts for anything that still depends on it.

4

Destroy after a safe period

Remove the old value for good, with delayed destruction as a safety net.

Simple Analogy

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
        
FIG 4 — The path of a secret from storage to use
1

The value is submitted

An authorized person or automation adds a version, sending the value over an encrypted connection.

2

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.

3

It is replicated

Copies are stored in the locations set by the replication policy, for durability and availability.

4

An application asks for it

The application proves its identity, usually through the service account attached to its runtime.

5

Permission is checked

IAM confirms that this identity has the accessor role on that secret.

6

The value is returned and logged

The payload is decrypted and sent back, and the access can be written to audit logs.

Simple Analogy

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.

RoleWhat it allowsTypical holder
Secret Manager Secret AccessorRead the payload of secret versionsApplications and runtimes that need the value
Secret Manager Secret Version AdderAdd new versions to existing secretsRotation jobs and deployment tools
Secret Manager Secret Version ManagerAdd, enable, disable and destroy versionsRotation automation and operators
Secret Manager ViewerSee secret metadata, not the valuesAuditors and reviewers
Secret Manager AdminFull control, including permissionsA very small platform or security team
Rule 1

Grant on the secret

Give the accessor role on the specific secret, not on the whole project.

Rule 2

One identity per application

Use dedicated service accounts, so access can be traced and removed cleanly.

Rule 3

Separate reading from managing

Applications read. Automation adds versions. Humans seldom touch values at all.

Rule 4

Use conditions where helpful

IAM conditions can limit access by resource name or time, narrowing access further.

Simple Analogy

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.

!
Common Mistake

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.

Policy 1

Automatic replication

Google chooses and manages the locations. The simplest option, suitable when you have no strict data location rules.

Policy 2

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.

Option 3

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"]
        
FIG 5 — Choosing where secret data is stored
NeedSuggested choice
No special rules, want simplicityAutomatic replication
Data must stay in a country or regionUser-managed replication in permitted regions, or a regional secret
Workloads run in one region onlyA regional secret or a replica in that region
Multi-region application needing high availabilityReplicas in each region where it runs
i
Tip

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
Simple Analogy

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.

!
Common Mistake

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"]
        
FIG 6 — An automated rotation flow
1

Schedule triggers

On the due date, Secret Manager publishes a rotation message to the configured topics.

2

Automation creates a new credential

A function sets a new password or key in the target system, such as a database.

3

New version is added

The function stores the new value as the latest secret version.

4

Applications pick it up

Applications read the new value on their next fetch or restart.

5

Old credential is retired

After a grace period, the old version is disabled and the old credential is removed from the target system.

!
Common Mistake

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.

Simple Analogy

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.

StyleBehaviorBest forRisk
Specific numberAlways the same valueControlled releases and reproducible deploymentsMust update the number to rotate
LatestFollows the newest enabled versionAutomatic rotation with applications that re-read oftenA bad new value reaches everyone at once
AliasPoints where you decideStaged rollouts, such as testing a new value before promoting itNeeds 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.

Simple Analogy

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.

i
Tip

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.

Serverless

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.

Kubernetes

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.

Virtual machines

Compute Engine

Applications on a machine read secrets through client libraries or command line tools, authenticated by the machine’s service account.

Build and deploy

Cloud Build and pipelines

Build steps can read secrets they need, such as credentials for publishing packages, without placing them in build files.

Workflows

Workflows, Composer and Dataflow

Orchestrators and data pipelines fetch credentials for external systems at run time instead of storing them in job definitions.

Infrastructure as code

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"]
        
FIG 7 — Two ways a serverless service can receive a secret
Simple Analogy

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 storingConsider
A service account key fileAn attached service account or workload identity federation
A database passwordIdentity-based database authentication where supported
A shared admin passwordIndividual identities with limited roles
A long-lived tokenShort-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.

Simple Analogy

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.

i
Tip

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.

Question 1

Who read this secret?

Data access logs show the identity, time and source of each read.

Question 2

Who changed permissions?

Admin activity logs record changes to access policies.

Question 3

Was a version destroyed?

Logs show destruction requests, and notifications can alert you to scheduled destruction.

Question 4

Is something unusual happening?

Alerts on sudden spikes in reads, access from unexpected identities or failed attempts help detect abuse.

1

Enable data access logs for sensitive secrets

Turn on the right log types for Secret Manager in your audit configuration.

2

Route logs to a protected place

Send audit logs to a restricted bucket or dataset that administrators of the secrets cannot edit.

3

Create alerts

Alert on reads by unexpected identities, many failed attempts and secret deletions.

4

Review regularly

Check who has access, and remove access that is no longer needed.

Simple Analogy

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.

Layer 1

Least privilege

Per-secret roles, dedicated service accounts and no project-wide accessor roles.

Layer 2

VPC Service Controls

A perimeter that prevents secrets from being read from outside approved networks and projects, even by valid credentials.

Layer 3

Private access

Reach Secret Manager through private routes from networks without public internet access.

Layer 4

Customer-managed keys

Control over encryption keys where regulations require it.

Layer 5

Delayed destruction

A recovery window against accidental or malicious deletion of critical versions.

Layer 6

Organization policies

Rules set at the organization level, such as restricting where secrets may be stored.

Layer 7

Expiration

Secrets can be given an expiry time or lifespan, after which they are removed, which suits temporary credentials.

Layer 8

Separation of environments

Keep development, test and production secrets in different projects, with different people and rules.

Simple Analogy

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.

“A vault is only as strong as the list of people who hold the key to it.”
!
Common Mistake

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.

Versions
active versions are billed per location each month
Reads
access operations are billed in blocks
Destroyed
destroyed versions are not billed
Cost driverWhy it growsHow to control it
Active versionsEvery rotation adds a version that stays activeDisable and destroy old versions after a grace period
Replica locationsVersions are billed for each locationReplicate only where needed
Access operationsApplications that read on every requestRead once, cache in memory for a short time and refresh periodically
Rotation notificationsFrequent schedules across many secretsRotate at sensible intervals matched to risk
Audit loggingData access logs for busy secretsEnable where valuable, and manage log retention
!
Cost Reminder

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.

i
Tip

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
Simple Analogy

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.

“Secret Manager protects the secret; your habits protect the secret manager.”

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.

ANTI-PATTERN-01 Avoid
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.

ANTI-PATTERN-02 Avoid
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.

ANTI-PATTERN-03 Avoid
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.

ANTI-PATTERN-04 Avoid
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.

ANTI-PATTERN-05 Avoid
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.

1

Take inventory first

Find where secrets live today, in code, files, images and pipelines, and plan the move to the vault.

2

Eliminate what you can

Replace key files and passwords with identity based access where possible.

3

Name and label consistently

Use clear names, environment markers and labels for owner and purpose.

4

Grant least privilege per secret

Accessor roles on single secrets, adder roles for automation, and few administrators.

5

Choose replication deliberately

Match locations to residency rules and workload regions before creating production secrets.

6

Automate rotation with overlap

Add new versions, move applications, and retire the old one after a grace period.

7

Log, alert and review

Enable audit logs for sensitive secrets, alert on odd access and review permissions often.

8

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.

i
Run a Leak Drill

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.

ServiceWhat it stores or doesUse it for
Secret ManagerSensitive values such as passwords, API keys and tokensValues your application must read at run time
Cloud KMSEncryption keys and cryptographic operationsEncrypting and signing data, without exposing the key
Certificate ManagerTLS certificates for load balancers and servicesManaging and renewing public certificates
Configuration and parameter servicesOrdinary, non-secret settingsFeature flags, endpoints and tuning values
Service account identityShort-lived credentials for workloadsAuthenticating to Google Cloud without stored keys
Cloud Storage with encryptionFiles and large objectsLarge 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"]
        
FIG 8 — A simple path for choosing where a sensitive value belongs
Simple Analogy

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

Q1What is Secret Manager in one sentence?

It is Google Cloud’s managed service for storing, controlling access to, auditing and rotating sensitive values such as passwords, API keys and certificates.

Q2What is the difference between a secret and a secret version?

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.

Q3How does an application read a secret safely?

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.

Q4Does Secret Manager rotate secrets automatically?

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.

Q5What does latest mean?

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.

Q6Can I recover a destroyed secret version?

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.

Q7Where is my secret data stored?

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.

Q8Should I use environment variables or mounted files?

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.

Q9How much does it cost?

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.

Q10Is Secret Manager the same as Cloud KMS?

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.

Q11Can I store large files in it?

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.

Q12What should I do if a secret leaks?

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.