Skip to content

fix(devices): signing in links this computer, from anywhere in the app or on a server - #126

Open
naidx0 wants to merge 43 commits into
mainfrom
fix/signin-links
Open

naidx0 wants to merge 43 commits into
mainfrom
fix/signin-links

Conversation

@naidx0

@naidx0 naidx0 commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

TL;DR

Signing in to GitHub links this computer to the person's other computers wherever the sign-in happens: first run, Settings > Profile, or seq-node --github on a server. When the account links a computer, each of the person's computers says so in a notice that waits to be read, with Remove, and a computer the person removed stays removed while the account still lists it, also after the circle starts again without it or the app stops mid-removal. A computer keeps the same UDP port across launches and redials its others at once after sleep or a network change.

Problem

  • Profile sign-in didn't link. Signing in to GitHub from Settings > Profile signed the person in, but the computer never joined their others. Only the first-run sign-in turned linking on. A computer signed in that way also never started linking at launch.
  • Servers needed a typed code. A server running seq-node could link only by a typed device code, so linking by account was app-only.
  • Account links were silent. When the account linked a new computer, the person's other computers said nothing. A computer they didn't expect could join their circle unseen.
  • Remove didn't hold. A computer removed in Devices but still listed on the account's gist was linked again by the next round.
  • The port moved every launch. Each launch took a new UDP port, so the direct addresses other computers remembered stopped working after every restart.
  • Slow reconnect. After sleep or a move to another network, a computer waited out its redial backoff (up to 15 s) before trying its others again.

Cause

  • Profile sign-in. github::app_finish accepted the peer notice only when App_.link was set, and only the first run's app_start_linking set it. Profile called app_start.
  • Launch. boot::wake_if_github asked for Need::Boot, which needs a recorded notice yes. A Profile sign-in never recorded one, so the node stayed off at every launch.
  • seq-node. node.rs never started github_link and had no sign-in of its own.
  • Joined notice. github_link::Linker::step said the yes and marked the row account, but recorded nothing anyone was told.
  • Remove. Linker::step checked only the gist and the joiner's was_removed flag. It never read the circle's own removal record, which Remove writes. That record alone can't carry it either: "Start again without it" founds a new circle that has no record of the computer, and Machine::unlink wrote the device list and the circle in two writes, so a stop between them left the computer linked through the stored circle.
  • Port. iroh::bind_main kept iroh's default 0.0.0.0:0 and [::]:0 unless a bind address was set.
  • Redial. start_dial doubles the backoff up to redial_max, and only a successful register reset it. Neither a wake nor a network change did.

