[PR #5598] [MERGED] Launcher: persist Microsoft sign-ins when no keychain is available #6378

Closed
opened 2026-11-03 06:19:30 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/5598
Author: @JulesB40
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: ccr-b42808eb-bs7uli


📝 Commits (10+)

  • e878abf Launcher: keep Microsoft sign-ins in a file where no keychain answers
  • e7b5953 Launcher: fix the secrets-file tests' names and comparison
  • d1eca94 Launcher: lock the secrets file across processes, hand it back to the keychain
  • b617e63 Launcher: read the keychain and the secrets file together on Linux
  • ab8797a Launcher: keep the Tailscale token out of the secrets file, say where sign-ins sit
  • 82ea5d1 Launcher: never hold the secrets file's lock while the keychain prompts
  • f795e86 Launcher: serialize keychain writes so a hand-over can't undo a sign-out
  • f9fe596 Launcher: a run started on an old secrets file finds it after a hand-over
  • a307a24 Launcher: count the secrets file's keys before the start's hand-over
  • 82dee15 Launcher: keep counting a secret another process renewed in the file

📊 Changes

10 files changed (+1076 additions, -37 deletions)

View changed files

📝 docs/launcher-commands.md (+1 -1)
📝 docs/microsoft-account.md (+32 -4)
📝 launcher/Cargo.lock (+1 -0)
📝 launcher/Cargo.toml (+2 -0)
📝 launcher/README.md (+6 -3)
📝 launcher/src/account.rs (+450 -24)
📝 launcher/src/account/tests.rs (+576 -0)
📝 launcher/src/cli.rs (+1 -1)
📝 launcher/src/internet.rs (+4 -4)
📝 launcher/src/mcp.rs (+3 -0)

📄 Description

🤖 Opened by JulesB40's AI agent (Codex, GPT-6.1), not by JulesB40 personally.

What and why

Fixes #5095.

Many Linux systems run no Secret Service (GNOME Keyring, KWallet). The launcher then kept Microsoft sign-ins in memory only, so players had to sign in again at every start.

On Linux and FreeBSD, the secrets the keychain refuses now go to account-secrets.json in the launcher's data folder (FileStore and Layered in launcher/src/account.rs). macOS and Windows keep the keychain (or memory) as before.

  • Readable and writable by the player only (0600 on Unix). Each change to the file holds account-secrets.lock (std File::lock) across its read and replace, and each write goes through a temporary file of its own, to serialize file updates and replace the destination atomically.
  • No store is picked once per run: every read takes the file's copy first (written while the keychain was away, so it's the newer one) and the keychain's otherwise; every write goes to the keychain, and to the file only when it refuses. A launcher that wrote to the file keeps reading, renewing and signing out after another process hands the file to the keychain.
  • The file's lock is never held while the keychain is asked (it can wait on an unlock prompt). A file entry the keychain took is removed only if it still holds what was read before, so another process's newer write stays (and stays counted as seen in the file). Keychain writes hold account-secrets.keychain.lock instead, and the start's hand-over reads each entry again under it, so it never puts back a token another process renewed or signed out meanwhile; only keychain writes wait on a prompt, as they would on the keychain itself.
  • Once the keychain refuses or doesn't answer (a dismissed prompt), the run stops asking it and keeps new secrets in the file, until it finds another process handed the keychain one it saw in the file (put there, read there, or there when it started, counted before its own hand-over): no prompt after a dismissed prompt.
  • Every start hands the keychain the file's secrets one at a time, up to the first it refuses; the file goes once it's empty.
  • Signing out while the keychain is away leaves an empty entry for the account, which hides the keychain's copy until a later start deletes it.
  • HORIZON_NO_KEYCHAIN still keeps secrets in memory (the launcher's tests).
  • Only sign-ins go to the file. The Tailscale credential goes through account::keychain(): the keychain, or memory for the run as before.
  • MCP account_list adds secrets_file: true while the file holds a sign-in (not for sign-out marks alone, nor a file that can't be read) (keychain keeps meaning "sign-ins outlast the launcher").
  • A broken file is an error naming only the error kind, line and column (serde's own message can quote a string the file holds); tokens still never reach accounts.json, logs or output.

This reverses a documented decision (docs/microsoft-account.md said the launcher "never falls back to a plain file"), so it's worth a maintainer's look:

  • The issue suggests a file for every OS. This keeps the keychain first and uses the file only on Linux and FreeBSD, for what the keychain refuses.
  • The owner gate's last owns answer now sits in a file the player can edit. A player could already write keychain items with secret-tool or Keychain Access, so the keychain didn't stop that either; the docs now say so.

Tests (new): a sign-in kept across starts with 0600 and no temporary file left; a broken file (cut short, a lone string, an array) refused without quoting it and never written over; 6 child processes writing and signing out at once lose nothing; the keychain taking back what the file kept while it was away; a launcher on the file still reading, renewing and signing out after another hands the file to the keychain; a keychain that takes A and refuses B, then A signs out, and no launcher reads A again while the keychain's copy goes at the next full hand-over; signing out while the keychain is away removes its copy at the next start; a keychain waiting on a prompt while another process reads and writes the file; a dismissed prompt asked once a run; a hand-over held on a prompt while a running launcher signs the same account out, or renews it, with the running launcher waiting and its change winning; what counts as a sign-in for secrets_file. Two launchers started on an old file while the keychain is away (one read the account, one didn't) both still read it after a third hands it over. Another process handing the account over right as a start's hand-over fails: the start still reads it. A launcher on the file renewing A during a start's hand-over of A, with B refused: after another start hands both over, the first reads the renewed A and B. With its fix taken out, the process and broken-file tests fail 3 runs out of 3, the prompt test times out, the ask-once test sees 5 calls instead of 1, the two hand-over race tests fail 3 runs out of 3, and the three hand-over tracking tests fail without their fixes. All 40 account tests and tests/owner_gate.rs pass. Not tested: a real sign-in on a desktop with no Secret Service.

Docs: docs/microsoft-account.md, launcher/README.md and the sign-out help (docs/launcher-commands.md, regenerated).

Size: 984 lines of code, over the ~500 guideline; most of it is the tests the reviews asked for. Happy to split it if a maintainer prefers.

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

None: the launcher's own account storage.

Other projects' code

none

Self-check

Results below were reported by Claude Code for 82dee15. Codex reviewed the source but has not independently rerun the Rust suite.

pr_ready (tools/pr_ready.py --quick --base upstream/main on vm, against upstream/main at c9d8e3efa, 55 s)

Check Result
Scope ⚠️ 8 files, +990 −37; 984 lines of code: over 500, split it if it can ship in parts
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 510 passed (48 s)
rustfmt ➖ no Rust change
clippy ➖ no Rust change
tests ➖ no crate touched
doc tests ➖ no crate touched
content root tests ➖ content root untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ✅ (2 s)
Rust ⚠️ 1.97.0 is older than CI's stable (1.99): clippy may flag lints CI doesn't, update with rustup update
launcher clippy ✅ (1 s)
launcher tests ✅ 356 passed (3 s)
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 Generated with Claude Code (implementation) and Codex (submission and review).

https://claude.ai/code/session_01DG1mYGWXNxQzmhMnjB36p1


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/5598 **Author:** [@JulesB40](https://github.com/JulesB40) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `ccr-b42808eb-bs7uli` --- ### 📝 Commits (10+) - [`e878abf`](https://github.com/horizon-rust/horizon/commit/e878abf1fdab14c1099d3858201a8a9ca80f591c) Launcher: keep Microsoft sign-ins in a file where no keychain answers - [`e7b5953`](https://github.com/horizon-rust/horizon/commit/e7b5953ba427dfecf32ac14249c53257bb022739) Launcher: fix the secrets-file tests' names and comparison - [`d1eca94`](https://github.com/horizon-rust/horizon/commit/d1eca94f9c35d8879762feb21af4e88b612c5c3b) Launcher: lock the secrets file across processes, hand it back to the keychain - [`b617e63`](https://github.com/horizon-rust/horizon/commit/b617e637b47996c78e207fa0cced1688f9dcbacf) Launcher: read the keychain and the secrets file together on Linux - [`ab8797a`](https://github.com/horizon-rust/horizon/commit/ab8797a5bd200db89bc6c32304757bb007d6c421) Launcher: keep the Tailscale token out of the secrets file, say where sign-ins sit - [`82ea5d1`](https://github.com/horizon-rust/horizon/commit/82ea5d145f98c0fab6d847083bf94686eafc7dfa) Launcher: never hold the secrets file's lock while the keychain prompts - [`f795e86`](https://github.com/horizon-rust/horizon/commit/f795e86510fd26b53b46255b682e86650f7baef8) Launcher: serialize keychain writes so a hand-over can't undo a sign-out - [`f9fe596`](https://github.com/horizon-rust/horizon/commit/f9fe596cbaa76cd2eaa245136351b0504f7fad4e) Launcher: a run started on an old secrets file finds it after a hand-over - [`a307a24`](https://github.com/horizon-rust/horizon/commit/a307a24a633fa92441f9279b387220bd04c24271) Launcher: count the secrets file's keys before the start's hand-over - [`82dee15`](https://github.com/horizon-rust/horizon/commit/82dee152fb5bccb60408722e5b28177844fc84b2) Launcher: keep counting a secret another process renewed in the file ### 📊 Changes **10 files changed** (+1076 additions, -37 deletions) <details> <summary>View changed files</summary> 📝 `docs/launcher-commands.md` (+1 -1) 📝 `docs/microsoft-account.md` (+32 -4) 📝 `launcher/Cargo.lock` (+1 -0) 📝 `launcher/Cargo.toml` (+2 -0) 📝 `launcher/README.md` (+6 -3) 📝 `launcher/src/account.rs` (+450 -24) 📝 `launcher/src/account/tests.rs` (+576 -0) 📝 `launcher/src/cli.rs` (+1 -1) 📝 `launcher/src/internet.rs` (+4 -4) 📝 `launcher/src/mcp.rs` (+3 -0) </details> ### 📄 Description > 🤖 Opened by JulesB40's AI agent (Codex, GPT-6.1), not by JulesB40 personally. ## What and why Fixes #5095. Many Linux systems run no Secret Service (GNOME Keyring, KWallet). The launcher then kept Microsoft sign-ins in memory only, so players had to sign in again at every start. On Linux and FreeBSD, the secrets the keychain refuses now go to `account-secrets.json` in the launcher's data folder (`FileStore` and `Layered` in `launcher/src/account.rs`). macOS and Windows keep the keychain (or memory) as before. - Readable and writable by the player only (0600 on Unix). Each change to the file holds `account-secrets.lock` (std `File::lock`) across its read and replace, and each write goes through a temporary file of its own, to serialize file updates and replace the destination atomically. - No store is picked once per run: every read takes the file's copy first (written while the keychain was away, so it's the newer one) and the keychain's otherwise; every write goes to the keychain, and to the file only when it refuses. A launcher that wrote to the file keeps reading, renewing and signing out after another process hands the file to the keychain. - The file's lock is never held while the keychain is asked (it can wait on an unlock prompt). A file entry the keychain took is removed only if it still holds what was read before, so another process's newer write stays (and stays counted as seen in the file). Keychain writes hold `account-secrets.keychain.lock` instead, and the start's hand-over reads each entry again under it, so it never puts back a token another process renewed or signed out meanwhile; only keychain writes wait on a prompt, as they would on the keychain itself. - Once the keychain refuses or doesn't answer (a dismissed prompt), the run stops asking it and keeps new secrets in the file, until it finds another process handed the keychain one it saw in the file (put there, read there, or there when it started, counted before its own hand-over): no prompt after a dismissed prompt. - Every start hands the keychain the file's secrets one at a time, up to the first it refuses; the file goes once it's empty. - Signing out while the keychain is away leaves an empty entry for the account, which hides the keychain's copy until a later start deletes it. - `HORIZON_NO_KEYCHAIN` still keeps secrets in memory (the launcher's tests). - Only sign-ins go to the file. The Tailscale credential goes through `account::keychain()`: the keychain, or memory for the run as before. - MCP `account_list` adds `secrets_file: true` while the file holds a sign-in (not for sign-out marks alone, nor a file that can't be read) (`keychain` keeps meaning "sign-ins outlast the launcher"). - A broken file is an error naming only the error kind, line and column (serde's own message can quote a string the file holds); tokens still never reach accounts.json, logs or output. **This reverses a documented decision** (docs/microsoft-account.md said the launcher "never falls back to a plain file"), so it's worth a maintainer's look: - The issue suggests a file for every OS. This keeps the keychain first and uses the file only on Linux and FreeBSD, for what the keychain refuses. - The owner gate's last `owns` answer now sits in a file the player can edit. A player could already write keychain items with `secret-tool` or Keychain Access, so the keychain didn't stop that either; the docs now say so. Tests (new): a sign-in kept across starts with 0600 and no temporary file left; a broken file (cut short, a lone string, an array) refused without quoting it and never written over; 6 child processes writing and signing out at once lose nothing; the keychain taking back what the file kept while it was away; a launcher on the file still reading, renewing and signing out after another hands the file to the keychain; a keychain that takes A and refuses B, then A signs out, and no launcher reads A again while the keychain's copy goes at the next full hand-over; signing out while the keychain is away removes its copy at the next start; a keychain waiting on a prompt while another process reads and writes the file; a dismissed prompt asked once a run; a hand-over held on a prompt while a running launcher signs the same account out, or renews it, with the running launcher waiting and its change winning; what counts as a sign-in for `secrets_file`. Two launchers started on an old file while the keychain is away (one read the account, one didn't) both still read it after a third hands it over. Another process handing the account over right as a start's hand-over fails: the start still reads it. A launcher on the file renewing A during a start's hand-over of A, with B refused: after another start hands both over, the first reads the renewed A and B. With its fix taken out, the process and broken-file tests fail 3 runs out of 3, the prompt test times out, the ask-once test sees 5 calls instead of 1, the two hand-over race tests fail 3 runs out of 3, and the three hand-over tracking tests fail without their fixes. All 40 account tests and `tests/owner_gate.rs` pass. Not tested: a real sign-in on a desktop with no Secret Service. Docs: docs/microsoft-account.md, launcher/README.md and the sign-out help (docs/launcher-commands.md, regenerated). Size: 984 lines of code, over the ~500 guideline; most of it is the tests the reviews asked for. Happy to split it if a maintainer prefers. ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [x] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference None: the launcher's own account storage. ## Other projects' code none ## Self-check Results below were reported by Claude Code for 82dee15. Codex reviewed the source but has not independently rerun the Rust suite. **pr_ready** (`tools/pr_ready.py --quick --base upstream/main` on vm, against upstream/main at c9d8e3efa, 55 s) | Check | Result | | --- | --- | | Scope | ⚠️ 8 files, +990 −37; 984 lines of code: over 500, split it if it can ship in parts | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 510 passed (48 s) | | rustfmt | ➖ no Rust change | | clippy | ➖ no Rust change | | tests | ➖ no crate touched | | doc tests | ➖ no crate touched | | content root tests | ➖ content root untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ✅ (2 s) | | Rust | ⚠️ 1.97.0 is older than CI's stable (1.99): clippy may flag lints CI doesn't, update with `rustup update` | | launcher clippy | ✅ (1 s) | | launcher tests | ✅ 356 passed (3 s) | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 Generated with [Claude Code](https://claude.com/claude-code) (implementation) and [Codex](https://openai.com/codex/) (submission and review). https://claude.ai/code/session_01DG1mYGWXNxQzmhMnjB36p1 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:19:30 +07:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#6378
No description provided.