Skip to content
MSO CloudDocumentation

ADR 0058 — MSO Cloud as the identity and entitlement hub of an app family

On this page
  • Status: Accepted (operator, 2026-11-01). The operator answered the seven gate questions on 2026-11-01; the answers are recorded under "Operator decisions" below and in the programme plan, section 10. The customer email in gate 5 is still reviewed by the operator before it is sent.
  • Date: 2026-11-01
  • Owners: Platform / identity (apps/idp, packages/platform-contract, apps/web/src/auth, apps/web/src/app/api/platform).
  • Related: ADR 0002 (plugin registry), ADR 0010 (outbox), ADR 0012 (no plan layer), ADR 0016 (tenant hosts, host-only sessions), ADR 0034, ADR 0045 (upstream IdPs), ADR 0052, ADR 0054 (yng_auth), §57/§58/§60d (planes), §47 (nav hiding is not enforcement).
  • Plan: docs/plans/app-family-hub-2026-11.md — research, option scoring, expert debate, phases, gates.

Context#

MSO Cloud is becoming the front door for several apps that use MSO data. The first is ContentHeat (repo content-engine), which produces ad images, videos and posts from trend data. Its render workers (ffmpeg + Chromium, 10–12 GB containers) need their own scale and release cadence. Customers today keep two credentials and two URL families (msocloud.net, contentheat.younetgroup.com), and they complain. More apps already run on the same host (proofframe-*, curious-kids-content-studio).

Facts that constrain the design (verified 2026-11-01):

  • MSO is an OIDC client only: Auth.js next-auth 5.0.0-beta.32, stateless 14-day JWT carrying userId only (apps/web/src/auth/config.ts:373-375), host-only cookies (apps/web/src/app/api/auth/sso/route.ts:20-24). There is no issuer, no JWKS and no session revocation. Auth.js v5 never left beta (npm beta tag, last publish 2026-07-20).
  • ContentHeat has its own identity: better-auth 1.7.7 with passkey, twoFactor and nextCookies only (content-engine/packages/core/auth/auth.ts:310-330), a home-grown org/brand/RBAC model, Postgres 18, pg-boss and its own RLS. It has no integration with MSO.
  • The two registrable domains differ, so no parent-domain cookie is possible. White-label is live: 2 active org_domains, 7 orgs, 24 users, 40 memberships.
  • Better Auth refuses implicit account linking when the local user is unverified (better-auth/dist/oauth2/link-account.mjs:137-145, requireLocalEmailVerified ?? true). CE users default to email_verified=false (content-engine/packages/core/db/schema.ts:168), and MSO users has no verification column.
  • A direct DB read of MSO is closed by attested RLS (ADR 0054). Cube's JWT is a shared HS256 secret. MCP tools are chat-shaped and rate-limited.

Options scored by a TA, a CTO and a CPO against one weighted rubric (UX 20, security 20, scale 15, maintenance 15, data reuse 10, migration 10, time to value 10): (b) merge into one monorepo scored lowest (2.2–2.6 / 5). It is irreversible in practice, forces lockstep Next/React/TS/Postgres across 11.7k files, puts two audit suites into one verify, and blocks on ContentHeat's live work. (c) shell / iframe fights CE's frame-ancestors 'none' and third-party-cookie partitioning, and needs a shared session secret. (a) plain federation keeps two URL families and has no entitlement core. The chosen hybrid e1 scored highest with every reviewer (4.0–4.45 / 5).

Decisions#

D1 — Topology: platform core + satellites

MSO owns identity, membership, org role, app entitlement, the launcher and the platform API. A satellite app owns its repo, database, workers and deploy, signs users in as an OIDC relying party, and runs on its own browser origin <app>.msocloud.net. Never: a path zone on an MSO host (same origin would let an app XSS reach MSO's session), an iframe, a parent-domain cookie, a shared SESSION_SECRET, or satellite access to MSO Postgres, Redis, Cube or MCP.

D2 — One issuer, served by a certified sidecar

The issuer is https://msocloud.net. The new deployable apps/idp runs panva oidc-provider 9.13.x (MIT; OpenID-certified Basic/Config OP, RP-Initiated and Back-Channel Logout). It sits behind Traefik PathPrefix(/oauth2, /.well-known/openid-configuration, /.well-known/jwks.json) on the platform host, with a Cloudflare cache bypass. Its configuration:

  • grants: authorization code + PKCE S256, refresh-token rotation, and client credentials;
  • client authentication by private_key_jwt;
  • ES256 keys with JWKS overlap rotation;
  • RFC 9068 JWT access tokens and RFC 8707 resource indicators;
  • static first-party clients, with dynamic registration and dev interactions off;
  • a Redis adapter on msocloud-redis-prod under its own key prefix.

The sidecar holds no SESSION_SECRET, no app DB URL and no user table. Its signing keys and the client keys live in yng_auth.idp_keys, envelope-encrypted with the existing secret-encryption key (operator, 2026-11-01). The sidecar reads them through a dedicated role yng_idp that can only SELECT that table, and receives the decrypt key as a container secret. It resolves the MSO session through GET /api/internal/idp/session (bearer, same posture as /api/edge/traefik-dynamic), which returns only {sub, sid, amr, auth_time, email, email_verified}. The implementation is replaceable behind the frozen issuer and claim contract (D14).

D3 — Server-side session id first

sid joins the Auth.js JWT at sign-in, with a new table yng_auth.auth_sessions(sid, user_id, created_at, last_seen_at, revoked_at, amr text[], auth_time, origin_host). The session callback, which already reads users on every request, also checks revoked_at (60 s cache). This ships before any OIDC route. It also closes MSO's own gap: today no session can be revoked.

D4 — Tenant-host users reach satellites with zero prompts

The authorize step runs on the platform host only, because panva's interaction cookie is scoped to the issuer host and Better Auth's authorizationUrl is static. A launcher tile on any MSO host links to GET /api/apps/launch/<app>?next= on the host where the session lives. That route mints a single-use, 60-second handoff token bound to the sid, using the existing magic-link mechanism (apps/web/src/auth/magic-link.ts). /api/auth/idp-handoff on the platform host consumes the token, mints a platform-host session carrying the same sid, and redirects to the app, which runs prompt=none. Audit rows record the origin host. This reverses ADR 0016's refusal for the tenant→platform direction only.

White-label orgs are not gated (operator, 2026-11-01). Their users may pass through msocloud.net redirects without UI. A cold deep link from a white-label user lands on the issuer with an org hint, and the issuer renders that org's branded sign-in page (ADR 0045), so the user never sees a generic MSO login (D13).

D5 — Verified email in MSO

users.email_verified_at timestamptz is set by the first successful sign-in of any method (password, magic link, Google, LDAP, org OIDC). MSO has no self-registration: an account exists only through an admin or an org IdP, so the address is admin-asserted (operator, 2026-11-05; every user unverified on that day was backfilled). The ID token's email_verified derives from this column only.

D6 — Claim contract

The ID token carries iss, sub (users.id), aud, exp, iat, auth_time, nonce, sid, amr[], acr, email, email_verified, name, locale. Under the namespace https://msocloud.net/claims/ it also carries orgs: [{id, slug, name, role, brand_ids|null, apps[]}] (capped at 50; beyond that orgs_truncated: true and the app pulls /me), active_org, active_brand and super_admin.

An access token is at+jwt with aud=https://msocloud.net/api/platform, client_id, scope, jti, exp ≤ 10 min and exactly one org_id. App-specific roles live in the app.

D7 — Entitlement reuses the install ledger

  • The manifest enum gains kind:'satellite' (packages/plugin-host/src/manifest.ts:219). A satellite manifest carries clientId, launchUrl, scopes and planIds.
  • org_plugin_installations gains additive columns plan text, limits jsonb, valid_to timestamptz, status. A trial is a valid_to value, with no code branch.
  • requirePlugin() is reused. Nav gets one closed-union member, app_launcher, which renders a grid from GET /api/platform/v1/me/launcher.
  • org_app_assignments(org_id, app_id, user_id, is_sample) records who may use an app, without any role. It lands with the first seat-capped plan.
  • Apps check entitlement twice: from the apps[] claim at login, and server-side through the entitlement endpoint, with a 5-minute cache invalidated by webhook.

D8 — Provisioning: org pushed, user just-in-time

Installing an app for an org pushes the org and its brands to the app (POST <app>/api/platform/provision/org, client-credentials). Users and memberships are created just-in-time from claims at every login. MSO→app webhooks come from job_outbox (ADR 0010): org.app.changed, membership.changed, user.disabled, trends.updated. They are signed with HMAC-SHA256, carry an X-MSO-Event-Id for idempotency, and retry with backoff. A nightly reconciliation asserts member counts per org against /orgs/{id}/members. SCIM is reserved for a third-party satellite.

D9 — Linking an existing app account requires proof of both accounts

An existing app user links only by authenticating with the app credential once, followed by an explicit linkSocial({provider:'mso'}), or through an audited super-admin bulk link for one org. The mso provider is never in trustedProviders, requireLocalEmailVerified stays at its default, and click-only confirmation is not a control. A linked user keeps no app-local password, passkey or TOTP. Org links are made by a super-admin only and can be reversed per org.

Role floor:

MSO role ContentHeat role
owner owner
admin admin
editor creator
viewer viewer

App admins may overlay finer app roles within the MSO role and viewable_brand_ids bound. MSO super-admin maps to app super-admin only behind an app opt-in, which is off by default.

D10 — Platform API v1, one scope per data plane

The API lives at /api/platform/v1. The first endpoints are /me, /me/launcher, /orgs/{id}/entitlements, /orgs/{id}/members, /orgs/{id}/brands and /orgs/{id}/social/trends (+ /counts). The trends endpoints serve the 3rd-party market-intel plane only.

Each route requires exactly its plane's scope (platform:orgs.read, platform:entitlements.read, platform:social.read; marketing and marketplace get their own scope when a consumer exists). The sidecar refuses a client-credentials token for an org without the app installed, so enforcement happens at the data, not in nav (§47). Apps land the data as their own provenance class (ContentHeat: CONNECTOR, source_key='mso-social'). RFC 8693 token exchange is deferred.

D11 — Logout everywhere

Sign-out anywhere triggers RP end_session with id_token_hint. The sidecar then revokes the sid (auth_sessions.revoked_at) and sends an OIDC back-channel logout_token to every client with that sid. The post-logout redirect is MSO /api/auth/signout, which clears the Auth.js cookie. Admin disable and "sign out everywhere" fan out the same way. Target: ≤ 5 s to a 401 in every app, measured in the pilot. Front-channel logout is not used.

D12 — Shared packages

@younetgroup/platform-contract (Zod 4 schemas, CONTRACT.md, a vi copy bundle and the J1–J6 conformance e2e spec) and @younetgroup/design-tokens (CSS variables) are published to GitHub Packages under the younetgroup org via changesets. GitHub's npm registry requires the package scope to equal the owner, so the published scope is @younetgroup, not the internal @yng. Satellite repos belong in the same GitHub org, so one read:packages token and one access list cover every app. A repo outside the org builds with a fine-grained read:packages token passed as a BuildKit secret, never as a build arg. Minor versions are additive; a breaking change gets a new major kept 90 days beside the old one.

The launcher/top bar is a markup + CSS contract each app renders, held to a screenshot parity gate (≤ 1 % at 3 widths). A React @yng/suite-nav is created only on a trigger: the second React satellite, or the gate failing twice. It may depend only on react >=19 <20.

D13 — White-label satellites (in the main programme)

The authorization request carries an org hint (login_hint plus the namespaced org parameter). The issuer's interaction renders that org's branded sign-in (ADR 0045), and home-realm discovery on the platform sign-in maps email → org host → D4 handoff. heat.<customer> as a CNAME served by the app (dynamic baseURL/trustedOrigins) ships in a parallel lane, with no install gate. Per-host issuers stay deferred.

D15 — Data ownership: analytics in MSO, creative operations in the app

  • MSO owns analytical data and every analytical view. That means the warehouse planes (§57/§58/§60d): social trends from the market-intel plane, marketing and marketplace performance, dashboards, charts and AI analysis. There is one source of truth, reused by every app, the MSO dashboards and the data assistant.
  • The app owns its operational data. For ContentHeat: briefs, generated assets (RustFS), render jobs, brand kits, approval workflow and schedules. This is workflow state and binary media, not warehouse material.
  • MSO → app. The app pulls Platform API v1 (D10) and receives trends.updated webhooks. It keeps a read-through projection (CONNECTOR, source_key='mso-social'), so a render never blocks on MSO uptime. MSO stays authoritative, and a daily count reconciliation in both gates proves the projection matches (§53).
    • Amended by ADR 0061 D7: the trend dataset keeps source_key = 'socialtrend' in the app; mso-social is not introduced. D4-D5 there replace the /social/trends pull with the trend-feed routes.
  • App → MSO. On publish the app emits content.published (asset id, channel post id, org, brand, campaign) to /api/platform/v1/events. MSO's own ad and social connectors pull the post's performance and attribute it to the generated creative (lineage). The app never pushes performance numbers.
  • Views. The app deep-links to the MSO dashboard through the launcher for analysis, with no iframe (option c is rejected). Inline it renders at most small pickers (for example, choosing a trend) from API data, using the shared design tokens.
  • Pattern. The platform holds the system of record and exposes it through a scoped API. Apps hold only their own domain data. Shopify's Admin API with its apps, and HubSpot and Salesforce platform objects, work the same way. In data-mesh terms, each domain is the source-aligned owner of its own data.

D14 — Auth.js → Better Auth is its own decision

MSO's migration off Auth.js v5 beta is ADR 0059 (decision gate 2027-Q2), never a precondition. The sidecar stays after that migration unless @better-auth/oauth-provider is verified to cover back-channel logout, acr_values/max_age step-up, private_key_jwt, RFC 9068 and RFC 8707, and passes the same conformance suite behind the frozen issuer.

Operator decisions (2026-11-01)#

# Question Decision
1 ContentHeat WIP Committed: the CE tree is clean apart from .claude/settings.local.json. The CE decision takes D225, the next free number.
2 msocloud-idp + Redis prefix Approved
3 Key storage yng_auth, encrypted at rest; the sidecar reads through role yng_idp (D2)
4 Pilot MSO mso-demo (3 members, 0 custom domains, read-only check) ↔ ContentHeat "FWD Demo"
5 White-label In the main programme with redirects through msocloud.net, no install gate (D4, D13)
6 Package registry GitHub Packages under younetgroup (D12); the CE repo moved to younetgroup/content-engine-platform on 2026-11-01
7 Dev capacity Slice raised to 64 GB, CPUQuota 2400 %, load ≤ 32, 4 slots each for tsc/vitest/audit
8 Where analytics live MSO warehouse; apps read via Platform API v1 (D15)

Consequences#

  • Customers keep one credential and one URL family (msocloud.net, <org>.msocloud.net, <app>.msocloud.net), with an app launcher, the org/brand context carried in the URL, and logout everywhere.
  • Each app keeps its own release cadence, scale and rulebook. The only shared code is a versioned contract package checked by contract tests in both CIs. Next/React/TS/Postgres majors move independently.
  • MSO takes on operating an IdP. Accepted controls: a 7-day patch SLA for oidc-provider, better-auth* and jose; the OpenID conformance suite before the pilot and after every oidc-provider minor; an external review of the authorization server before the second customer org.
  • Enforcement: a new rule pack .claude/rules/platform-family.md (§178+) with audits no-wildcard-redirect-uri, platform-scope-per-plane and satellite-analytics-source (a satellite holds no warehouse-plane table that is not a CONNECTOR projection) in audit:all.

Rejected#

Option Reason
Merge monorepo Irreversible in practice, lockstep upgrades, two audit suites in one gate, blocks on CE's live work.
Iframe / micro-frontend shell CE forbids framing, third-party-cookie partitioning, no SSO without a shared session secret.
Path zones on MSO hosts Same browser origin; a cookie Path is not a security boundary.
Hand-built authorization server on jose The same author writes the server and its oracle; 1.5–3k LOC of protocol code to review. Fallback only if a container is refused.
@better-auth/oauth-provider first Requires migrating every MSO auth surface before the first satellite login.
Keycloak / Zitadel / WorkOS / Clerk A third user store, a JVM/Go service on a shared prod host, or offshore identity.
Bespoke launch token without OIDC No silent re-auth, no standard logout.
SCIM or RFC 8693 in v1 No consumer.
trustedProviders / click-only linking Account takeover.
Per-host issuers N discovery docs and N RP configs for 2 domains.
Front-channel logout Broken by cookie partitioning.