Skip to content

feat(oidc-in): P2-1a upstream provider registry + generic OIDC federation core - #347

Merged
voidvec merged 4 commits into
masterfrom
feat/p2-1a-upstream-provider-registry
Nov 17, 2026
Merged

voidvec merged 4 commits into
masterfrom
feat/p2-1a-upstream-provider-registry

Conversation

@voidvec

@voidvec voidvec commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Purpose

P2-1 batch A (roadmap v1.7.0): the OIDC-in generic upstream federation registry — DB-driven upstream providers, the generic authorize/exchange protocol, and admin CRUD. Batch B (Keycloak E2E), C (google/wechat/github migration onto the registry), D (admin UI) follow.

What lands

Storage & domain

  • V045__upstream_providers.sql: registry table (provider_key/display_name/issuer/client creds/scopes/claims_mapping/endpoint_overrides/enabled; key-format CHECK; partial index on enabled)
  • IUpstreamProviderRepository port + PostgresUpstreamProviderRepository (async Mapper, vector-callback idiom; UNIQUE(provider_key) → duplicate_key token)
  • OidcUpstreamAuthService (identity layer, drogon-free): discovery fetch with 10-min per-issuer cache → authorize-URL builder (pure) → code exchange (client_secret_post) → userinfo → claims mapping (defaults sub/email/preferred_username/name) → reuses the same AccountLinkFlow as google/wechat/github (oauth2_subject_mappings.provider = provider_key). HTTP is injected via two transport seams — the whole protocol is unit-tested without a live upstream.

Drogon layer

  • SocialLoginGuard gains a dynamic provider set: registry keys ride the exact same origin/binding-cookie/one-time-state machinery as the social providers; the authorize URL is built from the pre-resolved endpoint (endpoint_overrides or last discovery) so the guard stays synchronous.
  • UpstreamProviderRuntime: refresh glue (list enabled → resolve endpoints → push to guard) + 60s loop; admin mutations refresh immediately.
  • UpstreamLoginController — POST /api/auth/oidc/{provider}/login (same {code,state} contract and first-party token-pair response as the social logins, via SocialTokenIssuer).
  • UpstreamProviderAdminController — /api/admin/upstream-providers CRUD (roles:read/roles:write per the claim-mappings precedent; client_secret is write-only — client_secret_set bool only, empty on update keeps it). Reserved social keys are rejected upfront.
  • GET /api/auth/providers merges registry entries (type: "oidc", display_name) into the login-page listing; the authorize endpoint accepts registry keys.

Sync points (all updated): openapi.yaml (6 operations + 2 schemas; provider enums opened for registry keys), route manifest, Property4 fingerprint (sorted), migration + api-diff baselines ratified, docs/api/openapi.json regenerated, python/go/ts clients regenerated.

Tests

  • Unit (OidcUpstreamAuthServiceTest, 9 cases): authorize-URL escaping, overrides short-circuit, discovery parse + per-issuer cache + issuer-mismatch failure, happy-path create (form fields asserted), existing-mapping no-create, custom claims mapping + missing-sub refusal, auto-create-off refusal, upstream failure mapping.
  • Integration (postgres legs, hermetic via endpoint_overrides): full admin CRUD lifecycle (create/list/get/409/400-reserved/update-keeps-secret/login-page merge/authorize transaction URL assertions/delete), plus login-exchange guard validation (unknown provider 404, cross-site 403, replayed state 400).
  • Fixture: injectLoginGuard() re-binds the runtime onto the test guard so the registry keeps working inside the test process.

Verification

  • Local WSL full suite: 62364 assertions, 62355 passed — only remaining failures are the known local-lab AuditExport artifact (CI-green historically, unrelated to this change); fingerprint + both new P2 integration cases green.
  • All local gates pass (spec governance, migration, api-diff, arch-guard, double-move, test-naming, SDK drift).

voidvec and others added 2 commits November 16, 2026 12:56
…tion core

