Draft: feat(oauth): store the Rails primary key as source_id

What

Add source_id BIGINT (nullable) to oauth_clients and oauth_refresh_tokens, on Postgres and YugabyteDB. It stores the gitlab-rails primary key of the replicated row: oauth_applications.id for clients, oauth_access_tokens.id for refresh tokens.

Why

The target state of Layer 4 reconciliation (gitlab-org/gitlab#632159) will compare Rails and IAM in ranges of (owning_cell_id, source_id). The Rails worker loops by id, so IAM must store the same key. Topology Service uses this pattern: it stores the Rails primary key in claims.source_id and ListRecords ranges by it. We agreed with @ifarkas to follow the same pattern as the Topology Service Cells worker.

How

  • source_id is required (> 0) on CreateClient, UpsertClient and the refresh token Upsert. ManagedClient returns it.
  • Set once at insert on both tables. A later upsert never changes it, like created_at.
  • BIGINT, not Topology's BYTES(16): both Rails primary keys are bigint.
  • NULL only for IAM-native (dynamic) clients. The registry accepts 0 only for a dynamic client, the same rule as owning_cell_id.

Notes

  • Breaking change: Rails UpsertClient fails until Rails sends source_id. Only the sandbox has data, and we fix it by hand.
  • Stacked on auth/iam!699. When it merges, this MR targets main.

Related to gitlab-org/gitlab#628424

🤖 Drafted by Claude

Edited by Daniele Bracciani

Merge request reports

Loading
Loading