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

Published
Length
3 min read

Luis Felipe Dias

All posts

Teams pair Gerrit and Google Pub/Sub to stream code review events to downstream services. This setup triggers automated builds, checks, and alerts as soon as developers push changes. Gerrit tracks every patch set, comment, and merge in your git repos. Google Pub/Sub moves those event messages to build runners and test apps at scale. Together, they remove slow polling scripts from your daily release pipeline. How Gerrit and Google Pub/Sub share events and permissions Gerrit creates a JSON eve

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 Gerrit and Google Pub/Sub to stream code review events to downstream services. This setup triggers automated builds, checks, and alerts as soon as developers push changes.

Gerrit tracks every patch set, comment, and merge in your git repos. Google Pub/Sub moves those event messages to build runners and test apps at scale. Together, they remove slow polling scripts from your daily release pipeline.

How Gerrit and Google Pub/Sub share events and permissions

Gerrit creates a JSON event each time a developer updates a code review. An event plugin reads this internal stream and sends messages to a topic. Google Pub/Sub receives the payload and stores it until workers read it.

To make this work, the Gerrit host needs permission to publish messages. Teams create a dedicated cloud service account for the Gerrit server. That account gets a publisher role on the target topic only.

Downstream build workers use their own service accounts to read from subscriptions. They pull the review event, check out the code, and run tests. When tests finish, workers post scores back to the Gerrit API.

This split keeps read and write duties clear across the whole pipeline. The code host only writes events, and the test runners only read them. Each part of the system holds the minimum rights needed for its job.

Common failure modes and how to scope roles

Many teams start by sharing one broad service account across all build tools. If a key leaks, an attacker can read source code and delete topics. Shared keys also make audit logs hard to read during an incident.

Another common issue is storing static JSON key files on the Gerrit server. Old keys stay on disks for years without rotation. Anyone with host access can copy that file and send fake build events.

End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Unlogged queries back to the Gerrit database or API also create blind spots. When a worker posts a review score, teams need to know which job ran. Without strict role scoping, a test script might merge code by mistake.

You can fix these risks by binding narrow roles to each workload identity. Give the Gerrit node permission to publish to one specific topic path. Give each worker group a subscriber role for its own queue only.

Restrict network paths so only known worker subnets can call the Gerrit API. Turn on cloud audit logs for both publish and subscribe actions. Review these logs often to spot odd traffic or failed login attempts.

Keeping event payloads clean and safe

Code review comments and commit messages sometimes hold sensitive data by mistake. Developers might paste emails, phone numbers, card numbers, or national IDs into a review. Once Gerrit sends that event to a topic, many apps will read it.

Data masking rewrites matched fields in results before downstream tools store them. This step keeps sensitive strings out of build logs and chat alerts. Teams should also set short message retention times on their event topics.

Dead-letter queues help you handle broken messages without losing track of failed builds. If a worker cannot parse an event, Pub/Sub moves it to a holding topic. Engineers can inspect the bad payload and fix the parser logic safely.

Govern statements and responses across databases and APIs

Good config and scoped roles are needed setup. They do not check single queries in flight or mask sensitive fields in returned rows. Across Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, and internal HTTP endpoints, hoop.dev runs beside each supported service as an open-source proxy, a sidecar for your database or API.

First, hoop.dev guardrails block banned queries before they run. Then hoop.dev data masking rewrites matched sensitive values in responses in memory. The audit trail records every statement and verdict per resource. Furthermore, hoop.dev holds SOC 2 Type II and is open source on GitHub.

Frequently asked questions

How does Gerrit send events to Google Pub/Sub?

Gerrit uses an event broker plugin that listens for internal review actions. The plugin formats each action as a message and sends it to a topic.

What cloud role does the Gerrit server need?

The Gerrit server needs the Pub/Sub Publisher role on the target topic. It should not have rights to read subscriptions or change project settings.

How do we stop duplicate builds when Pub/Sub retries a message?

Make your build workers check the Gerrit patch set ID and event timestamp first. If a build for that exact event already exists, the worker skips it.

The query runs. The emails stay hidden.