Change

  • One sign-in rule. Every successful GitHub App sign-in accepts the notice and starts the node, wherever it began (the link flag and app_start_linking are gone). Profile's GitHub row says so in one line before the sign-in: "Signing in links this computer to your others on this account."
  • At launch. A computer holding a GitHub App session starts its node and records the yes (Need::GitHub), so a sign-in made on an older build links too. The old test row "signed in but no notice yet does not start" is a contract change, rewritten in its own commit with the reason.
    • The first yes recorded this way also sets a pending record in the peer store (account_start), in the same write as the yes. The app says "This computer now links to your others on your GitHub account, since it is signed in to GitHub." in a notice that waits to be read, at launch and on devices://account_start, and clears the record only when the notice is read. A launch notice the window missed (the event goes out before the window exists) or the person didn't read is said at the next launch. The old test that it shows once is a contract change, rewritten in its own commit.
  • seq-node --github.
    • Signs in with GitHub's device flow beside the node, never in front of it. It prints the code and where to enter it once, and the linker picks the session up when the person's yes lands.
    • A code that runs out is said in one line, and the node carries on with the links it has. A session GitHub stops renewing (refresh token revoked) is said in one line, and the code is offered again the same way (node::keep_github_session).
    • A sign-in that can't start because GitHub can't be reached (a server that boots before its network) is said once and tried again each minute until it starts. One that can never start here (github_app::may_start_later says no) is said once and stops.
    • Keeps the session in the OS credential store, or in memory only when the computer has none. Never a file.
    • Runs github_link with that session (spawn_with, token_in). It doesn't publish the friend card, since a server's user name isn't the person's name.
    • Signed in, it shows no device code and asks no typed yes (node::By::Account). --github with --join is refused.
  • Said, with Remove, until read.
    • When the linker says a yes, both sides record the other in their own peer store (account_joined).
    • The app shows " linked through your GitHub account" wherever the person is, with Remove, in a notice that waits to be read. Under it, the start of the computer's key fingerprint tells two computers of one name apart, and they are always two notices.
    • One notice per computer, found by its key (Toast::about), so a computer renamed while its notice shows gets no second one.
    • The record stays until the person reads the notice (a click on it, or a Remove that worked), so one not read when the app quits is said again at the next launch. A Remove that fails says why and leaves the notice up and unread (Toast::try_action, an action that says whether it worked). The node's start says devices://changed, so a record kept from before launch is said even when the window looked first.
    • The kit gains Toast::until_read, which only these notices use. Such a toast is never folded into another, pushed out by newer ones or cleared by a route change.
    • seq-node prints the line and marks it told only once the line was written.
    • The account-linked computer's Devices row keeps saying "GitHub" after the notice is gone.
    • CORE-API rows next to devices_remove say all of this, with the new devices_account_start and devices_account_start_seen.
  • Remove holds.
    • Each computer keeps the keys the person removed on it in its own peer store (devices_removed, the newest 256), written in the same write as its device list by Remove and by "Start again without it". The linker's removed() asks this list beside the circle's removal record, in all four linking paths (asks, held yeses, posting an invite, redeeming one).
    • Remove marks itself half done (devices_unlinking) in that same write, and the circle's write clears the mark. A computer that stopped between the two finishes the removal at its next start (Machine::finish_removal), so nothing is lost between the writes.
    • A removed computer is not linked again while the gist lists it, even with linked forced high on its side, after a restart, after a circle started again without it, and after a stop mid-removal. Only linking it by hand in Devices takes it off the list.
  • Same port. The endpoint asks for the first of three UDP ports derived from the machine key (iroh::home_ports, 20000 to 29999). The port must be free on IPv4 and IPv6 alike, or IPv4 alone on a computer without IPv6 (free_on_both). It takes any port when all three are taken.
  • Redial at once. On a wake (the wall clock ran ahead of the monotonic one, or a tick came late), iroh is told the network moved, then every backoff resets and redials go out at once. This happens at most once in ten seconds, since a loop starved of time reads like a wake on each late tick, and a late tick never bursts. A second wake inside the ten seconds is held and done when they end. A change in this computer's own direct addresses redials at once too.
  • No real GitHub in a test world. One rule, github_app::Site, decides whether a run may reach github.com: the GitHub App sign-in and renewal, the connectors' GitHub token renewal (connectors.rs now passes Site::here()) and the gist calls (CurlGh::call takes its base from the same Site). Under a debug profile every one is refused before curl runs. A source scan fails on a sign-in or renewal call that passes the bare curl.
  • Module docs. iroh.rs, iroh_net.rs, github_link.rs, github_app.rs and node.rs say what each party sees, as listed below.

Scope

