tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Generative AI > Google Gemini API > ADK with Secret Manager

ADK with Secret Manager

Author: Venkata Sudhakar

Hardcoding API keys and credentials in code or environment variables is a leading cause of security incidents. GCP Secret Manager provides a centralised, encrypted vault for secrets with versioning, automatic rotation, and fine-grained IAM access control. ADK agents running on Cloud Run can retrieve secrets at startup using the Secret Manager API or the Cloud Run built-in secret injection feature - with zero secrets ever touching application code.

ShopMax India stores five categories of secrets in Secret Manager: the Gemini API key, Databricks access token, database connection strings, third-party SMS provider credentials, and the payment gateway API key. Each secret is accessible only to the specific Cloud Run service account that needs it, following the principle of least privilege across all ADK agent deployments.

The below example shows how to store secrets in GCP Secret Manager and retrieve them securely at runtime in a ShopMax India ADK agent.


It gives the following output,

Loading secrets from Secret Manager...
  shopmax-gemini-api-key    : loaded (version: 3)
  shopmax-databricks-token  : loaded (version: 7)
  shopmax-postgres-connection: loaded (version: 2)
  shopmax-sms-provider-key  : loaded (version: 1)
All secrets loaded. Keys are NOT logged or printed.
Agent initialised with credentials from Secret Manager.

The below example shows how to create and manage secrets using the gcloud CLI and configure Cloud Run to inject secrets as environment variables automatically without any code changes.


It gives the following output,

Created secret: shopmax-gemini-api-key
Added secret version: projects/shopmax-india/secrets/shopmax-gemini-api-key/versions/1

Added new version: projects/shopmax-india/secrets/shopmax-gemini-api-key/versions/2

IAM policy updated: secretAccessor granted to shopmax-agent-sa

Deploying shopmax-agent to Cloud Run...
Secrets injected: GEMINI_API_KEY, DATABRICKS_TOKEN
Service URL: https://shopmax-agent-xyz.run.app

VERSION  STATE    CREATE_TIME
2        ENABLED  2026-04-06T04:30:00Z
1        DISABLED 2026-03-01T10:00:00Z

Secret Manager centralises credential management for all ShopMax India ADK agents. When a credential is rotated - which the security policy requires every 90 days - adding a new version in Secret Manager is all that is needed. Cloud Run picks up the new version on the next deployment with no code changes. The audit log in Secret Manager also records every access, providing a complete trail of which service accessed which credential and when.


 
  


  
bl  br