~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

The host moves an account here for someone signed in to the console

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:host/account-move

What changes

The host moves an account for someone signed in to the console. A person signed in to the console signs in to the account they're moving, at its own server (/console/move/login?handle=<account>&back=<page>). The host asks it for what a move needs and no more:

  • atproto;
  • a createAccount service token for this host's #opensocial service;
  • identity:*;
  • reading its own repos and files in spaces (space:*?authority=*&action=read_self).

The browser stays signed in as the person, and a move's sign-in that comes back to a browser no longer signed in as them is refused. The host keeps the account's tokens, one account per person for a day at most, and does each step itself:

  • getAccountMove: the account signed in for the caller to move, if any, and whether its move is started.
  • startAccountMove {address?}: the account's token for this host, from its server. Then the copy, as importAccount makes it, and the account's spaces, as importAccountSpace takes them. Then its server is asked to email the code. Started again, it starts over.
  • finishAccountMove {code}: the account's server signs the operation, the move finishes as completeImport does, and the tokens are given back.
  • cancelAccountMove: the tokens are given back and forgotten, and a copy not yet finished is discarded.

Calls to the account's server. They are DPoP-bound to a key made for the sign-in (with ath). Each takes the nonce the server asks for. A token is refreshed before it lapses, or once if the server refuses it as lapsed, as it may while the code is in the mail. The tokens are also given back when the person signs in to another account to move.

Spaces come only from a server that says it holds them (describeServer's spacesAlpha), for the console's move and for opensocial import alike. A stock PDS, as most are yet, hands a method it lacks to its app view, which refuses it in no one way (the reference PDS answers 502), so listing spaces there failed the whole move. An account on such a server now moves with nothing more to bring. This also puts back \n in the command's output strings, where an earlier edit of mine had left raw line breaks.

Smaller changes:

  • importAccount's and completeImport's work moves into Host::import_as and Host::complete_import_as, which both paths share.
  • A pending sign-in carries the server its DID document named, as well as the person it's for.
  • The console's client metadata declares the move's scope beside atproto.

Why

You chose the command first, then a console page in which the host signs in to the account. The browser holds no PDS tokens, since the host is the console's OAuth client, so the host has to be the one calling the account's server.

The person's own sign-in still asks for atproto alone and keeps nothing. Only this one asks for more, only for a move, and only until the move ends. signing-in.md says so.

How it was checked

tests/account_move.rs uses a fake that is both the account's server and its authorization server. It answers only calls bound to a token it gave and the key that token was given for, checking ath and htu. It asks for a nonce first, as atproto's servers do. It can take a token as lapsed once, or give one that lasts less than the host waits for.

  • The whole move: nothing signed in at first; the move's sign-in, checking the scope asked for and that the person stays signed in; a second sign-in giving back the first's tokens; and a start where the token lapses partway. The start brings three spaces: a memberspace with a file, an empty space of the account's own, and someone else's space over two pages of listSpaces. Then a wrong code, which the server refuses, and the right one, which finishes the move and gives the tokens back.
  • Refreshing and refusals: a server without spaces, from which none are asked for; a token refreshed before it lapses; cancelling discards the copy; NotFound and NotStarted; an unreachable server reported as UpstreamFailure.
  • The sign-in itself: refused without a console session, and refused when the browser comes back no longer signed in.

The import tests pass unchanged after the refactor. account_move.rs and console_login.rs are at 100% here. cargo test --workspace passes.

Shortcomings

  • No page yet. The page that drives this is the next pull, stacked on this one. Its end-to-end flow already passes on my machine against the stock reference PDS: the real approval page, DPoP-bound calls, the createAccount token, the emailed code and the PLC signature.
  • One long request. startAccountMove does everything in one request, so a big account means a long wait with no progress shown.

🤖 Generated with Claude Code

Approved

This pull lets a console user sign in to the account they're moving, at its own server, with a DPoP-bound OAuth sign-in. The host keeps the tokens and runs getAccountMove, startAccountMove, finishAccountMove and cancelAccountMove itself. The import and completion logic moves into import_as and complete_import_as, which the old endpoints now share. The refactor looks behaviour-preserving. The DPoP handling (nonce retry, ath, one refresh retry on invalid_token) and the mover-must-still-be-signed-in check in the callback read correctly. I did not read the lexicon JSON files, the docs pages or tests/account_move.rs; the pull says the tests pass.

One thing to fix, though it doesn't block the merge:

  • Expired rows are never cleared. account_move rows older than a day are hidden by move_of but never deleted or revoked. The access and refresh tokens and the DPoP private key stay in SQLite, and the refresh token stays valid at the account's server. This is the "a day at most" promise in the body. Delete and revoke stale rows when they are found, or sweep them.

Minor:

  • A sign-in that returns to a browser no longer signed in as the mover is refused after the token exchange, and those tokens are left unrevoked.
  • renew sends an empty refresh token when the server issued none, so the failure surfaces as a vague upstream error.
crates/group-host/src/account_move.rsline 66Outdated

These lines can no longer be read.

review.knotless.dev

started > now - KEPT_FOR only hides expired rows. They stay with their tokens and key, and the tokens are never revoked. Delete and give back an expired row when it is found, or sweep them.

chadtmiller.com

Fixed in 3b12100: the host's hourly sweep (the uploads' loop in serve) deletes moves kept past a day and gives their tokens back (Host::sweep_moves). move_of still hides one lapsed between sweeps. Covered by gives_back_and_forgets_a_move_kept_a_day.

