Skip to content

feat(j5): a server joins J5 Connect by its owner signing in - #1323

Merged
Jacksondr5 merged 12 commits into
j5/mainfrom
j5code/j5-connect-self-registration
Dec 1, 2026
Merged

Jacksondr5 merged 12 commits into
j5/mainfrom
j5code/j5-connect-self-registration

Conversation

@Jacksondr5

@Jacksondr5 Jacksondr5 commented Dec 1, 2026 •

Copy link
Copy Markdown
Owner

Problem

To join a J5 Connect, a J5 server needed its operator to register an OIDC client by hand and pass the server's Owner an id and secret. J5 Connect's "Joining" criteria (AC2, AC3, AC5–AC7, AC9) say instead that the Owner joins by signing in, and the J5 Connect decides under its own policy whether that account may add servers.

Closes #1272. The contracts and server for the admin UI (#1271) landed first in #1316, which this builds on.

What changed

J5 Connect image (infra/j5-connect)

  • The registration endpoint. register.py is a stdlib service on loopback. Caddy routes /j5/registrations* to it; everything else still goes to Dex.
    1. A J5 server starts a registration, server to server, and gets back a claim token that only it holds.
    2. The Owner's browser signs in through the image's own static Dex client, j5-connect-registrar.
    3. If the policy lets that account add servers, the server's client is created through Dex's gRPC API, the same path j5-connect clients uses (feat(infra): manage J5 Connect clients without restarting #1264).
    4. The browser goes back to the server, which claims {clientId, clientSecret, subject} or {error: "not_allowed", account}.
  • Who may add servers is the operator's choice, set by J5_CONNECT_REGISTER:
    • allow-list: the default. Verified emails only, managed live with j5-connect allow add|remove|list.
    • everyone: for a company J5 Connect whose identity provider admits only employees.
    • group:<name>: oidc only, matched against the groups claim.
  • Redirect URIs must be an exact http(s)://host[:port]/api/j5/identity/callback, checked as the raw string, so CR/LF can't reach Dex or a redirect's headers. The endpoint also caps body size, nesting, registrations in progress and stalled clients.
  • Registering by hand with j5-connect clients add is unchanged, as an operator's runbook tool.

Server

  • Starting a join. j5.identity.startJoin({ issuer, returnAddress, addresses }) replaces the client-id-and-secret join RPC and returnUrls. It registers the server with every address it has, to come back to the address the Owner's browser is on.
    • Over SSH or a relay there's no such address, so it's refused with JoinNeedsAddressError (AC6).
    • An unreachable J5 Connect, or one without self-registration, is refused with J5ConnectUnreachableError.
    • A J5 Connect that isn't HTTPS is refused with OidcError (AC5).
  • Finishing a join. Back from the J5 Connect, the server claims its client and runs every check against the J5 Connect.
    • One transaction then takes the pending join, confirms its starter is still an Owner (AC1), forgets the old client's accounts when switching, and installs the new client.
    • Joins and leaves change the client one at a time.
    • The step that ends the old client's devices and stores the new secret runs to completion even if the browser goes away.
  • The Owner's own sign-in. The server then signs the Owner in with the new client (purpose = 'join'), and binds only the account the J5 Connect approved (AC3, admin-ux item 2).
    • If that account is someone else's, or another account signs in, the server says so, as adding a sign-in would (AC20).
    • A refusal is kept as joinRefused for Settings to put into words (item 1). The browser lands on /pair?j5-join=joined|refused|failed.
  • Leaving. leave, and joining in place of another client, keep the asking device as a plain owner device tied to no sign-in (AC7, item 10). leave(null) keeps none, for J5 Connect: managed policy key limits.j5Connect #1275's forced leave. A leave also drops a join still in progress.
  • j5.identity.get gains thisDeviceSignedIn (item 9).
  • CLI. j5 auth connect join <issuer> joins by signing in: it prints an address to open on the server's machine, and binds the first owner. With --client-id and --client-secret-file, it's the runbook's by-hand path.
  • Migration 065 adds pending joins, the last refusal, and join_subject on the sign-in row. A copied dev database drops the first two.

Runbooks (their own commits, for Jackson's OK)

  • j5-connect.md gains self-registration: the policy, the allow-list commands, and Caddy's second route.
  • It also says that whoever approves a join becomes the joining Owner's sign-in. The Eng Lead's call, per AC3 and the no-forgery ruling.
  • j5-connect-migration.md now joins by signing in.

One thing to know. Joining goes through the identity provider twice: once to approve the account, and once to give the server a refresh token for its new client. With GitHub, or an IdP that has a session, the second trip is usually an instant redirect. With Google it may ask for consent again (promptType: consent); I haven't tried it.

Live testing

  • J5 Connect image: live, on the Compose test profile (test/offboarding.py, extended).
    • An account off the allow-list is refused, and no client is created.
    • After j5-connect allow add, the same account registers, the client is listed, and a sign-in through it exchanges a code for tokens.
    • The rest of the offboarding test passes.
  • Server join flow: covered by Identity.test.ts against the in-process fake J5 Connect: joining, a refusal, unreachable, non-HTTPS, no return address, the approved-account check, a taken account, keeping the asker, and a leave or lowered Owner landing mid-join. The tests also cover a sign-in through the old client after a switch, a leave waiting for a switch, and an interrupted switch.
  • Not exercised live: a real J5 server and browser joining the image end to end. The join row is J5 Connect: admin UI/UX for sign-in, joining and letting people in (web and desktop) #1271's UI, so that pass belongs with J5 Connect: admin UI/UX for sign-in, joining and letting people in (web and desktop) #1271's live test.

Checklist

  • One concern: the description has no "also"
  • Tests cover the changed behavior (backend changes ship with focused tests)
  • UI changes: before/after screenshots above, and a video for motion or interaction — no UI here; the join row and Leave… are J5 Connect: admin UI/UX for sign-in, joining and letting people in (web and desktop) #1271's
  • Live testing: the section above says what ran live and what did not
  • Upstream-owned files: each one is recorded in FORK.md (case text and file-table row) in this PR — none touched
  • Upstream product: any change to what upstream's product does has a human decision linked above and a register entry in docs/j5/product/upstream.md — none
  • Surfaces: entry points, clients, providers, contracts, reverse states, connection modes (see AGENTS.md)
  • Docs: definitions under docs/j5/product/ and user docs rewritten where this changes them — runbooks only; the definition already describes this

Reviews

  • Sol (accuracy), 7 rounds. Rounds 1–6 found races and gaps, all fixed or answered in the commits above. Round 7 found nothing blocking or should-fix, and one of its two nits is fixed. I dropped the other, which only made a test stricter, because it disturbed a later test in the same file.
  • Fable (security), 1 round:
    • A CR/LF header injection through redirect URIs: fixed.
    • The endpoint's limits: hardened.
    • A forwarded approval binds the approver: documented.
  • CodeRabbit: hit its free-review limit and didn't review.

Built by Claude Opus 5.5 in Claude Code, running in J5 Code.

🤖 Generated with Claude Code

@vercel

vercel Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
j5-code Ready Ready Preview Dec 1, 2026 3:26am UTC

Request Review

@github-actions github-actions Bot added size:XXL 1,000+ effective changed lines (test files excluded in mixed PRs). vouch:trusted Author is trusted by repo permissions or the VOUCHED list. labels Dec 1, 2026
@Jacksondr5
Jacksondr5 force-pushed the j5code/j5-connect-self-registration branch from 130dcac to 4443e90 Compare December 1, 2026 02:19
@Jacksondr5
Jacksondr5 force-pushed the j5code/j5-connect-self-registration branch from 4443e90 to 90cefb4 Compare December 1, 2026 02:20
@Jacksondr5
Jacksondr5 force-pushed the j5code/j5-connect-self-registration branch from d5c6780 to bb58f8b Compare December 1, 2026 02:27
@Jacksondr5
Jacksondr5 added this pull request to stack #1330 December 1, 2026 02:45
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 51 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 3ba4ed0 and f52c6eb.

Files selected for processing: 27

  • apps/server/src/j5/a2a/Migrations.test.ts
  • apps/server/src/j5/a2a/Migrations.ts
  • apps/server/src/j5/a2a/migrations/065_IdentityJoin.ts
  • apps/server/src/j5/identity/Identity.test.ts
  • apps/server/src/j5/identity/Identity.ts
  • apps/server/src/j5/identity/IdentityHttp.ts
  • apps/server/src/j5/identity/Registration.ts
  • apps/server/src/j5/identity/cliConnect.ts
  • apps/server/src/j5/identity/identityRpc.ts
  • apps/server/src/j5/identity/test-support/fakeConnect.ts
  • apps/server/src/j5/persistence/neutraliseCopiedDatabase.test.ts
  • apps/server/src/j5/persistence/neutraliseCopiedDatabase.ts
  • apps/server/src/j5/wsRpc.ts
  • docs/j5/runbooks/j5-connect-migration.md
  • docs/j5/runbooks/j5-connect.md
  • infra/j5-connect/.dockerignore
  • infra/j5-connect/.env.example
  • infra/j5-connect/Caddyfile
  • infra/j5-connect/Dockerfile
  • infra/j5-connect/clients.py
  • infra/j5-connect/compose.yaml
  • infra/j5-connect/connect.py
  • infra/j5-connect/register.py
  • infra/j5-connect/test/check_config.py
  • infra/j5-connect/test/offboarding.py
  • packages/contracts/src/j5/clientRpcPermissions.ts
  • packages/contracts/src/j5/identity.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Base automatically changed from j5code/j5-connect-admin-server to j5/main December 1, 2026 02:59
Jacksondr5 and others added 9 commits November 30, 2026 21:59
The image gains a registration endpoint: a J5 server starts a registration
server to server, its owner signs in through the image's own registrar
client, and when J5_CONNECT_REGISTER's policy (allow-list, everyone, or
group:<name>) lets the account add servers, the server's client is created
through Dex's API and claimed by the server with a token only it holds,
together with the account it approved. `j5-connect allow add|remove|list`
manages the allow-list live.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
`j5.identity.startJoin` registers the server at a J5 Connect's registration
endpoint, with every address of it, to come back to the address the owner's
browser is at; over SSH or a relay there is none, and it is refused. Back from
the J5 Connect, the server claims its client, joins, and signs the owner in
with it, so the account the J5 Connect approved becomes their sign-in. A
refusal is kept for Settings as `joinRefused`. Leaving, or joining in place of
another client, keeps the asking device, tied to no sign-in, and
`thisDeviceSignedIn` says whether this device came from sign-in. A leave drops
a join still on its way back. `j5 auth connect join <issuer>` joins by signing
in; with a client id and secret it is the operator's by-hand path.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
… rule

The runbook gains self-registration: J5_CONNECT_REGISTER's allow-list,
everyone and group rules, and the allow-list commands, which the public J5
Connect section now points to. Registering by hand stays, for recovery. The
migration runbook joins by signing in.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A redirect URI is checked as the raw string it is stored and redirected to,
so CR, LF and other characters a URL parser drops can't reach Dex or a
redirect's headers. The server's state must be URL-safe, a callback with
any other state settles nothing, and the endpoint refuses a negative or
over-deep body, times out a stalled client, and holds more registrations.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The join on its way back is taken only after J5 Connect hands over its
registration, so a leave meanwhile leaves it nothing to finish; it finishes
only while its Owner still is one (AC1). A sign-in answered after a switch to
another client at the same J5 Connect records nothing (AC7). When the account
J5 Connect approved is already another person's, the joining Owner is told
whose, as adding a sign-in would tell them (AC20).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…at once

The pending join is taken, its Owner's level read, the old client's accounts
forgotten and the new client installed in one transaction, after every check
against J5 Connect. A leave, a lowered Owner, or a sign-in through the old
client that lands at any point before it is refused or forgotten (AC1, AC7).
The client's secret is stored only once the join holds.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…was added

A switch ends the old client's devices before the new secret is stored, so a
secret that can't be written strands none of them. A join whose second sign-in
is another account than the one J5 Connect approved answers as a sign-in not
added (AC3). A copied dev database drops joins on their way back and the last
refusal, with their claim token and account.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The client row and the secret store change apart, so two joins, or a join
and a leave, interleaving could leave a secret for another client, or one
for a server that left. Each now finishes before the next starts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Jacksondr5 and others added 2 commits November 30, 2026 21:59
The switch's last step, ending the old devices and storing the new secret,
runs to the end once begun, and stores the secret even when some devices
don't end, so the client row and the secret always name the same client.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@Jacksondr5
Jacksondr5 merged commit 4b2e6c3 into j5/main Dec 1, 2026
41 checks passed
@Jacksondr5
Jacksondr5 deleted the j5code/j5-connect-self-registration branch December 1, 2026 04:39

This branch was successfully deployed

1 active deployment
Preview — f52c6eb2 Deployed Dec 1, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL 1,000+ effective changed lines (test files excluded in mixed PRs). vouch:trusted Author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

J5 Connect: self-registration (a server joins by its owner signing in)

1 participant