From defd722cc2e7fa4b0e16064cfe84aa1ebcdfcf00 Mon Sep 17 00:00:00 2001 From: mnovak Date: Tue, 17 Nov 2026 20:59:42 +0100 Subject: [PATCH] [docs] Previews (the API for Fabrica, names, the token from the team vault), Ianitor anywhere (Linux, Docker, Windows Server in Caddy mode, NixOS), team sign-in in api.md, the Custos ticket's T4 part; release 0.2.0: the pipeline builds and tests the Linux tarball, the Windows zip and the image; the NixOS previews option; Docker and Linux smoke scripts --- .fabrica/artifex/release.yaml | 38 ++++++++++-- .fabrica/notes/0.2.0.md | 17 ++++++ Cargo.lock | 10 ++-- Cargo.toml | 2 +- apps/web/package.json | 2 +- deploy/docker/Dockerfile | 2 +- deploy/nixos/module.nix | 40 +++++++++++++ docs/api.md | 18 ++++++ docs/custos-ticket.md | 18 ++++++ docs/deploy/anywhere.md | 80 +++++++++++++++++++++++++ docs/previews.md | 107 ++++++++++++++++++++++++++++++++++ packages/ui/package.json | 2 +- scripts/package-windows.mjs | 39 +++++++++++++ scripts/smoke-docker.sh | 89 ++++++++++++++++++++++++++++ scripts/smoke-linux.sh | 100 +++++++++++++++++++++++++++++++ 15 files changed, 549 insertions(+), 15 deletions(-) create mode 100644 .fabrica/notes/0.2.0.md create mode 100644 docs/deploy/anywhere.md create mode 100644 docs/previews.md create mode 100644 scripts/package-windows.mjs create mode 100644 scripts/smoke-docker.sh create mode 100644 scripts/smoke-linux.sh diff --git a/.fabrica/artifex/release.yaml b/.fabrica/artifex/release.yaml index e05263b..8489dd9 100644 --- a/.fabrica/artifex/release.yaml +++ b/.fabrica/artifex/release.yaml @@ -1,7 +1,9 @@ -# Ianitor Domi: the Gitea release of a v* tag (docs/release.md). Ianitor ships no binary (the server builds it with -# Nix and the deploy pipeline switches it in), so a release is its notes and screenshots of the web UI, published under -# a SHA256SUMS signed by domi-release through Custos; release-notes.md is also the release's text on Gitea. -# The Windows runner (the Fabrica app on Mark's PC) runs it: `fabrica`, node and pnpm are on every step's PATH. +# Ianitor Domi: the Gitea release of a v* tag (docs/release.md). Since 0.2.0 (T4) a release carries the programs: +# the Linux tarball and its one-line installer (systemd), the Windows Server zip (Caddy mode), next to the notes and +# screenshots of the web UI, all under a SHA256SUMS signed by domi-release through Custos. The Docker image is built +# from the same Dockerfile; it is not pushed to a registry yet (docs/deploy/anywhere.md). +# The Windows runner (the Fabrica app on Mark's PC) runs it: `fabrica`, node, pnpm, cargo and Docker Desktop are on +# every step's PATH; the Linux parts build inside Docker (deploy/docker/Dockerfile), never on the host. # No Gitea webhook to the hub yet: a pushed tag is started on demand (the hub's POST /api/runs, ref v). # `notes` is Fabrica's release notes since the previous v* tag (Fabrica docs/12_release_kit.md); `shots` takes the # same files as `fabrica aula shots` (core docs/FORMATS.md, "Fabrica: the Aula page") from the built web UI against @@ -22,6 +24,27 @@ steps: - id: test needs: [install] run: pnpm --filter web test + # The whole Rust workspace on Linux (the differential suite against Caddy, Pebble ACME, the edge suites), in the CI + # image; two jobs, so Docker Desktop's memory holds. + - id: linux-tests + needs: [version] + run: docker build --load -f deploy/docker/Dockerfile --target ci -t ianitor-ci:${{ version }} . && docker run --rm --memory 6g ianitor-ci:${{ version }} cargo test --workspace --locked -j 2 + # Windows: the Caddy-mode tests and the differential suite with Windows paths (Pingora against Windows Caddy; + # IANITOR_CADDY_BIN names caddy.exe on the runner). + - id: windows-tests + needs: [version] + run: cargo test --workspace --locked + - id: windows + needs: [check, test, windows-tests] + run: cargo build --release --locked -p ianitor-control --no-default-features && pnpm --filter web build && node scripts/package-windows.mjs + artifacts: ["target/dist/ianitor-*-windows-x86_64.zip"] + - id: linux + needs: [linux-tests] + run: docker build -f deploy/docker/Dockerfile --target dist --output type=local,dest=target/dist . + artifacts: ["target/dist/ianitor-*-linux-x86_64.tar.gz", "target/dist/install.sh"] + - id: image + needs: [linux-tests] + run: docker build --load -f deploy/docker/Dockerfile -t ianitor:${{ version }} . - id: notes run: fabrica notes artifacts: ["target/notes/release-notes.md", "target/notes/release-notes.json"] @@ -30,13 +53,16 @@ steps: run: node apps/web/scripts/shots.mjs artifacts: ["target/aula/aula-*.png", "target/aula/aula.json"] - id: approve - needs: [version, notes, shots] - approve: "Publish Ianitor ${{ tag }}: its notes and screenshots?" + needs: [version, notes, shots, windows, linux, image] + approve: "Publish Ianitor ${{ tag }}: the Linux tarball, the Windows Server zip, notes and screenshots?" - id: publish needs: [approve] publish: gitea-release: true files: + - "**/ianitor-*-linux-x86_64.tar.gz" + - "**/install.sh" + - "**/ianitor-*-windows-x86_64.zip" - "**/release-notes.md" - "**/release-notes.json" - "**/aula-*.png" diff --git a/.fabrica/notes/0.2.0.md b/.fabrica/notes/0.2.0.md new file mode 100644 index 0000000..38c84c6 --- /dev/null +++ b/.fabrica/notes/0.2.0.md @@ -0,0 +1,17 @@ +Ianitor Domi now runs for any small team, not only on a NixOS server, and gives Fabrica a preview address for +every branch. + +- **Install anywhere.** A one-line installer for Linux with systemd, a Docker image with a compose file, and + Windows Server, where Ianitor runs with Caddy as its engine (same screens, same route files; Pingora's Windows + support is still preliminary). The NixOS module stays. +- **Branch previews.** Fabrica asks for `--.` and gets it, with a certificate + from the Domi CA or Let's Encrypt; it closes when the branch is merged or its time runs out. Any branch name works: + unusual characters, dots and long names all become a safe address, and two branches never share one. +- **A token that can only do previews.** Fabrica's token opens and closes previews and nothing else, and previews + may only point where you allow, never at Ianitor's own admin ports. +- **Your team, without Authelia.** The installer prints a sign-in link for the first admin; admins invite the rest + with a link. Members change hosts and previews; admins also manage people, tokens, the engine and certificates. + Authelia still works where you have it. +- **Previews screen.** See every open preview in one click, close one in two. +- **Routes on any git host.** Push the routes repository to Gitea, GitHub or GitLab. +- **Tested on Windows too.** The comparison of Pingora and Caddy now also runs on Windows, with Windows paths. diff --git a/Cargo.lock b/Cargo.lock index 4bc91fe..ce19c31 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1304,7 +1304,7 @@ dependencies = [ [[package]] name = "ianitor-control" -version = "0.1.0" +version = "0.2.0" dependencies = [ "axum", "base64 0.22.1", @@ -1333,7 +1333,7 @@ dependencies = [ [[package]] name = "ianitor-core" -version = "0.1.0" +version = "0.2.0" dependencies = [ "base64 0.22.1", "domi-pki", @@ -1350,7 +1350,7 @@ dependencies = [ [[package]] name = "ianitor-diff" -version = "0.1.0" +version = "0.2.0" dependencies = [ "ianitor-control", "ianitor-core", @@ -1365,7 +1365,7 @@ dependencies = [ [[package]] name = "ianitor-edge" -version = "0.1.0" +version = "0.2.0" dependencies = [ "arc-swap", "async-trait", @@ -1393,7 +1393,7 @@ dependencies = [ [[package]] name = "ianitor-testkit" -version = "0.1.0" +version = "0.2.0" dependencies = [ "bytes", "futures-util", diff --git a/Cargo.toml b/Cargo.toml index 87ef073..def1a2b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,7 +3,7 @@ resolver = "3" members = ["crates/core", "crates/edge", "crates/control", "tests/diff", "tests/support"] [workspace.package] -version = "0.1.0" +version = "0.2.0" edition = "2024" rust-version = "1.89" license = "MPL-2.0" diff --git a/apps/web/package.json b/apps/web/package.json index c5adebc..ae1073c 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -1,6 +1,6 @@ { "name": "web", - "version": "0.1.0", + "version": "0.2.0", "private": true, "license": "MPL-2.0", "description": "Ianitor Domi web UI (Svelte 5, runes, TypeScript strict). A pure client of the control API.", diff --git a/deploy/docker/Dockerfile b/deploy/docker/Dockerfile index 945bc49..5b3240a 100644 --- a/deploy/docker/Dockerfile +++ b/deploy/docker/Dockerfile @@ -59,7 +59,7 @@ RUN cargo build --release --locked -p ianitor-edge \ && strip target/release/ianitor-edge target/release/ianitor-control FROM node:22-bookworm-slim AS web -RUN corepack enable +RUN corepack enable && corepack prepare pnpm@10.28.0 --activate WORKDIR /src COPY package.json pnpm-lock.yaml pnpm-workspace.yaml ./ COPY apps/web/package.json apps/web/package.json diff --git a/deploy/nixos/module.nix b/deploy/nixos/module.nix index 34699d1..19a2f1f 100644 --- a/deploy/nixos/module.nix +++ b/deploy/nixos/module.nix @@ -90,6 +90,16 @@ let password_credential = "pki-password"; }; } + // lib.optionalAttrs (cfg.previews.domain != null) { + # Branch previews for Fabrica (T4, docs/previews.md). + previews = { + domain = cfg.previews.domain; + tls = cfg.previews.tls; + auth = cfg.previews.auth; + upstreams = cfg.previews.upstreams; + default_ttl_secs = cfg.previews.defaultTtlSeconds; + }; + } ); hardening = { @@ -222,6 +232,36 @@ in }; }; + previews = { + domain = mkOption { + type = types.nullOr types.str; + default = null; + example = "preview.example.org"; + description = "Branch previews for Fabrica live under this domain (`--.`); a wildcard DNS record must point here. Null: previews are off."; + }; + tls = mkOption { + type = types.enum [ "domi" "letsencrypt" ]; + default = "domi"; + description = "Certificates for previews: the Domi CA (internal) or Let's Encrypt (public, one certificate per preview)."; + }; + auth = mkOption { + type = types.enum [ "none" "forward-auth" ]; + default = "forward-auth"; + description = "Whether previews are behind Authelia (forward-auth) or open to anyone with the address."; + }; + upstreams = mkOption { + type = types.listOf types.str; + default = [ ]; + example = [ "10.0.0.0/8" "127.0.0.1:20000-29999" ]; + description = "What previews may send traffic to (networks, address:port ranges, names). Control's own port and Caddy's admin are never allowed."; + }; + defaultTtlSeconds = mkOption { + type = types.ints.positive; + default = 72 * 3600; + description = "How long a preview lives when Fabrica does not say."; + }; + }; + ui = { hostname = mkOption { type = types.nullOr types.str; diff --git a/docs/api.md b/docs/api.md index 8674ae6..192e79c 100644 --- a/docs/api.md +++ b/docs/api.md @@ -272,6 +272,24 @@ secret = "ui-proof" # listed in ianitor.toml: secrets = ["ui-proof"] Why not the Unix socket now: edge's upstreams are `host:port` in the schema; a socket upstream is a schema and compiler change in both engines, and the proof header needs neither. +## Team sign-in without Authelia (T4) + +On a server without Authelia, people sign in with links (crates/control/src/team.rs): + +- `ianitor-control team setup-link --config ` prints the first admin's link, `https:///#signin=isc_…` + (one use, 7 days, only while the team has nobody). The UI posts the code to `POST /api/v1/session` (no token; the + `X-Ianitor-UI: 1` header and a same-origin page are required) and gets the `__Host-ianitor` cookie (HttpOnly, + Secure, SameSite=Strict, 30 days). +- Admins invite: `POST /api/v1/team/invites {name, role}` → `{link_fragment}` (Settings → Team → Invite). +- `GET /api/v1/team`, `DELETE /api/v1/team/members/{id}` (the last admin stays), `PUT /api/v1/team/me/root` + (your Tessera root), `POST /api/v1/session/end`. +- A `member` gets `403 team.admin_only` on tokens, the team, the engine switch and the CA's renewal and requests. + Browser writes need `X-Ianitor-UI: 1` (`403 request.csrf`). + +## Branch previews (T4) + +`/api/v1/previews`, and tokens with `"scope": "previews"` that may call nothing else: docs/previews.md. + ## Certificates (the Domi CA) Everything is in [pki.md](pki.md); the calls: diff --git a/docs/custos-ticket.md b/docs/custos-ticket.md index 0afeb54..6f7f675 100644 --- a/docs/custos-ticket.md +++ b/docs/custos-ticket.md @@ -92,3 +92,21 @@ against the `domi-approve` public key before issuing. No new crypto in Custos. with `pathlen:0`, after a match-code approval on the phone. - A CSR with another CN, a bad signature or a request for a CA without pathLen 0 is refused. - An `x509_csr` request against any other key is `out_of_scope`. + +## T4 (2026-11-17): what Ianitor on any server needs from Custos + +Not filed; written for the Custos session that picks it up. Each item has a working stand-in in Ianitor today. + +1. **A target kind for an HTTP API token** (`http-token`: `host`, `secret`), so the team vault can hold Ianitor's + previews-only token and hand it to Fabrica per preview deployment through `target.request` (CustosPublic + `docs/TEAM.md`, "Target credentials"). Stand-in: the `registry` kind (a token with a host), docs/previews.md. +2. **A generic team approval** (`approve.request`: a canonical statement, the request's match code on every + member's card, an answer that carries the existing `custos team approval v1` statements and a proof + `verify_proof` can check), so Ianitor can ask a teammate to approve an admin change (a new API token, a member, + the engine switch, a renewal) without asking the team's release key to sign anything. Signing a dummy artifact + with `sign.request` is not a stand-in: Ianitor would choose the digest the release key signs. Stand-in: admin + changes need the admin role (crates/control/src/team.rs). +3. **A browser Domi key** (Fundamentum's web client): a WebCrypto key certified by the member's Tessera root, so a + sign-in is a signed challenge, not a link. Stand-in: one-time setup and invite links that make a session cookie; + members may record their Tessera root, and the team list shows its match code (`tessera match v1`, the same + digits Custos shows). diff --git a/docs/deploy/anywhere.md b/docs/deploy/anywhere.md new file mode 100644 index 0000000..f307d10 --- /dev/null +++ b/docs/deploy/anywhere.md @@ -0,0 +1,80 @@ +# Ianitor anywhere (T4) + +Four ways to run Ianitor, one config model. Fabrica's coherence roadmap (`docs/32_coherence.md`, §2.5 and T4). + +| | Engine | Package | Install | Secrets | +| :-- | :-- | :-- | :-- | :-- | +| Linux with systemd | Pingora (edge) | `ianitor-X.Y.Z-linux-x86_64.tar.gz` + `install.sh` | one line, below | `/var/lib/ianitor/credentials` (0700, random, made by setup) | +| Docker | Pingora (edge) | the image from `deploy/docker/Dockerfile`, `deploy/docker/compose.yaml` | `docker compose up -d` | the `state` volume's `credentials/` | +| Windows Server | **Caddy** (Caddy mode) | `ianitor-X.Y.Z-windows-x86_64.zip` | `install.ps1` | `%ProgramData%\Ianitor\credentials` (ACL: Administrators, SYSTEM, LocalService) | +| NixOS | Pingora, Caddy fallback | the flake (`nixosModules.ianitor`) | `nixos-rebuild` | systemd credentials (`LoadCredential`) | + +Everywhere: control listens on 127.0.0.1:7878 only; only the engine binds 80 and 443; the web UI is the admin host +(`IANITOR_ADMIN_HOST`) through the engine. Without Authelia, people sign in with team links (Settings → Team, +docs/api.md); the installer prints the first admin's link (`ianitor-control team setup-link`). + +## Linux (systemd) + +```bash +curl -fsSL https://gitea.marek-novak.cz/mnovak/Ianitor/releases/download/v0.2.0/install.sh | sudo IANITOR_ADMIN_HOST=ianitor.example.org IANITOR_PREVIEW_DOMAIN=preview.example.org IANITOR_PREVIEW_UPSTREAMS=10.0.0.0/8 sh +``` + +It checks the tarball against the release's `SHA256SUMS`, installs `/usr/local/bin/ianitor-{control,edge}`, the web +UI, `ianitor-control.service` and `ianitor-edge.service` (users `ianitor` and `ianitor-edge`, the NixOS module's +hardening), writes `/etc/ianitor/control.toml` once (`deploy/linux/setup.sh`: every `IANITOR_*` variable is +listed there), starts both and prints the sign-in link. Running it again upgrades and keeps config and state. No +Caddy fallback here (the engine switch is NixOS-only); header-rule secrets need a `LoadCredential=` line each. + +## Docker + +```bash +cd deploy/docker && printf 'IANITOR_ADMIN_HOST=ianitor.example.org\nIANITOR_PREVIEW_DOMAIN=preview.example.org\nIANITOR_PREVIEW_UPSTREAMS=app\n' > .env && docker compose up -d && docker compose exec control ianitor-entrypoint setup-link +``` + +Two services from one image: `edge` (ports 80/443) and `control` in edge's network namespace, so the API stays on +loopback. Read-only root, no capabilities, `no-new-privileges`, user 10001. Previews of other containers: attach them +to the compose network and list their names in `IANITOR_PREVIEW_UPSTREAMS`. + +## Windows Server (Caddy mode) + +Pingora's Windows support is preliminary upstream, so Windows runs control with Caddy as the data plane: same UI, +same TOML, compiled to Caddy JSON; the differential suite runs on Windows with Windows paths to keep that honest. +From the unpacked zip, in an elevated PowerShell (Git for Windows installed): + +```bash +powershell -ExecutionPolicy Bypass -File install.ps1 -AdminHost ianitor.example.org -PreviewDomain preview.example.org -PreviewUpstreams "10.0.0.0/8,127.0.0.1:20000-29999" +``` + +Three services as LocalService, restarted on failure: `IanitorCaddy` (`caddy run` on the last good `caddy.json`), +`IanitorControl` (`ianitor-control service control`) and `IanitorGuard` (the Caddy trial deadline, its own process +so a hung control cannot leave Caddy on an unconfirmed change). Caddy 2.11.7 is fetched by the installer and its +SHA-512 checked against the pinned value. Caddy's admin API listens on 127.0.0.1:2019 (Windows has no Unix socket +for it); any local process could reach it, so the machine should run nothing untrusted. Logs: +`%ProgramData%\Ianitor\logs`. Domi certificates have no revocation list, so Windows' own TLS (Schannel, curl.exe) +needs `--ssl-no-revoke`; browsers accept them once the Domi root is trusted. + +## NixOS + +Unchanged (`nixosModules.ianitor`, docs/deploy/beside-caddy.md), plus `services.ianitor.previews.{domain, tls, auth, +upstreams, defaultTtlSeconds}`. + +## The Domi CA anywhere + +With `tls = domi` the root stays offline (`ianitor-control ca init` on another machine). Start the intermediate in +the UI (Certificates → banner Renew) or `POST /api/v1/certs/intermediate/renewal`, sign the CSR offline +(`ianitor-control ca sign`), install it (`ianitor-control pki install --config `), then restart control so +it adds the admin host with a certificate it can now issue. `scripts/smoke-windows.ps1` does all of it with a +throw-away root. + +## Routes on any git host + +`IANITOR_ROUTES_REMOTE` (an `https://` URL on Gitea, GitHub or GitLab) and `IANITOR_ROUTES_HOST` +(`gitea`, `github` → user `x-access-token`, `gitlab` → `oauth2`); the token goes in the credentials folder as +`routes-token`. Kept changes are pushed there, as on NixOS. + +## Smoke tests (what was run for T4, 2026-11-17) + +- Windows: `scripts/smoke-windows.ps1` (installer with `-NoService`, Caddy and control in the console, PKI, the + preview client, the preview through Caddy, close). The services themselves (SCM start, LocalService ACLs, ports 80 + and 443) were not exercised on this PC. +- Docker and Linux: see the T4 handover in docs/ROADMAP.md. diff --git a/docs/previews.md b/docs/previews.md new file mode 100644 index 0000000..e054399 --- /dev/null +++ b/docs/previews.md @@ -0,0 +1,107 @@ +# Branch previews (T4) + +Every branch Fabrica builds can get its own address: `--.`, with a certificate +from the Domi CA (internal) or Let's Encrypt (public). It closes when the branch is merged, or when its lifetime +runs out. Fabrica's coherence roadmap, `docs/32_coherence.md` in Fabrica, phase T4. + +## Set up (once per server) + +1. A wildcard DNS record for the preview domain points at the server: `*.preview.example.org`. +2. `[previews]` in control.toml (the installers write it from `IANITOR_PREVIEW_DOMAIN` and + `IANITOR_PREVIEW_UPSTREAMS`; NixOS: `services.ianitor.previews`): + +```toml +[previews] +domain = "preview.example.org" +tls = "domi" # or "letsencrypt" (one certificate per preview; mind the rate limits) +auth = "none" # or "forward-auth" (behind the site's Authelia) +upstreams = ["10.0.0.0/8", "127.0.0.1:20000-29999", "app.internal", "*.svc.internal:8080"] +default_ttl_secs = 259200 # 72 h; min_ttl_secs 300, max_ttl_secs 30 days, max_previews 100, sweep_secs 30 +``` + +`upstreams` is the allow list of where previews may send traffic: a network (`10.0.0.0/8`, `fd00::/8`), an +address with a port or port range (`127.0.0.1:20000-29999`), a name (`app.internal`) or every name under a suffix +(`*.svc.internal`), each with an optional port. Nothing else is accepted. Whatever the list says, a preview can never +point at control's own port, Caddy's admin port (2019 and the configured one), an unspecified, link-local or +multicast address, or an IPv4-mapped IPv6 address. A name is checked as written, not as it resolves: list only names +you control. + +3. A token for Fabrica that may only manage previews: + `ianitor-control token create --name "Fabrica previews" --scope previews --config `, or + Settings → API → *Previews only* → New token. It goes into the Custos team vault (see *The token* below). + +## The API + +All calls carry `Authorization: Bearer `; the token may be a full one or a previews-only one. A previews-only +token gets `403 token.scope` on every other route, reads included. + +| Call | Body | Answer | +| :-- | :-- | :-- | +| `POST /api/v1/previews` | `{project, branch, upstream, ttl?}` | `202 {preview, apply}`: opens the branch's preview, or moves it (new upstream, new lifetime) | +| `GET /api/v1/previews/{hostname}` | | `200 {preview}` with `state`: `applying`, `live` or `failed` (with `problem`) | +| `GET /api/v1/previews` | | `200 {items, domain}` | +| `POST /api/v1/previews/close` | `{project, branch}` | `202 {apply}`: on merge or branch deletion; `404` when there is none | +| `DELETE /api/v1/previews/{hostname}` | | `202 {apply}`; `404 preview.not_found` for any host that is not a preview | + +- `project` is Fabrica's project name (`mnovak/Arca`, `github:acme/web`): 1–128 of `A-Za-z0-9._/:-`. +- `branch` is the branch as the git host names it, any characters except control characters, up to 255 bytes. +- `upstream` is `http(s)://host:port` with no path, user or query, and must be in the allow list. +- `ttl` is seconds (default `default_ttl_secs`). +- A preview is an ordinary host file in the routes repository (`hosts/.toml` with a `[preview]` table), + so it goes through the same validation, compilers, differential tests and commit-confirmed apply (trial, watch, + revert) as any host, and shows in History. Its answers carry `X-Robots-Tag: noindex, nofollow`. +- The apply is live when `GET /api/v1/previews/{hostname}` says `live`; poll every 2 s. A failed apply (the branch + build did not answer during the watch) says `failed` with Ianitor's reason, and the preview is not served. +- Errors: `preview.off` (no `[previews]`), `preview.taken` (another host or branch has that name), + `preview.branch`, `preview.project`, `preview.ttl`, `preview.upstream`, `preview.upstream_not_allowed`, + `preview.too_many`, `token.scope`. + +## Names + +The label is `--` (core `preview::label`, tests in `crates/core/tests/preview.rs`): + +- each part is lowercased, every run of other characters than `a-z0-9` becomes one `-`, dashes trimmed; the project + part is the repository name only (after the last `/` or `:`); +- if that lost anything (case, a character, the owner, length), the part gets `-` and 6 hex digits of SHA-256 of + the whole original, so `feature/login` and `feature-login`, or `alice/app` and `bob/app`, never share a host; +- the branch part is 3–40 characters, the project part 1–20, so the label is at most 62 and never has `--` in + positions 3–4 (reserved for IDNA; Let's Encrypt refuses those). + +| Project | Branch | Host | +| :-- | :-- | :-- | +| `shop` | `fix-42` | `fix-42--shop.preview.example.org` | +| `mnovak/Arca` | `main` | `main--arca-4a93cc.preview.example.org` | +| `github:acme/Web.App` | `feature/Ünï ../../etc` | `feature-n-etc-50d099--web-app-4ff2e1.preview.example.org` | + +Two branches can still collide only by a 24-bit hash collision; control then answers `409 preview.taken` instead of +taking the other branch's host. + +## The token, from the Custos team vault + +The previews-only token is a secret: it lives in the team vault, and Fabrica gets it per deployment, the way it +gets any target credential (Custos `docs/27_team_vault.md`, Fabrica `docs/handover/t1-sign-request.md`): the preview +build is signed under the team's `preview` environment (0 approvals: the test key signs at once), the sign reply's +ticket authorises one `target.request` for the Ianitor target of that project and environment, and the token comes +back sealed to Fabrica's one-time key. Fabrica uses it for that deployment and drops it. + +Custos's target kinds today are `ssh-key`, `winrm`, `openssh`, `registry` and `kubeconfig`; an API token for an HTTP +service has no kind of its own yet. Until Custos adds one (`http-token`, written up in docs/custos-ticket.md), keep +it as `registry` (a token with a host), which carries the same fields. + +## A client + +`scripts/preview.sh` (curl and jq) and `scripts/preview.ps1` are what a Fabrica pipeline step runs until Fabrica has +a preview step of its own: + +```bash +IANITOR_URL=https://ianitor.example.org IANITOR_PREVIEW_TOKEN=… scripts/preview.sh open mnovak/Arca "$BRANCH" http://10.0.0.7:8080 86400 +``` + +```bash +scripts/preview.sh close mnovak/Arca "$BRANCH" +``` + +## Screens + +Previews (the nav): every open preview with its state, branch, project, upstream and when it closes (1 click); +Close → Close preview (2 clicks). diff --git a/packages/ui/package.json b/packages/ui/package.json index 71f8664..1fbc695 100644 --- a/packages/ui/package.json +++ b/packages/ui/package.json @@ -1,6 +1,6 @@ { "name": "@ianitor/ui", - "version": "0.1.0", + "version": "0.2.0", "private": true, "license": "MPL-2.0", "description": "The shared dark Domi theme (murex palette) and its Svelte components.", diff --git a/scripts/package-windows.mjs b/scripts/package-windows.mjs new file mode 100644 index 0000000..a77d707 --- /dev/null +++ b/scripts/package-windows.mjs @@ -0,0 +1,39 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0. If a copy of the MPL was not distributed with this +// file, You can obtain one at https://mozilla.org/MPL/2.0/. + +// The Windows Server release zip (Caddy mode, T4): ianitor-control.exe (release build without +// the test hooks), the built web UI and deploy/windows/install.ps1, in +// target/dist/ianitor--windows-x86_64.zip. Caddy is not in it: install.ps1 fetches the +// pinned version and checks its SHA-512. +// +// cargo build --release -p ianitor-control --no-default-features +// pnpm --filter web build +// node scripts/package-windows.mjs + +import { cpSync, existsSync, mkdirSync, readFileSync, rmSync } from "node:fs"; +import { join } from "node:path"; +import { execFileSync } from "node:child_process"; + +const root = new URL("..", import.meta.url).pathname.replace(/^\/([A-Za-z]:)/, "$1"); +const version = /^version = "([^"]+)"/m.exec(readFileSync(join(root, "Cargo.toml"), "utf8"))?.[1]; +if (!version) throw new Error("no version in Cargo.toml"); +const target = process.env.CARGO_TARGET_DIR || join(root, "target"); +const exe = join(target, "release", "ianitor-control.exe"); +const web = join(root, "apps", "web", "dist"); +for (const p of [exe, web]) if (!existsSync(p)) throw new Error(`missing ${p}: build it first`); + +const name = `ianitor-${version}-windows-x86_64`; +const out = join(root, "target", "dist"); +const stage = join(out, name); +rmSync(stage, { recursive: true, force: true }); +mkdirSync(stage, { recursive: true }); +cpSync(exe, join(stage, "ianitor-control.exe")); +cpSync(web, join(stage, "web"), { recursive: true }); +cpSync(join(root, "deploy", "windows", "install.ps1"), join(stage, "install.ps1")); +cpSync(join(root, "LICENSE"), join(stage, "LICENSE")); +const zip = join(out, `${name}.zip`); +rmSync(zip, { force: true }); +execFileSync("powershell", ["-NoProfile", "-Command", `Compress-Archive -Path '${stage}\\*' -DestinationPath '${zip}'`], { stdio: "inherit" }); +rmSync(stage, { recursive: true, force: true }); +console.log(zip); diff --git a/scripts/smoke-docker.sh b/scripts/smoke-docker.sh new file mode 100644 index 0000000..66fcf2e --- /dev/null +++ b/scripts/smoke-docker.sh @@ -0,0 +1,89 @@ +#!/usr/bin/env bash +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# Docker end to end (T4): deploy/docker/compose.yaml with the image, a throw-away Domi root, +# a branch build in another container, Fabrica's client (scripts/preview.sh) with a +# previews-only token, the preview through edge (Pingora) from the host, close. Ports 28080 and +# 28443 on 127.0.0.1; everything is removed at the end (containers, volumes, the network). +# +# scripts/smoke-docker.sh +set -euo pipefail + +IMAGE=$1 CTL=$2 WORK=$3 +REPO=$(cd "$(dirname "$0")/.." && pwd) +P=ianitor-smoke +export COMPOSE_PROJECT_NAME=$P IANITOR_IMAGE=$IMAGE IANITOR_HTTP_PORT=28080 IANITOR_HTTPS_PORT=28443 +export IANITOR_ADMIN_HOST=ianitor.smoke.test IANITOR_TLS=domi IANITOR_DOMI_ROOT=/var/lib/ianitor/domi-root.crt +export IANITOR_PREVIEW_DOMAIN=pv.smoke.test IANITOR_PREVIEW_UPSTREAMS=app:8080 +DC=(docker compose -f "$REPO/deploy/docker/compose.yaml") +step() { echo "== $*"; } +ok() { echo " ok: $*"; } +fail() { echo "FAILED: $*" >&2; exit 1; } +cleanup() { + "${DC[@]}" down -v --remove-orphans >/dev/null 2>&1 || true + docker rm -f $P-app >/dev/null 2>&1 || true +} +trap cleanup EXIT +[ ! -e "$WORK" ] || fail "$WORK exists; give a new folder" +mkdir -p "$WORK" +# In edge's network namespace: the loopback API (curl and jq from a throw-away Alpine). +inside() { docker run --rm -i --network container:$P-edge-1 alpine:3.20 sh -c "apk add -q curl jq >/dev/null && $1"; } + +step "a throw-away Domi root (offline step)" +printf 'smoke-test-offline-passphrase' > "$WORK/pass" +"$CTL" ca init --out "$WORK/root" --passphrase-file "$WORK/pass" >/dev/null 2>&1 || fail "ca init" +docker volume create ${P}_state >/dev/null +docker run --rm -i -v ${P}_state:/v alpine:3.20 sh -c 'cat > /v/domi-root.crt && chown 10001:10001 /v /v/domi-root.crt' < "$WORK/root/domi-root.crt" +ok "root in the state volume" + +step "docker compose up" +"${DC[@]}" up -d >/dev/null 2>&1 || fail "compose up" +for i in $(seq 60); do inside "curl -s -o /dev/null http://127.0.0.1:7878/" 2>/dev/null && break; sleep 2; done +ADMIN=$("${DC[@]}" exec -T control ianitor-control token create --name smoke --config /var/lib/ianitor/control.toml 2>/dev/null | tail -n1) +FABRICA=$("${DC[@]}" exec -T control ianitor-control token create --name fabrica --scope previews --config /var/lib/ianitor/control.toml 2>/dev/null | tail -n1) +[ -n "$ADMIN" ] && [ -n "$FABRICA" ] || fail "tokens" +ok "control up, tokens made" + +step "the intermediate, signed offline" +rid=$(inside "curl -s -X POST -H 'Authorization: Bearer $ADMIN' http://127.0.0.1:7878/api/v1/certs/intermediate/renewal | jq -r .request_id") +inside "curl -s -H 'Authorization: Bearer $ADMIN' http://127.0.0.1:7878/api/v1/pki-requests/$rid/csr" > "$WORK/int.csr" +"$CTL" ca sign --root "$WORK/root" --csr "$WORK/int.csr" --out "$WORK/int.crt" --yes --passphrase-file "$WORK/pass" >/dev/null 2>&1 || fail "ca sign" +"${DC[@]}" exec -T control sh -c 'cat > /tmp/int.crt && ianitor-control pki install /tmp/int.crt --config /var/lib/ianitor/control.toml' < "$WORK/int.crt" >/dev/null 2>&1 || fail "pki install" +"${DC[@]}" restart control >/dev/null 2>&1 +for i in $(seq 60); do + inside "curl -s -H 'Authorization: Bearer $ADMIN' http://127.0.0.1:7878/api/v1/hosts" 2>/dev/null | grep -q ianitor.smoke.test && break + sleep 2 +done +ok "intermediate installed; admin host added" + +step "a branch build in its own container" +docker run -d --name $P-app --network ${P}_default --network-alias app python:3.12-alpine \ + sh -c 'mkdir /s && echo "hello from fix-42" > /s/index.html && python -m http.server 8080 --directory /s' >/dev/null +sleep 3 + +step "Fabrica opens the preview (scripts/preview.sh, previews-only token)" +url=$(inside "IANITOR_URL=http://127.0.0.1:7878 IANITOR_PREVIEW_TOKEN=$FABRICA sh -s -- open shop fix-42 http://app:8080 3600" < "$REPO/scripts/preview.sh") +[ "$url" = "https://fix-42--shop.pv.smoke.test/" ] || fail "preview URL: $url" +ok "preview URL $url" +body=$(curl -sS --cacert "$WORK/root/domi-root.crt" --resolve fix-42--shop.pv.smoke.test:28443:127.0.0.1 https://fix-42--shop.pv.smoke.test:28443/ || true) +[ "$body" = "hello from fix-42" ] || fail "the preview through edge: $body" +ok "the preview answers through edge (Pingora) from the host, with a Domi certificate" +code=$(curl -s -o /dev/null -w '%{http_code}' --cacert "$WORK/root/domi-root.crt" --resolve ianitor.smoke.test:28443:127.0.0.1 https://ianitor.smoke.test:28443/api/v1/team || true) +[ "$code" = 401 ] || fail "admin host: $code" +ok "the admin host reaches control and needs a sign-in (401)" +code=$(inside "curl -s -o /dev/null -w '%{http_code}' -H 'Authorization: Bearer $FABRICA' http://127.0.0.1:7878/api/v1/hosts") +[ "$code" = 403 ] || fail "preview token on hosts: $code" +ok "the preview token cannot read the hosts (403)" + +step "closed on merge" +inside "IANITOR_URL=http://127.0.0.1:7878 IANITOR_PREVIEW_TOKEN=$FABRICA sh -s -- close shop fix-42" < "$REPO/scripts/preview.sh" >/dev/null +for i in $(seq 45); do + code=$(curl -s -o /dev/null -w '%{http_code}' --cacert "$WORK/root/domi-root.crt" --resolve fix-42--shop.pv.smoke.test:28443:127.0.0.1 https://fix-42--shop.pv.smoke.test:28443/ || true) + [ "$code" != 200 ] && break + sleep 2 +done +[ "$code" != 200 ] || fail "still served after close" +ok "gone after close ($code)" +echo "SMOKE PASSED" diff --git a/scripts/smoke-linux.sh b/scripts/smoke-linux.sh new file mode 100644 index 0000000..79ebd37 --- /dev/null +++ b/scripts/smoke-linux.sh @@ -0,0 +1,100 @@ +#!/usr/bin/env bash +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at https://mozilla.org/MPL/2.0/. +# +# Plain Linux with systemd, end to end (T4): a Debian container with systemd as PID 1 stands in +# for a fresh server. deploy/linux/install.sh installs the release tarball (IANITOR_TARBALL, no +# download), a throw-away Domi root signs the intermediate, a branch build runs on 127.0.0.1, +# Fabrica's client (scripts/preview.sh) opens the preview with a previews-only token, and the +# preview answers through edge (Pingora, under systemd) on a published port; then it is closed. +# The container and its image are removed at the end. +# +# scripts/smoke-linux.sh +set -euo pipefail + +DIST=$1 CTL=$2 WORK=$3 +REPO=$(cd "$(dirname "$0")/.." && pwd) +C=ianitor-smoke-linux +step() { echo "== $*"; } +ok() { echo " ok: $*"; } +fail() { echo "FAILED: $*" >&2; docker exec $C journalctl --no-pager -n 60 -u ianitor-control -u ianitor-edge 2>/dev/null || true; exit 1; } +cleanup() { docker rm -f $C >/dev/null 2>&1 || true; docker rmi -f $C:latest >/dev/null 2>&1 || true; } +trap cleanup EXIT +[ ! -e "$WORK" ] || fail "$WORK exists; give a new folder" +mkdir -p "$WORK" +tarball=$(ls "$DIST"/ianitor-*-linux-x86_64.tar.gz | head -n1) +[ -f "$tarball" ] && [ -f "$DIST/install.sh" ] || fail "no tarball or install.sh in $DIST" +version=$(basename "$tarball" | sed 's/^ianitor-\(.*\)-linux-x86_64.tar.gz$/\1/') + +step "a fresh Debian with systemd" +docker build -q -t $C:latest - >/dev/null <<'EOF' +FROM debian:bookworm-slim +RUN apt-get update && apt-get install -y --no-install-recommends systemd systemd-sysv dbus git curl jq python3 ca-certificates \ + && rm -rf /var/lib/apt/lists/* +STOPSIGNAL SIGRTMIN+3 +CMD ["/sbin/init"] +EOF +docker run -d --name $C --privileged --cgroupns=host -v /sys/fs/cgroup:/sys/fs/cgroup:rw \ + --tmpfs /run --tmpfs /run/lock -p 127.0.0.1:38443:443 $C:latest >/dev/null +for i in $(seq 30); do docker exec $C systemctl is-system-running 2>/dev/null | grep -qE 'running|degraded' && break; sleep 1; done +ok "systemd is up" + +step "a throw-away Domi root (offline step)" +printf 'smoke-test-offline-passphrase' > "$WORK/pass" +"$CTL" ca init --out "$WORK/root" --passphrase-file "$WORK/pass" >/dev/null 2>&1 || fail "ca init" +docker exec $C mkdir -p /etc/ianitor +docker cp "$WORK/root/domi-root.crt" $C:/etc/ianitor/domi-root.crt +docker cp "$tarball" $C:/tmp/ +docker cp "$DIST/install.sh" $C:/tmp/install.sh + +step "install.sh (the one line, with the tarball given instead of downloaded)" +docker exec -e IANITOR_TARBALL=/tmp/$(basename "$tarball") -e IANITOR_ADMIN_HOST=ianitor.smoke.test -e IANITOR_TLS=domi \ + -e IANITOR_DOMI_ROOT=/etc/ianitor/domi-root.crt -e IANITOR_PREVIEW_DOMAIN=pv.smoke.test \ + -e IANITOR_PREVIEW_UPSTREAMS=127.0.0.1:20000-29999 $C sh /tmp/install.sh > "$WORK/install.log" 2>&1 \ + || { cat "$WORK/install.log"; fail "install.sh"; } +grep -q '#signin=isc_' "$WORK/install.log" || { cat "$WORK/install.log"; fail "no sign-in link printed"; } +ok "installed $version; both units active: $(docker exec $C systemctl is-active ianitor-control ianitor-edge | tr '\n' ' ')" + +as_ianitor() { docker exec $C runuser -u ianitor -- "$@"; } +ADMIN=$(as_ianitor ianitor-control token create --name smoke --config /etc/ianitor/control.toml 2>/dev/null | tail -n1) +FABRICA=$(as_ianitor ianitor-control token create --name fabrica --scope previews --config /etc/ianitor/control.toml 2>/dev/null | tail -n1) +api() { docker exec $C curl -s -H "Authorization: Bearer $1" "${@:2}"; } + +step "the intermediate, signed offline" +rid=$(api "$ADMIN" -X POST http://127.0.0.1:7878/api/v1/certs/intermediate/renewal | jq -r .request_id) +api "$ADMIN" "http://127.0.0.1:7878/api/v1/pki-requests/$rid/csr" > "$WORK/int.csr" +"$CTL" ca sign --root "$WORK/root" --csr "$WORK/int.csr" --out "$WORK/int.crt" --yes --passphrase-file "$WORK/pass" >/dev/null 2>&1 || fail "ca sign" +docker cp "$WORK/int.crt" $C:/tmp/int.crt +docker exec $C chmod 0644 /tmp/int.crt +as_ianitor ianitor-control pki install /tmp/int.crt --config /etc/ianitor/control.toml >/dev/null 2>&1 || fail "pki install" +docker exec $C systemctl restart ianitor-control +for i in $(seq 60); do api "$ADMIN" http://127.0.0.1:7878/api/v1/hosts 2>/dev/null | grep -q ianitor.smoke.test && break; sleep 2; done +ok "intermediate installed; admin host added" + +step "a branch build on 127.0.0.1:23456" +docker exec -d $C sh -c 'mkdir -p /srv/app && echo "hello from fix-42" > /srv/app/index.html && python3 -m http.server 23456 --bind 127.0.0.1 --directory /srv/app' +sleep 2 + +step "Fabrica opens the preview (scripts/preview.sh, previews-only token)" +docker cp "$REPO/scripts/preview.sh" $C:/tmp/preview.sh +url=$(docker exec -e IANITOR_URL=http://127.0.0.1:7878 -e IANITOR_PREVIEW_TOKEN="$FABRICA" $C sh /tmp/preview.sh open shop fix-42 http://127.0.0.1:23456 3600) +[ "$url" = "https://fix-42--shop.pv.smoke.test/" ] || fail "preview URL: $url" +ok "preview URL $url" +body=$(curl -sS --cacert "$WORK/root/domi-root.crt" --resolve fix-42--shop.pv.smoke.test:38443:127.0.0.1 https://fix-42--shop.pv.smoke.test:38443/ || true) +[ "$body" = "hello from fix-42" ] || fail "the preview through edge: $body" +ok "the preview answers through edge (Pingora under systemd), with a Domi certificate" +code=$(api "$FABRICA" -o /dev/null -w '%{http_code}' http://127.0.0.1:7878/api/v1/hosts) +[ "$code" = 403 ] || fail "preview token on hosts: $code" +ok "the preview token cannot read the hosts (403)" + +step "closed on merge" +docker exec -e IANITOR_URL=http://127.0.0.1:7878 -e IANITOR_PREVIEW_TOKEN="$FABRICA" $C sh /tmp/preview.sh close shop fix-42 >/dev/null +for i in $(seq 45); do + code=$(curl -s -o /dev/null -w '%{http_code}' --cacert "$WORK/root/domi-root.crt" --resolve fix-42--shop.pv.smoke.test:38443:127.0.0.1 https://fix-42--shop.pv.smoke.test:38443/ || true) + [ "$code" != 200 ] && break + sleep 2 +done +[ "$code" != 200 ] || fail "still served after close" +ok "gone after close ($code)" +echo "SMOKE PASSED"