Claim OAuth application UID across cells

Related to #562061 (closed)

Rollout: #634688

What does this MR do and why?

  • Claims Authn::OauthApplication#uid in the Topology Service so it is unique across cells. Applications replicate to the global IAM database, where uid is the primary key (discussion).
  • Gated by cells_claims_oauth_applications (beta, off). Enabling it also backfills existing applications through the claims verification worker.
  • Releases uid claims in CleanupDynamicApplicationsWorker, which removes applications with delete and so skips the claim callbacks.

How to set up and validate locally

Steps

1. Setup

  1. Run the Topology Service from gitlab-org/cells/topology-service!585 (merged):

    cd gitlab-topology-service
    git fetch && git checkout 562061-oauth-application-uid-claim && make generate
    gdk restart gitlab-topology-service
  2. In a Rails console, confirm cells is enabled, turn on the flag, and store the shared attributes:

    Gitlab.config.cell.enabled
    # => true
    
    Feature.enable(:cells_claims_oauth_applications)
    attrs = { redirect_uri: 'http://localhost:1234/cb', scopes: 'api', owner: User.first, organization: Organizations::Organization.first }
  3. Store a helper to read the uid claims:

    claims() { gdk psql -d topology_service -c "SELECT bucket_value, source_type, subject_type, subject_id FROM claims WHERE bucket_type = 21;"; }

2. Creating an application claims its uid

app = Authn::OauthApplication.create!(name: 'Claim test', **attrs)
app.uid
claims
# expected output: one row, bucket_value = app.uid, source_type = 16, subject_type = 1, subject_id = the organization ID

3. A uid claimed by another cell is rejected

delete skips callbacks, so the claim stays behind as if another cell owned it:

uid = app.uid
app.delete

Authn::OauthApplication.create!(name: 'Duplicate', uid: uid, **attrs)
# expected output: rejected with "uid has already been taken"

4. Destroying an application releases its claim

app = Authn::OauthApplication.create!(name: 'Destroy test', **attrs)
app.destroy!
claims
# expected output: no row for the destroyed app's uid

5. Existing applications are backfilled

Feature.disable(:cells_claims_oauth_applications)
legacy = Authn::OauthApplication.create!(name: 'Legacy', **attrs)
# the verification worker skips records updated in the last hour
legacy.update_column(:updated_at, 2.hours.ago)
claims
# expected output: no row for legacy.uid
Feature.enable(:cells_claims_oauth_applications)
Cells::ClaimsVerificationWorker.new.perform('Authn::OauthApplication')
claims
# expected output: a row for legacy.uid; the orphaned claim from step 3 is removed

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Hakeem Abdul-Razak

Merge request reports

Loading
Loading