| 1 | # Runbook |
| 2 | |
| 3 | > Attempt #2's only setup instructions lived in a plan file describing an architecture |
| 4 | > that had already been deleted, so they were actively wrong. Keep this file honest: |
| 5 | > if a command here doesn't work, fix it or delete it. |
| 6 | |
| 7 | ## Status |
| 8 | |
| 9 | The app boots and serves. Everything marked **(#2)** is carried from the previous |
| 10 | attempt and has **not** been re-verified against Topcoat — treat it as a sketch. |
| 11 | |
| 12 | ## Requirements |
| 13 | |
| 14 | - **rustc ≥ 1.95** — Topcoat 0.5 requires it, and on an older toolchain `cargo add |
| 15 | topcoat` silently resolves to an empty `topcoat v0.0.0` placeholder rather than |
| 16 | failing. Verified on 1.97.1. |
| 17 | - `git` on `PATH` (from Milestone 3 — `git init --bare` creates repos, and from |
| 18 | Milestone 4 `git http-backend` serves the protocol). **`cargo test` needs it too**: |
| 19 | `DiskGitStorage`'s tests run real `git init`, so a machine without `git` fails the |
| 20 | suite, not just the app. |
| 21 | |
| 22 | ## Dev setup |
| 23 | |
| 24 | ```bash |
| 25 | cargo run |
| 26 | cargo test |
| 27 | ``` |
| 28 | |
| 29 | ```bash |
| 30 | cargo install topcoat-cli |
| 31 | topcoat dev |
| 32 | ``` |
| 33 | |
| 34 | `topcoat dev` builds, bundles assets, watches sources, and live-reloads pages that |
| 35 | include `topcoat::dev::script()`. Press `r` to force a rebuild. |
| 36 | |
| 37 | ## Configuration |
| 38 | |
| 39 | `STEID_`-prefixed env vars via `dotenvy` + `envy`, read into `AppConfig`. Every value |
| 40 | has a default, so a bare `cargo run` works with no environment at all. |
| 41 | |
| 42 | Live now: |
| 43 | |
| 44 | ``` |
| 45 | STEID_DATABASE_URL=sqlite:steid.db?mode=rwc # default |
| 46 | STEID_DATA_DIR=./data # default; bare repos, read from M3 |
| 47 | STEID_INSECURE_COOKIES=false # default; see below |
| 48 | STEID_ALLOW_PRIVATE_WEBHOOKS=false # default; see below |
| 49 | ``` |
| 50 | |
| 51 | There is deliberately **no owner password in configuration** — the owner is created |
| 52 | through the claim flow instead. See |
| 53 | [0002](decisions/0002-first-run-claim-not-config-bootstrap.md). |
| 54 | |
| 55 | The bind address is **not** a `STEID_` variable — Topcoat owns it: |
| 56 | |
| 57 | ```bash |
| 58 | HOST=0.0.0.0 PORT=8080 cargo run |
| 59 | ``` |
| 60 | |
| 61 | That supersedes attempt #2's `STEID_LISTEN_ADDR`. |
| 62 | |
| 63 | ### `STEID_INSECURE_COOKIES` — development only |
| 64 | |
| 65 | Topcoat's session cookie is `__Host-` prefixed and `Secure`. `Secure` means the browser |
| 66 | only keeps it over a trustworthy origin, and browsers disagree about whether |
| 67 | plain-HTTP `localhost` qualifies. Where it doesn't, **the failure is completely |
| 68 | silent**: the server issues a session and records the row, the browser discards the |
| 69 | cookie, and every page renders signed out with no error anywhere. This cost an |
| 70 | afternoon; the symptom looks exactly like broken auth logic. |
| 71 | |
| 72 | Setting `STEID_INSECURE_COOKIES=true` swaps in `InsecureCookieTokenStore` — the same |
| 73 | cookie without `Secure` and without the prefix, named `steid-dev-session` so it can |
| 74 | never be confused with a hardened one. `HttpOnly` and `SameSite=Lax` are kept. Boot |
| 75 | prints a warning while it's on. |
| 76 | |
| 77 | **Never set this on a deployed instance.** Without `Secure` the session cookie travels |
| 78 | unencrypted and anyone on the network path can lift it and become that user. Behind |
| 79 | TLS, leave it unset. |
| 80 | |
| 81 | A gitignored `.env` in the repo root sets it for local work. Keep `.env` and |
| 82 | `.env.prod` out of git — both are gitignored. |
| 83 | |
| 84 | ### `STEID_ALLOW_PRIVATE_WEBHOOKS` — development only |
| 85 | |
| 86 | A webhook URL is refused if it points at this machine or its own private network, in two |
| 87 | places: `WebhookUrl::new` when it is saved, and again on every resolved address before the |
| 88 | request is dialled. That is the SSRF defence, and it is also what makes the **end-to-end |
| 89 | webhook check impossible to run** — proving that a real push signs and delivers a real |
| 90 | payload needs a receiver, and the receiver is a script on `127.0.0.1`. |
| 91 | |
| 92 | `STEID_ALLOW_PRIVATE_WEBHOOKS=true` relaxes **only the address rules**, in both halves at |
| 93 | once so the form and the sender cannot disagree. The scheme, credentials in the authority, |
| 94 | the port, the length and the packed spellings of an address (`127.1`, `2130706433`) are |
| 95 | refused with it on exactly as without: those are wrong wherever they point. |
| 96 | |
| 97 | **Never set this on a deployed instance.** With it on, anyone who can add a hook can make |
| 98 | the server issue requests inside its own network and read the response body back off the |
| 99 | deliveries page — the metadata endpoint of a cloud instance included. Boot prints a |
| 100 | warning while it is on. |
| 101 | |
| 102 | It exists because the alternative was worse: the check previously needed a temporary patch |
| 103 | to the source, and a patch is invisible and easy to leave in place. |
| 104 | |
| 105 | ## First run |
| 106 | |
| 107 | ```bash |
| 108 | cargo run |
| 109 | ``` |
| 110 | |
| 111 | An unclaimed instance prints a setup token and redirects every route to `/auth/setup`. |
| 112 | Paste the token, choose a handle, email, and password, and the owner is created and |
| 113 | signed in. |
| 114 | |
| 115 | The token is **held in memory only**, so every restart mints a new one — including |
| 116 | each rebuild under `topcoat dev`. Use the most recent one printed. Once claimed, no |
| 117 | token is minted at all and `/auth/setup` redirects away. |
| 118 | |
| 119 | Sign in at `/auth/login` with the **email**, not the handle. |
| 120 | |
| 121 | ## Repo layout on disk (Milestone 3) |
| 122 | |
| 123 | Bare repos at `{STEID_DATA_DIR}/{handle}/{name}.git`, created with no template (so no |
| 124 | `.sample` hooks) and `HEAD` pinned to `refs/heads/main` regardless of the host's |
| 125 | `init.defaultBranch`. See [0006](decisions/0006-git-binary-behind-narrow-ports.md). |
| 126 | |
| 127 | Created empty — no initial commit and no branch, like GitHub. |
| 128 | |
| 129 | Creating one refuses rather than reusing a directory that already exists, so an orphan |
| 130 | left by a create that died mid-way blocks that name until it is removed by hand. |
| 131 | |
| 132 | ## Git transport (Milestone 4) |
| 133 | |
| 134 | Smart HTTP, delegated to `git http-backend`, authenticated with personal access tokens |
| 135 | over HTTP Basic — see [0001](decisions/0001-git-over-http-not-ssh.md). No SSH, no host |
| 136 | keys, no `authorized_keys`. |
| 137 | |
| 138 | ```bash |
| 139 | git clone http://host/{handle}/repos/{name}.git |
| 140 | ``` |
| 141 | |
| 142 | Fill in the token workflow and the `body_limit` setting once this is built. |
| 143 | |
| 144 | ## Deployment (container) |
| 145 | |
| 146 | A `Dockerfile` at the repo root builds a self-contained image. Two stages: `rust:1.97-bookworm` |
| 147 | compiles and bundles, `debian:bookworm-slim` runs. ~206 MB. |
| 148 | |
| 149 | ```bash |
| 150 | docker build -t steid . |
| 151 | docker volume create steid-data |
| 152 | docker run -d --name steid -p 3000:3000 -v steid-data:/data steid |
| 153 | docker logs steid |
| 154 | ``` |
| 155 | |
| 156 | Verified end to end on 2026-08-29: the image builds, boots, applies migrations, |
| 157 | creates `/data/steid.db`, serves `/auth/setup` with its stylesheet, and `git init |
| 158 | --bare` succeeds inside `/data/repos` as the non-root user. |
| 159 | |
| 160 | ### The build needs `topcoat asset bundle`, not just `cargo build` |
| 161 | |
| 162 | `cargo build --release` alone produces a binary that **fails to boot**. `main` calls |
| 163 | `AssetBundle::load()`, which walks up from the executable looking for |
| 164 | `assets/manifest.toml`; without one it returns `NotFound` and the process exits before |
| 165 | serving anything. `build.rs` does not write that bundle — it only runs Tailwind and |
| 166 | stages icons into `OUT_DIR`, where they are embedded in the binary. |
| 167 | |
| 168 | The bundle comes from the CLI, which the builder stage installs: |
| 169 | |
| 170 | ```bash |
| 171 | cargo install topcoat-cli --version 0.5.0 --locked |
| 172 | topcoat asset bundle --release |
| 173 | ``` |
| 174 | |
| 175 | It writes `target/assets/`, which must be copied **next to the binary** in the runtime |
| 176 | image — `/app/steid` finds `/app/assets`. This is the same step `topcoat dev` performs |
| 177 | for you, and the reason a hand-built binary serves stale CSS. |
| 178 | |
| 179 | Two build-time consequences worth knowing: |
| 180 | |
| 181 | - The build **needs network access**: `build.rs` downloads the standalone Tailwind CLI |
| 182 | from GitHub releases, and the bundler downloads any remote asset. |
| 183 | - The image is **Debian, not Alpine, on both sides**. Those Tailwind binaries are |
| 184 | glibc-linked, so a musl builder fails during `cargo build`. |
| 185 | |
| 186 | The builder mounts the cargo registry and `target/` as BuildKit caches. There is |
| 187 | deliberately **no dummy-`main.rs` dependency-caching trick**: `build.rs` scans the real |
| 188 | sources for Tailwind classes, and a faked source tree yields a stale stylesheet — a |
| 189 | wrong answer that still builds, which is the worst kind. |
| 190 | |
| 191 | ### Configuration in a container |
| 192 | |
| 193 | The image sets these defaults, so the `docker run` above needs no `-e` flags at all: |
| 194 | |
| 195 | ``` |
| 196 | STEID_DATABASE_URL=sqlite:/data/steid.db?mode=rwc |
| 197 | STEID_DATA_DIR=/data/repos |
| 198 | HOST=0.0.0.0 # Topcoat's, not STEID_-prefixed — see Configuration above |
| 199 | PORT=3000 |
| 200 | ``` |
| 201 | |
| 202 | No public URL is configured anywhere: the origin is derived from the `Host` header and |
| 203 | `X-Forwarded-Proto`, so a proxy that forwards both needs nothing further. |
| 204 | |
| 205 | **`STEID_INSECURE_COOKIES` is deliberately unset in the image and must stay unset.** |
| 206 | The session cookie is `Secure`, which means the deployment needs TLS — assume a |
| 207 | terminating proxy in front (Caddy, nginx, a platform router). Setting the variable to |
| 208 | paper over a missing certificate hands every session cookie to anyone on the network |
| 209 | path. `.dockerignore` excludes `.env` for the same reason: the dev `.env` sets it, and |
| 210 | copying it in would silently unharden a deployed image. |
| 211 | |
| 212 | ### State is one volume |
| 213 | |
| 214 | Everything that must survive a restart lives under `/data`: the SQLite database as a |
| 215 | file directly in it, the bare repositories under `/data/repos`. `VOLUME ["/data"]` is |
| 216 | declared, so a container started without `-v` still keeps its state — in an anonymous |
| 217 | volume that is easy to lose track of. Name it. |
| 218 | |
| 219 | `/data` itself must be writable, not just the database file: SQLite creates `-wal` and |
| 220 | `-shm` siblings next to it. |
| 221 | |
| 222 | The container runs as uid **10001** (`steid`). A named volume inherits that ownership |
| 223 | from the image on first use. A **bind mount does not** — `-v /srv/steid:/data` starts |
| 224 | root-owned and the app fails to write, so `chown 10001:10001 /srv/steid` on the host |
| 225 | first. |
| 226 | |
| 227 | ### Claiming a deployed instance |
| 228 | |
| 229 | The setup token is printed to **stdout only, and only while the instance is |
| 230 | unclaimed**. It is held in memory, so every restart — including every redeploy — |
| 231 | mints a new one, and a claimed instance mints none at all. |
| 232 | |
| 233 | There is no way to recover it other than the platform's logs: |
| 234 | |
| 235 | ```bash |
| 236 | docker logs steid | tail -20 |
| 237 | ``` |
| 238 | |
| 239 | Read the token from the **most recent** boot, then claim at `https://your-host/auth/setup`. |
| 240 | Until it is claimed every route redirects there, so an instance left unclaimed on a |
| 241 | public address is an open door — claim it immediately after the first deploy. |
| 242 | |
| 243 | ## Manual verification checklist (#2) |
| 244 | |
| 245 | Attempt #2 verified these by hand each milestone but never wrote down the steps. They |
| 246 | are the smoke test for Milestones 4–5. The auth rows assumed SSH keys; the shape of |
| 247 | the check still holds with tokens substituted: |
| 248 | |
| 249 | - [x] Create a repo via the web UI → bare repo appears at |
| 250 | `{data_dir}/{handle}/{name}.git` *(Milestone 3; also checked that the name |
| 251 | normalises, that a duplicate re-renders the form, and that a private repo 404s |
| 252 | for a signed-out visitor)* |
| 253 | - [ ] `git clone` an empty repo → succeeds |
| 254 | - [ ] `git clone` a repo with history → succeeds |
| 255 | - [ ] `git clone` a non-existent repo → clean error, not a hang or panic |
| 256 | - [ ] First push to an empty repo → succeeds |
| 257 | - [ ] Push to a repo with history → succeeds |
| 258 | - [ ] Push a repo large enough to exercise the `body_limit` cap → succeeds |
| 259 | - [ ] Clone with no credentials → rejected, and the prompt is comprehensible |
| 260 | - [ ] Clone with a valid token → succeeds |
| 261 | - [ ] Revoke the token → subsequent clone rejected at auth |
| 262 | - [ ] Clone a private repo as a non-member → rejected |
| 263 | - [ ] Push as a non-owner member → rejected |
| 264 | |
| 265 | Worth automating as an integration test rather than re-running by hand a fourth time. |
| 266 | |
| 267 | ## `.gitignore` |
| 268 | |
| 269 | Applied: `/target`, `/data`, `*.db*`, `.env`, `.env.prod`. |
| 270 | |
| 271 | **Do not add `/plans`.** Attempt #2 did, and that is why these docs had to be |
| 272 | hand-carried between repos. |
| 273 | |
| 274 | ## Deploying this instance |
| 275 | |
| 276 | The operator's path, as opposed to `README.md`, which is written for a stranger |
| 277 | installing their own. `jpgill.dev` serves two roles from one box: this instance, |
| 278 | and the place everyone else downloads Steid from. |
| 279 | |
| 280 | ### Order matters |
| 281 | |
| 282 | 1. **Provision — AWS Lightsail**, **Debian 13** blueprint (12 also works). Lightsail rather than EC2 |
| 283 | deliberately: it *is* AWS's VPS product, where EC2 makes you assemble the same box out |
| 284 | of a VPC, security groups, an EBS volume and an Elastic IP, with per-GB egress on top. |
| 285 | Either architecture works — releases are built for `x86_64` and `aarch64`, and |
| 286 | `install.sh` picks between them from `uname -m`, so a Graviton instance is fine. |
| 287 | |
| 288 | **Not Amazon Linux**, which Lightsail pre-selects: `install.sh` is Debian-family, and |
| 289 | it stops with a clear message on anything without `apt-get` rather than half-installing. |
| 290 | Ubuntu 22.04/24.04 work too. Debian 13 and 12 are both verified end to end in a |
| 291 | container — including that Caddy installs, since its apt repository URL is |
| 292 | codename-independent and that was the only plausible difference between them. |
| 293 | |
| 294 | Three Lightsail-specific things, each of which breaks the deployment silently if |
| 295 | missed: |
| 296 | |
| 297 | - **Attach a static IP.** A Lightsail instance takes a *new* public IP on stop/start. |
| 298 | Without one, a reboot changes the address, DNS points at nothing, and Caddy's |
| 299 | certificate renewals start failing with no obvious cause. Free while attached to a |
| 300 | running instance. |
| 301 | - **Open 80 and 443** in the instance's Networking tab. Only 22 is open by default, |
| 302 | and **Let's Encrypt validates over port 80** — a firewall that allows 443 alone |
| 303 | fails at certificate issuance, not at first request. |
| 304 | - **Snapshots are not backups.** They are whole-disk and live in the same AWS account. |
| 305 | The two state paths still want copying somewhere else. |
| 306 | 2. **DNS first, then install.** `dig +short jpgill.dev` must return the box's IP |
| 307 | *before* `install.sh` runs. Caddy requests a certificate on startup; if DNS has not |
| 308 | propagated it fails and backs off, and the resulting error points nowhere useful. |
| 309 | 3. **First install uses `--tarball`.** There is a bootstrap: this instance is what will |
| 310 | serve the releases, so at that moment there is nowhere to download from. |
| 311 | |
| 312 | ```sh |
| 313 | scp dist/steid-0.1.0-x86_64-unknown-linux-gnu.tar.gz install.sh root@<ip>:/root/ |
| 314 | ssh root@<ip> './install.sh --domain jpgill.dev \ |
| 315 | --tarball ./steid-0.1.0-x86_64-unknown-linux-gnu.tar.gz' |
| 316 | ``` |
| 317 | |
| 318 | Then `curl https://jpgill.dev/healthz` — over https, with a real certificate. |
| 319 | |
| 320 | ### Becoming the distribution host |
| 321 | |
| 322 | Only this instance does this. Uncomment the two `handle` blocks in |
| 323 | [deploy/Caddyfile](../deploy/Caddyfile) and rsync the artefacts into a **versioned** |
| 324 | directory, matching the URL `install.sh` builds |
| 325 | (`${RELEASE_BASE_URL}/v${VERSION}/…`): |
| 326 | |
| 327 | ```sh |
| 328 | rsync dist/*.tar.gz dist/*.sha256 root@<ip>:/var/lib/steid/dist/v0.1.0/ |
| 329 | rsync install.sh root@<ip>:/var/lib/steid/dist/ |
| 330 | ``` |
| 331 | |
| 332 | **Those Caddy paths shadow Steid.** Nothing lives at |
| 333 | `/{handle}/repos/{name}/releases` today, so nothing breaks — but when Steid grows a real |
| 334 | release feature at that URL, Caddy will keep winning and the feature will look broken. |
| 335 | Delete the blocks then. The URL is deliberately the one that feature will use, so links |
| 336 | published now survive it. |
| 337 | |
| 338 | `/install.sh` at the root is safe permanently rather than by luck: `OrgName` allows only |
| 339 | `[a-z0-9-]`, so no handle can contain a dot and none can ever collide with it. A |
| 340 | root-level `/releases` would **not** be safe — it is a valid handle shape. |
| 341 | |
| 342 | ### What is verified, and what is not |
| 343 | |
| 344 | Verified in a Debian 12 container with `systemctl` stubbed: prerequisites install, the |
| 345 | tarball extracts, `/opt/steid` and `/var/lib/steid` get the right owners and modes, the |
| 346 | `steid` user is created with `nologin`, the env file and unit and Caddyfile are written, |
| 347 | and **the binary starts as the `steid` user**. The artifact itself was booted on Debian |
| 348 | 11 (glibc 2.31) and served pages. |
| 349 | |
| 350 | **Not verified anywhere but a real box:** the systemd unit lifecycle, and Caddy's ACME |
| 351 | certificate issuance. Expect the first real run to need a fix or two. |
| 352 | |
| 353 | ### One bug already found this way |
| 354 | |
| 355 | `install.sh` defaulted to a `musl` target while `release.sh` had moved to `gnu`. The |
| 356 | symptom was `checksum mismatch` — because the installer was looking for a tarball that |
| 357 | was never built. The two defaults must agree; both now say so in a comment. |