Repository navigation
Device sessions: account info, password change, signing devices out - #14
Open
Skyfuller1303 wants to merge 12 commits into
Open
Skyfuller1303 wants to merge 12 commits into
Skyfuller1303 wants to merge 12 commits into
Conversation
Migration 0007 gives a device its client kind, platform and app version and, once revoked, the time and the reason, and gives a user the time of the last password change (plus a disabled time nothing reads yet). All of it is additive, BIGINT on Postgres, and the flag stays the check. Meta gets create_device_with and redeem_with, rename_device, revoke_device_as, revoke_other_devices, revoke_all_devices, account, change_password and reset_password. Flag, time and reason are set together and only by the first revoke. A password change or reset sets the hash, revokes the devices and deletes the account's invite and pairings in one transaction. Tests run on both databases, including the migration from 0006. Co-Authored-By: Claude <noreply@anthropic.com>
New: GET /account, POST /account/password, PATCH /devices/{id} and
POST /devices/revoke-others. Sign-in and join take an optional client
kind, platform and app version, checked before a try is counted. The
device list shows them with the time and reason of a revoke; all new
fields are optional on the wire.
Changing the password answers a wrong current password with 403
wrong_password, never 401, since the agent reads every 401 on a
signed-in route as a revoked device. It is limited to five tries per
account in 15 minutes, takes a password-check slot, and ends the revoked
devices' live connections at once. Password and name bodies are read up
to the new TINY_JSON_BYTES (4 KiB).
wrong_password and forbidden move into the shared error codes; the local
API refers to them. The agent, app and desktop only change where they
build the extended types.
Co-Authored-By: Claude <noreply@anthropic.com>
user reset-password now revokes every device of the account (reason reset) and deletes its open invite and pairings, so a stolen token does not outlive the old password. --keep-devices restores the old behaviour for the devices. device revoke-all signs out an account's devices without touching the password. Both print how many devices they ended; device revoke records the admin as the reason. Co-Authored-By: Claude <noreply@anthropic.com>
The API table and error codes in the design document, the password and sign-out commands, the live-connection delay of the command line and the rollout note (an older server refuses the newer database) in the server guide. Co-Authored-By: Claude <noreply@anthropic.com>
…evice A /changes long-poll that was waiting when its device was signed out through the API now ends at once, and one that wakes for any other reason looks the device up again before it answers, so a device signed out by the command line gets 401 instead of the next change set. The live endpoint listens for revocations and looks the device up before the upgrade, so a revoke between the sign-in check and the subscription is not missed. Co-Authored-By: Claude <noreply@anthropic.com>
change_password checks, inside its transaction, that the calling device is still signed in (it may have been revoked while the password was hashed) and answers 401 if not. A password that changed meanwhile is now 409 conflict instead of 400 invalid. Both are new MetaError variants mapped in the server. set_password_hash had no caller outside a test and is removed. A new test breaks the pairing deletes with a trigger and checks that a password change, an admin reset and a revoke-others undo everything on SQLite and Postgres. Co-Authored-By: Claude <noreply@anthropic.com>
The long-poll now listens for revocations and looks its device up before it waits, so a revoke between the sign-in check and the wait is not missed, and looks it up once more after the change set is fetched, as the last step before the answer, so a revoke during the fetch is not answered with changes. Co-Authored-By: Claude <noreply@anthropic.com>
…changes a password change_password locked the caller's device row and then the user's row, while revoke_other_devices from another device locked its own device and then the user's, and reset_password locked the user before the devices. On Postgres two of them at once could deadlock and fail with a database error. All of them now take the user's row first (a no-op update), then the devices, then the pairings. A new scenario runs password changes, sign-outs and an admin reset at the same moment, over and over, on both databases and expects only successes, conflicts and signed-out callers. The test trigger helper also drops its Postgres function. Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
…-in adds a device redeem consumed the invite and then updated the user, while a password reset locks the user and then deletes the invite, so the two could deadlock on Postgres. redeem now finds the invite or pairing with a plain read, locks the account, and consumes the code again under the lock; a code that is gone by then is invalid_code. create_pairing locks the account first too. A password sign-in verified the password outside any transaction, so a reset or change that committed meanwhile could be followed by a new device. sign_in_device locks the account and compares the stored hash again before it creates the device; if it differs, login answers as for a wrong password. New scenarios run redeems, a sign-in, a pairing and a reset at the same moment on both databases and expect no database error and no live device once the reset is done. Co-Authored-By: Claude <noreply@anthropic.com>
The invite delete and the pairing update now name the account the plain read found, so a code hash removed and made again for another account between that read and the lock is refused as invalid_code instead of adding a device to the wrong account. Co-Authored-By: Claude <noreply@anthropic.com>
This was referenced Nov 4, 2026
The server (device sessions) shows a device's client_kind, platform and app_version in the device list, but the agent never sent them. Every sign-in and join of the agent now says it is an agent, which operating system it runs on and its own version, cut to the server's 32-byte limit. A server-backed test checks that the device list shows them after both.
This was referenced Nov 6, 2026
Author
|
Update: the agent now sends its device details ( |
This was referenced Nov 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An account can now see and end its device sessions, and a person can change their own password over the API. A password change or reset signs the other devices out, so a stolen token doesn't outlive it. Device tokens keep their format and still don't expire. Agents and apps keep working unchanged; the new request and response fields are optional.
Server
client_kind,platform,app_version,revoked_msandrevoke_reasontodevices, andpassword_changed_msanddisabled_mstousers.disabled_msis created for a later change; nothing reads it yet.POST /auth/loginandPOST /jointake optionalclient_kind(agent,desktoporcli),platformandapp_version, at most 32 bytes each. They are shown in the device list and never used for a permission. A bad value isinvalid, checked before the try is counted.GET /accountreturns the signed-in account:{user_id, username, role, created_ms, password_changed_ms, two_factor_enabled}.two_factor_enabledis alwaysfalsefor now.POST /account/passwordtakes{current_password, new_password}and answers 204. One transaction sets the new hash, signs out every other device (reasonpassword) and deletes the account's open invite and pairings. The device that asked stays signed in.403 wrong_password, never 401: the agent reads any 401 on a signed-in route as "revoked" and signs out.400 weak_password.409 conflict. If the calling device was signed out meanwhile, nothing changes and the answer is 401.GET /devicesgainsclient_kind,platform,app_version,revoked_msandrevoke_reason. The reason is one ofuser,others,password,admin,disabled,two_factor,idleorreset; only the first revoke sets the time and reason.PATCH /devices/{id}renames one of your devices that isn't revoked.POST /devices/revoke-otherssigns out every other device and answers{revoked: n}.usersrow first. That one lock order keeps them from deadlocking on Postgres. A join code is consumed only for the account it was found for after that lock, so a code made again for another account in between is refused asinvalid_code.Command line
user reset-passwordnow signs out every device of the account (reasonreset) and deletes its open invite and pairings.--keep-deviceskeeps the devices signed in, but the codes are deleted either way. It prints how many devices were signed out.device revoke-all <user>(reasonadmin).device revokenow records reasonadmin.Agent
client_kindagent, its operating system asplatformand its version asapp_versionwhen it signs in (also in the second step of a two-factor sign-in, once Two-factor sign-in (TOTP and recovery codes) #19 is in) and when it joins. Each is cut to 32 bytes and control characters are dropped. The desktop app signs in and joins through the agent, so those devices show asagenttoo.login_and_join_send_the_agents_device_detailsin the agent's end-to-end tests checks what the server stores.Protocol
codes::WRONG_PASSWORDandcodes::FORBIDDENare now incraft-cloud-proto, and the local API uses them from there.AccountInfo,ChangePasswordRequest(itsDebughides both passwords, with a test),RenameDeviceRequest,RevokedOthers. Optional client fields are added toLoginRequestandJoinRequest, and#[serde(default)]fields toDeviceInfo.craft-cloud-apigets the matching client calls.Docs
docs/design/sync.mdcovers the routes, error codes, the "never 401 except for the token" rule and device sessions.docs/server.mdcovers the CLI, the signing-out delays and the upgrade note: an older server refuses a database migrated to 0007, so take a backup before upgrading.Testing
cargo fmt --all,cargo check --workspace --all-targets --lockedandcargo clippy --workspace --all-targets --locked -- -D warningspass.cargo test -p craft-cloud-meta -p craft-cloud-server -p craft-cloud-api -p craft-cloud-proto --lockedpasses. That is 141 meta tests, 99 in the server'stests/api.rs, 61 server lib, 9 server CLI, 22 api and 59 proto.CRAFT_CLOUD_REQUIRE_BACKENDS=1(141) and the server tests withCRAFT_CLOUD_TEST_PGpass. The server tests ran without S3; a newon_sqlite_and_postgres!helper intests/api.rsruns the account scenarios on Postgres without it.cargo +1.94 check --all-targets --lockedpasses for the changed crates (api, proto, meta, server, app).--test-threads=1on an earlier commit of this branch (in parallel they crash on Windows, onmainas well; Desktop tests: share one wgpu device (fixes a crash in parallel runs on Windows) #35 fixes that).Not tested, or known
cargo xtask ci: fmt, licenses, icons and clippy pass. The test step fails on my machine under a 16 GiB memory cap, becausean_app_that_misbehaves_is_refused_or_dropped_and_the_rest_go_oninlive_documentsruns out of memory (it does so alone and single-threaded on unmodifiedmaintoo, see Agent test an_app_that_misbehaves_is_refused_or_dropped_and_the_rest_go_on needs more than 16 GiB #15). CI here should show whether it's only my limit.maintoday (egui needs 1.95, andcrates/syncuses if-let guards), so only the changed crates were checked on 1.94.api.rsexplains the order.Left open (happy to change)
idlerevoke reason is reserved for an opt-in setting later.Ported and adapted from my own prototype (Skyfuller1303/craftcloud, MIT OR Apache-2.0).