Building and implementing CI/CD pipelines · Topic 3 of 4
Cloud KMS, Secret Manager, Parameter Manager and Secret Injection
Manage pipeline secrets and config on Google Cloud: Cloud KMS, Secret Manager, Certificate Manager, Parameter Manager and Workload Identity Federation.
- 5 min
- Cloud KMS holds keys; Secret Manager holds secret values; Parameter Manager holds config.
- Certificate Manager manages TLS certificates for load balancers.
- Workload Identity Federation replaces service account keys for external pipelines.
What it is
Pipelines and services need configuration (feature settings, endpoints) and secrets (passwords, API tokens, TLS keys). Neither belongs in source code or container images.
Google Cloud gives each kind of value its own managed home, controlled by IAM and audited. The skill the exam tests is choosing the right store and injecting values at the right moment.
How it works
Which service holds what
| Service | Holds | Typical use |
|---|---|---|
| Cloud Key Management Service (Cloud KMS) | Encryption keys; the key material does not leave the service | CMEK for storage and databases, signing keys for attestations, encrypting data in apps |
| Secret Manager | Secret values as numbered versions | Database passwords, API tokens, OAuth client secrets |
| Certificate Manager | TLS certificates for load balancers, Google-managed or uploaded | HTTPS certificates for many domains, with automatic renewal for Google-managed ones |
| Parameter Manager | Configuration parameters with versions, in formats such as YAML or JSON | Application config per environment; parameters can reference Secret Manager secrets |
| Workload Identity Federation | No stored value at all: external identities exchange their own tokens | GitHub Actions, GitLab, AWS or on-premises CI calling Google Cloud without keys |
Cloud KMS basics
Keys live in key rings in a location. Each key has versions; set a rotation period so new versions are created automatically, while old versions still decrypt older data.
| Protection level | Where the key is |
|---|---|
| Software | Google's software key store |
| HSM | Cloud HSM, a hardware security module |
| External | An external key manager, with Cloud EKM |
Grant roles/cloudkms.cryptoKeyEncrypterDecrypter on the single key to the service agent or workload that needs it, never broadly on the project.
Secret Manager
printf 's3cr3t-value' | gcloud secrets create db-password \
--replication-policy=automatic --data-file=-
gcloud secrets add-iam-policy-binding db-password \
--member="serviceAccount:web-runtime@shop-web-prod.iam.gserviceaccount.com" \
--role="roles/secretmanager.secretAccessor"
- Grant Secret Manager Secret Accessor per secret to the runtime identity only.
- Rotation: a rotation schedule sends Pub/Sub notifications; a function adds a new version and updates the backend.
- Pin a specific version in production, or use
latestdeliberately, and disable old versions before destroying them. - Choose user-managed replication or regional secrets when the secret must stay in certain locations.
Workload Identity Federation
An external pipeline presents its own OIDC or SAML token to a workload identity pool provider. Google exchanges it for a short-lived token, and the pipeline acts with roles granted to the federated identity, or by impersonating a service account.
Restrict the provider with an attribute condition, for example only one GitHub repository and branch. For GKE, Workload Identity Federation for GKE lets a Kubernetes service account act with IAM roles, so pods need no key files either.
Build versus runtime secret injection
| Build time | Runtime | |
|---|---|---|
| What | Secrets the build needs: registry tokens, signing keys | Secrets the running app needs: database password, API keys |
| Where | Cloud Build availableSecrets and secretEnv | Cloud Run --set-secrets, GKE Secret Manager add-on or CSI driver |
| Risk | Secret baked into an image layer or log | Secret exposed to anyone who can read the env or file |
| Rotation | Needs a rebuild to pick up | New instances or reads pick up the new version |
steps:
- name: node:20
entrypoint: bash
args: ['-c', 'npm config set //registry.npmjs.org/:_authToken=$$NPM_TOKEN && npm ci']
secretEnv: ['NPM_TOKEN']
availableSecrets:
secretManager:
- versionName: projects/acme-ci/secrets/npm-token/versions/latest
env: NPM_TOKEN
gcloud run deploy web --image="$IMAGE" --region=europe-west1 \
--set-secrets=DB_PASSWORD=db-password:3,/secrets/api/key=api-key:latest
The first mapping sets an environment variable from version 3; the second mounts the latest version as a file. Prefer runtime injection for application secrets: the image stays secret-free, the same image runs in every environment, and rotation needs no rebuild.
A worked example
An audit finds a database password in a Dockerfile and a service account key stored as a GitHub secret. The engineer moves the password to Secret Manager, grants Secret Accessor to the Cloud Run runtime service account only, and mounts it at runtime.
GitHub Actions now authenticates through Workload Identity Federation, with an attribute condition for the one repository. The key is deleted and key creation is blocked by organization policy.
How the exam asks about this
- "A GitHub Actions workflow must deploy to Google Cloud without storing any long-lived credential." Use Workload Identity Federation with an attribute condition on the repository.
- "The application must pick up a rotated API key without rebuilding the image." Inject it at runtime from Secret Manager.
- "Data in Cloud Storage must be encrypted with a key the company controls and rotates." Use a Cloud KMS key with a rotation period as CMEK.
What to remember for the exam
- Cloud KMS holds keys; Secret Manager holds secret values; Parameter Manager holds config.
- Certificate Manager manages TLS certificates for load balancers.
- Workload Identity Federation replaces service account keys for external pipelines.
- Grant Secret Accessor per secret to the runtime identity, not to developers.
- Prefer runtime injection; use
availableSecretswhen the build itself needs a secret.
Passing a secret as a Docker build argument or writing it in a build step leaves it in the image layers or build logs. Use secretEnv in the build and runtime injection for the app.
Common mistakes
Storing secrets in environment variables in the repository or Terraform state. They are then visible to anyone with repository or state access. Reference Secret Manager instead.
Granting Secret Accessor on the whole project. Every secret becomes readable by that identity. Grant it on each secret.
Using Cloud KMS to store a password. KMS encrypts with keys it keeps; to store and retrieve a value, use Secret Manager.
Check yourself
Why is runtime injection usually better than build time injection for app secrets?
The image contains no secret, the same image runs in every environment, and rotated versions are picked up without a rebuild.
What limits which external workflows can use a workload identity pool?
An attribute condition on the provider, for example matching a single repository and branch.
Which service manages TLS certificates for load balancers?
Certificate Manager, which can provide Google-managed certificates that renew automatically.
Topic 3 of 4 in Building and implementing CI/CD pipelines
Test yourself on Building and implementing CI/CD pipelines
The full Google Cloud Professional Cloud DevOps Engineer question bank has 751 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by Google Cloud. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.