steid

@jamesgill /

steid/plans/wave-c.md
Markdown16.3 KBRendered·Source·Blame·History·Raw

Phase 2, wave C: Steid's remaining items (draft briefs)

Researched 2026-11-01, read-only, against main at 85a0324 (Steid 0.8.2 published). Not approved yet: each brief has decisions for the author, listed at the end with the recommendation first. No code until the author says go. File and line references are as of 85a0324; launch.md's for these items are stale where noted.

The gate on 85a0324: cargo test exit 0 (1,426 + 10 passed, 13 ignored), cargo clippy --all-targets 0 warnings, cargo fmt --check clean. No date-dependent test was found. cargo audit was not run (it writes its database outside target/). Nothing on main blocks a release.

The shape

  • 2.16 takes 2.20's merge edges, and 2.17 takes 2.20's installer item: same files, same reasoning.
  • 2.20's rest splits into 2.20a (local hardening) and 2.20b (storage).
  • Round 1, in parallel: 2.13; 2.16 with the merge edges; 2.20a with its paired console commit (merged together); 2.20b.
  • Round 2: 2.17 with the installer item, after 2.13 merges (it reuses 2.13's config reading, and shares main.rs, config.rs, the README and the runbook).
  • Then 2.19's security review, folded with the console's "who sees what" review.
  • No migration under the recommended options, so launch 1.2's rollback proof still waits past this release. install.sh changes reach tenants only when the root install.sh is republished.

Files two items share: src/main.rs and src/application/config.rs (2.13, 2.17); src/cli/reset_password.rs (2.13, 2.17); README.md (2.13, 2.17, 2.20b); plans/runbook.md (2.13, 2.17, 2.20b); install.sh (2.13's messages, 2.17's installer item); the console's src/domain/steid_handle.rs (2.20a).

2.13: commands run by hand read the installed config

Facts:

  • main.rs:20 runs dotenvy::dotenv().ok(): ./.env in the working directory and every parent, never overriding a set variable, its error discarded. Defaults: sqlite:steid.db?mode=rwc and ./data (application/config.rs:219-225).
  • reset-password makes an empty database and stays silent. It opens with mode=rwc and migrates (main.rs:40-44, infrastructure/database.rs:10-16), and an unknown handle prints nothing and exits 0 by design (cli/reset_password.rs:8-34; security-2026-09-10.md:130). So /opt/steid/steid reset-password you from a root shell makes $PWD/steid.db, prints nothing and exits 0.
  • restore falls back the same way (cli/restore.rs:46, default ./data). Only backup refuses a missing file (cli/backup.rs:44-54).
  • The unit sets WorkingDirectory=/opt/steid and EnvironmentFile=/etc/steid/steid.env (install.sh:586-592). Documented at README.md:196 and install.sh:538, :829.
  • The console already does it right: it sources the file, cds, and runs runuser -u steid -- … (console shell.rs:329-341), and treats a non-zero exit and "no link on stdout" alike (console fleet.rs:883-898), so an unknown-handle exit 1 is safe.
  • dotenvy cannot read everything install.sh writes: it rejects \` (parse.rs:155-161), which env_quote writes for a backtick (install.sh:138), and expands a bare $ (progress.md:95-98 warned of this).
  • Found, not in launch.md: a root restore --replace (as the README shows) chowns nothing (application/backup.rs, infrastructure/backup.rs, cli/restore.rs), so the new steid.db and repositories would be root-owned under a service running as steid. Reasoned, not reproduced.

Do:

  1. Subcommands load, before AppConfig::from_env: STEID_ENV_FILE if set (must exist), else /etc/steid/steid.env if present, else ./.env (development). The process environment always wins. A file that exists but cannot be read or parsed is a hard error naming the file and line, never the value.
  2. Say on stderr where the configuration came from, and the database path.
  3. reset-password never creates a database: check the file exists, as backup.rs:48-54 does, and open without rwc.
  4. restore refuses to run on built-in defaults (decision C2).
  5. An unknown handle exits non-zero with one stderr line (decision C3).
  6. Docs: README :196, the backup/restore section and the configuration table; install.sh's two messages; the runbook; current.md, progress.md; amend security-2026-09-10.md:130 or record why it changed.

Tests: resolution with a temp file via STEID_ENV_FILE (used; overridden by the environment; unreadable or malformed refuses); reset-password against a missing database errors and makes no file; restore with no configured source refuses before writing; if the reader is hand-written, one test per env_quote spelling.

Owns: src/main.rs, src/cli/{mod,reset_password,restore,backup}.rs, a new src/cli/env_file.rs, src/application/config.rs, README.md, install.sh messages, plans/*. Size: medium. No migration.

2.16: a merge that fails partway finishes or says so (with 2.20's merge edges)

Facts:

  • merge_pull (application/pull_request.rs): update_ref (:831-833), then delete_ref(..).await? (:837-846), record_push (:863), pull.merge and pulls.save (:865-866), close_referenced (:872).
  • The doc comment is wrong (:714-715): a failed source delete returns early, leaving the target moved, the request open, no push event and no webhook.
  • The page says the opposite of what happened: GitMergeError::Stale reads "the branch moved while the merge was being prepared, so nothing was changed" (port.rs:1354-1356), re-rendered by web/pulls.rs:1757-1762 after the target has moved.
  • A retry (reasoned): merge-commit and fast-forward read NothingToMerge (:1031-1033) and stay stuck open; a squash reads Ready and writes a second, empty squash commit.
  • The fake cannot reach this: InMemoryGitMerge::stale() fails every ref update (git/merge.rs:352-357); only whole-stale is tested (pull_request_tests.rs:981).
  • Merge edges (2.20): a merge can delete the default branch, guarded only in the UI (pull_request.rs:422-429, web/pulls.rs:1444-1456, passed through at :1744). Merge commits carry the account's email (web/pulls.rs:1730-1734 → git/merge.rs:245-251).

Do:

  1. Once update_ref succeeds the merge has landed: a failed or stale source delete is not an error; Merged gains "source kept" and the page says so. Reorder to pulls.save (merged) → record_push → close_referenced. A storage failure after the move is its own error naming the commit ("merged into main at abc1234, but recording it failed: …"), never "nothing was changed".
  2. Fix the doc comment, and make Stale's sentence true wherever it can still appear.
  3. Refuse delete_source on the default branch before any write (decision M3); the author email per decision M2.
  4. The fake gains a stale-on-delete-only knob.

Tests: target moved and source delete stale (merged, one push event, source kept, Ok); pulls.save failing after the move (an error naming the commit); delete_source on the default branch refused with no ref touched; the author email; a disk-level stale source if cheap (git/merge.rs has a bare-repo fixture).

Owns: src/application/{pull_request,pull_request_tests,error}.rs, src/application/port.rs, src/infrastructure/git/merge.rs, src/infrastructure/web/pulls.rs, plans/*. Size: medium. No migration.

Facts:

  • public_origin builds the reset link from X-Forwarded-Proto and Host (web/context.rs:320-341), passed by POST /auth/forgot (web/password.rs:137-139) to request_password_reset, which mails issued.link(origin) (application/password_reset.rs:107-166).
  • AppConfig::public_url is an unvalidated Option<String>, documented "Only the command line reads this" (config.rs:186-195).
  • Docker is the exposed case: HOST="0.0.0.0" (Dockerfile:81) and no STEID_PUBLIC_URL (runbook.md:301-302).
  • Other public_origin callers are not mailed to a victim: web/webhook.rs:299, web/git.rs:457, web/atom.rs:105,154,203, web/repo.rs:912, web/pulls.rs:1805.
  • The installer item: install.sh:509 writes STEID_PUBLIC_URL=https://${DOMAIN}, which is https:// under --no-caddy without --domain, so reset-password prints https:///auth/reset/…. The console reads that line with sed 's#^STEID_PUBLIC_URL=https://##p' (console shell.rs:625, :658): keep it unquoted. Console tenants always pass --domain and configure no SMTP.

Do: validate public_url once (an http/https origin with a host and no path, query or fragment); the forgot handler and the CLI use it; without a usable value, decision P1; with no --domain, install.sh writes a commented placeholder instead of https://; docs (config.rs, the README configuration table, runbook.md:301, :592, the Dockerfile comment, the runbook's Docker section, plans/*).

Tests: the validator for each spelling (unset, https://, trailing slash, a path, http://localhost:3000); the mailed link begins with the configured origin; reset-password with an unusable value; optionally an HTTP test with a forged Host.

Owns: src/infrastructure/web/{password,context}.rs, src/application/config.rs, src/main.rs (only if checked at boot), src/infrastructure/mail.rs, src/cli/reset_password.rs, README.md, plans/runbook.md, Dockerfile (comment), install.sh:500-510. Size: small to medium. No migration.

2.20a: local hardening (run_allowing's cap, reserved handles)

Facts:

  • run_allowing is uncapped: run_within_allowing (git_query.rs:1209-1275) collects command.output() whole, for merge_base (:718) and merge_preview (:1061, merge-tree --write-tree, whose conflict listing grows). A capped twin exists, run_capped_allowing (:1305), with MAX_RUN_BYTES 32 MiB (:1142).
  • RESERVED (domain/org.rs:31-62) lacks healthz and metrics, which are top-level static routes, so a handle by either name is shadowed.
  • Cross-repository: the console's STEID_RESERVED (console domain/steid_handle.rs:23) has a drift test (:240-262) reading Steid's checkout. Adding reserved words to Steid turns the console's cargo test red until the console's copy matches.

Do: route both callers through the capped runner (too_large past MAX_RUN_BYTES); add both words to RESERVED, sorted; one console commit, merged in the same session, adding them to STEID_RESERVED.

Tests: oversized output through the allowing path refuses; both words refused. Owns: src/infrastructure/git_query.rs (and tests), src/domain/org.rs, console src/domain/steid_handle.rs. Size: small.

2.20b: storage (WAL, transactions, the stranded rename)

Facts:

  • WAL: database::open sets only foreign_keys (infrastructure/database.rs:24-31) and sqlx 0.9 sets no journal_mode, so the database is in rollback-journal mode (the dev database reads delete), while the docs claim WAL (README.md:371, :501; runbook.md:318; Dockerfile:73-75; install.sh near :494). Restore is already WAL-safe (infrastructure/backup.rs:103-111). An older binary opens a WAL file unchanged.
  • Transactions: create_owner saves organisation, user and membership separately (application/claim.rs:285-287); create_organization saves organisation then membership (application/org.rs:66-74); seed_owner sets home separately. A failure between writes leaves an organisation holding the owner's handle (every later seed or claim refused), or a user with no membership (claimed, but managing nothing). The existing pattern is a transaction inside one adapter method (sqlite.rs:1354, :1450).
  • The stranded rename: rename moves the directory, then saves the row (application/repo.rs:485-500). Dying between them, the boot sweep quarantines the new directory as an orphan (application/reconcile.rs:90-147), and nothing repairs the row.

Do: WAL per decision S1 (one option in database::open, and a test that a file database reports wal); transactions per S2; the sweep pairs exactly one row-less directory with exactly one directory-less row of the same handle and moves the directory back, leaving anything ambiguous as now, logged (S3).

Tests: the pragma on a temp file, and an existing rollback-journal file converted on open; a failing second write leaves nothing (in memory) and the SQLite transaction rolls back; the pairing heuristic is pure, including a two-and-two refusal.

Owns: src/infrastructure/database.rs (and database_compat_tests.rs), src/application/{claim,org,reconcile}.rs, src/domain/repository/*, src/infrastructure/repository/{sqlite,in_memory}.rs, src/infrastructure/app.rs, README.md, plans/runbook.md. Size: medium. No migration under the recommendations.

The decisions, recommendation first

All decided 2026-11-03 by the author, "do all rec": every recommendation below, and S0 "yes" — a password reset also revokes the account's API tokens, and a sweep removes old .backup/ directories, expired sessions and used password_resets rows. Put the S0 items in 2.20b (storage and sweeps) unless the build plan finds a better home, and say where. Held by the author on 2026-11-03: the console comes first (B3, then console 0.7.0); Steid's builds start later, on the author's go, from these briefs and decisions.

2.13, config:

  • C1, how to read steid.env. (b) a small reader accepting exactly what install.sh writes, refusing anything else by line number; (a) dotenvy from_path, a third dialect; (c) no Rust parsing, an installed wrapper script (also fixes root ownership, but not for Docker or manual installs).
  • C2, when restore refuses. (b) only when nothing configured the location; (a) whenever the database file is missing (breaks restoring into a fresh Docker volume).
  • C3, an unknown handle in reset-password. (b) one stderr line, exit 1; (a) silent, exit 0 (the silence is what hides the wrong-database case).
  • C4, running as root. (a) refuse when euid is 0, printing the runuser line; (b) chown after a restore; (c) document only.
  • C5, does serve read the file too? No: systemd supplies it, and a parse refusal must not stop a restart.

2.16, merges:

  • M1, a request left open after a storage failure. (a) say so only (the reorder makes it rare); (b) mark merged automatically when the target contains the source tip; (c) an owner-only "mark as merged" control.
  • M2, the merge commit's email (commits are permanent). (b) <handle>@users.noreply.invalid or similar; (a) the account email; (c) derived from STEID_PUBLIC_URL; (d) a per-user commit-email setting.
  • M3, the default branch as source with Delete checked. (a) refuse the whole merge; (b) merge and silently keep the branch.

2.17, reset links:

  • P1, mail configured but no usable STEID_PUBLIC_URL. (a) refuse to boot, said in the release notes; (b) treat as unable to mail, with a warning; (c) fall back to Host (leaves the hole).
  • P2, scope. (a) reset mail only now; (b) every public_origin uses it when set.
  • P3, existing STEID_PUBLIC_URL=https:// lines. Refuse only when mail is configured.

2.20:

  • S0, scope. Are "a password reset ends sessions but leaves tokens alive" and "nothing sweeps .backup/, expired sessions or used password_resets rows" (launch.md's 2.20, not current.md's line) in this batch?
  • R1, existing holders of healthz or metrics keep their handle, still shadowed: a note only.
  • S1, WAL. (a) enable it, synchronous FULL (the docs already promise it); (b) stay on rollback-journal and fix the six docs.
  • S2, transactions. (a) one purpose-built port method per multi-row write, each a single SQLite transaction, noted in architecture.md; (b) a unit-of-work port (an ADR); (c) compensating deletes.
  • S3, the stranded rename. (a) the pairing heuristic, no migration; (b) a recorded rename intent, a migration.

Not confirmed by the research: the squash-retry double commit (reasoned), root-owned files after a hand-run restore (reasoned), SQLite chowning its journal siblings when run as root (from memory), and cargo audit's result. Also found: steid/CLAUDE.md says cargo audit shows "zero vulnerabilities" while the workspace CLAUDE.md says "three known warnings"; one is out of date.