crates/group-host/src/account_move.rsline 206Outdated

These lines can no longer be read.

review.knotless.dev

With no refresh token this sends an empty one. Return a clear error such as "sign in to the account again" instead.

chadtmiller.com

Fixed in 3b12100: with no refresh token, renewing fails with SignInAgain ("the account's sign-in has lapsed: sign in to it again"), now in both lexicons' errors. Covered by the same new test.

Asked for changes

The new commit asks describeServer before listing spaces, in both the host and the opensocial command. It also restores \n in the command's output. This round has one thing to fix, and last round's expiry finding is still open.

  • A failed describeServer drops the spaces without a word. described.unwrap_or_default()["spacesAlpha"] == true turns a timeout, a 5xx or bad JSON into "holds no spaces". The move then carries on and finishes, and finishAccountMove moves the identity, which can't be undone. An account whose server hiccuped once would lose its spaces. Return the error when the request fails, and treat only a successful answer without spacesAlpha: true as "none". The same applies in crates/opensocial/src/lib.rs. The test only covers the server answering false, so add one where describeServer fails.
  • Last round's expiry finding is not addressed. Rows older than a day are still only hidden, not deleted, and their tokens are never revoked. Both inline comments from last round, on expired rows and on the empty refresh token, are still open. The earlier review did not block on these, and this one doesn't either, but the "a day at most" promise is still not kept.
crates/group-host/src/account_move.rslines 356 to 357Outdated

These lines can no longer be read.

review.knotless.dev

A failed describeServer is read as "no spaces", and the move goes on to move the identity. Pass the error up when the request fails. Read only a successful answer's spacesAlpha.

chadtmiller.com

Fixed in 3b12100: a describeServer that fails stops the move with UpstreamFailure, before the code is asked for, in the host and in opensocial import alike. Only a successful answer without spacesAlpha: true means no spaces. Covered by stops_rather_than_move_without_what_it_cannot_read_or_renew.

Approved

All three open findings are now fixed at 3b12100.

  • Failed describeServer: the host's describeServer call now returns an upstream error through .map_err(upstream)?, so a failed call stops the move before it asks for the code or moves the identity. opensocial import does the same with ?. Only a successful answer without spacesAlpha: true means "no spaces". The new test stops_rather_than_move_without_what_it_cannot_read_or_renew covers a failing describeServer.
  • Expired rows: Host::sweep_moves runs every hour from serve. It deletes rows kept more than a day with DELETE ... RETURNING and revokes their tokens. gives_back_and_forgets_a_move_kept_a_day checks both the revocation and the deletion.
  • No refresh token: renewing now fails with SignInAgain, which is tested.

Remaining minor point, not blocking: a move sign-in that comes back to a browser no longer signed in as the mover is still refused after the token exchange, and I did not check whether those tokens are revoked.

Merged as f23e3f3