What each outside party can see after this change

  • GitHub. What it already saw from a first-run sign-in, now also from Profile sign-ins and from seq-node --github:
    • the account's one secret gist (keys, names, relay addresses, device codes that end in ten minutes, never a token or a direct address);
    • the computer's IP on each call, every 30 s while signed in;
    • the device-flow sign-in itself, and a new one when GitHub ends a server's session. A server that can't reach GitHub when it starts tries the sign-in once a minute until it can, so GitHub sees the first try that gets through.
      The joined record, the launch record and the removed list never leave the person's computers. A test profile never reaches github.com.
  • n0's relays (the default). Unchanged in kind: this computer's IP and machine key while online, and which keys it exchanges packets with, never contents. A computer signed in from Profile now runs its node, so it now shows up there. The quick redial sends earlier what the backoff would have sent later, at most once in ten seconds.
  • The LAN and anyone on the path. The UDP port is now the same at every launch, on every network, for IPv4 and IPv6. Whoever watches this computer's traffic on two networks can tell by the port (one of 10,000) that it's probably the same computer. A relay already learns that from the key.
  • Linked computers. Unchanged: a direct peer learns the other's IP addresses. Circle members already shared the removal record, signed by the remover. The removed list is each computer's own and is never sent.

A gist attacker

  • Can read the gist (a secret gist is unlisted, not private):
    • They learn the person's computer names, keys and relays, as before.
    • They can redeem a live device code and ask to link. The ask waits for a yes because their key isn't on the account's list.
    • In the app it shows in Devices like any ask. seq-node --github asks no typed yes, so on a server nobody answers it.
    • They can't link, can't read a chat (frames are sealed per recipient) and get no token.
  • Can write the gist (holds the account, or a token with gist access):
    • They can list a key of their own under any name, and the person's online, signed-in computers link it as one of theirs. This was true before this change, and it is what linking by account means.
    • What changes: each of the person's computers says " linked through your GitHub account", with the start of the key's fingerprint, wherever the app is, until the person reads it. seq-node prints it. Remove now holds: a key the person removed is not linked again while it stays listed.
    • Both records are written locally by the person's computers, never read from the gist, so the attacker can't suppress or forge the notice, or lift a removal.
    • They can't take a token from the gist, can't link a computer that is offline or signed out, and can't stop Remove. Deleting the gist unlists the computers. Existing links stay, since they live in each computer's peer store.

Left alone on purpose

  • The gist's polling, ETags and one shared file (a later part), and local discovery.
  • The New picker, the env channel and the chat view (other work in flight).
  • seq-node has no single-instance lock: two seq-node --github processes on one computer run two device flows.
  • A computer that hasn't joined the circle yet can link a removed computer before it learns of the removal. The removed list is per computer, and the circle's record reaches it only when it joins.
  • An add by another member that crosses a removal survives it. The rule for that is decided and is a later part.
  • After "Start again without it", the removed computer keeps its old circle, which still names this one, so on its side it still lists this computer until it is removed there too (1020, unchanged). This computer doesn't link it again.
  • Code comments that still point at docs/PEER-CHATS-PLAN.md and docs/design/device-to-device.md, which don't exist in the repo. The one in iroh.rs is removed; the others are outside this change.

Before and after

602
i-device-joined

602 is Profile signed out, now with the line under GitHub. i-device-joined is new, so the base has no picture of it; the start of the key's fingerprint is its hover detail. The last round changed no screen, so these are the shots from the round before.

Steps Before After
Sign in to GitHub from Settings > Profile, then open Devices > Add The notice still asks; no node runs; the person's other computers never see this one The row said beforehand that signing in links this computer; Add goes straight to linking, and the account links it to the person's others
Launch a computer that holds a GitHub session from an older build but never recorded the notice The node stays off The node starts, records the yes and says that this computer now links to the person's others, until that is read
seq-node --work ~/work --github --accept-notice on a server The flag does nothing; it shows a device code to type on the laptop The node starts at once; GitHub's code and address show once; when the person says yes it links by the account and prints "Linked Studio Mac through your GitHub account." once
The code on a server runs out, or GitHub ends its session (no sign-in there) One line each; the node carries on with its links, and a session that ended offers the code again
A server starts before its network is up (no sign-in there) One line saying GitHub can't be reached and that it tries each minute; it signs in once the network is up
The account links a new computer Nothing is said "Desk PC linked through your GitHub account" shows on each of the person's computers, with Remove, until it is read; unread at quit, it shows again at the next launch; renamed meanwhile, it is still one notice
Press Remove on that notice and the removal fails (no notice) The error is said and the notice stays up and unread
Remove a computer the account still lists, also by "Start again without it", or quit mid-removal It is linked again within a round It stays removed until the person links it by hand
Restart a computer New UDP port; remembered direct addresses fail until a relay re-introduces them Same port on IPv4 and IPv6; remembered addresses reach it
Wake from sleep, or join another network Redials wait out the backoff, up to 15 s Redials go out at once, and a second wake within ten seconds when they end

