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

Published
Length
3 min read

Luis Felipe Dias

All posts

Using google pub/sub and oidc together lets apps send and read messages without static keys. This setup replaces long-lived secrets with short-lived identity tokens during runtime. Teams use this pair to connect outside workloads to cloud message queues. Your app gets a token from an identity provider and trades it for cloud permissions. You can also let push queues send signed tokens to your web endpoints. How google pub/sub and oidc handle identity and data flow Data flows between these tw

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.

Using google pub/sub and oidc together lets apps send and read messages without static keys. This setup replaces long-lived secrets with short-lived identity tokens during runtime.

Teams use this pair to connect outside workloads to cloud message queues. Your app gets a token from an identity provider and trades it for cloud permissions. You can also let push queues send signed tokens to your web endpoints.

How google pub/sub and oidc handle identity and data flow

Data flows between these two systems in two main directions. First, an external app or human user wants to publish or pull a message. Second, a push queue needs to send a message to a secure web app.

In the first flow, the user or app logs in with an identity provider. That provider gives back a signed token based on OpenID Connect rules. Google Cloud checks this token through workload identity federation. If the check passes, the cloud grants a temporary role to the caller. The caller can then write a message to a topic or read from a subscription.

In the second flow, the message queue acts as the caller. When a new message arrives, the push subscription creates a signed token. This token belongs to a specific cloud service account. The queue attaches the token to the web request and sends the message out. Your receiving web app checks the token signature and audience field before doing work.

Common failure modes with tokens and service roles

Many teams make mistakes when they first set up this identity flow. The most common error is sharing one broad service account across many different apps. If one app gets compromised, the attacker can read every topic in your project. Shared accounts also ruin your audit logs. You can see which service account read a message, but not which human or app.

Another big risk comes from skipping token checks on push endpoints. Some engineers set up a push subscription with a token, then forget to check it. Anyone who finds the web URL can send fake data to your app. Your app must check the token issuer, expiration time, and audience on every call.

End-to-End Encryption + K8s OIDC Authentication: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Overly broad roles also create big security gaps for your team. Teams often grant project-wide editor roles just to get a queue working fast. Instead, you should scope roles down to the single topic or subscription level. Give publish rights only to senders, and give pull rights only to readers.

Scoping network paths and permissions for message queues

Good security requires tight rules on both identity and network paths. Start by mapping each external workload or team group to a narrow role. Use attribute conditions in your identity pool to check claims from the token. For example, only allow tokens from a specific source repo or user group.

Keep your network paths closed to public traffic whenever you can. Put your receiving web apps behind private load balancers or internal networks. Make sure every message read or write shows up in your cloud audit logs. Turn on data access logs so you can track who reads sensitive topics. If messages hold emails or card numbers, mask those fields in results.

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 do push subscriptions use identity tokens?

A push subscription attaches a signed token to each outgoing web request. Your receiving app checks this token against public keys to confirm the sender identity.

Can external apps publish messages without service account keys?

Yes, external apps can trade an identity token for temporary cloud permissions. This flow uses workload identity federation so you never download a static key file.

How do we audit which user read from a subscription?

Map individual user claims from your identity token into your cloud audit logs. This step records the real caller identity instead of a generic service account name.

The query runs. The emails stay hidden.