Cloud Run Secret Rotation with Secret Manager Volumes

PCDOE By islever Editorial Last updated

Managing infrastructure. Troubleshooting issues.

Short answer

D Create a secret in Secret Manager, deploy to Cloud Run using a mounted volume, and update the secret version weekly.

Question

You are deploying a containerized application to Cloud Run. The application needs a password to connect to the database to fetch data. The password must be rotated each week to meet your company’s security requirements. You need to implement an easy- to-manage password rotation policy. What should you do?
    1. Deploy the container to Cloud Run. 2. Create a new container each week with the new database password set as an environment variable in a Dockerfile. 3. Deploy the new container to Cloud Run, and migrate the traffic to the new version.
    1. Create a secret in Secret Manager to hold the password. 2. Deploy the container to Cloud Run, and use the latest version of the secret as an environment variable. 3. Create a new version of the secret with the new password in Secret Manager each week.
    1. Deploy the container to Cloud Run. 2. Create a new container each week with the new database password set as a secret during the build phase. 3. Deploy the new container to Cloud Run, and migrate the traffic to the new version.
    1. Create a secret in Secret Manager to hold the password. 2. Deploy the container to Cloud Run, and use the latest version of the secret as a mounted volume. 3. Create a new version of the secret in Secret Manager each week.
    Correct Answer

Key Takeaways

The main trap is choosing environment variables for rotation; mounted volumes are preferred for frequent updates and security compliance.

Learn how to securely rotate database passwords for Cloud Run apps using Google Secret Manager and mounted volumes instead of baking secrets into images.

Common mistake: Choosing option B (environment variable injection) is common but less suitable for frequent rotation without app-side reload support compared to volumes.

Expert Analysis

The question requires managing a rotating password for a Cloud Run application. The key constraint is 'easy-to-manage' and 'rotated each week'.

Option A suggests baking the password into the Dockerfile as an environment variable. This is insecure because secrets are baked into the image layer, making them visible in container registries and difficult to rotate without rebuilding and redeploying the entire service every week. It violates security best practices.

Option B proposes using Secret Manager and injecting the secret as an environment variable at runtime. While Secret Manager is the correct service, Cloud Run injects secrets as environment variables only once at startup. If the application does not support dynamic reloading of environment variables from the OS level (which most do not natively handle via standard env vars), this approach fails for rotation without redeployment. More importantly, Cloud Run's documentation recommends mounting secrets as volumes for applications that need to read fresh credentials or rotate them frequently without restarts, or specifically notes that env var injection happens at start time.

Option C involves building a new container weekly with the secret embedded during build. This is operationally heavy and insecure for the same reasons as Option A: secrets are part of the image artifact. It is not an easy-to-manage solution.

Option D uses Secret Manager and mounts the secret as a volume. Cloud Run supports mounting Secrets Manager secrets as files in a container's filesystem. When the secret is updated in Secret Manager, the mounted file can be refreshed (depending on the mount configuration and application logic) or, more commonly, the application reads the file at runtime. For frequent rotations where the app needs to pick up new credentials without a full redeployment cycle (or if the app checks the file periodically), a mounted volume is the preferred mechanism over static environment variables. Even if the app requires a restart, using a volume is often cited in exam contexts as the 'correct' way to handle secrets that might change or need to be kept out of env vars. However, the primary distinction here is between baking secrets in images (A/C) vs using Secret Manager (B/D). Between B and D, mounting as a volume is often the recommended pattern for database passwords to avoid exposing them in process lists or logs, and allows the application to read the latest version if configured to poll or if the mount reflects updates. The comment provided by users also points to D, highlighting that A and C are incorrect due to security vulnerabilities.

Therefore, using Secret Manager and mounting the secret as a volume is the most secure and manageable approach among the choices.

Official Reference

https://cloud.google.com/run/docs/configuring/secrets

This link opens the official vendor documentation in a new tab.

Exam Strategy

When asked about secret management in Cloud Run, always look for 'Secret Manager' as the source. Then distinguish between 'Environment Variable' and 'Mounted Volume'. For rotation or security-sensitive fields like DB passwords, 'Mounted Volume' is often the better answer to prevent exposure in logs/processes and allow file-based reading.

Frequently Asked Questions

Why not use environment variables for secret rotation in Cloud Run?

Environment variables are injected at startup. Rotating them requires a full redeployment. Mounted volumes allow the application to read updated secrets from the filesystem, which can be more flexible depending on the app's design.

Is it safe to bake secrets in Dockerfiles?

No. Secrets baked into Docker images are stored in the image layers and can be extracted from container registries. This is a significant security vulnerability.

More PCDOE FAQ →

Discussion 1 contributions

Compiled from public community threads and reader submissions, lightly edited for clarity. Handles and vote tallies are shown as recorded, and comments reflect the views of individual contributors.

From public community threads 1

  1. BlackCoffee 👍 1 Answered D
    D - mount as volume A and C are incorrect: Baking passwords directly into Dockerfiles or hardcoding secrets during the image build phase is a severe security vulnerability.

Reader comments & corrections

No reader corrections yet — spotted an error or have a note? Share it below.

Log in to comment, report an error, or add a note about this question.

Submitted for moderation before publishing. Keep it helpful and respectful.

Practice All PCDOE Questions

Access 75 questions with complete answers and detailed explanations.

View Full PCDOE Practice Test →

← Back to PCDOE Study Guide