The Simplest Way to Make GCP Secret Manager and Google Pub/Sub Work Like They Should
You pair gcp secret manager and google pub/sub to automate key rotation and event alerts. Secret Manager sends messages to a Pub/Sub topic whenever a secret changes or expires. This setup lets your apps refresh their keys right when a change happens. Your team avoids manual restarts and stops using old credentials in production. Every update flows through a central queue that your services can read. How gcp secret manager and google pub/sub share events and roles Secret Manager stores API ke
Your coding agents run with your access.
Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.
You pair gcp secret manager and google pub/sub to automate key rotation and event alerts. Secret Manager sends messages to a Pub/Sub topic whenever a secret changes or expires.
This setup lets your apps refresh their keys right when a change happens. Your team avoids manual restarts and stops using old credentials in production. Every update flows through a central queue that your services can read.
How gcp secret manager and google pub/sub share events and roles
Secret Manager stores API keys, database passwords, and certificates for your cloud projects. When someone creates a new version or sets a rotation schedule, the store emits an event. It pushes this event to a Pub/Sub topic that you choose.
To make this work, Secret Manager uses a dedicated service identity in your project. You must grant the publish role to this identity on your target topic. Without that role, the secret store cannot send alerts to the message queue.
Once the message lands in the topic, subscriber apps or cloud functions read it. The message body contains metadata about which secret changed and what action took place. It never holds the raw secret value itself.
Your subscriber app reads the notice and then calls the Secret Manager API. That app uses its own service role to fetch the new secret version. This two-step flow keeps raw passwords out of your message logs.
Common failure modes and how to scope permissions
Many teams fail by giving one shared service account broad rights across both tools. If an app can read every secret and every topic, one bug exposes your whole project. Attackers who grab that key can read all stored credentials at once.
GCP Secret Manager + End-to-End Encryption: architecture patterns and best practices
Continue reading? Get the full guide.
Free. No spam. Unsubscribe anytime.
Another common issue is missing audit logs for secret reads and topic pulls. When developers debug message flows from their laptops, they often pull production keys locally. If you do not log every secret fetch, you lose track of who saw what.
You can fix this by scoping roles down to each single secret and topic. Give the Secret Manager identity write rights only on the specific rotation topic. Give each subscriber app read rights only on the single secret it needs to run.
Set up private network paths so traffic stays inside your cloud network. Turn on data access logs for Secret Manager so every read leaves a clear record. Also watch dead-letter queues in Pub/Sub to catch failed rotation runs early.
Managing developer debug sessions and secret rotation
Even with tight service roles, humans still need to test and fix broken rotation jobs. An engineer might need to inspect a stuck message or check a secret version. Granting permanent admin roles to humans breaks the safe model you built for your apps.
Instead, keep human roles separate from machine roles at all times. Require peer approval before anyone reads a live secret or publishes a test event. When teams must inspect payload data, masking rewrites matched fields like emails or card numbers in results.
Add runtime guardrails and masking beside your databases and APIs
Login rules, role grants, and CI checks govern who connects to your stack. Yet any allowed script, engineer, or AI agent still runs commands with the full scope of its role. For workloads on Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes, SSH, or internal HTTP services, hoop.dev sits beside the service as an open-source proxy, a sidecar for your database or API.
Before a query runs, hoop.dev guardrails check the statement against your rules. An AI Analyzer you configure can score intent or hold risky calls for human review. Next, hoop.dev data masking rewrites sensitive fields in responses, and each verdict is logged per listener. Explore the MIT-licensed project on GitHub.
Frequently asked questions
Does Secret Manager send the actual secret value inside the Pub/Sub message?
No, the message only contains metadata like the secret name, event type, and timestamp. Your app must make a separate call to Secret Manager to read the new value.
What happens if a rotation function fails to process a Pub/Sub message?
Pub/Sub will retry sending the message based on the retry rule you set up. You should attach a dead-letter topic to catch messages that fail after several tries.
Can one Pub/Sub topic receive alerts from many different secrets?
Yes, you can link many secrets in your project to one central Pub/Sub topic. Your subscriber app can read the message attributes to see which specific secret triggered the alert.
Related guides
In this post