The Simplest Way to Make CircleCI and Google Pub/Sub Work Like They Should

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams pair circleci and google pub/sub to send real-time build events to cloud apps. CircleCI runs your code tests and sends messages to a Pub/Sub topic for other services. This workflow lets downstream tools react to build passes or failures right away. Your cloud apps can read those messages and start new tasks or update dashboards. How circleci and google pub/sub share data and permissions Data flows in one direction during a normal build pipeline run. A CircleCI job finishes a step and s

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.

Teams pair circleci and google pub/sub to send real-time build events to cloud apps. CircleCI runs your code tests and sends messages to a Pub/Sub topic for other services.

This workflow lets downstream tools react to build passes or failures right away. Your cloud apps can read those messages and start new tasks or update dashboards.

How circleci and google pub/sub share data and permissions

Data flows in one direction during a normal build pipeline run. A CircleCI job finishes a step and sends a payload to Google Cloud. Google Pub/Sub receives that message and holds it in a topic for readers. Subscribed cloud workers then pull the message and run their own tasks.

To make this work, CircleCI must log in to Google Cloud first. The safest method uses OpenID Connect tokens instead of static service keys. CircleCI creates a short-lived token for each job run and sends it out. Google Cloud checks this token against a workload identity pool rule. When the check passes, the job gets a temporary role to send messages.

You can also use a service account key stored in CircleCI project settings. Still, static keys stay valid until a human rotates them by hand. Federated identity tokens expire fast and lower your risk of leaked secrets.

Common failure modes and how to scope roles

Many teams make the mistake of sharing one service account across all pipelines. When every job uses the same broad role, any build can touch any topic. A broken script in a test branch might send bad data to production topics. Broad roles also let attackers move across your cloud project if a build fails.

Unlogged messages cause another big problem for platform and security teams. Standard build logs show that a script ran, but they miss the exact payload. If a job sends sensitive user data like emails or phone numbers, nobody knows. Without field masking to rewrite matched fields, private data can leak into downstream queues.

End-to-End Encryption + CircleCI Security: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

You can fix these risks by scoping roles down to the topic level. Give each CircleCI project its own identity rule in Google Cloud. Grant that identity permission to publish to one specific topic and nothing else. Never give project-wide editor roles to a build runner.

Network paths between the runner and the cloud API also need tight controls. If you run self-hosted CircleCI runners, place them in a private subnet. Allow outbound traffic only to the Google API endpoints your jobs need. Turn on cloud audit logs for Pub/Sub so you can track who sent what.

Keeping build pipelines fast and safe

Good pipeline design keeps secrets out of build scripts and job logs. Teams should review IAM bindings every quarter to remove old project rules. Clear boundaries between test topics and production topics stop bad deploys before they spread. When you pair tight identity rules with good logs, your event pipelines stay safe.

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

Should I use service account keys or OIDC for CircleCI and Google Pub/Sub?

Use OIDC with Google Workload Identity Federation whenever you can. It removes the need to store or rotate static JSON keys inside CircleCI.

What IAM role does a CircleCI job need to send messages?

Grant the Pub/Sub Publisher role on the single topic the job needs. Do not grant this role at the project or folder level.

How can I stop CircleCI from sending test messages to production topics?

Create separate identity rules for main branches and feature branches in Google Cloud. Bind the production topic role only to jobs that run on the main branch.

The query runs. The emails stay hidden.