Skip to content

Cloud IAM and shadows

With Cloud IAM authorization on (auth.methods: [gcp-iam]), Google decides who may do what, exactly as for Pub/Sub. You keep granting roles/pubsub.publisher, roles/pubsub.subscriber and the rest on topics, subscriptions and projects. lowtide asks Google about each call with the caller’s own token.

For every topic, subscription and snapshot, the gateway keeps a shadow: a resource with the same name in real Pub/Sub. Shadows are empty and carry no traffic. They exist to hold IAM policies. For a topic you migrated from Pub/Sub, the shadow is simply the original topic, with its existing IAM policy.

On each request, lowtide asks Google, with the caller’s token, whether the caller holds the permission the Pub/Sub API itself would require:

  • on the resource, with Pub/Sub’s testIamPermissions: publish, consume, get, update, delete, and so on;
  • on the project, with Resource Manager’s testIamPermissions, for creating and listing.

Because Google evaluates the request, groups, custom roles, IAM conditions, deny policies and inheritance from folders and the organization all apply. An invalid or expired token gets UNAUTHENTICATED. A missing permission gets PERMISSION_DENIED.

Manage access as you do for Pub/Sub: in the Google Cloud console, with gcloud pubsub topics add-iam-policy-binding, or with Terraform IAM resources, pointed at either Pub/Sub or lowtide. lowtide forwards getIamPolicy, setIamPolicy and testIamPermissions to the shadow with the caller’s credentials, so only callers allowed to change a policy can change it.

Your callers need no new roles.

  1. TLS on (tls.enabled: true). The chart refuses Cloud IAM authorization without it, because clients send tokens only over TLS.

  2. The shadow role for the gateway’s service account, in every project whose names the cluster serves. It is a custom role with only these permissions:

    • pubsub.topics.create
    • pubsub.subscriptions.create and pubsub.topics.attachSubscription
    • with snapshot shadows on: pubsub.snapshots.create and pubsub.subscriptions.consume

    The Terraform module creates it as lowtideShadows_<cluster> in each gcp_iam_projects project and grants it. When lowtide sets up the cluster, you create it with the grant commands and the provisioner binds it.

  3. auth.methods: [gcp-iam] and an auth.internalTokenSecret.

The gateway never reads, lists, updates or deletes shadows with its own identity, and never reads or changes their IAM policies. That is why the role has no get, list, update or delete permissions.

lowtide doesn’t record which subscription a snapshot was taken from, so shadow snapshots hang off one anchor subscription per topic, <topic>-lowtide-snapshot-anchor. Creating a snapshot in Pub/Sub requires consume on its source, so the shadow role then includes pubsub.subscriptions.consume on the project. That permission would let the gateway pull from any subscription in the project. The gateway never does, but if you don’t use snapshots, turn snapshot shadows off (gcp_iam_snapshot_shadows = false in the module, or Snapshot shadows off when you create the cluster). Snapshot permissions are then checked on the project.

Caching. Decisions are cached per token, resource and permission. Allows are kept for 5 minutes and denies for 30 seconds (auth.gcpIam.allowTtlMs, denyTtlMs). A revoked grant can keep working for up to 5 minutes. A new grant can take up to 30 seconds to apply.

IAM outages. If Google’s IAM can’t be reached, allows that expired less than 10 minutes ago (staleMs) are reused. Callers with nothing cached get UNAVAILABLE, not a denial.

New resources. A new topic’s or subscription’s shadow is created before the create call returns. A reconciler, one pod at a time every 10 minutes (shadowReconcileMs), creates any that are missing. While a shadow is missing, permissions are checked on the project, which is what the caller would inherit on a fresh resource.

Deletion. Shadows are never deleted automatically. A deleted lowtide topic leaves its shadow in Pub/Sub, empty.

Cross-project subscriptions. A subscription can be in another project than its topic, as in Pub/Sub. Its shadow is created in the subscription’s project, so the gateway needs the shadow role in both projects.

Push subscriptions with OIDC tokens. As in Pub/Sub, setting oidc_token.service_account_email needs iam.serviceAccounts.actAs on that account (for example Service Account User), checked with the caller’s token. The gateway mints the tokens with its own identity, so its service account needs Service Account Token Creator on each push service account (push_oidc_service_accounts in the module). Pub/Sub’s own service agent needs the same.

Detached subscriptions. After a migration, a Pub/Sub subscription that was handed over is detached. It keeps its IAM policy and keeps answering testIamPermissions, so it still authorizes lowtide’s consumers. Pub/Sub deletes subscriptions that see no activity for 31 days, and the policy with them, so a migrated subscription is set to never expire. The console and lowtide-migrate finish do this for you. If you detach one yourself, run gcloud pubsub subscriptions update SUBSCRIPTION --expiration-period=never.

Mirroring. While a topic is mirrored, its shadow topic in Pub/Sub receives every message, and so do shadow subscriptions on it. Shadow subscriptions are pull subscriptions that nobody pulls, with 10-minute retention, so messages expire before Pub/Sub charges for storing them.

The shadows hold your IAM policies. Don’t delete Pub/Sub topics or subscriptions that a lowtide cluster serves with Cloud IAM authorization, including detached ones.