Shots: built with the shot feature, scenes 602 and i-device-joined, light and dark, in a throwaway profile and data folder; looked at.

Verification

Each of these failed before its change, for the reason the test names, and passes now:

  • pages::settings::account::tests::signing_in_on_profile_links_this_computer
  • pages::settings::account::tests::the_github_row_says_signing_in_links_this_computer
  • tests::a_machine_signed_in_to_github_starts_its_node_at_boot (contract rewritten in its own commit)
  • tests::an_older_sign_in_that_starts_linking_at_launch_says_so_once
  • tests::the_launch_notice_of_an_older_sign_in_is_kept_until_read (launches the app the launch way: the event goes out before the window, then a second launch on a copy of the store; it first failed to compile, on the new API; with the record planted out it fails)
  • pages::settings::where_::devices_tests::an_older_sign_in_that_starts_linking_at_launch_says_so_until_read (contract rewritten in its own commit)
  • tests::a_joined_record_kept_from_before_launch_is_said_once_the_node_is_up
  • iroh::tests::a_restarted_node_keeps_its_port_and_moves_only_when_it_is_taken
  • iroh::tests::a_home_port_is_free_only_when_both_families_have_it
  • iroh::tests::a_node_that_wakes_from_sleep_redials_at_once
  • iroh::tests::a_starved_loop_wakes_at_most_once_in_ten_seconds (a fake clock: a minute of ticks seven seconds late gives at most seven resets; its control shows every one reads like a wake)
  • iroh::tests::a_late_tick_is_not_followed_by_a_burst
  • iroh::tests::a_second_wake_inside_ten_seconds_is_done_when_they_end
  • peers::iroh_net::tests::the_endpoint_asks_for_its_keys_own_port_on_every_start
  • peers::github_link::tests::each_computer_the_account_links_is_told_once
  • peers::github_link::tests::a_computer_the_person_removed_stays_removed_while_the_account_lists_it (300 rounds on both sides with the key listed, linked forced high and a redeem tried from the removed side, then the remover rebuilt from its store; a link by hand then works and clears the mark; each of the four paths planted out fails it)
  • peers::github_link::tests::a_computer_removed_by_starting_the_circle_again_stays_removed
  • peers::github_link::tests::a_removal_cut_off_before_the_circle_was_written_still_holds (a store trigger refuses the circle write; its control reads the stored circle still naming the computer; then the store is closed and opened again; with finish_removal planted out it fails)
  • peers::github_link::tests::the_gist_calls_and_the_sign_in_refuse_the_same_runs
  • github_app::tests::every_github_sign_in_and_renewal_goes_through_the_site (its control finds a planted bare call)
  • overlays::toast::tests::a_notice_that_waits_to_be_read_is_never_pushed_out_folded_or_cleared
  • overlays::layer::tests::an_action_that_fails_leaves_its_notice_up_and_unread (it first failed to compile, on the new API)
  • pages::settings::where_::devices_tests::a_computer_the_account_links_is_said_once_with_remove (contract rewritten in its own commit: showing the notice no longer marks it told)
  • pages::settings::where_::devices_tests::a_joined_notice_not_read_is_said_again_at_the_next_launch
  • pages::settings::where_::devices_tests::a_joined_notice_is_never_pushed_out_by_other_toasts
  • pages::settings::where_::devices_tests::two_computers_of_one_name_are_two_notices_each_removing_its_own
  • pages::settings::where_::devices_tests::a_remove_that_fails_leaves_the_notice_up_and_unread
  • pages::settings::where_::devices_tests::a_computer_renamed_while_its_notice_shows_is_not_said_twice
  • node::tests::a_server_marks_a_computer_told_only_once_its_line_is_written
  • node::tests::a_server_signs_in_beside_the_node_and_the_linker_picks_the_session_up
  • node::tests::a_server_whose_code_runs_out_says_so_once_and_carries_on
  • node::tests::a_server_whose_github_session_is_revoked_says_so_and_offers_the_code_again
  • node::tests::a_server_that_boots_before_its_network_signs_in_once_it_is_up
  • node::tests::a_server_signed_in_to_github_links_by_the_account_and_shows_no_code
  • node::tests::a_server_links_by_the_account_or_by_a_code_not_both
  • github_app::tests::a_test_world_never_reaches_github