- V045 upstream_providers table (+ generated ORM model)
- identity: IUpstreamProviderRepository port + OidcUpstreamAuthService
  (discovery cache / authorize URL / code exchange / userinfo claims
  mapping / AccountLinkFlow reuse; injectable transport seams)
- storage-postgres: PostgresUpstreamProviderRepository (async Mapper)
- drogon: SocialLoginGuard dynamic providers + authorize-URL build;
  UpstreamProviderRuntime (refresh glue, 60s loop); UpstreamLoginController
  (/api/auth/oidc/{provider}/login); UpstreamProviderAdminController
  (/api/admin/upstream-providers CRUD, roles:read/write, secret
  write-only); login-page listing merges registry entries
- wiring: IdentityAssembly/ControllerRegistration/test_main
- tests: OidcUpstreamAuthServiceTest (fakes) + admin CRUD/login-guard
  integration (hermetic via endpoint_overrides)
- openapi.yaml: 6 new operations + schemas (enum opened for registry keys)
- route manifest + Property4 fingerprint (sorted) + migration/api-diff
  baselines ratified; openapi.json regenerated; python/go/ts clients
  regenerated from the updated spec
- SocialMockFixture injectLoginGuard re-binds the UpstreamProviderRuntime
  onto the test guard (setGuardTarget) so registry providers stay
  authorizable inside the test process; runtime gains buildDynamic()
  shared by commit()/setGuardTarget()
- identity service drops trantor logging (layer is drogon-free);
  controller/regstration include fixes; unique_lock corrections;
  unit-test namespace/capture fixes
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T10:14:46.343638Z 83d9883 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 83d98833a6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +92 to +94
endpoints.authorize = overrides.get("authorize", "").asString();
endpoints.token = overrides.get("token", "").asString();
endpoints.userinfo = overrides.get("userinfo", "").asString();

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Validate endpoint override value types before persisting them

An admin request containing endpoint_overrides: {"token": {}} passes parseBody() because validation only checks that the outer value is an object. The mutation then invokes refresh(), and these asString() calls throw for the nested object inside the asynchronous repository callback. With no exception handler around endpoint resolution, malformed persisted configuration can terminate the server again on startup or periodic refresh. Validate individual override values as strings before saving and make endpoint resolution report malformed configuration through its callback.

Useful? React with 👍 / 👎.

Comment on lines +118 to +119
lock.unlock();
self->commit(std::move(records), std::move(endpointsMap));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject stale refresh results before publishing the snapshot

If a periodic refresh reads an enabled provider and waits on discovery, an intervening admin disable/delete can complete its own refresh and remove that provider. When the older discovery request finishes, this unconditional commit republishes the old enabled record and restores it to SocialLoginGuard; findForLogin() also trusts that stale snapshot, so authentication remains available despite the successful disable/delete until another refresh corrects it. Assign refresh generations and prevent older results from overwriting a newer published snapshot.

Useful? React with 👍 / 👎.

Comment on lines +476 to +478
::drogon::HttpClient::newHttpClient(host, ::drogon::app().getLoop())
->sendRequest(req, [cb = std::make_shared<
fulla::identity::OidcUpstreamAuthService::FetchCallback>(std::move(cb))](

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Contain exceptions when constructing upstream HTTP requests

The admin validator accepts an issuer such as https:// because it only checks the scheme prefix. Discovery then reaches this HTTP-client construction with an empty host, and transport setup exceptions escape the asynchronous refresh callback rather than producing a failed discovery result. The existing DrogonOAuthHttpClient.cc explicitly guards this same malformed-host failure in both transport methods, but the new GET and form-POST seams bypass those guards. Reuse that adapter or catch transport setup exceptions in both seams and invoke the failure callback so a bad registry URL cannot terminate the server.

Useful? React with 👍 / 👎.

@voidvec
voidvec merged commit 9d081a7 into master Nov 17, 2026
17 checks passed
@voidvec
voidvec deleted the feat/p2-1a-upstream-provider-registry branch November 17, 2026 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant