| 1 | # Phase 2, wave C: Steid's remaining items (draft briefs) |
| 2 | |
| 3 | **Researched 2026-11-01, read-only, against `main` at `85a0324`** (Steid 0.8.2 published). |
| 4 | **Not approved yet:** each brief has decisions for the author, listed at the end with the |
| 5 | recommendation first. No code until the author says go. File and line references are as |
| 6 | of `85a0324`; `launch.md`'s for these items are stale where noted. |
| 7 | |
| 8 | **The gate on `85a0324`:** `cargo test` exit 0 (1,426 + 10 passed, 13 ignored), |
| 9 | `cargo clippy --all-targets` 0 warnings, `cargo fmt --check` clean. No date-dependent test |
| 10 | was found. `cargo audit` was not run (it writes its database outside `target/`). Nothing |
| 11 | on `main` blocks a release. |
| 12 | |
| 13 | ## The shape |
| 14 | |
| 15 | - **2.16 takes 2.20's merge edges**, and **2.17 takes 2.20's installer item**: same files, |
| 16 | same reasoning. |
| 17 | - **2.20's rest splits** into **2.20a** (local hardening) and **2.20b** (storage). |
| 18 | - **Round 1, in parallel:** 2.13; 2.16 with the merge edges; 2.20a with its paired console |
| 19 | commit (merged together); 2.20b. |
| 20 | - **Round 2:** 2.17 with the installer item, after 2.13 merges (it reuses 2.13's config |
| 21 | reading, and shares `main.rs`, `config.rs`, the README and the runbook). |
| 22 | - **Then 2.19's security review**, folded with the console's "who sees what" review. |
| 23 | - **No migration** under the recommended options, so launch 1.2's rollback proof still |
| 24 | waits past this release. `install.sh` changes reach tenants only when the root |
| 25 | `install.sh` is republished. |
| 26 | |
| 27 | **Files two items share:** `src/main.rs` and `src/application/config.rs` (2.13, 2.17); |
| 28 | `src/cli/reset_password.rs` (2.13, 2.17); `README.md` (2.13, 2.17, 2.20b); |
| 29 | `plans/runbook.md` (2.13, 2.17, 2.20b); `install.sh` (2.13's messages, 2.17's installer |
| 30 | item); the console's `src/domain/steid_handle.rs` (2.20a). |
| 31 | |
| 32 | ## 2.13: commands run by hand read the installed config |
| 33 | |
| 34 | **Facts:** |
| 35 | - `main.rs:20` runs `dotenvy::dotenv().ok()`: `./.env` in the working directory and every |
| 36 | parent, never overriding a set variable, its error discarded. Defaults: |
| 37 | `sqlite:steid.db?mode=rwc` and `./data` (`application/config.rs:219-225`). |
| 38 | - **`reset-password` makes an empty database and stays silent.** It opens with `mode=rwc` |
| 39 | and migrates (`main.rs:40-44`, `infrastructure/database.rs:10-16`), and an unknown handle |
| 40 | prints nothing and exits 0 by design (`cli/reset_password.rs:8-34`; |
| 41 | `security-2026-09-10.md:130`). So `/opt/steid/steid reset-password you` from a root shell |
| 42 | makes `$PWD/steid.db`, prints nothing and exits 0. |
| 43 | - **`restore` falls back the same way** (`cli/restore.rs:46`, default `./data`). Only |
| 44 | `backup` refuses a missing file (`cli/backup.rs:44-54`). |
| 45 | - The unit sets `WorkingDirectory=/opt/steid` and `EnvironmentFile=/etc/steid/steid.env` |
| 46 | (`install.sh:586-592`). Documented at `README.md:196` and `install.sh:538`, `:829`. |
| 47 | - The console already does it right: it sources the file, `cd`s, and runs |
| 48 | `runuser -u steid -- …` (console `shell.rs:329-341`), and treats a non-zero exit and "no |
| 49 | link on stdout" alike (console `fleet.rs:883-898`), so an unknown-handle exit 1 is safe. |
| 50 | - **dotenvy cannot read everything `install.sh` writes:** it rejects `` \` `` |
| 51 | (`parse.rs:155-161`), which `env_quote` writes for a backtick (`install.sh:138`), and |
| 52 | expands a bare `$` (`progress.md:95-98` warned of this). |
| 53 | - **Found, not in launch.md:** a root `restore --replace` (as the README shows) chowns |
| 54 | nothing (`application/backup.rs`, `infrastructure/backup.rs`, `cli/restore.rs`), so the |
| 55 | new `steid.db` and repositories would be root-owned under a service running as `steid`. |
| 56 | Reasoned, not reproduced. |
| 57 | |
| 58 | **Do:** |
| 59 | 1. Subcommands load, before `AppConfig::from_env`: `STEID_ENV_FILE` if set (must exist), |
| 60 | else `/etc/steid/steid.env` if present, else `./.env` (development). The process |
| 61 | environment always wins. A file that exists but cannot be read or parsed is a hard |
| 62 | error naming the file and line, never the value. |
| 63 | 2. Say on stderr where the configuration came from, and the database path. |
| 64 | 3. `reset-password` never creates a database: check the file exists, as `backup.rs:48-54` |
| 65 | does, and open without `rwc`. |
| 66 | 4. `restore` refuses to run on built-in defaults (decision C2). |
| 67 | 5. An unknown handle exits non-zero with one stderr line (decision C3). |
| 68 | 6. Docs: README :196, the backup/restore section and the configuration table; |
| 69 | `install.sh`'s two messages; the runbook; `current.md`, `progress.md`; amend |
| 70 | `security-2026-09-10.md:130` or record why it changed. |
| 71 | |
| 72 | **Tests:** resolution with a temp file via `STEID_ENV_FILE` (used; overridden by the |
| 73 | environment; unreadable or malformed refuses); `reset-password` against a missing database |
| 74 | errors and makes no file; `restore` with no configured source refuses before writing; if |
| 75 | the reader is hand-written, one test per `env_quote` spelling. |
| 76 | |
| 77 | **Owns:** `src/main.rs`, `src/cli/{mod,reset_password,restore,backup}.rs`, a new |
| 78 | `src/cli/env_file.rs`, `src/application/config.rs`, `README.md`, `install.sh` messages, |
| 79 | `plans/*`. **Size:** medium. No migration. |
| 80 | |
| 81 | ## 2.16: a merge that fails partway finishes or says so (with 2.20's merge edges) |
| 82 | |
| 83 | **Facts:** |
| 84 | - `merge_pull` (`application/pull_request.rs`): `update_ref` (`:831-833`), then |
| 85 | `delete_ref(..).await?` (`:837-846`), `record_push` (`:863`), `pull.merge` and |
| 86 | `pulls.save` (`:865-866`), `close_referenced` (`:872`). |
| 87 | - **The doc comment is wrong** (`:714-715`): a failed source delete returns early, leaving |
| 88 | the target moved, the request open, no push event and no webhook. |
| 89 | - **The page says the opposite of what happened:** `GitMergeError::Stale` reads "the branch |
| 90 | moved while the merge was being prepared, so nothing was changed" (`port.rs:1354-1356`), |
| 91 | re-rendered by `web/pulls.rs:1757-1762` after the target has moved. |
| 92 | - **A retry** (reasoned): merge-commit and fast-forward read `NothingToMerge` |
| 93 | (`:1031-1033`) and stay stuck open; a squash reads `Ready` and writes a second, empty |
| 94 | squash commit. |
| 95 | - The fake cannot reach this: `InMemoryGitMerge::stale()` fails every ref update |
| 96 | (`git/merge.rs:352-357`); only whole-stale is tested (`pull_request_tests.rs:981`). |
| 97 | - **Merge edges (2.20):** a merge can delete the default branch, guarded only in the UI |
| 98 | (`pull_request.rs:422-429`, `web/pulls.rs:1444-1456`, passed through at `:1744`). Merge |
| 99 | commits carry the account's email (`web/pulls.rs:1730-1734` → `git/merge.rs:245-251`). |
| 100 | |
| 101 | **Do:** |
| 102 | 1. Once `update_ref` succeeds the merge has landed: a failed or stale source delete is not |
| 103 | an error; `Merged` gains "source kept" and the page says so. Reorder to `pulls.save` |
| 104 | (merged) → `record_push` → `close_referenced`. A storage failure after the move is its |
| 105 | own error naming the commit ("merged into `main` at `abc1234`, but recording it |
| 106 | failed: …"), never "nothing was changed". |
| 107 | 2. Fix the doc comment, and make `Stale`'s sentence true wherever it can still appear. |
| 108 | 3. Refuse `delete_source` on the default branch before any write (decision M3); the |
| 109 | author email per decision M2. |
| 110 | 4. The fake gains a stale-on-delete-only knob. |
| 111 | |
| 112 | **Tests:** target moved and source delete stale (merged, one push event, source kept, |
| 113 | `Ok`); `pulls.save` failing after the move (an error naming the commit); `delete_source` |
| 114 | on the default branch refused with no ref touched; the author email; a disk-level stale |
| 115 | source if cheap (`git/merge.rs` has a bare-repo fixture). |
| 116 | |
| 117 | **Owns:** `src/application/{pull_request,pull_request_tests,error}.rs`, |
| 118 | `src/application/port.rs`, `src/infrastructure/git/merge.rs`, |
| 119 | `src/infrastructure/web/pulls.rs`, `plans/*`. **Size:** medium. No migration. |
| 120 | |
| 121 | ## 2.17: reset links come from `STEID_PUBLIC_URL`, not `Host` (with 2.20's installer item) |
| 122 | |
| 123 | **Facts:** |
| 124 | - `public_origin` builds the reset link from `X-Forwarded-Proto` and `Host` |
| 125 | (`web/context.rs:320-341`), passed by `POST /auth/forgot` (`web/password.rs:137-139`) to |
| 126 | `request_password_reset`, which mails `issued.link(origin)` |
| 127 | (`application/password_reset.rs:107-166`). |
| 128 | - `AppConfig::public_url` is an unvalidated `Option<String>`, documented "Only the command |
| 129 | line reads this" (`config.rs:186-195`). |
| 130 | - **Docker is the exposed case:** `HOST="0.0.0.0"` (`Dockerfile:81`) and no |
| 131 | `STEID_PUBLIC_URL` (`runbook.md:301-302`). |
| 132 | - Other `public_origin` callers are not mailed to a victim: `web/webhook.rs:299`, |
| 133 | `web/git.rs:457`, `web/atom.rs:105,154,203`, `web/repo.rs:912`, `web/pulls.rs:1805`. |
| 134 | - **The installer item:** `install.sh:509` writes `STEID_PUBLIC_URL=https://${DOMAIN}`, |
| 135 | which is `https://` under `--no-caddy` without `--domain`, so `reset-password` prints |
| 136 | `https:///auth/reset/…`. The console reads that line with |
| 137 | `sed 's#^STEID_PUBLIC_URL=https://##p'` (console `shell.rs:625`, `:658`): keep it |
| 138 | unquoted. Console tenants always pass `--domain` and configure no SMTP. |
| 139 | |
| 140 | **Do:** validate `public_url` once (an `http`/`https` origin with a host and no path, |
| 141 | query or fragment); the forgot handler and the CLI use it; without a usable value, decision |
| 142 | P1; with no `--domain`, `install.sh` writes a commented placeholder instead of `https://`; |
| 143 | docs (`config.rs`, the README configuration table, `runbook.md:301`, `:592`, the |
| 144 | Dockerfile comment, the runbook's Docker section, `plans/*`). |
| 145 | |
| 146 | **Tests:** the validator for each spelling (unset, `https://`, trailing slash, a path, |
| 147 | `http://localhost:3000`); the mailed link begins with the configured origin; |
| 148 | `reset-password` with an unusable value; optionally an HTTP test with a forged `Host`. |
| 149 | |
| 150 | **Owns:** `src/infrastructure/web/{password,context}.rs`, `src/application/config.rs`, |
| 151 | `src/main.rs` (only if checked at boot), `src/infrastructure/mail.rs`, |
| 152 | `src/cli/reset_password.rs`, `README.md`, `plans/runbook.md`, `Dockerfile` (comment), |
| 153 | `install.sh:500-510`. **Size:** small to medium. No migration. |
| 154 | |
| 155 | ## 2.20a: local hardening (`run_allowing`'s cap, reserved handles) |
| 156 | |
| 157 | **Facts:** |
| 158 | - `run_allowing` is uncapped: `run_within_allowing` (`git_query.rs:1209-1275`) collects |
| 159 | `command.output()` whole, for `merge_base` (`:718`) and `merge_preview` (`:1061`, |
| 160 | `merge-tree --write-tree`, whose conflict listing grows). A capped twin exists, |
| 161 | `run_capped_allowing` (`:1305`), with `MAX_RUN_BYTES` 32 MiB (`:1142`). |
| 162 | - `RESERVED` (`domain/org.rs:31-62`) lacks `healthz` and `metrics`, which are top-level |
| 163 | static routes, so a handle by either name is shadowed. |
| 164 | - **Cross-repository:** the console's `STEID_RESERVED` (console `domain/steid_handle.rs:23`) |
| 165 | has a drift test (`:240-262`) reading Steid's checkout. **Adding reserved words to Steid |
| 166 | turns the console's `cargo test` red** until the console's copy matches. |
| 167 | |
| 168 | **Do:** route both callers through the capped runner (`too_large` past `MAX_RUN_BYTES`); |
| 169 | add both words to `RESERVED`, sorted; **one console commit, merged in the same session**, |
| 170 | adding them to `STEID_RESERVED`. |
| 171 | |
| 172 | **Tests:** oversized output through the `allowing` path refuses; both words refused. |
| 173 | **Owns:** `src/infrastructure/git_query.rs` (and tests), `src/domain/org.rs`, console |
| 174 | `src/domain/steid_handle.rs`. **Size:** small. |
| 175 | |
| 176 | ## 2.20b: storage (WAL, transactions, the stranded rename) |
| 177 | |
| 178 | **Facts:** |
| 179 | - **WAL:** `database::open` sets only `foreign_keys` (`infrastructure/database.rs:24-31`) |
| 180 | and sqlx 0.9 sets no `journal_mode`, so the database is in rollback-journal mode (the dev |
| 181 | database reads `delete`), while the docs claim WAL (`README.md:371`, `:501`; |
| 182 | `runbook.md:318`; `Dockerfile:73-75`; `install.sh` near `:494`). Restore is already |
| 183 | WAL-safe (`infrastructure/backup.rs:103-111`). An older binary opens a WAL file unchanged. |
| 184 | - **Transactions:** `create_owner` saves organisation, user and membership separately |
| 185 | (`application/claim.rs:285-287`); `create_organization` saves organisation then |
| 186 | membership (`application/org.rs:66-74`); `seed_owner` sets home separately. A failure |
| 187 | between writes leaves an organisation holding the owner's handle (every later seed or |
| 188 | claim refused), or a user with no membership (claimed, but managing nothing). The |
| 189 | existing pattern is a transaction inside one adapter method (`sqlite.rs:1354`, `:1450`). |
| 190 | - **The stranded rename:** rename moves the directory, then saves the row |
| 191 | (`application/repo.rs:485-500`). Dying between them, the boot sweep quarantines the new |
| 192 | directory as an orphan (`application/reconcile.rs:90-147`), and nothing repairs the row. |
| 193 | |
| 194 | **Do:** WAL per decision S1 (one option in `database::open`, and a test that a file |
| 195 | database reports `wal`); transactions per S2; the sweep pairs exactly one row-less |
| 196 | directory with exactly one directory-less row of the same handle and moves the directory |
| 197 | back, leaving anything ambiguous as now, logged (S3). |
| 198 | |
| 199 | **Tests:** the pragma on a temp file, and an existing rollback-journal file converted on |
| 200 | open; a failing second write leaves nothing (in memory) and the SQLite transaction rolls |
| 201 | back; the pairing heuristic is pure, including a two-and-two refusal. |
| 202 | |
| 203 | **Owns:** `src/infrastructure/database.rs` (and `database_compat_tests.rs`), |
| 204 | `src/application/{claim,org,reconcile}.rs`, `src/domain/repository/*`, |
| 205 | `src/infrastructure/repository/{sqlite,in_memory}.rs`, `src/infrastructure/app.rs`, |
| 206 | `README.md`, `plans/runbook.md`. **Size:** medium. No migration under the recommendations. |
| 207 | |
| 208 | ## The decisions, recommendation first |
| 209 | |
| 210 | **All decided 2026-11-03 by the author, "do all rec": every recommendation below, and S0 |
| 211 | "yes" — a password reset also revokes the account's API tokens, and a sweep removes old |
| 212 | `.backup/` directories, expired sessions and used `password_resets` rows.** Put the S0 |
| 213 | items in 2.20b (storage and sweeps) unless the build plan finds a better home, and say |
| 214 | 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. |
| 215 | |
| 216 | **2.13, config:** |
| 217 | - **C1, how to read `steid.env`.** (b) a small reader accepting exactly what `install.sh` |
| 218 | writes, refusing anything else by line number; (a) dotenvy `from_path`, a third dialect; |
| 219 | (c) no Rust parsing, an installed wrapper script (also fixes root ownership, but not for |
| 220 | Docker or manual installs). |
| 221 | - **C2, when `restore` refuses.** (b) only when nothing configured the location; (a) |
| 222 | whenever the database file is missing (breaks restoring into a fresh Docker volume). |
| 223 | - **C3, an unknown handle in `reset-password`.** (b) one stderr line, exit 1; (a) silent, |
| 224 | exit 0 (the silence is what hides the wrong-database case). |
| 225 | - **C4, running as root.** (a) refuse when euid is 0, printing the `runuser` line; (b) |
| 226 | chown after a restore; (c) document only. |
| 227 | - **C5, does `serve` read the file too?** No: systemd supplies it, and a parse refusal |
| 228 | must not stop a restart. |
| 229 | |
| 230 | **2.16, merges:** |
| 231 | - **M1, a request left open after a storage failure.** (a) say so only (the reorder makes |
| 232 | it rare); (b) mark merged automatically when the target contains the source tip; (c) an |
| 233 | owner-only "mark as merged" control. |
| 234 | - **M2, the merge commit's email (commits are permanent).** (b) |
| 235 | `<handle>@users.noreply.invalid` or similar; (a) the account email; (c) derived from |
| 236 | `STEID_PUBLIC_URL`; (d) a per-user commit-email setting. |
| 237 | - **M3, the default branch as source with Delete checked.** (a) refuse the whole merge; |
| 238 | (b) merge and silently keep the branch. |
| 239 | |
| 240 | **2.17, reset links:** |
| 241 | - **P1, mail configured but no usable `STEID_PUBLIC_URL`.** (a) refuse to boot, said in |
| 242 | the release notes; (b) treat as unable to mail, with a warning; (c) fall back to `Host` |
| 243 | (leaves the hole). |
| 244 | - **P2, scope.** (a) reset mail only now; (b) every `public_origin` uses it when set. |
| 245 | - **P3, existing `STEID_PUBLIC_URL=https://` lines.** Refuse only when mail is configured. |
| 246 | |
| 247 | **2.20:** |
| 248 | - **S0, scope.** Are "a password reset ends sessions but leaves tokens alive" and "nothing |
| 249 | sweeps `.backup/`, expired sessions or used `password_resets` rows" (launch.md's 2.20, |
| 250 | not current.md's line) in this batch? |
| 251 | - **R1, existing holders of `healthz` or `metrics`** keep their handle, still shadowed: a |
| 252 | note only. |
| 253 | - **S1, WAL.** (a) enable it, `synchronous` FULL (the docs already promise it); (b) stay on |
| 254 | rollback-journal and fix the six docs. |
| 255 | - **S2, transactions.** (a) one purpose-built port method per multi-row write, each a |
| 256 | single SQLite transaction, noted in `architecture.md`; (b) a unit-of-work port (an ADR); |
| 257 | (c) compensating deletes. |
| 258 | - **S3, the stranded rename.** (a) the pairing heuristic, no migration; (b) a recorded |
| 259 | rename intent, a migration. |
| 260 | |
| 261 | **Not confirmed by the research:** the squash-retry double commit (reasoned), root-owned |
| 262 | files after a hand-run `restore` (reasoned), SQLite chowning its journal siblings when run |
| 263 | as root (from memory), and `cargo audit`'s result. **Also found:** `steid/CLAUDE.md` says |
| 264 | `cargo audit` shows "zero vulnerabilities" while the workspace `CLAUDE.md` says "three |
| 265 | known warnings"; one is out of date. |