Skip to content

fix: reduce Secret Manager costs by resolving secrets at deploy time#86

Open
rozen03 wants to merge 1 commit into
masterfrom
fix-cloudrun-secretmanager-costs
Open

fix: reduce Secret Manager costs by resolving secrets at deploy time#86
rozen03 wants to merge 1 commit into
masterfrom
fix-cloudrun-secretmanager-costs

Conversation

@rozen03
Copy link
Copy Markdown
Collaborator

@rozen03 rozen03 commented May 20, 2026

This PR fixes the excessive Google Cloud Secret Manager costs caused by Cloud Run retrieving secrets on every cold start.

Currently, the workflow uses --set-secrets, which binds the Cloud Run instance to the Secret Manager directly, resulting in an API call for every mapped secret whenever a new instance is spun up. Given that the bot receives periodic traffic, these cold starts trigger 7 reads per interaction and 4 reads for the cron job, exceeding the GCP free tier.

Changes:

  1. Uses google-github-actions/get-secretmanager-secrets@v2 during deployment to resolve the secrets in the CI/CD pipeline.
  2. Injects the fetched secrets into Cloud Run using --set-env-vars and the ^@^ alternative delimiter (for safe escaping).
  3. Adds --clear-secrets to drop the old secret mappings.

This change completely eliminates Secret Manager access by Cloud Run at runtime (0 reads per cold start) while keeping the same variables securely available in the environment.

Resolves an issue where Cloud Run cold starts incur excessive Secret Manager API costs by resolving secrets continuously. This delegates fetching the secrets to GitHub Actions using `google-github-actions/get-secretmanager-secrets` and passes them securely to `gcloud run` as environment variables instead of using `--set-secrets`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant