Skip to content

feat(service-bridge): Phase C reverse-coupling endpoints + mode-aware hardening + HttpAuthzClient rename - #13

Merged
PMQ9 merged 5 commits into
wiki-v2from
feat/standalone-phase-c
Sep 4, 2026
Merged

PMQ9 merged 5 commits into
wiki-v2from
feat/standalone-phase-c

Conversation

@PMQ9

@PMQ9 PMQ9 commented Sep 4, 2026

Copy link
Copy Markdown

TL;DR

Phase C of the standalone boundary (wiki-v2 issue docmost#157), fork side: host the east-west endpoints the platform needs so it no longer reaches into Docmost's database, harden the whole service surface to be mode-aware fail-closed, and rename PlatformAuthzClient -> HttpAuthzClient. Pairs with the super PR on cccvu/wiki-v2 (merge THIS fork PR first, then that repoints the submodule to the merge commit).

Context

The platform used to reach DIRECTLY into Docmost's Postgres for workspace settings, the space/membership control plane, and the /v1 content read model. Every table/column it hard-coded is an upgrade landmine. This PR adds the fork-owned, service-secret-guarded endpoints that let the platform do all of that over HTTP instead, so Docmost owns its own schema again.

Related issues

  • Relates to cccvu/wiki-v2#157 (Phase C).

What changed

  • Mode-aware fail-closed (RemoteOnlyGuard) — the mirror of NativeAuthModeGuard. The service surface (/api/service/*, /api/collab/force-disconnect) used to be only "inert" in native mode by the accident of a missing secret; a native deployment that set PLATFORM_AUTHZ_SERVICE_SECRET would have activated the full privileged CCC surface. RemoteOnlyGuard now 404s the whole surface for ALL callers unless AUTHZ_MODE=remote, ordered BEFORE the auth guard so native never consults the secret. Applied to the existing controllers + every new one.
  • New /api/service/* endpoints (all in the fork-owned, boundary-excluded service-bridge/ module):
    • Group A: users/resolve, workspace/default, workspace/settings (GET/PATCH).
    • Group B: the /api/service/spaces/* control plane (list / detail / members / create / update / archive / unarchive / add / change-role / remove). create runs both inserts in ONE Kysely transaction so the space + creator-member rows fire the outbox atomically.
    • Group C: content/pages/list, content/spaces/list, content/spaces/:id, pages/resolve-space, pages/:id/permissions.
  • Least-privilege scopes — one new ServiceScope per capability (workspace:read, workspace:settings:write, users:resolve, pages:read, spaces:read, spaces:write, content:read).
  • Faithful SQL port — the queries reproduce the platform's exact semantics (soft-delete archive, the member upsert, the ms-truncated keyset) via sql templates, NOT the fork's own repos (which hard-delete + emit SPACE_DELETED events — different semantics that would drift the outbox). Reads use camelCase result keys because the fork's Kysely runs CamelCasePlugin.
  • Rename PlatformAuthzClient -> HttpAuthzClient (class + file + specs + all refs + port comment); PLATFORM_AUTHZ_* env vars deliberately unchanged (that rename is prod-coupled, deferred).
  • Contract — extend the canonical inbound service-bridge.openapi.json (17 paths, 20 schemas; redocly-clean) + README; a provider contract test asserts the implemented /api/service/* routes match the spec.

How this was tested

  • cd apps/server && pnpm exec jest src/service-bridge src/authz — 31 suites / 263 tests green (baseline .tsx email failures unchanged). tsc --noEmit clean.
  • New tests: RemoteOnlyGuard (native + secret set -> 404); the canonical-workspace invariant (oldest-non-deleted, incl. >1 and 0 cases); the transactional-create rollback (2nd insert fails -> spaces row rolled back, no partial space — via a spy Kysely that really compiles the SQL and records begin/commit/rollback); the Group C trust model (returns exactly the supplied ids, no re-authorization); scope+guard coverage for every route; the provider contract test.
  • npx @redocly/cli lint docs/integrations/authorization/*.json — clean.

Checklist

Scope

  • Complete and scoped to one logical concern (the fork side of Phase C) — follow-ups noted below.

Tests

  • New/changed behavior has tests (guard, invariant, rollback, trust-model, scope-coverage, contract).
  • Existing tests pass; new tests pass.

Docs & contracts

  • service-bridge.openapi.json + README extended; UPSTREAM_MODIFICATIONS.md (super) updated.
  • The inbound contract change is the point of this PR and is documented in the spec.

Safety (security-first, deny-by-default)

  • Mode-aware fail-closed hardening; least-privilege scopes; content endpoints are an explicit data plane that trusts the platform's PDP filter (documented + tested); transactional atomicity preserved.
  • Upstream boundary respected — all new code under the excluded service-bridge/ + authz/ prefixes; the one config seam (tsconfig.build.json test-exclude) is documented as seam fix(collab): bound the Yjs conflict scan one editor's frames can cost (wiki-v2 #816) #89.

Housekeeping

  • Related issue linked above.
  • Follow-ups identified below.

Known limitations / follow-ups

  • The PLATFORM_AUTHZ_* env-var rename stays deferred (prod-coupled).
  • Group D (the platform's sync/ trigger-outbox) is NOT part of this PR; its replacement with a fork-owned change-feed is tracked in cccvu/wiki-v2#171.
  • CI enforcement of the standalone boundary (native-smoke job, dep-cruiser graph, contract-replacement smoke) is tracked in cccvu/wiki-v2#172 (Phase D).

🤖 Generated with Claude Code

PMQ9 and others added 5 commits September 4, 2026 09:27
The east-west service surface (/api/service/*, /api/collab/force-disconnect)
was only "inert" in native mode by the accident of a missing service secret;
a native deployment that set PLATFORM_AUTHZ_SERVICE_SECRET would have activated
the full privileged CCC integration surface. RemoteOnlyGuard (the mirror of
NativeAuthModeGuard) 404s the surface for ALL callers whenever AUTHZ_MODE is not
remote, ordered before the auth guard so native never consults the secret. The
surface is now off by enforcement, not configuration.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
… (Groups A/B/C)

Move the platform's direct Docmost-DB access behind scoped, service-secret-guarded
east-west endpoints so Docmost owns its schema again:
- Group A: workspace default + settings, users/resolve, pages/resolve-space
- Group B: /api/service/spaces/* control plane (list/detail/members/create/update/
  archive/unarchive/add/change-role/remove); create is one Kysely transaction so the
  space + creator-member rows fire the outbox atomically
- Group C: /api/service/content/{pages,spaces}/list (filter-then-retrieve), getSpace,
  and pages/:id/permissions; a PRIVILEGED DATA PLANE that trusts the platform's PDP
  filter and does NOT re-authorize the supplied id set

New least-privilege ServiceScopes per route; a shared WorkspaceResolver is the single
source of the canonical (oldest non-deleted) workspace. Queries are a faithful `sql`
port of the platform's (soft-delete archive, exact member upsert, ms-truncated keyset),
NOT the fork's own repos (which hard-delete + emit events). Reads use camelCase result
keys because the fork's Kysely runs CamelCasePlugin.

Tests (kysely-spy testkit compiles real SQL): RemoteOnlyGuard, canonical-workspace
invariant, transactional-create rollback, Group C trust model, and scope/guard coverage
for every route.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
It is a transport (a fail-closed HTTP client for the authorization service), not
platform-specific — the name now matches the port contract + reference stub. Renames the
class and its file (platform-authz.client.ts -> http-authz.client.ts) plus the two sibling
specs; updates every fork reference and the port comment. The PLATFORM_AUTHZ_* env vars are
read as string literals and are deliberately left unchanged (that rename is prod-coupled and
deferred). Zero upstream edits (all under the fork-owned authz/ prefix).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
…se C surface

- service-bridge.openapi.json: add the workspace / spaces / pages / content operations
  (17 paths, 20 schemas), the new least-privilege scopes, the RemoteOnlyGuard mode note,
  and the content-plane trust note; redocly-lint clean.
- README: rewrite the inbound section around the endpoint families + the three binding
  properties (mode-gated, scoped, platform-is-the-authority).
- add a provider-side contract test that derives the /api/service/* route set from the
  spec and asserts the implemented controllers match it (drift fails the build).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
… review-round-1 gaps

Addresses the /pr-review-comprehensive round-1 findings on docmost#13 / wiki-v2#173:

- Cap regression: ContentListDto.ids was @ArrayMaxSize(1000) while the platform forwards up to
  content.maxListAuthorizedIds (default 10000), so a principal authorized on 1001-10000 objects
  passed the PDP belt then got a 400 on /v1 lists. Raise the cap to CONTENT_LIST_MAX_IDS (10000)
  and set the canonical maxItems in service-bridge.openapi.json. The provider contract test now
  binds the DTO caps (ids + limit) to the spec so the three can never silently diverge.
- Add service-workspace.service.spec.ts: proves the settings JSONB coalesce shallow-merge preserves
  sibling keys. This merge was untested in either repo (the platform docstring wrongly claimed fork
  coverage).
- Pin deleted_at + workspace_id confidentiality predicates in the content service spec, so a future
  edit dropping either fails CI instead of leaking trashed/cross-workspace content into /v1. Also
  cover listSpacesByIds, resolvePageSpace (default + includeDeleted), and listPagePermissions.
- Tighten scope-coverage to assert the exact least-privilege ServiceScope per route (documents the
  intentional pages:read vs content:read split), plus a no-stale-entries guard.
- Validate ContentCursorDto.updatedAt as ISO-8601 so a malformed cursor is a 400, not a 500.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@PMQ9
PMQ9 merged commit d6f7933 into wiki-v2 Sep 4, 2026
@PMQ9
PMQ9 deleted the feat/standalone-phase-c branch September 4, 2026 17:27
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