diff --git a/.ai/designs/accounts-and-sign-in.md b/.ai/designs/accounts-and-sign-in.md index 391beb4..5380c48 100644 --- a/.ai/designs/accounts-and-sign-in.md +++ b/.ai/designs/accounts-and-sign-in.md @@ -1,6 +1,7 @@ # Accounts and sign-in -Status: design, nothing built. Last updated 2026-11-25. +Status: built. Provider sign-in is tested against an in-process fake provider +only; no real GitHub, Discord or Google app has been used yet. Last updated 2026-11-25. The account system follows **piki**, the owner's Go project (`../piki`). Piki's `agents/data-auth-services.md` maps its auth code; the schema is in @@ -21,18 +22,26 @@ As in piki: - **First run:** `/setup` creates the instance owner with a username and password. It is only available while no user exists. -- **Signup toggle:** the owner turns public signup on or off. -- **Invite keys:** the owner can require an invite key for signup. A key has a name, a maximum - number of uses and an active flag, and records who used it. Signup with a key uses a path of - the form `/signup/`. +- **Signup mode:** an owner setting with three values. `closed` (the default): admins create + accounts. `invite`: only invite links work. `open`: anyone who can reach the site signs up at + `/signup`. +- **Invite keys:** admins create keys with a name, a maximum number of uses and an active + flag; each use is recorded. Signup with a key uses `/signup/`. Invite links work in the + `invite` and `open` modes. The use is counted in the same transaction that creates the + account, so a key cannot be used more often than allowed by racing requests. +- **Admin-created accounts:** admins create an account with a password from `/admin`, or with + `lore-forge create-user` on the server. ## Signing in -Three methods, all ending in the same kind of session: +Two methods, both ending in the same kind of session: 1. **Username and password.** 2. **A linked provider:** GitHub, Discord or Google. -3. **A passkey** (optional, registered from the profile). +Passkeys are not offered; see below. + +Password sign-in is rate limited in memory per username: ten failures within 15 minutes block +further attempts for that username until the window passes. The limit resets on restart. ### Provider sign-in @@ -57,6 +66,17 @@ Protocol notes: - GitHub and Discord are plain OAuth 2.0 authorization-code flows followed by an identity request. - Google is OpenID Connect with PKCE and a per-flow nonce; identity comes from the ID token. + The ID token's signature is not checked: it arrives directly from Google's token endpoint + over TLS, which OpenID Connect allows. Its issuer, audience, expiry and nonce are checked. +- Discord's flow uses no PKCE, as in piki. +- A flow expires after 10 minutes and is consumed with a single conditional update, so a + state value works once. +- Unlinking is refused when the provider is the account's last sign-in method and it has no + password. + +**Assumed, not verified:** the providers' endpoints and response shapes are taken from piki +and the providers' documentation. Tests run the whole flow against a fake provider served +in-process; the first real sign-in will confirm them. ### Provider configuration @@ -66,14 +86,15 @@ As in piki: - The settings page shows the exact callback URL to register with the provider. - Secrets are stored encrypted (AES-GCM) with a 32-byte key supplied through the environment. The same key protects lore-forge's token signing keys (see [token-issuer.md](token-issuer.md)). -- The owner sets the instance's canonical public URL. Callback URLs, passkey configuration and +- The owner sets the instance's canonical public URL. Callback URLs and the issuer URL derive from it, never from request headers. ### Passkeys -As in piki: optional, registered from the profile while signed in, usernameless sign-in with -user verification, only the public key stored. They are an additional sign-in method, not a -required second step. +**Dropped for now (owner, 2026-11-25).** Passwords and provider sign-in cover a self-hosted +studio, and passkeys would bring WebAuthn code and the UI's first script. If they return, the +design is piki's: optional, registered from the settings while signed in, usernameless sign-in +with user verification, only the public key stored. ## Sessions @@ -83,8 +104,10 @@ As in piki: - Cookies are `HttpOnly`, `Secure` in production and `SameSite=Lax`. Unsafe methods require a CSRF token. - "Stay signed in" keeps a session for 30 days after last use, up to 90 days in total. -- Each session records how it was created (password, provider, passkey) and its user agent. -- Users see their active sessions in their profile and can revoke one or all others. +- Each session records how it was created (password or provider) and its user agent. +- Users see their active sessions in their settings and can revoke one or all others. +- Changing the password ends the account's other sessions. Disabling an account ends all its + sessions and CLI logins. ### What lore-forge adds @@ -117,25 +140,40 @@ Repository and organisation permissions are in ## API tokens -As in piki, a user can create named API tokens, stored hashed, with scopes and optional -expiry. In lore-forge they serve two purposes: +As in piki, a user can create named API tokens, stored as SHA-256 hashes, with scopes and an +optional expiry. The secret starts with `lf_` and is shown once. Two scopes: -- authenticating to lore-forge's JSON API; -- logging the Lore CLI in without a browser, for CI. Lore defines API-key login as a token - exchange with the subject token type `urn:lore:params:oauth:token-type:api-key`. +- `api`: lore-forge's JSON API under `/api/v1` (`Authorization: Bearer`); +- `lore`: logging the Lore CLI in without a browser, for CI. Lore sends it as a token exchange + with the subject token type `api-key` or `urn:lore:params:oauth:token-type:api-key`. + +A CLI login started from a token records the token; revoking the token ends those logins. +Verified with `lore auth login --token-type api-key` by `scripts/e2e-lore.sh`. + +## Service accounts + +For CI and bots that should not act as a person. A service account belongs to a user or an +organisation namespace and is a `users` row with `kind = 'service'`. Its username is +`.`; person usernames cannot contain dots, so the two never collide. It has no +password and cannot sign in to the web UI. It holds grants like any user. + +Its secrets are API tokens with the `lore` scope. It logs in with the client credentials +grant: client ID is its username, client secret is a token. The login lasts an hour (or until +the token expires) and gets no refresh token. Owners of the namespace manage it under +`/settings/service-accounts` or `/orgs//service-accounts`. Verified with +`lore auth login --client-id` by `scripts/e2e-lore.sh`. ## Identity recorded by Lore Lore writes the caller's identity into revision history permanently. -**Recommended, not yet confirmed:** put a stable internal user ID in the token, not the -username, and have lore-forge answer Lore's name lookup service. Usernames can then change -without rewriting history, and the CLI still shows names. The alternative is to use the -username directly, which is simpler but makes usernames effectively permanent. +**Decided (owner, 2026-11-25):** the token carries a stable internal user ID, not the +username, and lore-forge answers Lore's name lookup service. Usernames can then change +without rewriting history, and the CLI still shows names. ## Open questions - Whether an invite may be redeemed directly with a provider, creating an account that never has a password. Piki does not allow this; the design currently matches piki. -- Whether usernames can be changed, which depends on the identity decision above and on - namespace renames (see [namespaces-and-access.md](namespaces-and-access.md)). +- Whether usernames can be changed. The identity decision above allows it as far as Lore + history is concerned; it still depends on namespace renames (see [namespaces-and-access.md](namespaces-and-access.md)). diff --git a/.ai/designs/architecture-overview.md b/.ai/designs/architecture-overview.md index bc6f029..79b3d5b 100644 --- a/.ai/designs/architecture-overview.md +++ b/.ai/designs/architecture-overview.md @@ -1,6 +1,7 @@ # Architecture overview -Status: design, nothing built. Last updated 2026-11-25. +Status: phase 1 walking skeleton built and verified against a real `loreserver`. Last updated +2026-11-25. ## What lore-forge is @@ -68,11 +69,14 @@ repository creates and deletes, and user name lookups. One cargo workspace, built as a modular monolith. Crate names are provisional. +Built so far: `forge-store`, `forge-access`, `forge-id`, `forge-lore`, `forge-web` and the +`lore-forge` binary. `forge-core` and `forge-events` come with phases 2 and 3. + | Crate | Responsibility | Design document | | --- | --- | --- | | `forge-id` | Accounts, sessions, provider linking, the token issuer | [accounts-and-sign-in.md](accounts-and-sign-in.md), [token-issuer.md](token-issuer.md) | | `forge-access` | Namespaces, orgs, teams, grants, role presets, the Lore registry service | [namespaces-and-access.md](namespaces-and-access.md) | -| `forge-lore` | Typed client for `loreserver` (gRPC and HTTP), minting on-behalf tokens. The only crate that depends on Lore's protocol definitions | [lore-integration.md](lore-integration.md) | +| `forge-lore` | Lore's protocols: serves `UserService` and `RepositoryRegistryService`, generates the `loreserver` config; later a typed client for `loreserver`. The only crate that depends on Lore's protocol definitions | [lore-integration.md](lore-integration.md) | | `forge-core` | Change requests, reviews, comments, landing | [forge-features.md](forge-features.md) | | `forge-events` | Lore notification subscriber: activity feed, webhooks | [forge-features.md](forge-features.md) | | `forge-web` | HTTP server, templates, JSON API | [web-ui.md](web-ui.md) | @@ -81,6 +85,14 @@ One cargo workspace, built as a modular monolith. Crate names are provisional. There is no separate worker process. Landing a change is a single call to `loreserver`, so background work runs as tasks inside the one binary. +### Desktop client + +A separate tree, `desktop/`, holds the client side: `forge-service` (a per-user Rust service +that drives Lore through liblore and runs policies such as autosync), `forge-desktop` (a C++ +tray application, Dear ImGui on vendored UHDK) and later `forge-tui`. The frontends talk to +the service over a local socket. It has its own Cargo workspace and `zig build`, so the server +never needs Zig. See [desktop-client.md](desktop-client.md). + ## Decisions | Topic | Decision | Source | @@ -96,21 +108,55 @@ background work runs as tasks inside the one binary. | Landing | Per-branch choice between review-gated and direct push | Owner | | Permission source | Grants managed in lore-forge, optional mapping from GitHub teams and Discord roles later | Recommended; owner had no preference | | Deployment | `loreserver` as a separate process; lore-forge generates its auth config | Recommended; owner had no preference | +| Lore binaries | The official release pinned with SHA-256 in `lore.lock`, fetched into `.lore/`; `scripts/start.sh` runs a whole deployment from `run/` | Owner, 2026-11-25 | +| Desktop client | A per-user client service (Rust, liblore) with a C++ Dear ImGui tray GUI (pixel-art look) on vendored UHDK and a later Rust TUI as frontends, in `desktop/` | Owner, 2026-11-25; details in [desktop-client.md](desktop-client.md) | | Audience | A self-hosted instance for one studio or community | Assumed; owner had no preference | | Per-repo tokens | Use Lore's per-repository token mode from the start | Recommended, not explicitly confirmed | -| Identity in Lore history | A stable internal user ID, with names resolved through lore-forge | Recommended, not explicitly confirmed | +| Identity in Lore history | A stable internal user ID, with names resolved through lore-forge | Owner, 2026-11-25 | +| Database library | `sqlx` with its built-in migrations | Owner, 2026-11-25 | +| Templates and interactivity | maud and vendored htmx | Owner, 2026-11-25 | +| Phase 1 order | Walking skeleton first: store, keys, issuer grants and registry, tested against a real `loreserver`; full account UI after | Owner, 2026-11-25 | | Who may create orgs | An owner setting, defaulting to instance admins only | Defaulted, not confirmed | +| Web UI look | The desktop client's pixel style: VGA font, Sweetie 16 palette | Owner, 2026-11-25 | +| Passkeys | Dropped for now; possibly later | Owner, 2026-11-25 | +| Service accounts | `users` rows of kind `service`, named `.`, logging in with client credentials | Implementation choice | +| Browser reads | As the viewer, with a one-minute read-only repository token per page view; file diffs computed in lore-forge because Lore's `ContentDiff` is unimplemented | Implementation choice | +| Browser layout | FILES, GRAPH and TREE, as in the desktop explorer | Owner, 2026-11-25 | +| Provider sign-in testing | Built and tested against an in-process fake; the owner registers real apps later | Owner, 2026-11-25 | +| Token lifetimes | Login token 1 h, scoped 5 min, CLI login 30 d idle / 90 d max | Defaulted, not confirmed | +| Ports | Pages, issuer and Lore's gRPC directory share one port, routed by content type | Implementation choice | +| Revocation speed | Token exchange checks the CLI login is live, so revoking a login ends repository access within five minutes | Implementation choice | ## Phases 1. **Identity.** `lore auth login` works end to end: accounts, provider sign-in, the issuer, namespaces, grants, per-repository tokens. Everything else depends on this. + - **Done (walking skeleton):** store and migrations, ES256 keys, discovery, JWKS, device + grant, refresh with rotation, token exchange, revocation, the registry and user directory + over gRPC, setup, password sign-in and device approval pages. Verified by + `scripts/e2e-lore.sh` against the Lore v0.14.0 release. `scripts/start.sh` starts a + deployment from this repository alone. + - **Done (accounts, milestone A):** signup modes and invite keys; GitHub, Discord and Google + sign-in and linking (tested against a fake provider); session and CLI-login lists; + organisation, team, member and grant pages; service accounts with the client credentials + grant; API tokens, API-key login and a first JSON API; key rotation from the UI and the + `rotate-signing-key` command; sign-in rate limiting; the admin pages; the pixel restyle. + API-key and client credentials logins are in the e2e test. + - **Remaining:** a first sign-in against each real provider. Passkeys are dropped for now. 2. **Read-only forge.** Repository list, file browser, history, diffs, locks, activity feed. + - **Done (browser, milestone B):** FILES, GRAPH and TREE tabs and a revision page with + diffs, read from `loreserver` as the viewer. Verified by unit tests against an in-process + fake and by `scripts/e2e-lore.sh` against the Lore v0.14.0 release, including a branch and + a merge. + - **Remaining:** history paging, downloads, locks, activity feed. 3. **Collaboration.** Branch-based change requests, reviews, comments, gated landing. 4. **Integrations.** Webhooks, Discord notifications, CI status checks, API tokens for CI. 5. **Game-development specifics.** Asset previews (textures, `.uasset` thumbnails), lock management. +The desktop client has its own milestones, in [desktop-client.md](desktop-client.md). Milestone +1, the GUI and tray shell over a stub service, is done. + ## Things to keep in mind - **Epic plans its own web client.** Lore's roadmap lists an open-source web client with code diff --git a/.ai/designs/forge-features.md b/.ai/designs/forge-features.md index 3ee0e05..db0399e 100644 --- a/.ai/designs/forge-features.md +++ b/.ai/designs/forge-features.md @@ -1,24 +1,42 @@ # Forge features -Status: design, nothing built. Last updated 2026-11-25. +Status: the repository browser (phase 2) is built; locks and the rest are design only. Last +updated 2026-11-25. These are phases 2 to 5 and are designed in less detail than identity. Each section says what Lore provides for it; see [lore-integration.md](lore-integration.md) for what was verified. ## Repository browser (phase 2) +Built, with the desktop explorer's three tabs (`crates/forge-web/src/pages/browse.rs`): + - **Repository list** per owner, and a dashboard of the repositories a user can reach. -- **File browser:** directory listings and file views at any branch or revision. -- **History:** revisions on a branch, with author names resolved by lore-forge. -- **Diffs:** between two revisions, and per file. -- **Downloads** through presigned URLs. +- **FILES:** directory listings at a branch tip or any revision, each entry with the revision + that last changed it; file views with line numbers. Text up to 512 KiB is shown; binary + files are named as such. +- **GRAPH:** the revision DAG across branches (the newest 50 revisions of up to 12 branches), + drawn with the desktop's lane layout as one SVG per row. Branch heads are tagged; merges are + hollow. Revisions are ordered so a child always precedes its parents, newest first. +- **TREE:** branches, the open branch's newest 50 revisions, and the open revision's changes. + What is open is in the URL, so it needs no script. +- **One revision:** message, author, parents, the changed files, and unified diffs of up to + 30 text files of up to 256 KiB each. -Backed by Lore's read-only `ThinClientService` (`RevisionTree`, `RevisionInfo`, -`RevisionDiff`, `ContentDiff`) and its HTTP content routes. A deployment can run a second, -read-only `loreserver` that mounts only that service, to keep browsing load off the main -server. +Not built yet: paging further back than the newest revisions, diffs between two arbitrary +revisions, downloads, and entries inside linked repositories (shown, not opened). -All reads are made as the browsing user; see [web-ui.md](web-ui.md). +**How it reads Lore.** Each page view gets a token from `Issuer::browse_token`: scoped to the +repository, carrying only `read`, valid one minute, refused if the viewer cannot read. With +it, lore-forge calls `loreserver`'s `RepositoryService.RepositoryGet` (default branch), +`RevisionService.BranchList` and `RevisionList`, `ThinClientService.RevisionInfo`, +`RevisionTree` and `RevisionDiff`, and fetches file content from loreserver's HTTP endpoint. +`ContentDiff` is unimplemented in Lore, so lore-forge diffs file content itself (`similar`). +`RevisionList` gives no messages or parents, so each listed revision costs one `RevisionInfo` +call, 16 at a time. See [lore-integration.md](lore-integration.md) for what was verified. + +The endpoints are set with `LORE_FORGE_LORE_GRPC_URL` (default `http://127.0.0.1:41337`) and +`LORE_FORGE_LORE_HTTP_URL` (default `http://127.0.0.1:41339`). A deployment can point them at +a second, read-only `loreserver` to keep browsing load off the main server; that is untested. ## Locks (phase 2, extended in phase 5) diff --git a/.ai/designs/lore-integration.md b/.ai/designs/lore-integration.md index b56dd51..d407891 100644 --- a/.ai/designs/lore-integration.md +++ b/.ai/designs/lore-integration.md @@ -1,9 +1,10 @@ # Lore integration -Status: design, nothing built. Last updated 2026-11-25. +Status: phase 1 integration verified end to end. Last updated 2026-11-25. Facts here were checked against Lore's `main` at commit `6b12f00` (2026-11-25), workspace -version `0.14.1-nightly`. Lore is pre-1.0, so re-check before relying on them. +version `0.14.1-nightly`, and the release-specific facts against the v0.14.0 release, which +`lore.lock` pins. Lore is pre-1.0, so re-check before relying on them. ## Minimum Lore version @@ -78,7 +79,7 @@ cannot. lore-forge must be up first. | Need | Lore surface | Verified | | --- | --- | --- | -| Browse trees, history, diffs | `lore.thin_client.v1.ThinClientService`: `RevisionTree`, `RevisionInfo`, `RevisionDiff`, `ContentDiff` | Proto read | +| Browse trees, history, diffs | `lore.thin_client.v1.ThinClientService`: `RevisionTree`, `RevisionInfo`, `RevisionDiff`; `RevisionService.BranchList`, `RevisionList`; `RepositoryService.RepositoryGet`; HTTP content | Verified end to end; see "Reading repositories" | | Download file content | HTTP `/v1/repository/{id}/content/{address}`, plus presigned URLs | Routes read | | Activity, webhooks, CI triggers | `NotificationService.Subscribe`. Events: branch created, pushed, deleted; resource locked, unlocked; obliterate | Proto read; `[notification] mode = "local"` is the default | | Locks | `LockService`: `Lock`, `Query`, `Status`, `Unlock`, `AdminLock` | Proto read | @@ -102,6 +103,16 @@ token permissions instead (see [forge-features.md](forge-features.md)). Both are defined in `lore-proto/proto/lore/user/v1/user.proto` and reached through `user_url`. +Verified in `docs/reference/lore-server-config.md`, `lore-server/src/authnz/auth.rs` and +`lore-transport/src/auth/ucs_auth.rs`: + +- Both services are served at the **same** `user_url`. +- They are **gRPC**. `loreserver` dials `user_url` with tonic; accepted schemes are + `ucs-auth`, `https` and `http`, with TLS used for `https`. So lore-forge must serve gRPC + (HTTP/2) as well as its web pages, and a reverse proxy in front of it must pass gRPC through. +- **Lore clients call `UserService` at `user_url` too**, not only `loreserver`, so it must be + reachable from wherever the CLI runs. Without `user_url`, clients show raw user IDs as names. + ### RepositoryRegistryService - **`RepositoryRegister(id, name)`** — `loreserver` calls this before storing a new repository, @@ -153,16 +164,96 @@ Both are defined in `lore-proto/proto/lore/user/v1/user.proto` and reached throu - **Forks.** Lore's roadmap lists forks as "later, exploring", so change requests are branch-based. +## Verified end to end + +`scripts/e2e-lore.sh` runs an unmodified `loreserver` and `lore` CLI against lore-forge, using +the configuration `lore-forge loreserver-config` generates. By default it uses the official +release pinned in `lore.lock`. As of 2026-11-25 it passes against the **v0.14.0 release**. An +earlier version of the test, which read claims with `--with-claims`, passed against a source +build of `6b12f00`. Whether `main` still has `--with-access-token` is unchecked. Together these +verify: + +- `loreserver` starts against lore-forge's discovery document and ES256 JWKS. +- `lore auth login` completes the device grant through lore-forge's approval page, over plain + http on localhost (the client allows loopback http). +- `lore repository create`, `commit`, `push` and `clone` work with exchanged + repository-scoped tokens, and the token Lore stores carries the `resources` claim. +- `lore repository list` is answered by the registry's `RepositoryList`. +- `lore auth info` resolves the user's display name through `UserService`. + `--with-access-token` prints the stored repository token, whose payload the test checks. + (`--with-claims` exists on `main` but not in v0.14.0.) +- A second user is refused create in another's namespace, clone and listing. +- `lore auth login --token-type api-key` (token from `LORE_TOKEN`) logs in through token + exchange with a lore-forge API token; the CLI sends the type `api-key` verbatim. +- `lore auth login --client-id ` (secret from `LORE_CLIENT_SECRET`) logs in + with the client credentials grant. A service account without a grant is refused clone; after + a grant it clones. +- `lore auth logout` reaches the revocation endpoint. +- `loreserver`'s ports can be moved with `[server.quic]`, `[server.grpc]` and `[server.http]` + `port` settings; the test uses this (`LORE_PORT`) to run beside a deployment from `run/`. +- How refusals surface: the registry's `INVALID_ARGUMENT` message reaches the CLI verbatim; + `NOT_FOUND` is reported by `loreserver` as `FAILED_PRECONDITION` "A required Auth entity was + not found"; `PERMISSION_DENIED` and an exchange `invalid_target` both show as "Not + authorized to access repository". + +## Release binaries + +Verified against the v0.14.0 GitHub release: + +- Each release publishes `lore--.tar.gz` and `loreserver--.tar.gz` + for `aarch64-apple-darwin`, `x86_64-unknown-linux-gnu` and `aarch64-unknown-linux-gnu`, plus + Windows and `-debug` variants. There is no Intel macOS build. +- GitHub records a SHA-256 for every asset, which `scripts/fetch-lore.sh --pin` copies into + `lore.lock`. +- Binaries sit at the archive root. The `loreserver` archive also holds sample configuration + in `config/`, which the fetch script keeps as `config-examples/`. +- `loreserver` has its defaults compiled in. A config directory holding only the generated + `forge.toml` is enough. The public QUIC endpoint listens on `0.0.0.0:41337`. Without + `[server.quic.certificate]`, it generates a self-signed certificate on every start. +- On macOS the `lore` CLI stores the key for its token store in the keychain + (`tokenstore_encryption_key`). Each process asks for access until "Always Allow" is chosen. +- v0.14.0's `user.proto` differs from `6b12f00` only in comments, so the vendored proto matches. + +## Reading repositories + +Read in Lore's source at `6b12f00` (the protos are identical in v0.14.0 apart from comments) +and confirmed by `scripts/e2e-lore.sh` against the v0.14.0 release: + +- The public gRPC endpoint (`[server.grpc]`, port 41337 over TCP) is plaintext HTTP/2 when it + has no certificate; there is no self-signed fallback as for QUIC. The CLI uses gRPC for + revision calls whatever the URL scheme. +- Partition-scoped calls (`RevisionService`, `ThinClientService`, `StorageService`) need + `authorization: Bearer ` and the repository ID as 16 raw bytes under + `lore-partition-bin` and `urc-repository-id-bin` (the CLI sends both). The token must be + repository-scoped: a login token matches no `resources` entry and is refused. Every read + call needs only `read`. +- `RepositoryGet` returns the default branch, fixed at creation (`main` is only the default + name). +- `BranchList` streams branches; `latest` is the tip's signature. +- `RevisionList` returns at most 100 revisions newest first, following first parents, with + paging signatures. Its items carry no message, author or parents; `RevisionInfo` does. +- `RevisionTree` takes a path prefix and a depth and can attribute each entry to the revision + that last changed it. `RevisionDiff` streams changes between two signatures. +- `ContentDiff` is unimplemented: it answers `UNIMPLEMENTED`. +- File content is served decoded on the HTTP port (41339) at + `GET /v1/repository//content/[-]` with the same bearer token, + and honours `Range`. The HTTP endpoint is plaintext. +- `lore branch merge ` commits the merge itself, with no message. +- Timestamps in `Revision` are milliseconds. + ## Unverified - How `BranchPush` with `fast_forward_merge` reports a conflict. - Whether a repository can be renamed, which decides whether namespaces can be renamed. - Whether identical content is deduplicated across repositories or only within one. -- The exact form of `user_url` and whether both services must share one endpoint. - Whether `NotificationService.Subscribe` is reachable by an external subscriber in the default `local` mode, and what permission it needs. -- What `loreserver` itself checks on repository create beyond asking the registry. +- What `loreserver` itself checks on repository create beyond asking the registry, other than + the error mapping above. - How stable `ThinClientService` is between releases. +- Whether a TreeNode in a linked repository can be read with a token for the parent + repository, or needs one for the linked repository. +- Paging `RevisionList` with `signature_backward`; the browser does not page yet. ## Upstream files worth reading diff --git a/.ai/designs/namespaces-and-access.md b/.ai/designs/namespaces-and-access.md index f5d9197..cd5d55c 100644 --- a/.ai/designs/namespaces-and-access.md +++ b/.ai/designs/namespaces-and-access.md @@ -1,6 +1,8 @@ # Namespaces and access -Status: design, nothing built. Last updated 2026-11-25. +Status: built for phase 1: namespaces, organisations, members, teams, grants and their pages, +the registry rules, service accounts. GitHub and Discord mapping is not. Last updated +2026-11-25. ## Namespaces @@ -51,14 +53,19 @@ same rules as creating a repository in the web UI. | --- | --- | | Create a repository in a personal namespace | That user | | Create a repository in an organisation | Members the organisation allows (owners by default) | -| Create an organisation | An instance setting. Defaulted to instance admins only; not yet confirmed | +| Create an organisation | The owner's `orgs.create` setting: instance admins (the default) or everyone. The creator becomes its owner. The default is not yet confirmed | ## Organisations and teams - **Members** belong to an organisation with an organisation role: owner or member. - **Teams** are named groups of members within one organisation. - **Base permission:** an organisation may give all its members a default role on all its - repositories (for example Reader), or none. + repositories (for example Reader), or none. Owner cannot be a base permission. +- An organisation always keeps at least one owner: the last one cannot be demoted or removed. +- Only members can join a team; removing a member from the organisation removes them from + its teams. Deleting a team deletes its grants. +- Organisation owners manage members, teams, settings and service accounts at + `/orgs//...`. Members see the organisation's members and teams. ## Role presets @@ -70,15 +77,19 @@ Permissions are presented as presets that map onto Lore's actions. | Writer | `write` | Push to unprotected branches, take locks | | Maintainer | `write`, `set-protected` | Also protect and unprotect branches | | Admin | `write`, `admin` | Also release others' locks, manage the repository | -| Owner | `owner` | Also delete the repository | +| Owner | `write`, `owner` | Also delete the repository | -Notes: +Verified in Lore's source at `6b12f00` (`lore-server/src/grpc/mod.rs`, +`lore-server/src/grpc/lock_service.rs`, `lore-server/src/authnz/resource_grants_authorizer.rs`): -- In Lore, any grant on a repository implies `read`. -- The mapping of `admin` and `owner` to specific operations is taken from Lore's - documentation: branch protection needs `owner`, `admin` or `set-protected`; repository delete - needs `owner` or `admin`. The table above should be re-checked against Lore's enforcement - points before implementation. +- **Actions are checked literally; none implies another**, except that any grant implies + `read`. So `owner` does not include `write`, which is why Owner lists both. +- Every "administer the repository" check accepts `owner` **or** `admin`: releasing others' + locks, protecting branches (which `set-protected` also allows), and deleting the repository. +- Pushes and branch changes need `write`; a push to a protected branch also needs + `push-protected`. +- Lore itself would let an Admin delete a repository. lore-forge's registry refuses the + unregister unless the caller has Owner, so in practice only Owner deletes. ### Advanced view @@ -99,7 +110,10 @@ account can be given it explicitly. See [forge-features.md](forge-features.md). A grant gives a subject a preset, plus optional extra actions, on a repository. -- **Subjects:** a user, a team, or a service account. +- **Subjects:** a user, a team, or a service account (which is a user row, so it is granted + by its `.` username). +- **Who manages them:** holders of the `admin` action on the repository (the Admin and Owner + presets) on its Access page. Only Owner holders can grant Owner. Every change is audited. - **Sources of a user's access to a repository**, combined by union: 1. the repository is in their personal namespace (Owner); 2. their organisation role and the organisation's base permission; diff --git a/.ai/designs/storage.md b/.ai/designs/storage.md index 961336f..d42c284 100644 --- a/.ai/designs/storage.md +++ b/.ai/designs/storage.md @@ -1,6 +1,7 @@ # Storage -Status: design, nothing built. Last updated 2026-11-25. +Status: phase 1 schema built (`crates/forge-store/migrations/`: `0001_initial.sql`, and +`0002_accounts.sql` for invites, providers, API tokens and service accounts). Last updated 2026-11-25. ## What lore-forge stores @@ -27,8 +28,16 @@ written periodically, not per request. See [token-issuer.md](token-issuer.md). ### Library -Not yet decided. `sqlx` (async, compile-time-checked queries, built-in migrations) is the -default candidate; `rusqlite` with a dedicated writer thread is the alternative. +**Decided (owner, 2026-11-25):** `sqlx`, with its built-in migrations embedded in the binary. + +Queries use sqlx's runtime-checked functions (`query`, `query_as` with `FromRow`), not its +compile-time `query!` macros, which need a live database or a committed `.sqlx` cache and +`sqlx-cli` on every schema change. sqlx 0.9 refuses SQL built at runtime, so every query is a +static string. Moving to the macros later is a mechanical change. + +Before 0.1.0, migrations may be edited in place rather than followed by new ones, as piki does +before its first release. `0002_accounts.sql` was added as a new migration anyway, so +deployments already started from `run/` keep their data. ## Data directory @@ -45,36 +54,36 @@ One 32-byte key, supplied through the environment, encrypts: - provider client secrets (GitHub, Discord, Google); - lore-forge's private token signing keys. -The key is not stored in the data directory. As in piki, losing it means provider secrets must +The key is not stored in the data directory. `scripts/start.sh` keeps it in `run/secret.key` +(mode 600), next to the data directory `run/forge-data/` rather than inside it, and tells the +operator to back it up separately. As in piki, losing it means provider secrets must be re-entered; here it also means new signing keys, which invalidates outstanding tokens and requires `loreserver` to pick up the new keys. Stored only as hashes, never recoverable: passwords, session tokens, refresh tokens, API tokens, device codes, invite-flow state. -## Tables (phase 1 sketch) - -Names are provisional. +## Tables (phase 1) ### Accounts — following piki | Table | Holds | | --- | --- | -| `users` | Username, display name, password hash, instance role, disabled flag | +| `users` | Username, display name, password hash, instance role, disabled flag, kind (`person` or `service`), owning namespace for service accounts | | `sessions` | Hashed token, user, method used, user agent, created, expires, revoked | | `invite_keys`, `invite_key_uses` | Key, name, maximum uses, active flag; who used it | | `oauth_provider_configs` | Provider, client ID, encrypted secret, enabled | | `oauth_identities` | `(provider, subject id)` → user; unique per user and provider | | `oauth_flows` | Hashed state, intent, PKCE verifier, nonce, expiry, used | -| `passkey_credentials`, `passkey_ceremonies` | Public keys; single-use ceremony state | -| `settings` | Instance settings: signup toggle, canonical URL, who may create organisations | +| `passkey_credentials`, `passkey_ceremonies` | Public keys; single-use ceremony state. Not created; passkeys are dropped for now | +| `settings` | Key-value instance settings: `signup.mode`, `orgs.create`. The canonical URLs come from the environment | ### Namespaces and access | Table | Holds | | --- | --- | | `namespaces` | Name, kind (user or organisation). The single name table | -| `orgs`, `org_members` | Organisation details; member and organisation role | +| `orgs`, `org_members` | Organisation details, base preset, whether members may create repositories; member and organisation role | | `teams`, `team_members` | Teams within an organisation | | `repos` | Lore repository ID, namespace, name, base permission, per-branch landing settings | | `grants` | Repository, subject (user, team or service account), preset, extra actions | @@ -84,10 +93,12 @@ Names are provisional. | Table | Holds | | --- | --- | | `signing_keys` | Key ID, algorithm, encrypted private key, public key, state | -| `device_codes` | Hashed device code, user code, client, status, expiry | -| `refresh_tokens` | Hashed token, user, created, last used, revoked. Shown in the session list | -| `service_accounts` | Non-human identities and their owner | -| `api_tokens` | Hashed token, owner, name, scopes, expiry, last used | +| `device_codes` | Hashed device code, user code, client, status, polling interval, expiry | +| `cli_logins` | One per `lore auth login`: user, client, created, last used, absolute expiry, revoked, the API token it started from. Shown in the session list | +| `refresh_tokens` | Hashed token, its login, created, superseded (for rotation and reuse detection) | +| `api_tokens` | Hashed token, owner, name, scopes, expiry, last used, revoked | + +Service accounts have no table of their own: they are `users` rows with `kind = 'service'`. ### Shared @@ -108,6 +119,5 @@ statuses. Full-text search can use SQLite's FTS5. ## Open questions -- `sqlx` or `rusqlite`. - How long to retain audit entries and activity events. - Whether exchanged-token activity is audited at all. diff --git a/.ai/designs/token-issuer.md b/.ai/designs/token-issuer.md index f7631e4..f68d3b0 100644 --- a/.ai/designs/token-issuer.md +++ b/.ai/designs/token-issuer.md @@ -1,6 +1,7 @@ # Token issuer -Status: design, nothing built. Last updated 2026-11-25. +Status: phase 1 built (`crates/forge-id/src/issuer/`); every grant below is exercised against +the Lore v0.14.0 release by `scripts/e2e-lore.sh`. Last updated 2026-11-25. lore-forge is the OpenID Connect issuer that `loreserver` trusts. This document covers what it must serve. The requirements come from Lore; see [lore-integration.md](lore-integration.md). @@ -16,14 +17,24 @@ other applications. ## Endpoints -| Endpoint | Purpose | -| --- | --- | -| `/.well-known/openid-configuration` | Discovery document | -| JWKS endpoint | Public signing keys, each with `alg` declared | -| Device authorization endpoint | Starts a CLI login | -| Token endpoint | All grants below | -| Revocation endpoint | `lore auth logout` | -| Device verification page | Browser page where the person approves a CLI login (part of the web UI) | +| Endpoint | Path | Purpose | +| --- | --- | --- | +| Discovery | `/.well-known/openid-configuration` | Discovery document | +| JWKS | `/oauth/jwks` | Public signing keys, each with `alg` declared | +| Device authorization | `/oauth/device_authorization` | Starts a CLI login | +| Token | `/oauth/token` | All grants below | +| Revocation | `/oauth/revoke` | `lore auth logout` | +| Device verification | `/device` | Browser page where the person approves a CLI login (part of the web UI) | + +The Lore CLI is a public client: it presents `client_id` (default `lore-cli`) and no secret. +Every grant checks the client ID. The one exception is the client credentials grant, where the +client is a service account authenticating with a secret, by HTTP Basic or in the form body; +discovery lists `none`, `client_secret_basic` and `client_secret_post`. + +**Verified in Lore's source (6b12f00) and by the e2e test:** Lore's client uses Basic when +discovery lists `client_secret_basic` and the form body otherwise. For API-key login it sends +the token type it was given verbatim, so lore-forge accepts both `api-key` and +`urn:lore:params:oauth:token-type:api-key`. ## Grants on the token endpoint @@ -31,9 +42,9 @@ other applications. | --- | --- | --- | | Device code (RFC 8628) | `lore auth login` | Login token and refresh token | | Refresh token | Lore client, automatically | New login token; refresh token rotated | -| Client credentials | CI, `lore auth login --client-id` | Login token for a service account | +| Client credentials | CI, `lore auth login --client-id` | Login token for a service account; no refresh token. The login lasts one hour or until the secret expires | | Token exchange (RFC 8693), login token in | Lore client, per repository | Repository-scoped token | -| Token exchange (RFC 8693), API token in | CI without a browser | Login token for the token's user | +| Token exchange (RFC 8693), API token in | CI without a browser, `lore auth login --token-type api-key` | Login token and refresh token for the token's user; the token needs the `lore` scope | The device grant must honour the polling rules Lore's client expects: `interval`, `slow_down`, `expired_token` and `access_denied`. @@ -50,7 +61,9 @@ A JWT access token (`typ: at+jwt`) identifying the user. | `sub` | Stable internal user ID | | `aud` | The `loreserver` deployment URL | | `identity` | The identity Lore records in history (see below) | -| `root_domains` | Hosts the token may be sent to, if `aud` alone does not cover them | +| `root_domains` | Hosts the token may be sent to: the `loreserver` host and lore-forge's own. Always set, because the CLI sends tokens to lore-forge's user directory too | +| `sid` | The CLI login the token belongs to; lets exchange refuse tokens of an ended login | +| `client_id`, `jti`, `scope` | As RFC 9068 describes | | `name`, `preferred_username` | For display | | `exp`, `iat` | Short lifetime; renewed by refresh | @@ -86,7 +99,13 @@ Audit records for exchanges are batched or sampled. See [storage.md](storage.md) ### Refresh tokens - Opaque, stored hashed, rotated on use. -- One per CLI login. Shown in the user's session list and revocable there. +- One CLI login (a `cli_logins` row) per `lore auth login`; its refresh tokens rotate within + it. Shown in the user's session list (`/settings/sessions`) and revocable there. A login + started from an API token or a service account secret ends when that token is revoked. +- **Reuse detection:** a rotated-out refresh token presented again ends the whole login, per + RFC 9700. A 60-second grace period lets a client retry a refresh whose response was lost. +- The login ends 30 days after its last refresh, or 90 days after it began, whichever is first, + matching "stay signed in" browser sessions. - Lore's client requests `offline_access` on every login; lore-forge issues a refresh token for it. - Revocation through the revocation endpoint ends the login. @@ -98,7 +117,10 @@ Audit records for exchanges are batched or sampled. See [storage.md](storage.md) - **Storage:** private keys are stored encrypted with the same environment-supplied key that protects provider secrets. - **Rotation:** the JWKS publishes the current key and the previous one. `loreserver` re-fetches - keys when it sees an unknown key ID, so rotation needs no server restart. + keys when it sees an unknown key ID, so rotation needs no server restart. The owner rotates + from `/admin/settings` or with `lore-forge rotate-signing-key` on the server; a running + lore-forge re-reads its keys every minute, so a rotation made by the command reaches it + within that time. Rotating twice retires the oldest key, ending tokens it signed. - **Stability:** keys persist across restarts. Lore's sample service regenerates its key on every start, which invalidates all outstanding tokens; lore-forge must not. @@ -106,13 +128,22 @@ Audit records for exchanges are batched or sampled. See [storage.md](storage.md) Lore records `identity` (or `sub` when absent) as the creator and committer of revisions. -**Recommended, not yet confirmed:** set it to the stable internal user ID and serve names +**Decided (owner, 2026-11-25):** set it to the stable internal user ID and serve names through Lore's `UserService`. See [accounts-and-sign-in.md](accounts-and-sign-in.md). +## Tokens for the web UI + +`Issuer::browse_token` mints a token for lore-forge's own pages to read a repository from +`loreserver` as the viewer: the viewer's identity, one `resources` entry for that repository +with only `read`, a one-minute lifetime, no `sid`. It is never handed to the browser. It is +refused when the viewer's grants do not include `read`. + ## Service accounts and CI - A service account is a non-human identity owned by a user or organisation. -- It logs in with client credentials, or with an API token through token exchange. +- It logs in with client credentials; its secrets are API tokens with the `lore` scope. + A person's own API token logs in through token exchange instead. +- Details are in [accounts-and-sign-in.md](accounts-and-sign-in.md). - It receives grants like any user. The `push-protected` action is how a CI account is allowed to push to a protected branch. @@ -121,11 +152,22 @@ through Lore's `UserService`. See [accounts-and-sign-in.md](accounts-and-sign-in | Change | Takes effect | | --- | --- | | Grant added or removed | Within five minutes, when the client's scoped token expires | -| CLI login revoked | When the current login token expires; no new tokens after that | +| CLI login revoked | Exchange refuses at once (it checks the login is live), so repository access ends within five minutes. The login token itself stays valid until it expires, at most an hour, for calls that name no repository | | User disabled | Same as a revoked login, for all of that user's logins | | Signing key rotated out | When removed from the JWKS | -Lifetimes for the login token and refresh token are not yet decided. +The exchange's liveness check is one indexed read. It keeps the exchange path free of writes. + +### Lifetimes + +Defaulted, not confirmed by the owner (`forge_id::issuer::Lifetimes`): + +| Item | Lifetime | +| --- | --- | +| Login token | 1 hour | +| Repository-scoped token | 5 minutes, never past the login token | +| CLI login (refresh) | 30 days idle, 90 days at most | +| Device code | 10 minutes, polled every 5 seconds | ## Security notes @@ -138,7 +180,5 @@ Lifetimes for the login token and refresh token are not yet decided. ## Open questions -- Login token and refresh token lifetimes. -- Whether the audience alone covers every host a token must reach, or a `root_domains` claim - is needed (relevant if `loreserver` and lore-forge are on unrelated domains). +- Confirm the lifetimes above. - Whether to keep an audit trail of token exchanges, and at what granularity. diff --git a/.ai/designs/web-ui.md b/.ai/designs/web-ui.md index 3d21e37..0d00e0a 100644 --- a/.ai/designs/web-ui.md +++ b/.ai/designs/web-ui.md @@ -1,6 +1,6 @@ # Web UI -Status: design, nothing built. Last updated 2026-11-25. +Status: phase 1 pages and the phase 2 repository browser are built. Last updated 2026-11-25. ## Approach @@ -13,13 +13,25 @@ no separate frontend application and no Node build step. | Templates | maud | Components are plain Rust functions, so a handler can return a whole page or one fragment. Askama is the alternative if HTML should live in template files | | Interactivity | htmx | Vendored, not fetched from a CDN | | Scripts | A few small hand-written ones | Only where HTML is not enough: diff viewer, image comparison, later 3D previews | -| Styles | Plain CSS with custom properties | | +| Styles | Plain CSS with custom properties | One stylesheet, `crates/forge-web/assets/app.css` | +| Look | The desktop client's pixel style: IBM VGA 8x16 font, Sweetie 16 palette, bevelled buttons, square panels | Owner, 2026-11-25 ("a similar facelift"). The font is self-hosted under `/static/`; its CC BY-SA licence is at `/licenses`, linked from every footer | | Assets | Embedded in the binary | One file to deploy | | Live updates | Server-sent events | Fed by Lore's notification stream: activity, lock state, CI status | | API | JSON under `/api/v1` | Calls the same core services as the pages; authenticated by API tokens | -The template and interactivity choices are recommendations that have not been explicitly -confirmed; "server-rendered" has. +All of these are confirmed by the owner; maud and htmx were confirmed on 2026-11-25. + +### One port for pages and gRPC + +Lore reaches the user directory and repository registry over gRPC at `user_url`. lore-forge +serves them on the same port as its pages and issuer, routing requests whose content type is +`application/grpc*` to the gRPC services and everything else to the web routes. So one public +URL is both the issuer and `user_url`. A reverse proxy in front must speak HTTP/2 to +lore-forge and pass gRPC through. + +htmx is not vendored yet: no phase 1 page needs it. Every phase 1 page works as plain forms: +a successful POST redirects with `?ok=` for its notice; a refused one re-renders the +form with the error and status 422. ## Why server rendering suits Lore @@ -47,8 +59,15 @@ Repository content is untrusted: Markdown, SVG and HTML files can carry script. - **Raw content on a separate origin.** Raw files and previews are served from a different hostname than the UI and issuer, so a malicious file cannot read session cookies or call the UI as the user. -- **Strict content security policy** on the main origin, with no inline script. Server - rendering makes this straightforward; htmx is configured to work without inline handlers. +- **Strict content security policy** on the main origin, with no inline script or style: + `default-src 'none'` with `'self'` for scripts, styles, fonts and images (`data:` images + too), `form-action 'self'`, `frame-ancestors 'none'`. A test renders every page and fails + on any `