These pin behaviour that already held:

  • node::tests::a_server_signs_in_to_github_in_the_terminal keeps its assertions on the new keeper.
  • node::tests::a_server_whose_sign_in_cannot_start_says_so_once_and_stops: an answer that can't change ends the keeper with one line.
  • github_app::tests::a_test_world_never_reaches_github (listed above) now also holds a session due for renewal, with its refresh token, under a test profile: its control renews it against a fake GitHub, and under the profile the renewal is refused and the session kept. The renewal in github_app already went through Site; the call that didn't was in connectors.rs, which the scan test above catches.
  • peers::github_link::tests::a_computer_the_account_links_is_a_full_member_of_the_circle: an account-linked computer is a circle member on both sides, on the same row a typed code gives. It has a negative control (a computer on another account joins no circle), and it fails when mark_account_link is planted out.

All of these ran with no test filter, in a throwaway debug profile and data folder for the app. The native and script rows ran at this head; the others at its parent 3d203121, since the last merge from main changed nothing outside native/ and docs:

Command Exit
cargo fmt --all -- --check 0
cargo clippy --workspace --all-targets --locked -- -D warnings 0
cargo clippy --locked -p seq-shell -p seq-peer --features seq-shell/peers,seq-peer/iroh --all-targets -- -D warnings 101: one lint, crates/seq-shell/tests/two_computers.rs:559, a file this change doesn't touch (same on main); 0 with that lint allowed
cargo nextest run --workspace --locked (5159 tests) 0
cargo nextest run --locked -p seq-shell --features peers (1160 tests) 0
cargo nextest run --locked -p seq-peer --features iroh (658 tests) 0
cargo nextest run --locked --manifest-path native/Cargo.toml --workspace -E 'not binary(launch_path)' (3818 tests) 0
cargo nextest run --locked --manifest-path native/Cargo.toml --workspace -E 'binary(launch_path)', run without a debug profile since launch_env refuses under one by design 0
cargo clippy --locked --manifest-path native/Cargo.toml --workspace --all-targets -- -D warnings 101: one lint, scenes/src/chat/run_card_tests.rs:292, a file this change doesn't touch (same on main); 0 with that lint allowed
node --test 'scripts/*.test.mjs' (604 tests, 10 skipped) 0

two_computers::a_restart_mid_sync_converges failed once in an earlier round, after its 90 s wait, while the machine was shared with other builds. It has passed in every run since. The cause was not found.

Not verified:

  • Two real computers on a real GitHub account over the internet, and the real device flow against github.com. Every test uses a fake GitHub, a fake device flow and an in-memory network.
  • A real sleep and wake on hardware, a real network change, and the port fallback behind a real router. That network_change goes out before the redials, and that bind_main passes over a home port free_on_both refuses, are covered by reading; the probe itself is tested on loopback.
  • seq-node --github on Linux or Windows, on a computer with no credential store, with a session GitHub really revoked, and on a server that really boots before its network.
  • A real app killed mid-removal. The test stops the circle write with a store trigger and opens the store again.
  • An upgrade from an older build that holds a GitHub session (the launch notice is tested with a store as such a build leaves it).

