Cloud Run Secret Rotation with Secret Manager Volumes
Short answer
D Create a secret in Secret Manager, deploy to Cloud Run using a mounted volume, and update the secret version weekly.
Question
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?
Is it safe to bake secrets in Dockerfiles?
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
-
BlackCoffee 👍 1 Answered DD - 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.
Related Analysis
Practice All PCDOE Questions
Access 75 questions with complete answers and detailed explanations.
View Full PCDOE Practice Test →