Skip to content

feat(social): P2-1c legacy social providers migrate onto the registry - #352

Merged
voidvec merged 3 commits into
masterfrom
feat/p2-1c-social-to-registry
Nov 18, 2026
Merged

voidvec merged 3 commits into
masterfrom
feat/p2-1c-social-to-registry

Conversation

@voidvec

@voidvec voidvec commented Nov 17, 2026

Copy link
Copy Markdown
Owner

Purpose

P2-1 batch C: google/wechat/github migrate onto the upstream registry — config becomes the first-boot seed only; afterwards the DB row is the runtime source of truth. Admin credential rotation and enable/disable now take effect without a restart.

Semantics

  • Seed (INSERT-only): at boot, IdentityAssembly seeds google/wechat/github rows from external_auth.* when credentials are configured (tier-gated enablement). ON CONFLICT is ignored — admin edits to the rows win and survive restarts. Deployments that never configured social keep the exact pre-P2-1c behavior (no rows, nothing advertised).
  • Runtime authority: every registry refresh (60s loop + any admin mutation) applies each legacy row to:
    • the provider service (setCredentials hot swap on all three),
    • the guard's static entry (updateStaticProvider: new creds + state binding; enabled=false removes the key → authorize/validate 404; an enabled row may enable a provider config never configured),
    • the login-page listing (never advertises a provider the guard would 404).
  • URL shapes are pinned: authorize URLs are built from the row's CURRENT credentials via the new buildSocialAuthorizeUrlWithCredentials — byte-identical to the historical config-based shapes (the config builder now delegates to it).
  • Admin CREATE still rejects the reserved keys (rows are born from the seed); PUT/DELETE work on them.
  • Fixture-safe: the legacy applier routes through the runtime's current guard (setGuardTarget replays legacy state), so the social mock fixture's guard swap keeps the registry functional in-process.

Tests

New integration case Integration_P2_UpstreamRegistry_LegacySocialRowDrivesStaticSurface (postgres legs): SQL-seeded enabled github row → login page lists it → authorize transaction carries the ROW credentials in the pinned GitHub URL shape → admin PUT disables → listing drops it + authorize 404s → admin CREATE still rejects reserved keys.

Verification

  • Local full suite: 62289/62298 (only the known local-lab AuditExport artifact; CI-green historically)
  • All local gates pass; SDK drift zero (no spec change); api-diff baseline ratified with --force — additive members to public classes, and v1.x promises source-level SemVer only (SDK guide §2)

Config becomes the FIRST-BOOT seed only (INSERT-only: admin edits to the
google/wechat/github rows win and survive restarts); after that the row
is the runtime source of truth -- credential rotation, enable/disable
take effect on the next refresh (60s loop or any registry mutation)
WITHOUT a restart:

- Google/WeChat/GitHub services gain setCredentials (hot swap)
- SocialLoginGuard: static entries become runtime-mutable
  (updateStaticProvider; enabled row may ENABLE a provider config never
  configured, redirect per the shared callback convention; disabled row
  removes the key -> authorize/validate 404); providers_ access locked
- authorize URLs built from CURRENT row credentials via the new
  buildSocialAuthorizeUrlWithCredentials (byte-identical shapes; the
  config-based builder delegates to it)
- UpstreamProviderRuntime: refresh over listAll (legacy rows need the
  disabled state too), legacy rows skipped from endpoint resolution and
  the dynamic set, new LegacyApplier seam (weak-ref to runtime, guard
  re-targeted via setGuardTarget + legacyState_ replay)
- AuthProvidersController: runtime per-key enable/disable keeps the
  login-page listing in lockstep (never advertises a 404ing provider)
- integration test: SQL-seeded github row drives the static surface
  (listing, authorize URL with row creds, admin PUT disable -> 404,
  admin CREATE still rejects reserved keys)
- api-diff baseline ratified (--force: additive members to public
  classes; v1.x promises source-level SemVer only)
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 17, 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-17T10:50:36.053125Z cf657f3 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: cf657f3ebb

ℹ️ 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 +624 to +629
if (key == "google")
googleAuthService->setCredentials(clientId, clientSecret);
else if (key == "wechat")
weChatAuthService->setCredentials(clientId, clientSecret);
else if (key == "github")
gitHubAuthService->setCredentials(clientId, clientSecret);

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 Update login-service wiring when enabling a legacy provider

When a provider was unconfigured or tier-disabled at startup, its login controller receives a null service pointer, and SocialLinkService likewise receives null for that provider. This applier updates credentials, the guard, and discovery, but never replaces those null pointers. Consequently, enabling the registry row advertises a working authorize URL while the callback still uses the config-based fallback in GoogleController, WeChatController, or GitHubController, which rejects the original missing credentials or uses stale ones; linking also remains unavailable. Update the effective service wiring along with the registry state so DB-driven enablement works through the actual code exchange, not just discovery and authorization.

Useful? React with 👍 / 👎.

Comment on lines +147 to +150
void setCredentials(std::string clientId, std::string clientSecret)
{
clientId_ = std::move(clientId);
clientSecret_ = std::move(clientSecret);

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 Synchronize credential updates with exchange requests

With concurrent request handling, the periodic registry refresh now writes these strings while GoogleAuthService::exchangeCodeForUser reads them to validate credentials and construct its token request. The equivalent new setters for WeChat and GitHub have the same problem. These are unsynchronized reads and writes to std::string, so even an unchanged row reapplied every 60 seconds introduces undefined behavior, potentially corrupting requests or crashing the server. Protect updates and reads together, and take one consistent credential-pair snapshot for each exchange.

Useful? React with 👍 / 👎.

{
disabledProviders_.insert(provider);
}
buildBody();

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 Synchronize rebuilding the provider discovery cache

In the multithreaded production configuration, every refresh with a legacy row calls this setter and buildBody(), which replaces cachedBody_, while AuthProvidersController::list() copies that same JSON value without synchronization. The cache was previously only built during startup, so making it runtime-mutable introduces a data race on ordinary discovery requests, even when no administrator changes anything. Serialize both cache publication and reads, or publish an immutable snapshot atomically; also protect the mutable provider collections against overlapping refreshes.

Useful? React with 👍 / 👎.

Comment on lines +143 to +144
std::lock_guard<std::mutex> stateLock(self->legacyMutex_);
self->legacyState_ = std::move(legacyState);

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 Remove legacy runtime entries when their registry rows disappear

After an enabled legacy row has been applied, deleting it through UpstreamProviderAdminController::remove() triggers a refresh, but this loop only applies rows that still exist. Replacing legacyState_ with an empty map does not remove the existing guard entry, clear the service credentials, or hide the discovery entry. Thus deleting an enabled Google, WeChat, or GitHub row leaves it usable and advertised for the remainder of the process, unlike deletion of a dynamic upstream. Reconcile previously applied legacy keys against the new records and explicitly disable removed keys.

Useful? React with 👍 / 👎.

@voidvec
voidvec merged commit 42eb592 into master Nov 18, 2026
13 checks passed
@voidvec
voidvec deleted the feat/p2-1c-social-to-registry branch November 18, 2026 03:48
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