To try it on two computers and a VM:

  1. Sign in to GitHub on computer A from Settings > Profile.
  2. Sign in on computer B from the first run or Profile. Within a round (30 s), each says " linked through your GitHub account" until it is read, and Devices lists both as computers.
  3. On a VM, run seq-node --work ~/work --github --accept-notice. The node starts at once; enter the code at github.com/login/device and watch it print "Linked through your GitHub account." A and B say the VM joined.
  4. Restart A and check that it binds the same UDP port. Sleep B for a minute and check it reconnects within a second of waking.
  5. Press Remove on one notice and check that the computer leaves Devices on both sides and does not come back within a few rounds, also after restarting both.

naidx0 added 15 commits December 2, 2026 23:15
@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Shots

Rendered by CI on GitHub's Windows runner, with its software renderer, at the default window size. Before is main, after is this pull request at b60e05f.

602

Before After
Light 602, light, before 602, light, after
Dark 602, dark, before 602, dark, after

i-device-joined

Before After
Light not in the base i-device-joined, light, after
Dark not in the base i-device-joined, dark, after

naidx0 added 14 commits December 3, 2026 00:37
…e next launch and tells two computers of one name apart
… most once in ten seconds, and late ticks never burst
… ran out or a session that ended in one line, and offers the code again
… renewal calls go through a site that refuses them there
…er, and an older sign-in that starts linking at launch says so once
# Conflicts:
#	crates/seq-shell/src/bin/seq-node.rs
…ircle starts again or the app stops mid-removal

Remove now records the removed computer in this computer's own store, in the same write as the device list, and
the account never links a computer in that set on its own; a link by hand takes it out. Starting a full circle
again without the computer adds it the same way. A removal cut off between the device list and the circle write
is finished at the next start.
… every run the sign-in refuses

The GitHub connector renewed an expired session through bare curl, so a test profile holding one posted to
github.com; it now goes through github_app::Site. The gist calls asked only the profile variable; they now ask the
same Site rule (a profile, or a port alone). A scan finds any GitHub App call passing bare curl, and the gate test
seeds a session due for renewal so it reaches the gate.
…once it is up

The GitHub keeper gave up for good when the sign-in did not start once. A start GitHub did not answer (not
reached, or an answer that was not GitHub's) is now said once and tried again each minute; an answer that cannot
change (GitHub refused it, or the run may not reach GitHub) still stops after one line.
…y end, not dropped

The wake limiter dropped a wake that came within ten seconds of the last: a lid opened twice in that time got no
network change and no backoff reset for the second wake. It is now held and done at the first tick once the ten
seconds are over, once.
…ead, and a renamed computer is not said twice

The joined notice's Remove ran, showed the error, and the toast then read and closed itself anyway, so a failed
Remove cleared the notice with the computer still linked. The kit's try_action keeps a toast as it was when its
action returns false. The notice is now found by the computer's key (Toast::about), not its name and key start,
so a computer renamed while its notice shows is not said again.
…ntil read, though the launch said it before the window

Contract change: the notice came from the devices://account_start event alone, so a window that was not there yet
(a --background launch, or a window that subscribed after the event) never said it, and it was a plain toast newer
ones pushed out. The test now starts the app the launch way and expects the notice kept until it is read.
… the store until it is read

The launch that records a GitHub session as the yes now keeps a notice record in the same write as the yes, and
the window reads it when it opens as well as on devices://account_start, so a --background launch or a window
that opens after the event does not lose it. The notice waits to be read (until_read), so later toasts and a page's
clearing never take it. CORE-API names devices_account_start and devices_account_start_seen.
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