From 0767576c4b23b53b3125f0dbe75adb731048d9ab Mon Sep 17 00:00:00 2001 From: CI Test Date: Tue, 10 Nov 2026 22:17:08 +0000 Subject: [PATCH 1/2] Add member sign-in, separate usage windows, and personal upstreams. A fresh install keeps the personal token as the inference credential, day and month usage stay separate, and a granted account is selectable only by its owner. Co-authored-by: Cursor --- AGENTS.md | 2 +- README.md | 2 +- architecture/deep-dive-dashboard.md | 8 +- architecture/deep-dive-on-prem-user-access.md | 45 +- architecture/deep-dive-routing.md | 6 + architecture/overview.md | 2 +- docs/api-reference.md | 12 +- docs/backup-restore.md | 4 +- docs/cli-reference.md | 9 +- docs/deployment.md | 11 +- docs/model-limits.md | 5 +- docs/providers.md | 7 + packaging/pypi/README.md | 2 +- plans/000-long-term-specification.md | 16 +- plans/001-terminology-and-domain-model.md | 3 + plans/002-long-term-roadmap.md | 8 +- ...rem-user-identity-and-policy-boundaries.md | 7 +- ...-0010-personal-upstream-account-custody.md | 201 +++++ ...-solo-sign-in-and-onboarding-credential.md | 226 ++++++ .../002-usage-windows-and-member-limits.md | 221 +++++ .../003-member-navigation-and-admin-roster.md | 221 +++++ ...4-personal-upstream-custody-and-routing.md | 307 +++++++ .../005-personal-upstream-browser-grant.md | 244 ++++++ plans/registry.md | 17 +- .../on-prem-member-access-roadmap.md | 342 ++++++++ .../db/migrations/0066_personal_upstream.sql | 35 + rust/assets/db/migrations/checksums.json | 3 +- rust/assets/runtime-manifest.json | 6 +- rust/config.example.toml | 8 +- rust/src/accounts/registry.rs | 15 +- rust/src/cli.rs | 64 ++ rust/src/config.rs | 70 +- rust/src/config_reload_policy.rs | 22 +- rust/src/coordinator/endpoints.rs | 10 +- rust/src/coordinator/finite.rs | 7 + rust/src/coordinator/streaming/coordinator.rs | 7 + rust/src/db/migrations.rs | 4 +- rust/src/identity.rs | 1 + rust/src/lib.rs | 1 + rust/src/model_policy.rs | 33 + rust/src/operations/config_mutation.rs | 331 +++++++- rust/src/personal_upstream.rs | 763 ++++++++++++++++++ rust/src/routing/eligibility.rs | 16 + rust/src/routing/router.rs | 12 + rust/src/runtime.rs | 344 +++++++- rust/src/runtime_lifecycle/generation.rs | 2 + rust/src/server/auth.rs | 10 +- rust/src/server/dashboard/admin.rs | 420 +++++++++- rust/src/server/dashboard/mod.rs | 16 +- rust/src/server/dashboard/render/admin.rs | 384 ++++++++- rust/src/server/dashboard/render/layout.rs | 77 +- rust/src/server/dashboard/tests.rs | 192 ++++- rust/src/server/health.rs | 22 +- rust/src/server/middleware.rs | 92 ++- rust/src/server/mod.rs | 33 +- rust/src/user_budget.rs | 250 ++++++ rust/tests/build_manifest.rs | 4 +- rust/tests/database_compatibility.rs | 14 +- rust/tests/on_prem_admin_ui.rs | 269 ++++++ rust/tests/on_prem_budgets.rs | 96 +++ rust/tests/on_prem_global_budgets.rs | 65 ++ rust/tests/on_prem_identity.rs | 157 ++++ rust/tests/on_prem_sessions.rs | 103 ++- rust/tests/routing_domain.rs | 71 ++ 64 files changed, 5754 insertions(+), 203 deletions(-) create mode 100644 plans/adrs/ADR-0010-personal-upstream-account-custody.md create mode 100644 plans/implementation/on-prem-member-access/001-solo-sign-in-and-onboarding-credential.md create mode 100644 plans/implementation/on-prem-member-access/002-usage-windows-and-member-limits.md create mode 100644 plans/implementation/on-prem-member-access/003-member-navigation-and-admin-roster.md create mode 100644 plans/implementation/on-prem-member-access/004-personal-upstream-custody-and-routing.md create mode 100644 plans/implementation/on-prem-member-access/005-personal-upstream-browser-grant.md create mode 100644 plans/subsystems/on-prem-member-access-roadmap.md create mode 100644 rust/assets/db/migrations/0066_personal_upstream.sql create mode 100644 rust/src/personal_upstream.rs diff --git a/AGENTS.md b/AGENTS.md index 5a82d317..d26972b5 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -36,7 +36,7 @@ providers/transport → `deep-dive-providers.md`; reload/restart → `model_policy.rs` on-prem user access, `providers/` transport, `runtime_lifecycle/` generations + `reload.rs` + `task_supervisor.rs`, `operations/` local lifecycle, `db/` + - `rust/assets/db/migrations/` v1–v65 immutable. + `rust/assets/db/migrations/` v1–v66 immutable. - Reusable policy crates: `rust/crates/eggpool-model-routing/` (neutral validation/compilation only; selector execution and affinity cache stay in `rust/src/`), `rust/crates/eggpool-client-config/` (portable Codex/OpenCode projection, profiles, `epc1` tokens, V1/V2 renderers, TOML/JSONC-preserving mutation; EggPool `Config`/catalog/DB/key/endpoint/CLI/file IO stays in `rust/src/operations/integrations.rs`), `rust/crates/eggpool-provider-profile/` (secret-free sans-I/O provider-profile contract plus the canonical bundled asset at `assets/_provider_profiles.toml`; `rust/src/provider_profile.rs` is the only EggPool reader), `rust/crates/eggpool-wire/` (neutral sans-I/O wire kernel; execution stays in `rust/src/`), `rust/crates/eggpool-connect/` (narrow `eggpool-connect` binary: plan/install/verify/backups/restore/remove with byte-exact backups, atomic writes, automatic rollback; no Axum/SQLite/Eggress, no proxy/agent/daemon). - Tooling only (never a runtime fallback): repo-root `pyproject.toml`, `scripts/`, `tests/tooling/`. `scripts/qualification_sbc.py` is the sole physical-SBC runner (loopback-only, aggregate-only, non-CI). Native tests live in `rust/tests/` (serial; there is no `coordinator_c012`; streaming files are `coordinator.rs`, `execution.rs`, `terminal.rs`, `timeout.rs`, `types.rs`, `diagnostics.rs`). - Config resolution: `--config` > `$EGGPOOL_CONFIG` > `~/.config/eggpool/config.toml` > `./config.toml`. Provider/upstream keys come from environment/`.env`, never committed; the server key lives under `[server]` (`api_key` via `eggpool newkey`, or `api_key_env`). Examples: `rust/config.example.toml`, `rust/config.local.example.toml`, `rust/config.sbc.example.toml`. diff --git a/README.md b/README.md index ba158646..4af03a4a 100644 --- a/README.md +++ b/README.md @@ -115,7 +115,7 @@ Generated configs reference `EGGPOOL_API_KEY` without embedding the key. Set it ## Dashboard & LAN Access -By default EggPool binds `0.0.0.0:11300` and serves a public read-only dashboard at `http://:11300/`. To share with desktops on your LAN, set `[integrations].advertise_base_url = "http://:11300/v1"`, run `eggpool rehash` (advertised URL is live-reloadable profile output; it never changes the listen socket), then export a profile with `eggpool configremote codex`. Lock it down with `[server].host = "127.0.0.1"` (local only) or `eggpool dashboard public --off` (key required on the dashboard too). See [Firewall](https://github.com/eggstack/eggpool/blob/main/docs/firewall.md). +By default EggPool binds `0.0.0.0:11300`. After `eggpool onboard`, sign in at `http://:11300/login` and export the one-time personal token as `EGGPOOL_API_KEY`. A database that is still `legacy_unmigrated` can serve a public read-only dashboard at `http://:11300/`. To share with desktops on your LAN, set `[integrations].advertise_base_url = "http://:11300/v1"`, run `eggpool rehash` (advertised URL is live-reloadable profile output; it never changes the listen socket), then export a profile with `eggpool configremote codex`. Lock a legacy dashboard down with `[server].host = "127.0.0.1"` (local only) or `eggpool dashboard public --off` (key required on that legacy dashboard too). See [Firewall](https://github.com/eggstack/eggpool/blob/main/docs/firewall.md). Browser password sign-in is shown only over loopback or trusted HTTPS proxy transport. A remote plaintext HTTP visit to `/login` receives an explanation diff --git a/architecture/deep-dive-dashboard.md b/architecture/deep-dive-dashboard.md index 5d073ed6..ed3580bb 100644 --- a/architecture/deep-dive-dashboard.md +++ b/architecture/deep-dive-dashboard.md @@ -154,9 +154,11 @@ page, not a fragment. `/admin/audit`, `/my-account`, `/my-account/models`, and the one-shot personal-token page) use `dashboard_standalone_page()`; the one-shot token page keeps its bare shell but still resolves the theme. -- **Navigation chrome.** The shared navigation (`DASHBOARD_NAVIGATION`) is - rendered by the dashboard layout and by every standalone shell, so there is - always a route back to the overview. Its destinations are fixed. +- **Navigation chrome.** Operator pages render `DASHBOARD_NAVIGATION`, so + an administrator always has a route back to the overview. Member pages for + `/my-account`, `/my-account/models`, and `/usage` render the member set: + My account, My models, Usage, and Password. An administrator viewing those + same pages keeps the operator set. - **Table chrome.** The stylesheet scopes the table chrome to `table.data`. Every table the renderers emit is opened through `DASHBOARD_TABLE_OPEN` or `DASHBOARD_TABLE_OPEN_COMPACT`, and a source-level guard fails if a table is diff --git a/architecture/deep-dive-on-prem-user-access.md b/architecture/deep-dive-on-prem-user-access.md index 0c8df59b..85a54cee 100644 --- a/architecture/deep-dive-on-prem-user-access.md +++ b/architecture/deep-dive-on-prem-user-access.md @@ -220,24 +220,38 @@ from the measured lookup overhead. `server/dashboard/admin.rs` owns the HTML surfaces and their form handlers. Every handler is a thin adapter: it validates the CSRF form field, resolves -the actor, and delegates to `identity.rs` or `model_policy.rs`. +the actor, and delegates to `identity.rs`, `model_policy.rs`, or +`personal_upstream.rs`. Admin surfaces: `/users`, `/profiles`, `/usage`, `/admin/audit`, and the `/admin/users/*` action family (create, state, password, token, revoke -tokens, profile assignment, override add/remove, budget), the +tokens, profile assignment, override add/remove, budget, personal-upstream +grant and remove), the `/admin/budget/instance*` family, and the `/admin/profiles/*` family (create, default, update, delete, rule add/remove, preference). Member surfaces: `/login`, `/logout`, `/account`, `/account/landing`, -`/account/password`, `/my-account`, `/my-account/models`, `/account/tokens`, -`/account/tokens/revoke`, `/usage`, and `/api/user-budget`. +`/account/password`, `/my-account`, `/my-account/models`, `/my-account/upstreams`, +`/my-account/upstreams/remove`, `/account/tokens`, +`/account/tokens/revoke`, `/usage`, and `/api/user-budget`. The personal +upstream form lives on My account. It is not a navigation item. The key field +is rendered only when that member's effective grant is allow, and a personal +API token cannot post it. A member who signs in lands on `/account/landing`, which links the member destinations (`/my-account`, `/my-account/models`, `/usage`) and exposes no administrative route and no administrative datum, so the member surface is -reachable without knowing a URL. An administrator who signs in lands on +reachable without knowing a URL. The same member destinations are the only +links in the navigation of `/my-account`, `/my-account/models`, and `/usage`. +An administrator keeps the operator navigation on those pages. An administrator who signs in lands on `/account`, which links back to the dashboard overview. +Usage projections stay inside one window kind. The administrator usage page +shows the current UTC day and the current UTC month as separate tables. +A member sees their own rows labeled day or month, the remaining allowance +on their own current windows, and the configured instance ceilings. Instance +usage totals stay on the administrator `/api/user-budget` response. + The route-role gate lives in `server/middleware.rs`, not here. A non-administrator browser principal is confined to the member surfaces; an administrator-only path answers `403` with a page that names the refusal and points at the member @@ -249,12 +263,13 @@ never a password, a token, or any other secret. The local CLI surface is `eggpool users`, whose subcommands are `bootstrap`, `add`, `disable`, `enable`, `show`, `list`, `reset-password`, `token`, -`revoke`, `enable-managed`, `policy`, `budget`, `global-budget`, and -`defaults`. +`revoke`, `enable-managed`, `policy`, `budget`, `global-budget`, +`defaults`, and `upstream`. `upstream add` reads the key from a TTY or +`--secret-stdin` and writes it only to the config-adjacent `.env`. ## Durable tables -The subsystem's tables are migrations 55–63 of the embedded chain: +The subsystem's tables are migrations 55–63 and 66 of the embedded chain: | Migration | Tables | |---|---| @@ -267,6 +282,7 @@ The subsystem's tables are migrations 55–63 of the embedded chain: | 61 `user_budget_enforcement` | enforcement column and worst-case hold/price-provenance columns on the budget tables | | 62 `instance_budgets` | `instance_budget_rules`, `instance_budget_reservations`, `instance_budget_usage`, `instance_budget_rule_audit` | | 63 `default_member_profile` | `policy_state.default_member_profile_id` | +| 66 `personal_upstream` | `personal_upstream_grants`, `personal_upstream_bindings` | `requests.user_id` is a nullable column without a foreign key, so disabling or removing a local user cannot erase request attribution. Internal semantic @@ -275,9 +291,11 @@ user-history queries; `identity::recent_user_requests` uses the `(user_id, started_at DESC, id DESC)` index, clamps reads to 500 rows, and returns content-free request facts. -No table stores a plaintext password, a plaintext token, a prompt, a raw -body, or a cache key. Backups therefore carry identity records and -non-recoverable credential digests only. +No table stores a plaintext password, a plaintext token, a provider key, a +prompt, a raw body, or a cache key. A personal upstream binding names the +provider, account, and user. The key stays in the operator environment file. +Backups therefore carry identity records and non-recoverable credential +digests only, plus the environment file when the backup includes it. ## Invariants @@ -289,6 +307,11 @@ non-recoverable credential digests only. disablement fails closed at commit time. - A policy snapshot is immutable for the request that admitted it. - Downstream user budgets and upstream provider quota remain independent. +- A personal upstream account is selectable only by its owner. No binding + means the account stays shared. The instance grant defaults to deny and + does not change routing. Disabling a user withdraws that user's active + bindings in the same transaction; enabling the user does not restore them. + Changing a grant does not withdraw a binding. - The single SQLite connection/gate/worker, WAL/NORMAL, the generation lease model, and the publication/finalization ownership are unchanged by this subsystem. diff --git a/architecture/deep-dive-routing.md b/architecture/deep-dive-routing.md index f3fcf4e8..74e90f21 100644 --- a/architecture/deep-dive-routing.md +++ b/architecture/deep-dive-routing.md @@ -50,6 +50,12 @@ derives it from `RoutingConfig` (`local_quota_mode`, `fairness_mode`, `fairness_ `capability_policy`). `RoutingRequestFacts::from_model_id` splits an optional `provider/model` suffix with `ModelCatalogCache::parse_model_provider`. +Before that per-account scoring, a generation snapshot of personal upstream +bindings drops an account that is withdrawn, ambiguously owned, or bound to +someone other than the request principal (`personal_upstream`). A missing +binding leaves the account shared. The legacy shared-key principal has no user +id and cannot select a bound account. + Per account, `candidate_for_account` checks, in order: enabled, usable credentials, requested provider (`no_provider` when the account has no provider vs `wrong_provider`), request surface (`RequestSurface`), requested/transcodable protocol, diff --git a/architecture/overview.md b/architecture/overview.md index 62924aad..36df49b2 100644 --- a/architecture/overview.md +++ b/architecture/overview.md @@ -353,7 +353,7 @@ is the only persistence boundary. `db/` owns only the `backup_to` snapshot primitive; backup orchestration lives in `operations/backup.rs` and crash repair in `runtime_lifecycle/recovery.rs` plus coordinator reconciliation. Migrations (`rust/assets/db/migrations/`, -currently v1–v65 with `checksums.json`) are embedded and immutable; commit or +currently v1–v66 with `checksums.json`) are embedded and immutable; commit or ownership ambiguity fails closed; startup reconciliation repairs only covered states. Repositories accept no unbounded diagnostic content and never store credentials, prompts, raw bodies, or cache keys. diff --git a/docs/api-reference.md b/docs/api-reference.md index 4ad4476c..fe890f1d 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -200,11 +200,13 @@ Requests denied because a hard rule cannot be bounded return HTTP 429 with machine code `hard_budget_not_enforceable` before any upstream submission. The response gives corrective guidance for an explicit output cap and, when applicable, an operator tariff. Exhausted rules use the code -`budget_exceeded`. Administrator responses additionally include -`instance_rules` and `instance_usage`: the single instance-wide ceiling -intersected with every per-user rule. Members never receive instance fields, -so one member cannot observe the shared ceiling or infer other users' -consumption from it. +`budget_exceeded`. `remaining` reports, for the target user's own current +UTC day and month rules, each ceiling minus settled usage minus active holds. +A dimension with no ceiling has `remaining: null`. Both member and +administrator responses include `instance_rules`, the configured shared +ceilings. Administrator responses additionally include `instance_usage`. +Members do not receive instance usage or another user's rows, so they cannot +infer who else consumed the shared ceiling. An optional `[admission_fairness]` policy can add process-local short-window request throttles before request-body collection. A throttle returns HTTP 429 diff --git a/docs/backup-restore.md b/docs/backup-restore.md index 88a6be43..4567a47a 100644 --- a/docs/backup-restore.md +++ b/docs/backup-restore.md @@ -49,7 +49,9 @@ and the SQLite database (plus `-wal`/`-shm` if present) into a single timestamped `.zip` archive. The database snapshot includes local users, budget rules and audit records, -active budget holds, and settled user/model usage. Restoring the snapshot +active budget holds, settled user/model usage, and secret-free personal +upstream bindings. The provider key for a personal account lives in `.env`, +which this backup includes when `include_env` is true. Restoring the snapshot preserves the remaining budget state; crash reconciliation settles unknown in-flight use conservatively before new requests resume. diff --git a/docs/cli-reference.md b/docs/cli-reference.md index 7e9f9fac..257b45c3 100644 --- a/docs/cli-reference.md +++ b/docs/cli-reference.md @@ -70,12 +70,17 @@ The same fields are available to an administrator browser session at | `eggpool users defaults clear` | Remove the default; future unassigned members remain deny-by-default | | `eggpool users show USER` | Show one user's role, state and forced-password-change status without secrets | | `eggpool users list` | List local usernames, role and status | -| `eggpool users disable USER` | Disable a user and revoke their sessions and personal tokens | -| `eggpool users enable USER` | Reactivate a user; previously revoked tokens remain revoked | +| `eggpool users disable USER` | Disable a user, revoke their sessions and personal tokens, and withdraw that user's personal upstream accounts | +| `eggpool users enable USER` | Reactivate a user; previously revoked tokens and withdrawn personal accounts stay withdrawn | | `eggpool users token USER` | Issue a personal inference, discovery, and integrations token (`--label` optional; `--show-secret` allows non-TTY output). Tool-execution scopes are not issued | | `eggpool users revoke USER` | Revoke all personal API tokens for a user | | `eggpool users reset-password USER` | Reset a local password and revoke that user's API tokens and browser sessions (`--password-stdin` supported) | | `eggpool users enable-managed` | Explicitly record managed access (`--actor ADMIN`, default `admin`); works even when retired legacy settings remain | +| `eggpool users upstream default allow\|deny` | Set the instance personal-upstream self-service default. A fresh database denies it | +| `eggpool users upstream grant USER allow\|deny\|inherit` | Set one user's self-service grant. Deny does not withdraw an account that is already bound | +| `eggpool users upstream add USER --provider ID --name ACCOUNT` | Bind a bundled-provider account to that user. The key comes from a TTY prompt or `--secret-stdin` and is written only to the config-adjacent `.env` | +| `eggpool users upstream list [USER]` | List personal bindings: user, provider, account, state, and environment-variable name. The key is not shown | +| `eggpool users upstream remove USER --provider ID --name ACCOUNT` | Withdraw the binding and remove the account from `config.toml` and `.env` | | `eggpool users policy create ID NAME allow\|deny` | Create an exact-rule model profile | | `eggpool users policy rule PROFILE MODEL allow\|deny` | Add or replace one exact model or `model/provider` rule | | `eggpool users policy assign USER PROFILE` | Assign a profile to a local user | diff --git a/docs/deployment.md b/docs/deployment.md index ce16ccce..67e956f7 100644 --- a/docs/deployment.md +++ b/docs/deployment.md @@ -55,7 +55,9 @@ prints the resolved config path. After install, `eggpool onboard` walks the operator through provider connections, configuration validation, and an optional server start. On a new database it also creates the initial local administrator with a -non-default password and prints one personal API token once. For unattended +non-default password and prints one personal API token once. That token is +the inference credential. The same run does not write a new `[server].api_key`. +Browser sign-in is `/login` on the listen address. For unattended bootstrap, pass `--password-stdin` and provide the password on stdin; the password is never accepted in argv. Secret output is suppressed when stdout is not a terminal unless `--show-secret` is explicitly passed. Existing databases keep their legacy @@ -75,7 +77,12 @@ member unassigned. Existing assignments are never changed by setting or clearing the default. No budget template is copied: user and instance budget rules remain independently configured. Personal tokens are for inference, model discovery, and the integration profile; they do not authorize dashboard -or admin pages. The configured server API key remains a legacy shared +or admin pages, and they cannot add or remove a personal upstream account. +On a small team, an administrator grants personal-upstream self-service from +the users page. A granted member submits one bundled-provider key on My +account. The key is written to the operator environment file and is not stored +in the database. Denying the grant does not remove an account that is already +bound. Adding an account for someone else stays `eggpool users upstream add`. The configured server API key remains a legacy shared inference credential only while the database is `legacy_unmigrated`. Do not share it with new users; issue an individual token instead. diff --git a/docs/model-limits.md b/docs/model-limits.md index 5dbca55f..d1e6be8b 100644 --- a/docs/model-limits.md +++ b/docs/model-limits.md @@ -224,8 +224,9 @@ count against it too. Each logical request counts once across failover and retries; hard/estimated semantics and the operator-tariff trust boundary match the per-user contract above. Global counters never depend on a user row, so disabling or deleting a user preserves history and remaining headroom. Members -see only their own rules and usage; instance ceilings and aggregate usage are -admin-visible only. +see their own rules, their own settled windows, and the remaining allowance +on those rules. They also see the configured instance ceilings. Instance +usage totals and other users' rows stay on the administrator response. Default member profiles do not create or copy budget rules. Configure user and instance ceilings separately; changing the default model profile leaves all diff --git a/docs/providers.md b/docs/providers.md index ddf0fc45..96a07ede 100644 --- a/docs/providers.md +++ b/docs/providers.md @@ -73,6 +73,13 @@ eggpool connect list eggpool connect ``` +A granted member can add one bundled-provider account from My account, and an +administrator can add one with `eggpool users upstream add`. The key is written +only to the config-adjacent `.env` as `api_key_env`. SQLite stores the +secret-free binding. The account is selectable only by that user. An account +with no binding stays shared. Members cannot supply a URL, proxy, header, or +weight. Amazon Bedrock is not a bundled provider and cannot be added this way. + ### Manual Configuration Add a provider block to `config.toml`: diff --git a/packaging/pypi/README.md b/packaging/pypi/README.md index 4006affe..015a0b90 100644 --- a/packaging/pypi/README.md +++ b/packaging/pypi/README.md @@ -115,7 +115,7 @@ Generated configs reference `EGGPOOL_API_KEY` without embedding the key. Set it ## Dashboard & LAN Access -By default EggPool binds `0.0.0.0:11300` and serves a public read-only dashboard at `http://:11300/`. To share with desktops on your LAN, set `[integrations].advertise_base_url = "http://:11300/v1"`, run `eggpool rehash` (advertised URL is live-reloadable profile output; it never changes the listen socket), then export a profile with `eggpool configremote codex`. Lock it down with `[server].host = "127.0.0.1"` (local only) or `eggpool dashboard public --off` (key required on the dashboard too). See [Firewall](https://github.com/eggstack/eggpool/blob/main/docs/firewall.md). +By default EggPool binds `0.0.0.0:11300`. After `eggpool onboard`, sign in at `http://:11300/login` and export the one-time personal token as `EGGPOOL_API_KEY`. A database that is still `legacy_unmigrated` can serve a public read-only dashboard at `http://:11300/`. To share with desktops on your LAN, set `[integrations].advertise_base_url = "http://:11300/v1"`, run `eggpool rehash` (advertised URL is live-reloadable profile output; it never changes the listen socket), then export a profile with `eggpool configremote codex`. Lock a legacy dashboard down with `[server].host = "127.0.0.1"` (local only) or `eggpool dashboard public --off` (key required on that legacy dashboard too). See [Firewall](https://github.com/eggstack/eggpool/blob/main/docs/firewall.md). Browser password sign-in is shown only over loopback or trusted HTTPS proxy transport. A remote plaintext HTTP visit to `/login` receives an explanation diff --git a/plans/000-long-term-specification.md b/plans/000-long-term-specification.md index ed8e1c74..0987cbf7 100644 --- a/plans/000-long-term-specification.md +++ b/plans/000-long-term-specification.md @@ -41,9 +41,13 @@ simultaneous generations; any team throughput/concurrency claim requires representative ordinary-server hardware, workload and storage measurements. This is not a SaaS, enterprise IAM, or multi-organization hosting product. Provider topology, upstream credentials, and routing configuration remain in -operator-owned TOML/environment files; human identity, access profiles, +operator-owned TOML/environment files. A member whose personal-upstream grant +allows it may submit one bundled-provider secret through the server process; +the process writes that secret only to the operator environment file, and +SQLite stores the secret-free binding. Human identity, access profiles, sessions, individual credentials, user quotas, and usage statistics belong in -SQLite. See accepted `plans/adrs/ADR-0002-on-prem-user-identity-and-policy-boundaries.md`. +SQLite. See accepted `plans/adrs/ADR-0002-on-prem-user-identity-and-policy-boundaries.md` +and accepted `plans/adrs/ADR-0010-personal-upstream-account-custody.md`. ## 2. End-state invariants (normative) @@ -111,9 +115,11 @@ SQLite. See accepted `plans/adrs/ADR-0002-on-prem-user-identity-and-policy-bound admission representation internally. - Upstream `accounts` and account quotas describe provider credentials/capacity, - never downstream people. Durable human identities, policy versions, browser - sessions, client credentials, and user usage are separate database-owned facts. - Provider TOML and local admin access must not be writable by ordinary users. + never downstream people. A separate personal-upstream binding may restrict + which principal can select an account. Durable human identities, policy + versions, browser sessions, client credentials, and user usage are separate + database-owned facts. Ordinary users still cannot write provider TOML or + the environment file directly. ## 4. Protocol and compatibility diff --git a/plans/001-terminology-and-domain-model.md b/plans/001-terminology-and-domain-model.md index d488aea8..68a019c1 100644 --- a/plans/001-terminology-and-domain-model.md +++ b/plans/001-terminology-and-domain-model.md @@ -16,6 +16,9 @@ this document is normative. upstream provider account. The initial user is the local administrator. - **Provider account** — an upstream configured provider credential and its health, scoring, and provider-quota state (`accounts` table). +- **Personal upstream binding** — a secret-free record that one configured + provider account may be selected only by one user. No binding means the + account is shared. A user remains distinct from a provider account. - **Principal** — authenticated downstream request identity (user ID and optional client credential ID); never trusted from caller-supplied identity headers. - **Client credential** — revocable per-user secret for agent/API access, distinct diff --git a/plans/002-long-term-roadmap.md b/plans/002-long-term-roadmap.md index c5d0ea5d..7c5fa706 100644 --- a/plans/002-long-term-roadmap.md +++ b/plans/002-long-term-roadmap.md @@ -86,9 +86,13 @@ Small teams are expected primarily on ordinary on-prem servers with durable storage; Pi/microSD tests are a lightweight solo regression baseline, not the default team throughput acceptance target. Authorized clients may route to operator-configured hosted or self-hosted LLMs; all provider secrets/topology -remain under TOML/environment ownership. +remain under TOML/environment ownership. A granted member may submit one +bundled-provider secret through the server for an account only that member +can spend. Solo installs keep shared operator accounts and do not ask for a +personal upstream key. -- Authority: `plans/adrs/ADR-0002-on-prem-user-identity-and-policy-boundaries.md` +- Authority: `plans/adrs/ADR-0002-on-prem-user-identity-and-policy-boundaries.md`, + `plans/adrs/ADR-0010-personal-upstream-account-custody.md`, and `plans/subsystems/on-prem-user-access-roadmap.md`. - Order: secure administrator bootstrap and user credentials; browser-session and route authorization; principal propagation/attribution; model-policy diff --git a/plans/adrs/ADR-0002-on-prem-user-identity-and-policy-boundaries.md b/plans/adrs/ADR-0002-on-prem-user-identity-and-policy-boundaries.md index 81bc8683..52518137 100644 --- a/plans/adrs/ADR-0002-on-prem-user-identity-and-policy-boundaries.md +++ b/plans/adrs/ADR-0002-on-prem-user-identity-and-policy-boundaries.md @@ -198,4 +198,9 @@ external identity dependency. ## Supersession -None. +Accepted ADR-0010 supersedes Decision items 1 and 7 only for the granted +personal-upstream path: the server process may accept one bundled-provider +secret into the operator environment file, and SQLite may store the +secret-free binding that restricts selection. The remainder of this Decision +stays in force, including one active administrator, no public signup, and no +organization id. The Decision text above is unchanged. diff --git a/plans/adrs/ADR-0010-personal-upstream-account-custody.md b/plans/adrs/ADR-0010-personal-upstream-account-custody.md new file mode 100644 index 00000000..5a3ba650 --- /dev/null +++ b/plans/adrs/ADR-0010-personal-upstream-account-custody.md @@ -0,0 +1,201 @@ +# ADR-0010: Personal upstream account custody + +Status: accepted + +Date: 2026-11-10 + +Decision owners: project maintainers (explicit product direction, 2026-11-10) + +Related specification sections: + +- `plans/000-long-term-specification.md#1-product-definition` +- `plans/000-long-term-specification.md#2-end-state-invariants-normative` +- `plans/000-long-term-specification.md#3-ownership-boundaries-normative` +- `plans/001-terminology-and-domain-model.md#identity-and-lifecycle-terms` +- `plans/002-long-term-roadmap.md#phase-5--optional-on-prem-small-team-access-and-budgeting` + +Affected subsystem roadmaps: + +- `plans/subsystems/on-prem-member-access-roadmap.md` +- `plans/subsystems/on-prem-user-access-roadmap.md` (closed; not reopened) + +## Context + +EggPool is one on-prem instance. Operator `eggpool connect` accounts are +shared by every principal whose model policy allows the model. +`rust/src/routing/` does not consult the caller. The `accounts` table stores +provider capacity facts and an environment-variable name, never a person and +never a secret value. + +Accepted ADR-0002 keeps upstream secrets in operator TOML and environment +files, forbids a provider-secret web editor, and says ordinary users must not +write provider configuration. The closed on-prem user-access roadmap lists +custom per-user provider secrets as a non-goal. That design is what shipped. + +The 2026-11-10 audit recorded the resulting gap. A member can see their own +usage, limits, models, and client credentials. A member cannot add an +upstream credential that only they can spend, and an administrator cannot +allow or deny that ability. The requested examples are an individual +OpenCode Go key and an individual Amazon Bedrock account. OpenCode Go is a +bundled provider profile. Amazon Bedrock is not. + +Long-term invariant 8 still requires credentials to stay out of SQLite, +logs, and diagnostics. The `accounts` table must continue to describe +provider capacity rather than downstream people. This ADR does not weaken +either rule. It proposes a narrow, grant-gated way for the server process +to accept one upstream secret and keep it in the operator secret file. + +## Decision drivers + +- Solo install and shared operator accounts remain the default. +- A small local team needs per-person upstream keys without sharing those + keys across the team. +- An administrator must be able to deny the ability for the instance, or + allow or deny it for one user. +- The member must not gain a shell, a config path, or a write to arbitrary + upstream URLs. +- A crash or a failed reload must not turn a personal account into a shared + account. +- Existing live reload, one SQLite writer, and generation publication stay + the only topology path. + +## Considered options + +### Option A — Keep every upstream account shared + +Members keep using operator keys, limited by model policy and budgets. +This preserves ADR-0002 and needs no secret-handling change. It leaves the +requested personal-key path closed. + +### Option B — Store the upstream secret in SQLite beside the user + +A member form writes the key into a user-owned table. Routing reads it per +request. This puts a credential in persistence, which invariant 8 forbids, +and it makes the `accounts` row describe a person. + +### Option C — Operator-mediated file custody and a secret-free binding + +The process writes the secret only to the config-adjacent environment file +and writes a non-secret binding row that names the owner. Shared accounts +have no binding. Eligibility consults the binding. Self-service exists only +when an administrator grant allows it. + +## Decision + +Option C, if this ADR is accepted. Until then, no milestone may implement it. + +1. **Default.** The instance self-service grant is `deny`. Existing shared + accounts stay shared. Solo onboarding does not ask for a personal + upstream key. +2. **Grant.** An instance default of `allow` or `deny`, and a per-user + value of `allow`, `deny`, or `inherit`. The user value wins when it is + not `inherit`. The grant controls self-service only. The active + administrator may register or remove a personal upstream for any user + while that user's self-service grant is `deny`. +3. **Custody.** The plaintext secret is read from a hidden TTY or stdin, + never from argv. The process writes it to the config-adjacent `.env` + resolved by `rust/src/operations/paths.rs`, under a new variable name. + The account stanza stores `api_key_env` only. SQLite, audit rows, reload + diagnostics, logs, and dashboard HTML do not receive the secret. +4. **Binding.** A new table binds one `(provider_id, account_name)` to one + `user_id`. It stores no secret. No row means the account is shared. + An `active` row means only that user can be routed to it. A `withdrawn` + row means nobody can be routed to it. A missing config account does not + become shared. Two bindings for one account are a failed migration, not + a choice. +5. **Publication.** The binding snapshot is fixed in the published + generation. In-flight work keeps its generation. The next publication + uses `config_reload_policy.rs::classify_transition`. Account topology + stays live-reloadable. This ADR adds no second reload list. +6. **Selection.** The filter runs before score, health, and quota choice. + It does not pin an account, bypass model policy, or bypass provider + health and quota. A legacy shared-key principal has no user id and + cannot select a bound account. +7. **Surface.** Self-service uses a browser session, the existing CSRF + check, and the existing local-or-trusted-HTTPS gate. Personal API + tokens do not authorize it. The member supplies an account name and a + secret for a bundled provider id. The server copies that provider's + endpoint from the bundled profile. The member does not supply a base + URL, proxy, or header. +8. **Providers.** Any bundled profile id is eligible, including + `opencode-go`. Adding Amazon Bedrock, or any other new provider, is a + separate provider-profile change and is not authorized here. + +On acceptance, amend only the sentences this ADR names: + +- `plans/000-long-term-specification.md` product definition: personal + upstream secrets remain operator-process files; a granted member may + submit one through the server; SQLite stores the binding only. +- `plans/000-long-term-specification.md` ownership boundaries: the + `accounts` table still does not describe a person; a separate binding + may restrict selection. Ordinary users still cannot write TOML or `.env` + directly. +- `plans/001-terminology-and-domain-model.md`: add the term for a personal + upstream binding. A user remains distinct from a provider account. +- `plans/002-long-term-roadmap.md` Phase 5: record this granted path and + keep the solo shared-account default. +- `plans/adrs/ADR-0002-on-prem-user-identity-and-policy-boundaries.md` + Supersession: state that this ADR supersedes Decision items 1 and 7 only + for the granted path. Do not rewrite the ADR-0002 Decision text. + +Invariant 8 is unchanged. Acceptance does not authorize a secret column. + +## Consequences + +### Positive + +- One person can spend their own provider key without exposing it to the + team. +- The administrator can turn self-service off for the instance or for one + person. +- Shared operator accounts and the solo install stay the default. + +### Negative + +- The server process becomes a writer of upstream secrets. A bug in the + file transaction can leak a key into a diagnostic or leave a withdrawn + account in config. +- Personal keys enlarge the generation's account topology. Health and quota + stay per account, so a bad personal key must not be allowed to suppress a + shared account. + +### Neutral or deferred + +- Amazon Bedrock and any other provider that is not already bundled. +- Member-supplied base URLs, proxies, and headers. +- Preferring a personal account over a healthier shared account. +- A second administrator. + +## Compatibility and migration + +Append one new migration after v65. Do not edit v1–v65. Existing accounts +gain no binding and remain shared. Existing `.env` entries stay. A personal +account name that collides with a configured account is rejected. Backup of +SQLite continues to exclude the secret; operators who back up the config +directory already back up `.env` and must treat that file as secret. + +## Security and reliability implications + +The secret crosses the browser only on the existing authenticated, +same-origin, CSRF-checked, transport-gated form, and only for a principal +whose effective grant is `allow` or for the active administrator. Failed +publication restores the previous config and `.env` bytes and removes or +withdraws the binding so the account cannot be selected as shared. Reload +diffs use the existing secret-path redaction. Disabling a user withdraws +eligibility of that user's active bindings on the next publication. + +## Verification + +A member without a grant receives no form and a rejected mutation. A member +with a grant can add a bundled provider account and is the only principal +who can be routed to it. Another member, the legacy shared key, and an +unauthenticated caller cannot. Revocation and a failed reload leave the +account ineligible. Tests assert the secret is absent from SQLite, audit +rows, and reload diagnostics. Default and `--no-default-features` serial +suites pass. + +## Supersession + +Accepted. Supersedes ADR-0002 Decision items 1 and 7 only for this granted +path. The remainder of ADR-0002 stays in force, including one active +administrator, no public signup, and no organization id. diff --git a/plans/implementation/on-prem-member-access/001-solo-sign-in-and-onboarding-credential.md b/plans/implementation/on-prem-member-access/001-solo-sign-in-and-onboarding-credential.md new file mode 100644 index 00000000..4a2300fb --- /dev/null +++ b/plans/implementation/on-prem-member-access/001-solo-sign-in-and-onboarding-credential.md @@ -0,0 +1,226 @@ +# On-Prem Member Access Milestone 001 — Solo sign-in and onboarding credential + +Status: active + +Repository baseline: `9da5e2d383c73035850c37f8125c145b8b7ff9ff` + +Source roadmap: + +- `plans/subsystems/on-prem-member-access-roadmap.md#milestone-1--solo-sign-in-and-onboarding-credential` + +Long-term requirements: + +- `plans/000-long-term-specification.md#1-product-definition` +- `plans/000-long-term-specification.md#2-end-state-invariants-normative` +- `plans/002-long-term-roadmap.md#phase-5--optional-on-prem-small-team-access-and-budgeting` + +Applicable ADRs: + +- `plans/adrs/ADR-0002-on-prem-user-identity-and-policy-boundaries.md` +- `plans/adrs/ADR-0004-browser-session-csrf-delivery-and-account-scoped-sign-in-throttling.md` +- None of ADR-0010. This milestone does not add upstream custody. + +Primary class: capability + +## 1. Objective + +A fresh `eggpool onboard` creates the local administrator and one personal +client token, and it does not also write a server API key that the same +command retires. A browser that opens a protected HTML page before signing +in is shown how to reach `/login`. + +## 2. Why this milestone is ready + +No hard or interface dependencies. ADR-0002 already requires the first +administrator and the personal token. This milestone aligns the fresh-install +output with that rule. + +## 3. Current implementation evidence + +`onboard` in `rust/src/runtime.rs` treats a missing database as +`bootstrap_admin = true` and `identity_initialized = false`. +`should_generate_legacy_server_key` returns true in that case, so the +command writes `[server].api_key` and then calls `identity::bootstrap_admin`, +which sets `admin_initialized`. `legacy_server_key_allowed` in +`rust/src/server/middleware.rs` is true only for `legacy_unmigrated`. + +The unit test `onboarding_does_not_create_a_legacy_key_after_admin_initialization` +covers a later run, after identity is already initialized. It does not cover +the same-run bootstrap. + +Unauthenticated requests that fall through to the session check return JSON +from `unauthorized`. `GET /login` already renders the sign-in document in +`rust/src/server/auth.rs` and is unconditionally public. +`rust/config.example.toml` says the server key generated by onboard still +guards inference. + +## 4. Invariants that must not regress + +- A fresh database with no server key still refuses to serve until an + administrator exists. +- `legacy_unmigrated` continues to accept the configured server key. +- After initialization, the server key still does not authenticate, and + `dashboard.public` still does not expose admin data. +- `/login` stays public. Inference paths stay authenticated. +- Passwords and tokens stay out of argv and out of logs. + +## 5. Scope + +### In scope + +- Same-run onboard key generation. +- Operator text after bootstrap. +- Unauthenticated HTML response for dashboard and account GET pages when + the access state is `admin_initialized` or `managed`. +- Comments and docs that tell a fresh install to use the retired server key. + +### Explicitly out of scope + +- Deleting a server key that was already in the file. +- Changing Argon2id, session cookies, or CSRF. +- Personal upstream accounts. +- A new authentication mode. + +## 6. Required production changes + +When onboard has decided it will bootstrap an administrator in this +invocation, skip server-key generation. The existing +`should_generate_legacy_server_key(false)` behavior for a later run stays. + +If a key is already present and this invocation bootstraps, leave the file +bytes unchanged and print that inference uses the one-time personal token, +not that server key. Print the token once through the existing +`print_one_time_secret` path. Print that browser sign-in is `/login` on the +listen address. + +For `GET` of a dashboard page or an account page, when the access state is +`admin_initialized` or `managed` and no session cookie is present, return +`303` to `/login` or a `no-store` HTML page that links to `/login`. Use the +existing sign-in document builder rather than a second visual language. +Apply this only to HTML navigation. `POST`, `/v1/*`, and `/api/*` keep the +JSON 401 body. `legacy_unmigrated` is unchanged, including a public +read-only dashboard. + +Update the `[server]` comment in `rust/config.example.toml`. Check +`rust/config.local.example.toml`, `README.md`, and `docs/deployment.md` for +the same fresh-install claim and make those sentences name the personal +token after bootstrap. + +## 7. Ordered work packages + +### Work package A — Same-run key decision + +Intent: The fresh database path does not write a key it is about to retire. + +Required changes: Split the "not yet initialized" predicate from the +"this run will bootstrap" predicate in `rust/src/runtime.rs`. Generate a +missing key only when this run will leave the database +`legacy_unmigrated`. + +Acceptance evidence: A test with no database and no key asserts no +`api_key` write before bootstrap. A test with identity already initialized +still asserts no key write. A test with an existing key asserts the bytes +are unchanged and the rendered guidance does not call that key the +inference credential. + +### Work package B — HTML sign-in handoff + +Intent: A browser opened to the dashboard after bootstrap can find `/login`. + +Required changes: In `rust/src/server/middleware.rs`, before the JSON +unauthorized return, detect the HTML GET case and delegate the body to +`rust/src/server/auth.rs`. Cache-Control is `no-store`. + +Acceptance evidence: A managed-state GET of `/` and `/usage` without a +cookie yields the sign-in handoff. A GET of `/v1/models` and +`/api/user-budget` without a credential yields JSON 401. A +`legacy_unmigrated` public dashboard GET still renders the dashboard. + +### Work package C — Operator sentences + +Intent: The template and the install docs describe the credential onboard +actually leaves in force. + +Required changes: Edit the comments and docs named in section 6. Do not +change the listen default or the legacy-key compatibility statement for +databases that are still `legacy_unmigrated`. + +Acceptance evidence: `scripts/validate_release_docs.py` passes. A search +of the edited files does not tell a post-bootstrap install to call +inference with the server key from that onboard run. + +## 8. Failure, cancellation, restart, contention semantics + +Onboard remains a foreground command. If bootstrap fails after config +creation, the command must not have written a new server key in the +bootstrap path. An interrupted password prompt leaves no administrator and +no new server key. The HTML handoff is stateless and does not create a +session. Restart of the server does not change the access state. + +## 9. Compatibility and migration + +No schema change. Existing `legacy_unmigrated` installs keep their server +key. Existing initialized installs are unaffected apart from the friendlier +unauthenticated HTML response. No config key is removed automatically. + +## 10. Required tests + +- Extend the onboard tests in `rust/src/runtime.rs`. +- Session and middleware coverage in `rust/tests/on_prem_sessions.rs` and + the middleware tests in `rust/src/server/middleware.rs`. +- Negative: `/v1` and `/api` stay JSON; legacy public dashboard stays + available; a managed POST without a session is not redirected into a + state-changing login. + +## 11. Required verification commands + +```bash +cargo fmt --manifest-path rust/Cargo.toml --all -- --check +cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets -- -D warnings +cargo test --manifest-path rust/Cargo.toml --lib runtime::tests -- --test-threads=1 +cargo test --manifest-path rust/Cargo.toml --test on_prem_sessions -- --test-threads=1 +cargo test --manifest-path rust/Cargo.toml --workspace --all-targets -- --test-threads=1 +uv run python scripts/validate_release_docs.py +``` + +## 12. Documentation updates + +- `rust/config.example.toml` +- `README.md` and `docs/deployment.md` where they describe the fresh + onboard credential +- `architecture/deep-dive-on-prem-user-access.md` only if a sentence says + onboard leaves the shared key in force for a new database + +## 13. Acceptance criteria + +- A new configuration and a new database, passed through onboard's + bootstrap path, contain an administrator, one personal token disclosure, + and no newly written `[server].api_key`. +- The command's stdout names `/login` and does not name the server key as + the token to export. +- A browser GET of `/` on a managed instance without a cookie can follow + one link or redirect to `/login`. +- `curl` of `/v1/models` without a key still receives JSON 401. +- A pre-existing legacy database still authenticates with its server key. + +## 14. Stop conditions + +Stop if fixing the key write would let a keyless non-loopback process +serve unauthenticated inference. Stop if the HTML handoff would apply to +`/v1` or to a credentialed API route. Stop if the only way to preserve a +legacy install is to keep generating a dead key on the fresh path. + +## 15. Closure evidence required + +Commands and results. Tests named above and the legacy-key negative. +Before/after description of onboard's writes. Confirmation that no +migration, dependency, or auth-mode change landed. Registry row moved +only in the closure commit. + +## 16. Handoff notes + +The personal token is already printed by `print_one_time_secret`. Do not +add a second disclosure path. The sign-in transport gate in +`rust/src/server/auth.rs` still refuses a password form over remote +plaintext HTTP. The handoff page may link to `/login`; it must not embed +a password form on an unsafe transport. Serial tests only. diff --git a/plans/implementation/on-prem-member-access/002-usage-windows-and-member-limits.md b/plans/implementation/on-prem-member-access/002-usage-windows-and-member-limits.md new file mode 100644 index 00000000..98587a96 --- /dev/null +++ b/plans/implementation/on-prem-member-access/002-usage-windows-and-member-limits.md @@ -0,0 +1,221 @@ +# On-Prem Member Access Milestone 002 — Usage windows and member limits + +Status: active + +Repository baseline: `9da5e2d383c73035850c37f8125c145b8b7ff9ff` + +Source roadmap: + +- `plans/subsystems/on-prem-member-access-roadmap.md#milestone-2--usage-windows-and-member-limits` + +Long-term requirements: + +- `plans/000-long-term-specification.md#2-end-state-invariants-normative` +- `plans/001-terminology-and-domain-model.md#identity-and-lifecycle-terms` + +Applicable ADRs: + +- `plans/adrs/ADR-0002-on-prem-user-identity-and-policy-boundaries.md` +- None of ADR-0010. + +Primary class: capability + +## 1. Objective + +Show usage inside a single window kind, and show a member their own limits, +their own remaining allowance, and the configured instance ceilings without +anyone else's consumption. + +## 2. Why this milestone is ready + +No hard dependencies. Settlement already writes one day row and one month +row. This milestone changes projection only. + +## 3. Current implementation evidence + +`user_budget.rs` settlement inserts a `day` row and a `month` row for the +same request. `usage_page` in `rust/src/server/dashboard/admin.rs` sums +`user_budget_usage` grouped by user and model, so each request contributes +twice and every historical window is folded in. `render_my_usage` prints +`window_start` and drops `window`. + +`GET /api/user-budget` in `rust/src/server/health.rs` returns `rules` and +`usage` for the caller. An administrator also receives `instance_rules` and +`instance_usage`. The comment states that omission is so a member cannot +infer other users' consumption. `docs/model-limits.md` says instance +ceilings are admin-visible only. + +Active holds live on `user_budget_reservations`. The member page mentions +holds and does not display them or a remaining figure. + +## 4. Invariants that must not regress + +- Settlement still writes both buckets. This milestone does not change + admission or the counters. +- A member query stays constrained to that member's `user_id`. +- An administrator is required to read another user's budget. +- Instance usage totals and other users' rows stay off the member payload. +- No secret, prompt, or raw body is added to the projection. + +## 5. Scope + +### In scope + +- Admin usage projection, member usage projection, and `/api/user-budget`. +- Remaining allowance against the caller's own rules. +- Instance ceiling configuration on the member projection. +- The `docs/model-limits.md` sentence that currently hides the ceiling + configuration as well as the aggregate. + +### Explicitly out of scope + +- Changing estimated versus hard enforcement. +- A schema migration. +- Redesigning the users-page budget form. That is milestone 003. +- Revealing remaining shared headroom. + +## 6. Required production changes + +Admin HTML shows the current UTC day and the current UTC month as separate +tables, each grouped by user and model inside that window kind and that +window start. Historical rows may appear in a third listing that is still +split by window kind. No query sums a day row with a month row. + +Member HTML adds the window kind column. It shows, for the current UTC day +and current UTC month, each applicable own rule's ceiling and the remaining +amount. Remaining is the ceiling minus settled usage in that window minus +active holds that count against that rule. A rule with a null ceiling for +a dimension shows no remaining for that dimension. Holds that are not yet +settled must not be omitted from the subtraction. + +Member HTML and the member JSON add the instance ceiling rules: model, +window, enforcement, and the four ceilings. They do not add instance usage, +other users, or a remaining figure for the instance ceiling. The page says +the shared ceiling also applies and that other people's consumption is not +shown. + +Administrator JSON keeps `instance_rules` and `instance_usage`. Adding +member fields is allowed. Removing or renaming `rules` or `usage` is not. +Microdollar values stay integers. Display may also show USD as +microdollars divided by 1_000_000. The stored unit does not change. + +The truncation notice uses the same cap the query applies, and it does not +tell the reader to edit the query. + +## 7. Ordered work packages + +### Work package A — Window-faithful reads + +Intent: Every displayed total is inside one window kind. + +Required changes: Replace the summing admin query. Include `window` in the +member row renderer. Keep the 500-row cap and make the notice describe the +cap that was applied. + +Acceptance evidence: A fixture with one settled request produces a day +total and a month total that each equal that request, not twice that +request. An admin page that renders both does not add them. + +### Work package B — Own remaining allowance + +Intent: A member can see headroom against their own rules. + +Required changes: Add a read in `rust/src/user_budget.rs` that returns +current-window settled totals and active hold totals for one user. Render +them on `/usage` and include them in `/api/user-budget` for that user. +An administrator requesting another `user_id` receives that user's own +remaining, not the instance remaining. + +Acceptance evidence: A rule of 100 requests, 40 settled, and 10 held +reports 50 remaining. A second user's rows do not appear. A dimension +without a ceiling has no numeric remaining. + +### Work package C — Instance ceiling configuration + +Intent: A member can see the shared cap that may deny them, without seeing +who else consumed it. + +Required changes: Load instance rules for the member response. Do not call +the instance usage query for a member. Update `docs/model-limits.md` and +the on-prem deep dive so ceiling configuration is member-visible and +instance usage remains admin-only. + +Acceptance evidence: Member JSON contains the ceiling numbers and omits +instance usage. Two members with different personal usage receive the same +ceiling object. Admin JSON still contains instance usage. + +## 8. Failure, cancellation, restart, contention semantics + +These are reads. A database error returns the existing degraded response +and does not render a partial table that looks complete. Remaining is +computed in one read of settled rows plus active reservations so a +concurrent settle cannot be subtracted twice by adding two independently +stale copies in the page. If that single read cannot be offered, return +the degraded response rather than a remaining figure. + +## 9. Compatibility and migration + +No migration. Clients that ignore unknown JSON fields keep working. +`rules` and `usage` stay. Document the added fields in +`docs/model-limits.md` and `docs/api-reference.md` if that page describes +`/api/user-budget`. + +## 10. Required tests + +- `rust/tests/on_prem_budgets.rs` and `rust/tests/on_prem_global_budgets.rs` + for the doubled-window regression, remaining arithmetic, and member + denial of another user's usage. +- Dashboard render tests in `rust/src/server/dashboard/tests.rs` for the + window column and the truncation sentence. +- A member principal fixture against `/api/user-budget` that asserts the + absence of instance usage keys. + +## 11. Required verification commands + +```bash +cargo fmt --manifest-path rust/Cargo.toml --all -- --check +cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets -- -D warnings +cargo test --manifest-path rust/Cargo.toml --test on_prem_budgets -- --test-threads=1 +cargo test --manifest-path rust/Cargo.toml --test on_prem_global_budgets -- --test-threads=1 +cargo test --manifest-path rust/Cargo.toml --lib server::dashboard::tests -- --test-threads=1 +cargo test --manifest-path rust/Cargo.toml --workspace --all-targets -- --test-threads=1 +uv run python scripts/validate_release_docs.py +``` + +## 12. Documentation updates + +- `docs/model-limits.md` +- `docs/api-reference.md` if it documents `/api/user-budget` +- `architecture/deep-dive-on-prem-user-access.md` projection paragraph + +## 13. Acceptance criteria + +- One settled request appears once in the current day total and once in + the current month total, and those totals are not added together. +- A member page names day and month on each usage row. +- Remaining matches ceiling minus settled minus active holds for that + member and window. +- A member response includes instance ceiling configuration and excludes + instance usage and other users. +- An administrator can still read instance usage. + +## 14. Stop conditions + +Stop if a correct remaining figure requires a second SQLite connection or +a change to settlement. Stop if showing ceiling configuration cannot be +done without also shipping instance usage to the member. Stop if the +change needs a migration. + +## 15. Closure evidence required + +The doubled-count fixture, the remaining fixture, and the member payload +assertion. Commands and results. A statement that settlement code and +schema checksums did not change. + +## 16. Handoff notes + +Do not "fix" the double count by deleting the month bucket. Both buckets +are the enforcement model. USD display is a rendering of the integer +microdollar value. Milestone 003 will show the same USD rendering on the +users page; keep one helper so the two pages cannot drift. Serial tests +only. diff --git a/plans/implementation/on-prem-member-access/003-member-navigation-and-admin-roster.md b/plans/implementation/on-prem-member-access/003-member-navigation-and-admin-roster.md new file mode 100644 index 00000000..24a07347 --- /dev/null +++ b/plans/implementation/on-prem-member-access/003-member-navigation-and-admin-roster.md @@ -0,0 +1,221 @@ +# On-Prem Member Access Milestone 003 — Member navigation and admin roster + +Status: active + +Repository baseline: `9da5e2d383c73035850c37f8125c145b8b7ff9ff` + +Source roadmap: + +- `plans/subsystems/on-prem-member-access-roadmap.md#milestone-3--member-navigation-and-admin-roster` + +Long-term requirements: + +- `plans/000-long-term-specification.md#1-product-definition` +- `plans/001-terminology-and-domain-model.md#identity-and-lifecycle-terms` + +Applicable ADRs: + +- `plans/adrs/ADR-0002-on-prem-user-identity-and-policy-boundaries.md` +- `plans/adrs/ADR-0004-browser-session-csrf-delivery-and-account-scoped-sign-in-throttling.md` + +Primary class: polish + +## 1. Objective + +Give a signed-in member navigation that contains only member destinations, +and make the users page show the profile, budget rules, overrides, and +credential labels that the administrator has already set. + +## 2. Why this milestone is ready + +No hard dependencies. Route authorization already confines a member to the +member surfaces. This milestone changes what those pages offer and what the +administrator can see. It does not grant new routes. + +Soft: if milestone 002 lands first, reuse its USD helper and do not replace +its usage tables. If it has not landed, format microdollars locally on the +users page and leave `/usage` alone. + +## 3. Current implementation evidence + +`DASHBOARD_NAVIGATION` in `rust/src/server/dashboard/render/layout.rs` is +one 17-link list. `dashboard_standalone_page` uses it for `/usage`, +`/my-account`, and `/my-account/models`. A member who follows Overview, +Users, Accounts, or Runtime receives the HTML 403 from +`member_refusal_html` in `rust/src/server/auth.rs`. + +`render_users_admin` prints username, role, state, and the password flag. +The actions cell stacks state, password, profile, override, budget, and +token forms. The profile `` of bundled profile ids. The secret input is +`type="password"` and `autocomplete="off"`. On success, redirect back to +`/my-account` without the secret in the query string. On failure, the +error page names the refusal and does not echo the secret. + +When the effective grant is `deny`, `/my-account` shows that self-service +is off and renders no secret input and no remove button. Direct POST still +checks the grant and returns 403. + +An administrator's users section shows the instance default, each user's +effective grant, and that user's personal account names. The administrator +can change the grant and can remove an account while the user's +self-service grant is deny. The administrator add-for-another-user action +may stay CLI-only if the browser remove and grant controls are present. +If a browser add-for-user form is included, it uses the same password +field rules and the same service, and it is `admin_only`. + +Member navigation from milestone 003 gains no new top-level item. The +control lives on My account. If milestone 003 has not landed, this page +still must not add operator links to the member view. + +## 7. Ordered work packages + +### Work package A — Route gate + +Intent: The new posts are browser-only and role-correct. + +Required changes: Register routes in `rust/src/server/mod.rs` and extend +the member and admin match lists in `rust/src/server/middleware.rs`. +Reject a personal API token with the existing 401 or 403 used for other +dashboard posts. + +Acceptance evidence: A personal token POST receives a refusal and does +not create a binding. An unauthenticated POST does not create a binding. +A member POST to the admin grant route receives the member 403 page. + +### Work package B — Administrator grant controls + +Intent: The administrator can allow or deny self-service without the CLI. + +Required changes: Forms on the users page calling the milestone 004 grant +and remove operations. Render account names only. + +Acceptance evidence: Setting deny hides the secret field and rejects a +later member add or remove. Accounts already bound to that user stay +selectable by that user until an administrator removes them or the user +is disabled. Those two operations are the milestone 004 withdraw paths. +A grant change does not delete files and does not withdraw bindings. + +### Work package C — Member add and remove + +Intent: A granted member can attach their own bundled-provider key. + +Required changes: The My account section and posts described in section 6. +The handler reads the form secret, calls the 004 add/remove service, and +drops the secret from memory without writing it to the response. + +Acceptance evidence: A granted member adds `opencode-go`, sees the account +name, and can complete an inference selection that uses it in the routing +test. Another member does not see the account and cannot select it. The +HTML response and the access log do not contain the secret. A denied +member has no secret input. Remove uses the 004 remove order. + +## 8. Failure, cancellation, restart, contention semantics + +The handler waits for the 004 service result. On failure it renders an +error and does not show a success list that includes the account. A +double submit is the 004 unique-name rejection. Browser disconnect after +the service commits is the same as a committed CLI add. Session +revocation uses the existing session fence so a disable that lands before +commit fails the write. + +## 9. Compatibility and migration + +No new table. No change to the inference body. New HTML routes are +additive. Personal tokens keep their current scopes. + +## 10. Required tests + +- `rust/tests/on_prem_admin_ui.rs` for grant rendering, denied-member + absence of the secret field, admin-only grant mutation, and member 403 + on the admin route. +- `rust/tests/on_prem_sessions.rs` for CSRF failure and personal-token + refusal. +- A routing assertion, reusing milestone 004's helper, that the account + created through the form is owner-only. +- A response-body assertion that the submitted secret is absent. + +## 11. Required verification commands + +```bash +cargo fmt --manifest-path rust/Cargo.toml --all -- --check +cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets -- -D warnings +cargo test --manifest-path rust/Cargo.toml --test on_prem_admin_ui -- --test-threads=1 +cargo test --manifest-path rust/Cargo.toml --test on_prem_sessions -- --test-threads=1 +cargo test --manifest-path rust/Cargo.toml --workspace --all-targets -- --test-threads=1 +uv run python scripts/validate_release_docs.py +``` + +Include `--no-default-features` clippy if the middleware or config path +changes in a way that touches proxy features. A pure HTML handler should +not need a dependency change. + +## 12. Documentation updates + +- `docs/deployment.md` small-team section: a granted member can add a + personal bundled-provider account from My account; the administrator + controls the grant. +- `architecture/deep-dive-on-prem-user-access.md` member surface list. +- `docs/api-reference.md` only if the new routes are documented as HTTP + API. HTML forms do not require an inference-API change. + +## 13. Acceptance criteria + +- Default deny: My account has no upstream secret field. +- An administrator can allow one user. That user can add an OpenCode Go + account in the browser and is the only principal routed to it. +- The administrator can deny the user again. The secret field is gone + and a member add or remove is refused. An account the administrator + has not removed stays selectable by that user. +- A personal API token cannot add or remove an upstream account. +- The secret appears in no HTML response, audit row, or log line produced + by the new handlers. +- Amazon Bedrock is not offered in the provider select. + +## 14. Stop conditions + +Stop if milestone 004 is not closed. Stop if the browser path needs a +second writer for `.env` or TOML. Stop if the shipped 004 service treats +a grant denial as withdrawing existing bindings; report that mismatch +instead of changing custody in this milestone. Stop if the provider +select would include an id that is not in the bundled profile asset. + +## 15. Closure evidence required + +The grant, denial, cross-user, token, and CSRF tests. A captured form +submission whose secret string is absent from the response and the +database. Commands and results. Registry closure of the roadmap only when +001–004 are already closed or are closed in the same commit by their own +records. + +## 16. Handoff notes + +Read the closed 004 service and call it. A grant denial blocks member +add and remove and leaves existing bindings selectable. User disable and +administrator remove are the withdraw paths. If 004 shipped denial as a +withdraw, stop and report that mismatch instead of changing custody here. +Serial tests only. Keep the member navigation limited to member +destinations. diff --git a/plans/registry.md b/plans/registry.md index d16cccbb..6d9b4fc3 100644 --- a/plans/registry.md +++ b/plans/registry.md @@ -16,6 +16,8 @@ New optional application-interoperability planning (2026-11-03): [ADR-0007](adrs Downstream application boundary (2026-11-10): [ADR-0009](adrs/ADR-0009-downstream-application-boundary.md) is accepted and supersedes ADR-0007's gateway and hosted-execution decisions. Ordinary inference still returns tool calls to the client. Application-boundary M001–M003 are closed and M004 is conditionally closed with disposition `not measured`. The MCP gateway and hosted runner are withdrawn, the content-free audit export is in place, and the local metadata profile is opt-in. Retrieval R002 is closed and supersedes R001 as an execution handoff. Embeddings stay. Tool-integration M003 and M004 evidence conditions are vacated rather than collected. No successor is registered. +On-prem member access (2026-11-10, baseline `9da5e2d383c73035850c37f8125c145b8b7ff9ff`): a review of solo install and small-team use found a fresh onboard that writes a server key the same run retires, usage totals that add day and month buckets, member pages that link into administrator 403s, and no way for a member to add an upstream account that only they can spend. [On-prem member access](subsystems/on-prem-member-access-roadmap.md) is the successor. On-prem user access M001–M024 stay closed and are not reopened. [ADR-0010](adrs/ADR-0010-personal-upstream-account-custody.md) is accepted with its named canonical amendments. M001–M005 are implemented in the working tree and are not closed. + Legacy archive (pre-251, immutable, top level): `plans/001-*` through `plans/250-*` plus `python_hotpath_dispatch_compression_optimization.md`. Most recently closed: Request Admission and Wire M008 (remote compaction capability @@ -103,7 +105,8 @@ No new runtime, schema or performance claim lands with these plans. | Persistence | active | `plans/subsystems/persistence-roadmap.md` | M011 closed — post-M010 roadmap/documentation reconciliation | M009/M010 closures accepted. Documentation/tooling-only corrective; production remains WAL/NORMAL. No technical persistence successor is registered. | | Deployment and packaging | active | `plans/subsystems/deployment-packaging-roadmap.md` | M008 and M009 closed | M009 resolves audited dependencies and adapts bounded backup member-name parsing; serial suites and locked release build passed. | | Dashboard | closed | `plans/subsystems/dashboard-roadmap.md` | M014 closed — operator surface presentation and accessibility corrective | Reopened on evidence at baseline `e6822d8f78`: M001–M013 remain closed. M014 is closed; the paired browser disposition needs the frozen oracle worktree and a browser, and the stale on-prem browser reference artifact has to be regenerated on hardware. | -| On-prem user access | closed | `plans/subsystems/on-prem-user-access-roadmap.md` | M024 closed — browser session CSRF delivery and member account surface corrective | Reopened on evidence at baseline `d04ad6831c6e030b7f5fc8a56501fdfecab982bd`: M001–M023 remain closed. `plans/adrs/ADR-0004-browser-session-csrf-delivery-and-account-scoped-sign-in-throttling.md` was accepted on 2026-10-23, and M024 implements that decision; it is closed. | +| On-prem user access | closed | `plans/subsystems/on-prem-user-access-roadmap.md` | M024 closed — browser session CSRF delivery and member account surface corrective | Reopened on evidence at baseline `d04ad6831c6e030b7f5fc8a56501fdfecab982bd`: M001–M023 remain closed. `plans/adrs/ADR-0004-browser-session-csrf-delivery-and-account-scoped-sign-in-throttling.md` was accepted on 2026-10-23, and M024 implements that decision; it is closed. The 2026-11-10 solo and small-team gaps are a new roadmap, not a reopening. | +| On-prem member access | active | [on-prem member access roadmap](subsystems/on-prem-member-access-roadmap.md) | M001–M005 active, not closed | ADR-0010 is accepted. Closure still needs the serial suite, the no-default gates, the locked release build, and a closure record. | | On-prem concurrency performance | active | `plans/subsystems/on-prem-concurrency-performance-roadmap.md` | M002 closed — ordinary-server synthetic baseline recorded | M001's Pi/microSD solo tail attribution stays conditionally closed; M002 authorizes no WAL/SQLite topology change. | | Operations CLI | active | `plans/subsystems/operations-cli-roadmap.md` | M003 closed — watchdog start-guard ownership correction | New subsystem roadmap opened at baseline `e6822d8f78` for `rust/src/operations/` and `rust/src/runtime.rs`, which no other roadmap claims as a primary owner. M001 is closed and M002 is closed through M003; no successor is registered in this subsystem. | | Request admission and wire | active | `plans/subsystems/request-admission-wire-roadmap.md` | M008 closed — remote compaction capability contract | ADR-0003 accepted; M001–M007 and M009 remain closed; M008 is closed; no successor is registered in this subsystem. | @@ -311,6 +314,8 @@ record is `plans/closure/deployment-packaging/008-status.md`. | Subsystem | Milestone | Status | Implementation plan | Dependencies / handoff note | |---|---|---|---|---| +None. + Application boundary and retrieval closure audit (2026-11-10, baseline `e049025274a397d7799c3ae21ed106947c2a1572`, uncommitted): searched the application-boundary and retrieval roadmaps, their implementation plans, and the ready, active, and blocked registry tables. M001, M002, M003, and R002 are closed. M004 is conditionally closed with disposition `not measured` and authorizes no optimization. No registered successor exists in either subsystem. Nothing else was blocked on these milestones, so nothing is promoted. Tool-integration M003 and M004 stay conditionally closed as historical records; their open evidence conditions stay vacated. The blocked table stays empty of R001. Runtime efficiency M004 closure audit: searched the runtime-efficiency roadmap, @@ -323,13 +328,21 @@ persistence roadmap. | Subsystem | Milestone | Status | Implementation plan | Handoff note | |---|---|---|---|---| - +| On-prem member access | M001 — solo sign-in and onboarding credential | active | [001](implementation/on-prem-member-access/001-solo-sign-in-and-onboarding-credential.md) | Implemented. Not closed. Does not implement ADR-0010. | +| On-prem member access | M002 — usage windows and member limits | active | [002](implementation/on-prem-member-access/002-usage-windows-and-member-limits.md) | Implemented. Not closed. Projection only; settlement stays. | +| On-prem member access | M003 — member navigation and admin roster | active | [003](implementation/on-prem-member-access/003-member-navigation-and-admin-roster.md) | Implemented. Not closed. | +| On-prem member access | M004 — personal upstream custody and routing | active | [004](implementation/on-prem-member-access/004-personal-upstream-custody-and-routing.md) | Implemented. Not closed. ADR-0010 is accepted. | +| On-prem member access | M005 — personal upstream browser grant | active | [005](implementation/on-prem-member-access/005-personal-upstream-browser-grant.md) | Implemented. Not closed. Calls the M004 service. | ## Blocked work | Subsystem | Milestone | Blocker | |---|---|---| +None. + +Unblock audit (on-prem member access, 2026-11-10): ADR-0010 is accepted with the named canonical amendments. M001–M005 are implemented in the working tree and sit in the active table. They are not closed. On-prem user access M001–M024 stay closed. Nothing else was waiting on this roadmap. + Unblock audit (application boundary, 2026-11-10, baseline `e049025274a397d7799c3ae21ed106947c2a1572`): ADR-0009 supersedes ADR-0007's gateway and hosted-execution decisions. Retrieval R001 is no longer a blocked handoff; R002 is the successor and is documentation only. Tool-integration M003 and M004 stay conditionally closed as historical records, and their open evidence conditions are vacated rather than promoted into new tool-integration work. Nothing else on the blocked table was waiting on R001. M004's missing shared host is an allowed `not measured` closure, not a registry block. The same-day closure audit above records M001–M003 and R002 closed and M004 conditionally closed. Nothing further is promoted. Unblock audit (on-prem user access reopening after M012 closure, baseline diff --git a/plans/subsystems/on-prem-member-access-roadmap.md b/plans/subsystems/on-prem-member-access-roadmap.md new file mode 100644 index 00000000..23823bf1 --- /dev/null +++ b/plans/subsystems/on-prem-member-access-roadmap.md @@ -0,0 +1,342 @@ +# On-Prem Member Access Roadmap + +Status: active + +Long-term references: + +- `plans/000-long-term-specification.md#1-product-definition` +- `plans/000-long-term-specification.md#2-end-state-invariants-normative` +- `plans/001-terminology-and-domain-model.md#identity-and-lifecycle-terms` +- `plans/002-long-term-roadmap.md#phase-5--optional-on-prem-small-team-access-and-budgeting` + +Related ADRs: + +- `plans/adrs/ADR-0002-on-prem-user-identity-and-policy-boundaries.md` (accepted; remains in force except where ADR-0010 narrows it) +- `plans/adrs/ADR-0004-browser-session-csrf-delivery-and-account-scoped-sign-in-throttling.md` (accepted) +- `plans/adrs/ADR-0010-personal-upstream-account-custody.md` (accepted) + +## 1. Purpose and ownership boundary + +Close the solo-install and small-team gaps found in the 2026-11-10 audit +without reopening the closed on-prem user-access roadmap. That roadmap's +M001–M024 records stay immutable. + +This roadmap owns the member-visible projection of identity, budgets, and +navigation, the fresh-install credential handoff, and, after ADR-0010 is +accepted, personal upstream custody. + +| Concern | Owner | +|---|---| +| Onboarding credential handoff | `rust/src/runtime.rs`, `rust/src/operations/config_mutation.rs` | +| Browser sign-in and route gate | `rust/src/server/auth.rs`, `rust/src/server/middleware.rs` | +| Usage and limit projection | `rust/src/server/dashboard/admin.rs`, `rust/src/server/dashboard/render/admin.rs`, `rust/src/server/health.rs`, `rust/src/user_budget.rs`, `rust/src/instance_budget.rs` | +| Navigation chrome | `rust/src/server/dashboard/render/layout.rs` | +| Personal upstream grant, binding, and eligibility | `rust/src/identity.rs` or a new sibling module under `rust/src/`, `rust/src/routing/eligibility.rs`, `rust/src/accounts/registry.rs`, `rust/src/config.rs`, `rust/src/config_reload_policy.rs` | +| Secret file | `rust/src/operations/paths.rs` and the config-adjacent `.env` writer already used for operator keys | + +`rust/src/coordinator/` keeps publication and settlement. `rust/src/db/` +keeps the single writer. Provider transport and the bundled profile +contract stay where they are. This roadmap does not add a provider. + +## 2. Work classification + +### Invariants + +- One SQLite writer, WAL/NORMAL, and generation publication stay in place. +- Credentials stay out of SQLite, logs, diagnostics, and reload diffs. +- Day and month usage buckets are never added together into one displayed total. +- A bound upstream account is never selectable by a different principal. +- Model policy, user budget, and provider health/quota still run. A personal + account cannot pin selection or skip them. + +### Capabilities + +- A fresh `eggpool onboard` leaves the operator with one working personal + token and a browser path to `/login`. +- A member sees their own limits, current-window usage, and remaining + allowance against their own rules, plus the configured instance ceilings + without anyone else's consumption. +- A member's pages link only to member destinations. +- An administrator can read each user's current profile, budgets, and + credential labels from the users page. +- After ADR-0010 is accepted, a granted member can add a bundled-provider + upstream account that only they can use, and an administrator can allow + or deny that ability for the instance or for one user. + +### Infrastructure + +- Secret-free binding rows and a generation-scoped eligibility snapshot. +- File transaction around TOML and `.env` that fails closed. + +### Polish + +- USD display beside stored microdollars. +- Users-page actions grouped so the current assignment is visible. + +## 3. Non-goals + +- Reopening or rewriting on-prem user-access M001–M024. +- A second administrator, public signup, SSO, or an organization id. +- Amazon Bedrock or any other provider that is not already in the bundled + profile asset. +- Member-supplied base URLs, proxies, headers, or weights. +- Preferring a personal account over the normal load-based choice among + accounts that member is allowed to use. +- Showing one member another member's usage, or the remaining headroom of + the shared instance ceiling. +- Editing v1–v65 migrations. v65 tool-grant tables stay unused by this work. + +## 4. Current state + +Baseline `9da5e2d383c73035850c37f8125c145b8b7ff9ff`. + +Fresh onboard in `rust/src/runtime.rs` generates `[server].api_key` and +then bootstraps the administrator in the same run. Bootstrap sets +`admin_initialized`, after which `legacy_server_key_allowed` rejects that +key. The operator's working credential is the one-time personal token. +`rust/config.example.toml` still says the server key generated by onboard +guards inference. + +An unauthenticated dashboard GET, once identity is initialized, receives +JSON `{"detail":"Sign in required"}` from `rust/src/server/middleware.rs`. +The sign-in form is `GET /login`. + +`user_budget_usage` stores one day row and one month row per settled +request. The admin usage query sums those rows by user and model. The +member table omits the window kind. `/api/user-budget` returns the member's +rules and usage. Instance rules and instance usage are added only for an +administrator. `docs/model-limits.md` says instance ceilings are +admin-visible only. + +`dashboard_standalone_page` renders the full operator navigation for member +pages. The users table shows role and state, then stacks every mutation in +one cell, without the current profile, overrides, budget rules, or +credential labels. + +`AccountConfig` and `AccountIdentity` have no owner. Routing eligibility +does not receive a user id. ADR-0010 is now accepted and is the authority for the granted path. + +## 5. Target architecture + +Solo and team installs share one process. The fresh path creates the +administrator and a personal client token and does not also create a server +key that the same command retires. Browser navigation to a protected HTML +page offers `/login`. Machine clients of `/v1` and `/api` keep JSON. + +Usage projections group by window. A member sees their rules, settled rows +labeled day or month, remaining allowance on their own current windows, and +the configured instance ceiling values. Instance usage totals stay on the +admin response. + +Member HTML uses a member navigation set. The users page shows the current +assignment and groups mutations under it. + +Personal upstreams, after acceptance, are shared accounts plus an optional +binding. The secret stays in `.env`. Selection subtracts accounts the +principal does not own before scoring. + +## 6. Dependency graph + +- M001, M002, and M003 have no hard dependencies. They may proceed in + parallel. Soft: M003 does not redesign the usage tables owned by M002. +- M004 has a hard dependency on acceptance of ADR-0010, including the + canonical sentence amendments that acceptance names. Interface: the + binding row and eligibility snapshot are the contract M005 consumes. +- M005 has a hard dependency on M004. It does not choose a second custody + design. + +## 7. Milestones + +### Milestone 1 — Solo sign-in and onboarding credential + +Class: capability + +Objective: A fresh onboard yields one usable personal token and a browser +path to sign in, and it does not present a server key that the same run +retires. + +Dependencies: none. + +Deliverable boundary: `rust/src/runtime.rs`, the unauthenticated HTML +response in `rust/src/server/middleware.rs` and `rust/src/server/auth.rs`, +and the operator sentences that describe the fresh-install key. + +User or operator value: Solo setup matches the credential that actually +works. + +Exit conditions: A new database onboard writes no `[server].api_key`. An +existing key is left in place and the command says inference uses the +personal token. Unauthenticated HTML GET of a dashboard or account page +in `admin_initialized` or `managed` offers `/login` and is `no-store`. +`/v1` and `/api` remain JSON 401. Legacy `legacy_unmigrated` behavior is +unchanged. + +Deferred work: Personal upstream keys. + +### Milestone 2 — Usage windows and member limits + +Class: capability + +Objective: Displayed usage does not add a day bucket to its month bucket, +and a member can see their own limits and remaining allowance. + +Dependencies: none. + +Deliverable boundary: usage queries, member and admin renderers, and +`GET /api/user-budget`. No schema change. + +User or operator value: A member can tell what they have spent and what +remains. An administrator sees per-user totals that match one window. + +Exit conditions: Admin totals are computed inside one window kind. Member +rows show the window kind. Remaining allowance for the current UTC day and +month subtracts settled usage and active holds for that member's own rules. +Instance ceiling configuration is visible to the member. Instance usage and +other users' rows are not. `docs/model-limits.md` matches that split. + +Deferred work: Editing another user's budget from a redesigned roster. That +is M003's presentation of rules M002 does not need to move. + +### Milestone 3 — Member navigation and admin roster + +Class: polish + +Objective: A signed-in member is offered only member destinations, and the +users page shows the assignment those destinations depend on. + +Dependencies: soft on M002, so the usage page's numbers stay M002's. + +Deliverable boundary: navigation markup and the users/profile renderers and +their tests. No new authority. + +User or operator value: A member stops landing on administrator 403 pages +from the navigation. An administrator can see the current profile, budget +rules, overrides, and credential labels. + +Exit conditions: Member HTML from `/my-account`, `/my-account/models`, and +`/usage` does not link to operator routes. Operator URLs still return the +member refusal. The users row shows the assigned profile, or that the +member is unassigned and therefore denied. Saved microdollar limits also +show USD. The stored unit remains microdollars. + +Deferred work: Personal upstream grant controls. Those wait for M005. + +### Milestone 4 — Personal upstream custody and routing + +Class: infrastructure + +Objective: Provide a secret-free binding and a CLI consumer so a personal +upstream account is eligible only for its owner. + +Dependencies: hard on ADR-0010 acceptance and the canonical amendments that +acceptance requires. + +Deliverable boundary: one new migration, the binding service, `.env` and +TOML transaction, generation snapshot, eligibility filter, and +`eggpool users upstream` subcommands. No browser form. + +User or operator value: A headless administrator can attach an individual +bundled-provider key to one user and can set the self-service grant. The +running server routes only that user to it. + +Exit conditions: The CLI contract in the implementation plan passes, +including failed-reload restoration and cross-user denial. The secret is +absent from the database and from diagnostics. Default grant is `deny`, so +an unconfigured instance behaves as it does today. This milestone is not a +completed member-facing capability; M005 is that consumer. + +Deferred work: The browser form and the users-page grant controls. + +### Milestone 5 — Personal upstream browser grant + +Class: capability + +Objective: Let a granted member add and remove their own bundled-provider +account in the browser, and let an administrator set the grant there. + +Dependencies: hard on M004. + +Deliverable boundary: member and admin HTML forms, route-role entries, and +browser tests. Custody and eligibility stay in M004. + +User or operator value: The small-team path no longer requires a shell to +add a personal OpenCode Go key, and the administrator can withdraw that +ability without editing TOML by hand. + +Exit conditions: A denied member sees no secret field and receives a +refusal. A granted member adds an account and can call through it. Another +member cannot. Personal API tokens cannot call the mutation. The +administrator can set instance and per-user grants and can remove an +account. + +Deferred work: New providers, custom endpoints, and account preference. + +## 8. Cross-cutting requirements + +Storage: M001–M003 and M005 add no tables. M004 appends the next migration +after v65 and a checksum. Bindings store ids and state only. + +Protocol: `/api/user-budget` may add fields. It does not remove or rename +`rules` or `usage`. Inference request bodies are unchanged. + +Security: M001 does not open a new unauthenticated inference path. M004 +rejects the secret from argv, logs, and SQLite. Self-service mutations +require a browser session. + +Concurrency: usage reads are consistent with the single writer. Binding +publication is generation-scoped. In-flight requests do not reselect. + +Observability: new audit actions record actor, action, and account name. +They do not record the secret. + +Performance: eligibility adds a membership test on the existing candidate +set. No new routing lock and no second database worker. + +Docs: operator docs change in the milestone that changes the behavior. +`AGENTS.md` does not gain a copy of this roadmap. + +## 9. Verification strategy + +Rust tests stay serial. Focused targets: + +- M001: `rust/src/runtime.rs` onboard tests, `rust/tests/on_prem_sessions.rs`, middleware auth tests. +- M002: `rust/tests/on_prem_budgets.rs`, `rust/tests/on_prem_global_budgets.rs`, `rust/src/server/dashboard/tests.rs`. +- M003: `rust/tests/on_prem_admin_ui.rs`, `rust/src/server/dashboard/tests.rs`. +- M004: `rust/tests/on_prem_identity.rs`, routing eligibility tests under `rust/tests/`, migration coverage in the database test target, `--no-default-features` check and clippy. +- M005: `rust/tests/on_prem_admin_ui.rs` and session CSRF tests. + +Closure of any milestone that changes `README.md` or `docs/` runs +`uv run python scripts/validate_release_docs.py`. The full serial workspace +suite is closure evidence, not a substitute for the focused tests. + +## 10. Risks and decision points + +ADR-0010 is accepted, with the named canonical amendments. The five +milestones are implemented in the working tree and are not closed: the full +serial suite, the no-default gates, and the locked release build are still +outstanding, and no closure record has been written. + +Showing instance ceiling values to members reveals the cap and does not +reveal other people's consumption. Showing remaining shared headroom would. +M002 keeps remaining shared headroom admin-only. + +A personal account that loses its binding before its config stanza is +removed would become shared. M004's state machine forbids that transition. + +## 11. Completion definition + +M001–M003 are closed on their exit conditions. M004 and M005 are closed +only after ADR-0010 is accepted and their own closure records exist. The +roadmap then closes. Solo onboard, member usage, member navigation, and +grant-controlled personal upstreams are the four observable results. No +Bedrock provider is implied. + +## 12. Milestone status + +| Milestone | Status | Implementation plan | Closure record | Blockers | +|---|---|---|---|---| +| 1 | active | [001](../implementation/on-prem-member-access/001-solo-sign-in-and-onboarding-credential.md) | — | closure suite outstanding | +| 2 | active | [002](../implementation/on-prem-member-access/002-usage-windows-and-member-limits.md) | — | closure suite outstanding | +| 3 | active | [003](../implementation/on-prem-member-access/003-member-navigation-and-admin-roster.md) | — | closure suite outstanding | +| 4 | active | [004](../implementation/on-prem-member-access/004-personal-upstream-custody-and-routing.md) | — | closure suite outstanding | +| 5 | active | [005](../implementation/on-prem-member-access/005-personal-upstream-browser-grant.md) | — | closure suite outstanding | diff --git a/rust/assets/db/migrations/0066_personal_upstream.sql b/rust/assets/db/migrations/0066_personal_upstream.sql new file mode 100644 index 00000000..7377667f --- /dev/null +++ b/rust/assets/db/migrations/0066_personal_upstream.sql @@ -0,0 +1,35 @@ +-- Secret-free personal upstream grants and bindings. +-- The plaintext provider secret stays in the config-adjacent environment file. +CREATE TABLE personal_upstream_grants ( + scope TEXT NOT NULL CHECK (scope IN ('instance', 'user')), + user_id TEXT NOT NULL DEFAULT '', + effect TEXT NOT NULL CHECK (effect IN ('allow', 'deny', 'inherit')), + updated_by TEXT, + updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (scope, user_id), + CHECK ( + (scope = 'instance' AND user_id = '' AND effect IN ('allow', 'deny')) + OR ( + scope = 'user' + AND length(user_id) BETWEEN 1 AND 64 + AND effect IN ('allow', 'deny', 'inherit') + ) + ) +); + +INSERT INTO personal_upstream_grants(scope, user_id, effect) +VALUES ('instance', '', 'deny'); + +CREATE TABLE personal_upstream_bindings ( + provider_id TEXT NOT NULL CHECK (length(provider_id) BETWEEN 1 AND 96), + account_name TEXT NOT NULL CHECK (length(account_name) BETWEEN 1 AND 96), + user_id TEXT NOT NULL CHECK (length(user_id) BETWEEN 1 AND 64), + state TEXT NOT NULL CHECK (state IN ('active', 'withdrawn')), + actor_id TEXT, + created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (provider_id, account_name) +); + +CREATE INDEX idx_personal_upstream_bindings_user + ON personal_upstream_bindings(user_id, state); diff --git a/rust/assets/db/migrations/checksums.json b/rust/assets/db/migrations/checksums.json index 1e1f9f44..0b84a4b3 100644 --- a/rust/assets/db/migrations/checksums.json +++ b/rust/assets/db/migrations/checksums.json @@ -64,6 +64,7 @@ "0062_instance_budgets.sql": "bcb0999e1be7944512f082164f763671bb5ce1b6e82c071470d3ff5f03e5ebac", "0063_default_member_profile.sql": "853cc2e66f6e667f7010c88471b525d2b459393b148aab3fe051b789cec02558", "0064_account_backoffs_null_identity.sql": "28f0414454cae68530e86cec9e63efa1137f6298189cd588093f1104efec759e", - "0065_tool_grants.sql": "757ce7d6e89585bf6f83246b5e4935d29639e037cd0047efcffc0fc160082aff" + "0065_tool_grants.sql": "757ce7d6e89585bf6f83246b5e4935d29639e037cd0047efcffc0fc160082aff", + "0066_personal_upstream.sql": "5f37ccad85c006e3e535322155d52a3bb75cc2fad649af54021c9905db742e4c" } } diff --git a/rust/assets/runtime-manifest.json b/rust/assets/runtime-manifest.json index 6f39bd5c..3a569840 100644 --- a/rust/assets/runtime-manifest.json +++ b/rust/assets/runtime-manifest.json @@ -5,7 +5,7 @@ "path": "db/migrations/checksums.json", "category": "sqlite-migrations", "source": "rust/assets/db/migrations/checksums.json", - "sha256": "4d5ec3aa10961525a910fa7999bfb697b04319f279c886019d92b9a924f8cb0c", + "sha256": "97200c8f40e5c01ce16141ca13deee45bcf79a3f007cc61b93ffc8e96390d983", "identity": "exact" }, { @@ -26,7 +26,7 @@ "path": "config/config.example.toml", "category": "configuration-template", "source": "rust/config.example.toml", - "sha256": "b3bc53a9d7063471c19a0d3d41ad2e6746e6f41d07e256490aba896afb585794", + "sha256": "0acf79017ee5b4a37415db4df3e8f577a3c7c425bff462bdb6831f60c68e8193", "identity": "exact" }, { @@ -51,7 +51,7 @@ "identity": "exact" } ], - "schema_migration_count": 65, + "schema_migration_count": 66, "schema_change": true, "ownership": "Rust build/runtime embeds these assets; source paths are canonical repository inputs", "rollback": "restore the source tree from Git history" diff --git a/rust/config.example.toml b/rust/config.example.toml index 398b06fb..31ea7190 100644 --- a/rust/config.example.toml +++ b/rust/config.example.toml @@ -1,7 +1,9 @@ [server] -# Canonical LAN bind default. The server listens on all interfaces; the -# server API key (generated by `eggpool onboard`) still guards inference and -# sensitive control endpoints. Bind to "127.0.0.1" explicitly for a +# Canonical LAN bind default. The server listens on all interfaces. A fresh +# `eggpool onboard` creates the local administrator and one personal API +# token; that token is the inference credential, and browser sign-in is +# `/login` on this address. A server API key guards inference only while the +# database is still `legacy_unmigrated`. Bind to "127.0.0.1" explicitly for a # loopback-only install. host = "0.0.0.0" port = 11300 diff --git a/rust/src/accounts/registry.rs b/rust/src/accounts/registry.rs index 2a761c88..1045fb7b 100644 --- a/rust/src/accounts/registry.rs +++ b/rust/src/accounts/registry.rs @@ -2,7 +2,7 @@ use std::{ collections::{BTreeMap, BTreeSet}, - env, fmt, + fmt, }; use serde::Serialize; @@ -96,6 +96,12 @@ impl fmt::Debug for CredentialStore { impl CredentialStore { /// Resolve configured inline/environment keys once, outside routing identity. pub fn from_config(config: &Config) -> Self { + Self::from_config_near(config, None) + } + + /// Resolve keys from the process environment and, when a config path is + /// known, the config-adjacent environment file. The value is never logged. + pub fn from_config_near(config: &Config, config_path: Option<&std::path::Path>) -> Self { let mut store = Self::default(); for provider in config.providers.values() { for account in &provider.accounts { @@ -103,16 +109,15 @@ impl CredentialStore { if account.api_key_env.is_empty() { return None; } - match env::var(&account.api_key_env) { - Ok(value) => Some(value), + match crate::config::account_secret_from_env(config_path, &account.api_key_env) { + Some(value) => Some(value), // Secret-free: log names only, never the value. A set // `api_key_env` with an unreadable variable is a // misconfiguration, not an unconfigured account. - Err(error) => { + None => { tracing::warn!( account = account.name.as_str(), env_var = account.api_key_env.as_str(), - reason = error.to_string(), "account key environment variable is unreadable; treating account as unconfigured" ); None diff --git a/rust/src/cli.rs b/rust/src/cli.rs index 5ab729e5..321eaf94 100644 --- a/rust/src/cli.rs +++ b/rust/src/cli.rs @@ -204,6 +204,70 @@ pub enum UsersCommand { /// Show, select, or clear the default profile for newly created members. #[command(subcommand)] Defaults(UsersDefaultsCommand), + /// Grant or attach a personal bundled-provider upstream account. + #[command(subcommand)] + Upstream(UsersUpstreamCommand), +} + +#[derive(Debug, Subcommand)] +pub enum UsersUpstreamCommand { + /// Set whether members may add a personal upstream account. + Default(UpstreamDefaultArgs), + /// Allow, deny, or inherit personal-upstream self-service for one user. + Grant(UpstreamGrantArgs), + /// Attach a bundled-provider account that only one user can spend. + Add(UpstreamAddArgs), + /// List personal upstream bindings. Secrets are not shown. + List(UpstreamListArgs), + /// Withdraw one user's personal upstream account. + Remove(UpstreamRemoveArgs), +} + +#[derive(Debug, clap::Args)] +pub struct UpstreamDefaultArgs { + #[arg(value_parser = ["allow", "deny"])] + pub effect: String, + #[arg(long, default_value = "admin")] + pub actor: String, +} + +#[derive(Debug, clap::Args)] +pub struct UpstreamGrantArgs { + pub username: String, + #[arg(value_parser = ["allow", "deny", "inherit"])] + pub effect: String, + #[arg(long, default_value = "admin")] + pub actor: String, +} + +#[derive(Debug, clap::Args)] +pub struct UpstreamAddArgs { + pub username: String, + #[arg(long)] + pub provider: String, + #[arg(long)] + pub name: String, + /// Read the upstream secret from stdin. The secret is never an argument. + #[arg(long)] + pub secret_stdin: bool, + #[arg(long, default_value = "admin")] + pub actor: String, +} + +#[derive(Debug, clap::Args)] +pub struct UpstreamListArgs { + pub username: Option, +} + +#[derive(Debug, clap::Args)] +pub struct UpstreamRemoveArgs { + pub username: String, + #[arg(long)] + pub provider: String, + #[arg(long)] + pub name: String, + #[arg(long, default_value = "admin")] + pub actor: String, } #[derive(Debug, Subcommand)] diff --git a/rust/src/config.rs b/rust/src/config.rs index f68d2812..cd7adecb 100644 --- a/rust/src/config.rs +++ b/rust/src/config.rs @@ -1897,8 +1897,76 @@ impl Config { .flat_map(|p| p.accounts.iter()) .collect() } +} + +pub(crate) fn account_secret_from_env(config_path: Option<&Path>, name: &str) -> Option { + if name.trim().is_empty() { + return None; + } + if let Ok(value) = env::var(name) { + return Some(value); + } + let mut paths = Vec::new(); + if let Some(config_path) = config_path + && let Some(parent) = config_path.parent() + { + paths.push(parent.join(".env")); + } + if let Some(explicit) = env::var_os("EGGPOOL_ENV") { + paths.push(PathBuf::from(explicit)); + } + paths + .into_iter() + .find_map(|path| env_file_assignment(&path, name)) +} +fn env_file_assignment(path: &Path, name: &str) -> Option { + let text = fs::read_to_string(path).ok()?; + for line in text.lines() { + let line = line.trim(); + if line.is_empty() || line.starts_with('#') { + continue; + } + let (key, raw) = line.split_once('=')?; + if key.trim() != name { + continue; + } + return Some(unquote_env_value(raw.trim())); + } + None +} + +fn unquote_env_value(raw: &str) -> String { + let Some(inner) = raw + .strip_prefix('"') + .and_then(|value| value.strip_suffix('"')) + else { + return raw.trim_matches('\'').to_owned(); + }; + let mut output = String::new(); + let mut escaped = false; + for character in inner.chars() { + if escaped { + output.push(character); + escaped = false; + } else if character == '\\' { + escaped = true; + } else { + output.push(character); + } + } + output +} + +impl Config { pub fn validate_account_credentials(&self) -> Result<(), ConfigError> { + self.validate_account_credentials_near(None) + } + + pub fn validate_account_credentials_near( + &self, + config_path: Option<&Path>, + ) -> Result<(), ConfigError> { for (provider_id, provider) in &self.providers { if provider.auth.mode == "none" && provider @@ -1915,7 +1983,7 @@ impl Config { let value = account .api_key .clone() - .or_else(|| env::var(&account.api_key_env).ok()); + .or_else(|| account_secret_from_env(config_path, account.api_key_env.as_str())); let Some(key) = value else { return Err(ConfigError::validation(format!( "Provider {provider_id:?} account {:?}: credential is not set", diff --git a/rust/src/config_reload_policy.rs b/rust/src/config_reload_policy.rs index 29834633..8b07e00f 100644 --- a/rust/src/config_reload_policy.rs +++ b/rust/src/config_reload_policy.rs @@ -307,8 +307,12 @@ fn diff_accounts(old: &Value, new: &Value, changes: &mut Vec) { for key in keys { let path = format!("accounts.{key}"); match (old_accounts.get(key), new_accounts.get(key)) { - (None, Some(_)) => changes.push(change(path, "", "", false)), - (Some(_), None) => changes.push(change(path, "", "", false)), + (None, Some(account)) => { + changes.push(change(path, "", account_env_name(account), false)) + } + (Some(account), None) => { + changes.push(change(path, account_env_name(account), "", false)) + } (Some(old_account), Some(new_account)) if old_account != new_account => { diff_structured(&path, old_account, new_account, changes) } @@ -317,6 +321,20 @@ fn diff_accounts(old: &Value, new: &Value, changes: &mut Vec) { } } +fn account_env_name(account: &Value) -> String { + account + .get("api_key_env") + .and_then(Value::as_str) + .filter(|value| { + !value.is_empty() + && value + .chars() + .all(|character| character.is_ascii_alphanumeric() || character == '_') + }) + .unwrap_or("") + .to_owned() +} + fn collect_accounts<'a>( value: &'a Value, accounts: &mut std::collections::BTreeMap, diff --git a/rust/src/coordinator/endpoints.rs b/rust/src/coordinator/endpoints.rs index 66dd1d61..a163c537 100644 --- a/rust/src/coordinator/endpoints.rs +++ b/rust/src/coordinator/endpoints.rs @@ -1345,6 +1345,7 @@ pub async fn execute_stream( /// account registry from durable accounts, and wires the finite/streaming /// coordinators with the configured retry budget. Failures to resolve /// provider wire profiles are fail-closed. +#[allow(clippy::too_many_arguments)] pub(crate) async fn build_inference_state_with_shared( config: &Config, database: &Database, @@ -1353,6 +1354,7 @@ pub(crate) async fn build_inference_state_with_shared( affinity: Arc, model_registry: ModelRouterRegistry, provider_profiles: BTreeMap>, + config_path: Option<&std::path::Path>, ) -> Result { build_inference_state_with_shared_and_accounts( config, @@ -1363,6 +1365,7 @@ pub(crate) async fn build_inference_state_with_shared( model_registry, provider_profiles, None, + config_path, ) .await } @@ -1381,8 +1384,9 @@ pub(crate) async fn build_inference_state_with_shared_and_accounts( model_registry: ModelRouterRegistry, provider_profiles: BTreeMap>, durable_accounts_override: Option>, + config_path: Option<&std::path::Path>, ) -> Result { - let credentials = CredentialStore::from_config(config); + let credentials = CredentialStore::from_config_near(config, config_path); let durable_accounts: Vec = match durable_accounts_override { Some(accounts) => accounts, None => database @@ -1534,6 +1538,9 @@ pub(crate) async fn build_inference_state_with_shared_and_accounts( ) .await .map_err(|error| format!("durable health hydration failed: {error}"))?; + let personal_bindings = crate::personal_upstream::load_snapshot(database) + .await + .map_err(|error| format!("personal upstream snapshot failed: {error}"))?; let router = RoutingRouter::with_shared_catalog( registry, shared_catalog, @@ -1541,6 +1548,7 @@ pub(crate) async fn build_inference_state_with_shared_and_accounts( Some(health), EligibilityPolicy::from_config(config), ) + .with_personal_bindings(personal_bindings) .with_quarantine(quarantine) .with_durable_health(DurableHealth::new( backoff_repository, diff --git a/rust/src/coordinator/finite.rs b/rust/src/coordinator/finite.rs index ba1385d6..eccf0ba4 100644 --- a/rust/src/coordinator/finite.rs +++ b/rust/src/coordinator/finite.rs @@ -704,6 +704,13 @@ impl FiniteCoordinator { attribution: Option, ) -> Result { request.attribution = attribution; + if let Some(user_id) = request + .attribution + .as_ref() + .and_then(|principal| principal.user_id.clone()) + { + request.routing_facts.principal_user_id = Some(user_id); + } let Some(model_id) = request.model_id() else { return Err(FiniteCoordinatorError::InvalidFacts); }; diff --git a/rust/src/coordinator/streaming/coordinator.rs b/rust/src/coordinator/streaming/coordinator.rs index 981e13da..61448b95 100644 --- a/rust/src/coordinator/streaming/coordinator.rs +++ b/rust/src/coordinator/streaming/coordinator.rs @@ -229,6 +229,13 @@ impl StreamingCoordinator { return Err(StreamingCoordinatorError::InvalidFacts); } + let mut request = request; + if let Some(user_id) = attribution + .as_ref() + .and_then(|principal| principal.user_id.clone()) + { + request.routing_facts.principal_user_id = Some(user_id); + } let mut attempt_number = 1_u32; let mut excluded_accounts = BTreeSet::new(); let mut preferred_account = None; diff --git a/rust/src/db/migrations.rs b/rust/src/db/migrations.rs index c0d0757b..696432ea 100644 --- a/rust/src/db/migrations.rs +++ b/rust/src/db/migrations.rs @@ -203,9 +203,9 @@ mod tests { #[test] fn canonical_inventory_is_complete_and_immutable() { MigrationRunner::validate_embedded_checksums().expect("canonical checksums match"); - assert_eq!(MigrationRunner::migrations().len(), 65); + assert_eq!(MigrationRunner::migrations().len(), 66); assert_eq!(MigrationRunner::migrations().first().unwrap().version, 1); - assert_eq!(MigrationRunner::migrations().last().unwrap().version, 65); + assert_eq!(MigrationRunner::migrations().last().unwrap().version, 66); } #[test] diff --git a/rust/src/identity.rs b/rust/src/identity.rs index 7781d34d..82a9274f 100644 --- a/rust/src/identity.rs +++ b/rust/src/identity.rs @@ -853,6 +853,7 @@ async fn set_user_enabled_with_fence( "UPDATE web_sessions SET revoked_at = CURRENT_TIMESTAMP WHERE user_id = ?1 AND revoked_at IS NULL", [&target_id], )?; + crate::personal_upstream::withdraw_user_bindings(connection, &target_id)?; } connection.execute( "INSERT INTO user_admin_audit(actor_id, action, target_kind, target_id) VALUES (?1, ?2, 'user', ?3)", diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 37aa7685..91bfb8c8 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -19,6 +19,7 @@ pub mod instance_budget; pub mod model_policy; pub mod model_router; pub mod operations; +pub mod personal_upstream; pub mod provider_profile; pub mod providers; pub mod quota; diff --git a/rust/src/model_policy.rs b/rust/src/model_policy.rs index 848579c6..31be2c0f 100644 --- a/rust/src/model_policy.rs +++ b/rust/src/model_policy.rs @@ -255,6 +255,39 @@ impl ModelPolicyService { .map_err(ModelPolicyError::Database) } + pub async fn list_profile_assignments( + &self, + ) -> Result, ModelPolicyError> { + self.database + .call(|connection| { + let mut statement = connection.prepare( + "SELECT user_id, profile_id FROM user_profile_assignments ORDER BY user_id", + )?; + statement + .query_map([], |row| Ok((row.get(0)?, row.get(1)?)))? + .collect() + }) + .await + .map_err(ModelPolicyError::Database) + } + + pub async fn list_user_overrides( + &self, + ) -> Result, ModelPolicyError> { + self.database + .call(|connection| { + let mut statement = connection.prepare( + "SELECT user_id, model_id, effect FROM user_policy_overrides \ + ORDER BY user_id, model_id", + )?; + statement + .query_map([], |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)))? + .collect() + }) + .await + .map_err(ModelPolicyError::Database) + } + pub async fn list_profile_rules( &self, ) -> Result, ModelPolicyError> { diff --git a/rust/src/operations/config_mutation.rs b/rust/src/operations/config_mutation.rs index 39285b7f..c5e7645b 100644 --- a/rust/src/operations/config_mutation.rs +++ b/rust/src/operations/config_mutation.rs @@ -15,6 +15,9 @@ use std::{ time::Duration, }; +#[cfg(unix)] +use std::os::unix::fs::PermissionsExt; + use toml::{Value, map::Map}; use crate::{ @@ -172,7 +175,7 @@ fn read_bounded(path: &Path) -> Result, MutationError> { fn validate_config_bytes(path: &Path, bytes: &[u8]) -> Result { let config = Config::from_toml_bytes(path, bytes)?; - config.validate_account_credentials()?; + config.validate_account_credentials_near(Some(path))?; Ok(config) } @@ -869,17 +872,36 @@ fn provider_block( template: &ProviderTemplate, account_name: &str, api_key: Option<&str>, + api_key_env: Option<&str>, +) -> Result { + provider_block_from_table( + &template.id, + template.data.clone(), + account_name, + api_key, + api_key_env, + ) +} + +fn provider_block_from_table( + provider_id: &str, + mut provider: Map, + account_name: &str, + api_key: Option<&str>, + api_key_env: Option<&str>, ) -> Result { - let mut provider = template.data.clone(); provider.insert("routing_priority".into(), Value::Integer(0)); let mut account = Map::new(); account.insert("name".into(), Value::String(account_name.into())); if let Some(api_key) = api_key { account.insert("api_key".into(), Value::String(api_key.into())); } + if let Some(api_key_env) = api_key_env { + account.insert("api_key_env".into(), Value::String(api_key_env.into())); + } provider.insert("accounts".into(), Value::Array(vec![Value::Table(account)])); let mut providers = Map::new(); - providers.insert(template.id.clone(), Value::Table(provider)); + providers.insert(provider_id.to_owned(), Value::Table(provider)); let mut root = Map::new(); root.insert("providers".into(), Value::Table(providers)); let rendered = toml::to_string_pretty(&Value::Table(root)).map_err(|error| { @@ -898,6 +920,7 @@ fn append_account( provider_id: &str, account_name: &str, api_key: Option<&str>, + api_key_env: Option<&str>, ) -> Result { let lines: Vec = text.lines().map(str::to_owned).collect(); let header = format!("providers.{provider_id}.accounts"); @@ -921,6 +944,9 @@ fn append_account( if let Some(api_key) = api_key { insertion.push(format!("api_key = {}", render_string(api_key))); } + if let Some(api_key_env) = api_key_env { + insertion.push(format!("api_key_env = {}", render_string(api_key_env))); + } let mut updated = lines; let index = end; if start.is_none() { @@ -1125,9 +1151,10 @@ pub fn connect_with_transition( &provider_id, &account_name, api_key.as_deref(), + None, )? } else { - let block = provider_block(&template, &account_name, api_key.as_deref())?; + let block = provider_block(&template, &account_name, api_key.as_deref(), None)?; let mut lines: Vec = original_text.lines().map(str::to_owned).collect(); let index = lines .iter() @@ -1366,6 +1393,302 @@ pub fn logout_with_transition( }) } +/// Previous file bytes captured before a personal-upstream publication. +/// +/// Restoring is explicit. Dropping the value leaves the published bytes in +/// place. The captured bytes are the previous files, never the new secret. +pub struct PersonalFileRollback { + config_path: PathBuf, + previous_config: Vec, + env_path: PathBuf, + previous_env: Option>, +} + +impl PersonalFileRollback { + pub fn restore(self) -> Result<(), MutationError> { + let _guard = lock_mutation(&self.config_path)?; + atomic_replace( + &self.config_path, + &self.previous_config, + existing_mode(&self.config_path)?, + )?; + match &self.previous_env { + Some(bytes) => { + #[cfg(unix)] + let mode = Some(fs::Permissions::from_mode(0o600)); + #[cfg(not(unix))] + let mode = None; + atomic_replace(&self.env_path, bytes, mode)?; + } + None => { + if self.env_path.exists() { + fs::remove_file(&self.env_path).map_err(MutationError::Write)?; + } + } + } + Ok(()) + } +} + +fn personal_account_text( + original_text: &str, + provider_id: &str, + account_name: &str, + api_key_env: &str, +) -> Result { + if !valid_identifier(provider_id) || !valid_identifier(account_name) { + return Err(MutationError::Invalid( + "provider id or account name contains unsafe characters".into(), + )); + } + if account_names(original_text) + .iter() + .any(|name| name == account_name) + { + return Err(MutationError::Invalid( + "account name is already configured".into(), + )); + } + let templates = load_provider_templates(None)?; + if !templates.contains_key(provider_id) { + return Err(MutationError::Invalid( + "provider is not a bundled profile".into(), + )); + } + if provider_exists(original_text, provider_id) { + append_account( + original_text, + provider_id, + account_name, + None, + Some(api_key_env), + ) + } else { + let profile = crate::provider_profile::bundled_profile(provider_id) + .map_err(|_| MutationError::Invalid("provider is not a bundled profile".into()))?; + let block = provider_block_from_table( + provider_id, + crate::provider_profile::provider_config_table(profile), + account_name, + None, + Some(api_key_env), + )?; + let mut lines: Vec = original_text.lines().map(str::to_owned).collect(); + let index = lines + .iter() + .position(|line| { + line_header(line).is_some_and(|header| header.starts_with("providers.")) + }) + .unwrap_or(lines.len()); + let block_lines: Vec = block.lines().map(str::to_owned).collect(); + lines.splice( + index..index, + block_lines + .into_iter() + .chain(std::iter::once(String::new())), + ); + Ok(format!("{}\n", lines.join("\n"))) + } +} + +fn env_assignment(name: &str, secret: &str) -> Result { + if secret.is_empty() + || secret.chars().any(|character| character.is_control()) + || secret.contains('\n') + || secret.contains('\r') + { + return Err(MutationError::Invalid( + "upstream secret was rejected".into(), + )); + } + let escaped = secret.replace('\\', "\\\\").replace('"', "\\\""); + Ok(format!("{name}=\"{escaped}\"\n")) +} + +fn upsert_env(existing: &str, name: &str, secret: &str) -> Result { + if existing.lines().any(|line| { + let key = line.split_once('=').map(|(key, _)| key.trim()); + key == Some(name) + }) { + return Err(MutationError::Invalid( + "upstream environment variable is already defined".into(), + )); + } + let mut text = existing.to_owned(); + if !text.is_empty() && !text.ends_with('\n') { + text.push('\n'); + } + text.push_str(&env_assignment(name, secret)?); + Ok(text) +} + +fn restore_env( + env_path: &Path, + previous: Option<&[u8]>, + mode: Option, +) -> Result<(), MutationError> { + match previous { + Some(bytes) => atomic_replace(env_path, bytes, mode), + None => { + if env_path.exists() { + fs::remove_file(env_path).map_err(MutationError::Write)?; + } + Ok(()) + } + } +} + +fn omit_env_assignment(existing: &str, name: &str) -> String { + let mut kept = existing + .lines() + .filter(|line| { + line.split_once('=') + .is_none_or(|(key, _)| key.trim() != name) + }) + .map(str::to_owned) + .collect::>(); + if kept.is_empty() { + return String::new(); + } + if !kept.last().is_some_and(|line| line.is_empty()) { + kept.push(String::new()); + } + format!("{}\n", kept.join("\n")) +} + +/// Publish one personal account stanza and its environment assignment. +/// +/// Classification happens before either file changes. A restart-required +/// transition writes nothing. +pub fn install_personal_account_files( + config_path: &Path, + env_path: &Path, + provider_id: &str, + account_name: &str, + api_key_env: &str, + secret: &str, +) -> Result<(PersonalFileRollback, ConfigTransition), MutationError> { + let _guard = lock_mutation(config_path)?; + let previous_config = if config_path.exists() { + read_bounded(config_path)? + } else { + Vec::new() + }; + let original_text = String::from_utf8(previous_config.clone()).map_err(|error| { + MutationError::Invalid(format!("configuration is not valid UTF-8: {error}")) + })?; + let updated = personal_account_text(&original_text, provider_id, account_name, api_key_env)?; + let old_config = Config::from_toml_bytes(config_path, original_text.as_bytes())?; + let candidate = Config::from_toml_bytes(config_path, updated.as_bytes())?; + let transition = classify_transition(&old_config, &candidate).map_err(|error| { + MutationError::Invalid(format!( + "configuration transition could not be classified: {error}" + )) + })?; + if transition.has_restart_required() { + return Err(MutationError::Invalid( + "personal account publication is restart-required".into(), + )); + } + let previous_env = if env_path.exists() { + Some(read_bounded(env_path)?) + } else { + None + }; + let env_text = String::from_utf8(previous_env.clone().unwrap_or_default()) + .map_err(|_| MutationError::Invalid("environment file is not valid UTF-8".into()))?; + let updated_env = upsert_env(&env_text, api_key_env, secret)?; + #[cfg(unix)] + let env_mode = Some(fs::Permissions::from_mode(0o600)); + #[cfg(not(unix))] + let env_mode = None; + atomic_replace(env_path, updated_env.as_bytes(), env_mode.clone())?; + if let Err(error) = candidate.validate_account_credentials_near(Some(config_path)) { + restore_env(env_path, previous_env.as_deref(), env_mode)?; + return Err(error.into()); + } + if let Err(error) = atomic_replace(config_path, updated.as_bytes(), existing_mode(config_path)?) + { + let _ = restore_env(env_path, previous_env.as_deref(), env_mode); + return Err(error); + } + Ok(( + PersonalFileRollback { + config_path: config_path.to_path_buf(), + previous_config, + env_path: env_path.to_path_buf(), + previous_env, + }, + transition, + )) +} + +/// Omit a personal account and its environment assignment. +pub fn omit_personal_account_files( + config_path: &Path, + env_path: &Path, + provider_id: &str, + account_name: &str, + api_key_env: &str, +) -> Result<(PersonalFileRollback, ConfigTransition), MutationError> { + let _guard = lock_mutation(config_path)?; + let previous_config = read_bounded(config_path)?; + let original_text = String::from_utf8(previous_config.clone()).map_err(|error| { + MutationError::Invalid(format!("configuration is not valid UTF-8: {error}")) + })?; + let updated = remove_account_block( + &original_text, + &AccountMatch { + provider_id: provider_id.to_owned(), + name: account_name.to_owned(), + api_key_env: api_key_env.to_owned(), + api_key: None, + }, + )?; + let old_config = Config::from_toml_bytes(config_path, original_text.as_bytes())?; + let candidate = validate_config_bytes(config_path, updated.as_bytes())?; + let transition = classify_transition(&old_config, &candidate).map_err(|error| { + MutationError::Invalid(format!( + "configuration transition could not be classified: {error}" + )) + })?; + if transition.has_restart_required() { + return Err(MutationError::Invalid( + "personal account removal is restart-required".into(), + )); + } + let previous_env = if env_path.exists() { + Some(read_bounded(env_path)?) + } else { + None + }; + let env_text = String::from_utf8(previous_env.clone().unwrap_or_default()) + .map_err(|_| MutationError::Invalid("environment file is not valid UTF-8".into()))?; + let updated_env = omit_env_assignment(&env_text, api_key_env); + atomic_replace(config_path, updated.as_bytes(), existing_mode(config_path)?)?; + #[cfg(unix)] + let env_mode = Some(fs::Permissions::from_mode(0o600)); + #[cfg(not(unix))] + let env_mode = None; + if let Err(error) = atomic_replace(env_path, updated_env.as_bytes(), env_mode) { + let _ = atomic_replace( + config_path, + &previous_config, + existing_mode(config_path).ok().flatten(), + ); + return Err(error); + } + Ok(( + PersonalFileRollback { + config_path: config_path.to_path_buf(), + previous_config, + env_path: env_path.to_path_buf(), + previous_env, + }, + transition, + )) +} + pub async fn apply_after_mutation( path: &Path, mode: ApplyMode, diff --git a/rust/src/personal_upstream.rs b/rust/src/personal_upstream.rs new file mode 100644 index 00000000..c38ae812 --- /dev/null +++ b/rust/src/personal_upstream.rs @@ -0,0 +1,763 @@ +//! Secret-free personal upstream grants and bindings. +//! +//! The plaintext provider secret is written only to the config-adjacent +//! environment file. SQLite records who may select the account. Routing reads +//! a generation snapshot of those rows and never a credential. + +use std::{ + collections::BTreeMap, + path::{Path, PathBuf}, +}; + +use sha2::{Digest, Sha256}; +use thiserror::Error; +use tokio_rusqlite::rusqlite::{self, OptionalExtension}; + +use crate::{ + config_reload_policy::ConfigTransition, + db::{Database, DatabaseError}, + operations::config_mutation::{ + ApplyMode, ApplyOutcome, MutationError, apply_after_mutation, + install_personal_account_files, omit_personal_account_files, + }, +}; + +#[derive(Debug, Error)] +pub enum PersonalUpstreamError { + #[error("administrator required")] + AdministratorRequired, + #[error("user was not found")] + UserNotFound, + #[error("provider is not a bundled profile")] + UnknownProvider, + #[error("account name is already in use")] + NameCollision, + #[error("upstream secret was rejected")] + SecretRejected, + #[error("self-service is not allowed")] + GrantDenied, + #[error("binding was not found")] + BindingNotFound, + #[error("publication failed and the previous files were restored")] + PublicationRestored, + #[error("the account is not routable and the files need operator repair")] + RepairRequired, + #[error(transparent)] + Database(#[from] DatabaseError), + #[error("{0}")] + Configuration(String), +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum GrantEffect { + Allow, + Deny, + Inherit, +} + +impl GrantEffect { + pub fn parse(value: &str) -> Option { + match value { + "allow" => Some(Self::Allow), + "deny" => Some(Self::Deny), + "inherit" => Some(Self::Inherit), + _ => None, + } + } + + pub const fn as_str(self) -> &'static str { + match self { + Self::Allow => "allow", + Self::Deny => "deny", + Self::Inherit => "inherit", + } + } +} + +#[derive(Debug, Clone, PartialEq, Eq)] +enum BindingState { + Active(String), + Withdrawn, + Ambiguous, +} + +/// Generation-scoped view of personal bindings. No row means the account is +/// shared. The snapshot stores no secret. +#[derive(Debug, Clone, Default, PartialEq, Eq)] +pub struct PersonalUpstreamSnapshot { + bindings: BTreeMap<(String, String), BindingState>, +} + +impl PersonalUpstreamSnapshot { + pub fn excludes( + &self, + provider_id: &str, + account_name: &str, + principal_user_id: Option<&str>, + ) -> bool { + match self + .bindings + .get(&(provider_id.to_owned(), account_name.to_owned())) + { + None => false, + Some(BindingState::Withdrawn | BindingState::Ambiguous) => true, + Some(BindingState::Active(owner)) => principal_user_id != Some(owner.as_str()), + } + } +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct PersonalBinding { + pub provider_id: String, + pub account_name: String, + pub user_id: String, + pub state: String, + pub env_var: String, +} + +pub fn upstream_env_var(provider_id: &str, account_name: &str) -> String { + let mut hasher = Sha256::new(); + hasher.update(provider_id.as_bytes()); + hasher.update([0]); + hasher.update(account_name.as_bytes()); + let digest = hasher.finalize(); + let hex = digest.iter().take(8).fold(String::new(), |mut text, byte| { + text.push_str(&format!("{byte:02x}")); + text + }); + format!("EGGPOOL_UPSTREAM_{hex}") +} + +pub fn personal_env_path(config_path: &Path) -> PathBuf { + if let Some(explicit) = std::env::var_os("EGGPOOL_ENV") { + return PathBuf::from(explicit); + } + config_path + .parent() + .unwrap_or_else(|| Path::new(".")) + .join(".env") +} + +pub async fn instance_grant(database: &Database) -> Result { + let effect = database + .call(|connection| { + connection.query_row( + "SELECT effect FROM personal_upstream_grants WHERE scope = 'instance' AND user_id = ''", + [], + |row| row.get::<_, String>(0), + ) + }) + .await?; + Ok(GrantEffect::parse(&effect).unwrap_or(GrantEffect::Deny)) +} + +pub async fn effective_grant( + database: &Database, + user_id: &str, +) -> Result { + let user_id = user_id.to_owned(); + let stored = database + .call(move |connection| { + let user: Option = connection + .query_row( + "SELECT effect FROM personal_upstream_grants WHERE scope = 'user' AND user_id = ?1", + [&user_id], + |row| row.get(0), + ) + .optional()?; + let instance: String = connection.query_row( + "SELECT effect FROM personal_upstream_grants WHERE scope = 'instance' AND user_id = ''", + [], + |row| row.get(0), + )?; + Ok((user, instance)) + }) + .await?; + let effect = match stored.0.as_deref().and_then(GrantEffect::parse) { + Some(GrantEffect::Inherit) | None => { + GrantEffect::parse(&stored.1).unwrap_or(GrantEffect::Deny) + } + Some(effect) => effect, + }; + Ok(match effect { + GrantEffect::Inherit => GrantEffect::Deny, + other => other, + }) +} + +pub async fn stored_user_grant( + database: &Database, + user_id: &str, +) -> Result { + let user_id = user_id.to_owned(); + let stored = database + .call(move |connection| { + connection + .query_row( + "SELECT effect FROM personal_upstream_grants WHERE scope = 'user' AND user_id = ?1", + [&user_id], + |row| row.get::<_, String>(0), + ) + .optional() + }) + .await?; + Ok(stored + .as_deref() + .and_then(GrantEffect::parse) + .unwrap_or(GrantEffect::Inherit)) +} + +pub async fn set_instance_grant( + database: &Database, + actor_id: &str, + effect: GrantEffect, +) -> Result<(), PersonalUpstreamError> { + if !matches!(effect, GrantEffect::Allow | GrantEffect::Deny) { + return Err(PersonalUpstreamError::Configuration( + "instance grant must be allow or deny".into(), + )); + } + write_grant(database, actor_id, "instance", "", effect, "instance").await +} + +pub async fn set_user_grant( + database: &Database, + actor_id: &str, + user_id: &str, + effect: GrantEffect, +) -> Result<(), PersonalUpstreamError> { + if GrantEffect::parse(effect.as_str()).is_none() { + return Err(PersonalUpstreamError::Configuration( + "user grant must be allow, deny, or inherit".into(), + )); + } + write_grant(database, actor_id, "user", user_id, effect, user_id).await +} + +async fn write_grant( + database: &Database, + actor_id: &str, + scope: &str, + user_id: &str, + effect: GrantEffect, + audit_target: &str, +) -> Result<(), PersonalUpstreamError> { + let actor_id = actor_id.to_owned(); + let scope = scope.to_owned(); + let user_id = user_id.to_owned(); + let audit_target = audit_target.to_owned(); + let effect_text = effect.as_str().to_owned(); + database + .with_transaction(move |connection| { + if !actor_is_admin(connection, &actor_id)? { + return Ok(Err(PersonalUpstreamError::AdministratorRequired)); + } + if scope == "user" && !user_exists(connection, &user_id)? { + return Ok(Err(PersonalUpstreamError::UserNotFound)); + } + connection.execute( + "INSERT INTO personal_upstream_grants(scope, user_id, effect, updated_by, updated_at) + VALUES (?1, ?2, ?3, ?4, CURRENT_TIMESTAMP) + ON CONFLICT(scope, user_id) DO UPDATE SET + effect = excluded.effect, + updated_by = excluded.updated_by, + updated_at = CURRENT_TIMESTAMP", + (&scope, &user_id, &effect_text, &actor_id), + )?; + connection.execute( + "INSERT INTO user_admin_audit(actor_id, action, target_kind, target_id) + VALUES (?1, 'upstream_grant', 'user', ?2)", + (&actor_id, &audit_target), + )?; + Ok(Ok(())) + }) + .await??; + Ok(()) +} + +pub async fn list_bindings( + database: &Database, + user_id: Option<&str>, +) -> Result, PersonalUpstreamError> { + let user_id = user_id.map(str::to_owned); + let rows = database + .call(move |connection| { + let mut statement = connection.prepare( + "SELECT provider_id, account_name, user_id, state + FROM personal_upstream_bindings + WHERE (?1 IS NULL OR user_id = ?1) + ORDER BY provider_id, account_name", + )?; + let mapped = statement.query_map([&user_id], |row| { + Ok(( + row.get::<_, String>(0)?, + row.get::<_, String>(1)?, + row.get::<_, String>(2)?, + row.get::<_, String>(3)?, + )) + })?; + mapped.collect::, _>>() + }) + .await?; + Ok(rows + .into_iter() + .map(|(provider_id, account_name, user_id, state)| { + let env_var = upstream_env_var(&provider_id, &account_name); + PersonalBinding { + provider_id, + account_name, + user_id, + state, + env_var, + } + }) + .collect()) +} + +pub async fn load_snapshot( + database: &Database, +) -> Result { + let rows = database + .call(|connection| { + let mut statement = connection.prepare( + "SELECT provider_id, account_name, user_id, state FROM personal_upstream_bindings", + )?; + let mapped = statement.query_map([], |row| { + Ok(( + row.get::<_, String>(0)?, + row.get::<_, String>(1)?, + row.get::<_, String>(2)?, + row.get::<_, String>(3)?, + )) + })?; + mapped.collect::, _>>() + }) + .await?; + let mut bindings = BTreeMap::new(); + for (provider_id, account_name, user_id, state) in rows { + let key = (provider_id, account_name); + let next = match state.as_str() { + "active" => BindingState::Active(user_id), + "withdrawn" => BindingState::Withdrawn, + _ => BindingState::Ambiguous, + }; + match bindings.get(&key) { + Some(_) => { + bindings.insert(key, BindingState::Ambiguous); + } + None => { + bindings.insert(key, next); + } + } + } + Ok(PersonalUpstreamSnapshot { bindings }) +} + +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub enum PublishMode { + Live, + Fail, +} + +/// One personal-account add or remove. The secret is borrowed only for the +/// write and is never stored on the binding. +pub struct PersonalAccountWrite<'a> { + pub actor_id: &'a str, + pub user_id: &'a str, + pub provider_id: &'a str, + pub account_name: &'a str, + pub secret: &'a str, + pub config_path: &'a Path, + pub env_path: &'a Path, + pub require_self_service: bool, +} + +pub async fn add_personal_account( + database: &Database, + write: PersonalAccountWrite<'_>, +) -> Result<(), PersonalUpstreamError> { + add_personal_account_publishing(database, write, PublishMode::Live).await +} + +pub async fn add_personal_account_publishing( + database: &Database, + write: PersonalAccountWrite<'_>, + publish: PublishMode, +) -> Result<(), PersonalUpstreamError> { + let PersonalAccountWrite { + actor_id, + user_id, + provider_id, + account_name, + secret, + config_path, + env_path, + require_self_service, + } = write; + validate_names(provider_id, account_name)?; + if !bundled_provider(provider_id) { + return Err(PersonalUpstreamError::UnknownProvider); + } + if !acceptable_secret(secret) { + return Err(PersonalUpstreamError::SecretRejected); + } + authorize(database, actor_id, user_id, require_self_service).await?; + if name_is_bound(database, provider_id, account_name).await? { + return Err(PersonalUpstreamError::NameCollision); + } + insert_binding( + database, + actor_id, + user_id, + provider_id, + account_name, + "active", + "upstream_add", + ) + .await?; + let env_var = upstream_env_var(provider_id, account_name); + let published = install_personal_account_files( + config_path, + env_path, + provider_id, + account_name, + &env_var, + secret, + ); + let (rollback, transition) = match published { + Ok(value) => value, + Err(error) => { + let _ = delete_binding(database, provider_id, account_name).await; + return Err(configuration_error(secret, error)); + } + }; + if run_publish(publish, config_path, &transition) + .await + .is_err() + { + let _ = rollback.restore(); + let _ = delete_binding(database, provider_id, account_name).await; + return Err(PersonalUpstreamError::PublicationRestored); + } + Ok(()) +} + +pub async fn remove_personal_account( + database: &Database, + write: PersonalAccountWrite<'_>, +) -> Result<(), PersonalUpstreamError> { + remove_personal_account_publishing(database, write, PublishMode::Live).await +} + +pub async fn remove_personal_account_publishing( + database: &Database, + write: PersonalAccountWrite<'_>, + publish: PublishMode, +) -> Result<(), PersonalUpstreamError> { + let PersonalAccountWrite { + actor_id, + user_id, + provider_id, + account_name, + config_path, + env_path, + require_self_service, + .. + } = write; + validate_names(provider_id, account_name)?; + authorize(database, actor_id, user_id, require_self_service).await?; + if !binding_is_active(database, provider_id, account_name, user_id).await? { + return Err(PersonalUpstreamError::BindingNotFound); + } + withdraw_binding(database, actor_id, provider_id, account_name).await?; + let env_var = upstream_env_var(provider_id, account_name); + let published = + omit_personal_account_files(config_path, env_path, provider_id, account_name, &env_var); + let (rollback, transition) = match published { + Ok(value) => value, + Err(_) => return Err(PersonalUpstreamError::RepairRequired), + }; + if run_publish(publish, config_path, &transition) + .await + .is_err() + { + let _ = rollback.restore(); + return Err(PersonalUpstreamError::RepairRequired); + } + delete_binding(database, provider_id, account_name).await +} + +impl PersonalUpstreamError { + pub fn kind(&self) -> &'static str { + match self { + Self::AdministratorRequired => "administrator_required", + Self::UserNotFound => "user_not_found", + Self::UnknownProvider => "unknown_provider", + Self::NameCollision => "name_collision", + Self::SecretRejected => "secret_rejected", + Self::GrantDenied => "grant_denied", + Self::BindingNotFound => "binding_not_found", + Self::PublicationRestored => "publication_restored", + Self::RepairRequired => "repair_required", + Self::Database(_) => "database", + Self::Configuration(_) => "configuration", + } + } +} + +async fn run_publish( + mode: PublishMode, + path: &Path, + transition: &ConfigTransition, +) -> Result<(), ()> { + match mode { + PublishMode::Fail => Err(()), + PublishMode::Live => live_publish(path, transition).await, + } +} + +async fn live_publish(path: &Path, transition: &ConfigTransition) -> Result<(), ()> { + match apply_after_mutation(path, ApplyMode::LiveOrReport, transition).await { + Ok( + ApplyOutcome::RehashApplied | ApplyOutcome::RehashNoop | ApplyOutcome::ServerNotRunning, + ) => Ok(()), + _ => Err(()), + } +} + +fn validate_names(provider_id: &str, account_name: &str) -> Result<(), PersonalUpstreamError> { + let valid = |value: &str| { + !value.is_empty() + && value.len() <= 96 + && value.chars().all(|character| { + character.is_ascii_alphanumeric() || character == '-' || character == '_' + }) + }; + if valid(provider_id) && valid(account_name) { + Ok(()) + } else { + Err(PersonalUpstreamError::Configuration( + "provider id or account name contains unsafe characters".into(), + )) + } +} + +fn acceptable_secret(secret: &str) -> bool { + !secret.is_empty() + && secret.len() <= 4096 + && !secret.chars().any(|character| character.is_control()) +} + +fn bundled_provider(provider_id: &str) -> bool { + crate::provider_profile::bundled_profile(provider_id).is_ok() +} + +fn configuration_error(secret: &str, error: MutationError) -> PersonalUpstreamError { + let message = error.to_string().replace(secret, "[redacted]"); + if message.contains("already configured") || message.contains("already defined") { + PersonalUpstreamError::NameCollision + } else if message.contains("not a bundled profile") { + PersonalUpstreamError::UnknownProvider + } else if message.contains("secret was rejected") { + PersonalUpstreamError::SecretRejected + } else { + PersonalUpstreamError::Configuration(message) + } +} + +async fn authorize( + database: &Database, + actor_id: &str, + user_id: &str, + require_self_service: bool, +) -> Result<(), PersonalUpstreamError> { + let actor_id = actor_id.to_owned(); + let user_id_owned = user_id.to_owned(); + let (admin, actor_is_user, active) = database + .call(move |connection| { + Ok(( + actor_is_admin(connection, &actor_id)?, + connection.query_row( + "SELECT EXISTS(SELECT 1 FROM users WHERE id = ?1 AND id = ?2 AND state = 'active')", + (&actor_id, &user_id_owned), + |row| row.get::<_, bool>(0), + )?, + user_exists(connection, &user_id_owned)?, + )) + }) + .await?; + if require_self_service { + if !actor_is_user { + return Err(PersonalUpstreamError::GrantDenied); + } + let effect = effective_grant(database, user_id).await?; + if effect != GrantEffect::Allow { + return Err(PersonalUpstreamError::GrantDenied); + } + return Ok(()); + } + if !admin { + return Err(PersonalUpstreamError::AdministratorRequired); + } + if !active { + return Err(PersonalUpstreamError::UserNotFound); + } + Ok(()) +} + +fn actor_is_admin( + connection: &rusqlite::Connection, + actor_id: &str, +) -> Result { + connection.query_row( + "SELECT EXISTS(SELECT 1 FROM users WHERE id = ?1 AND role = 'admin' AND state = 'active')", + [actor_id], + |row| row.get(0), + ) +} + +fn user_exists(connection: &rusqlite::Connection, user_id: &str) -> Result { + connection.query_row( + "SELECT EXISTS(SELECT 1 FROM users WHERE id = ?1)", + [user_id], + |row| row.get(0), + ) +} + +async fn name_is_bound( + database: &Database, + provider_id: &str, + account_name: &str, +) -> Result { + let provider_id = provider_id.to_owned(); + let account_name = account_name.to_owned(); + Ok(database + .call(move |connection| { + connection.query_row( + "SELECT EXISTS( + SELECT 1 FROM personal_upstream_bindings + WHERE account_name = ?1 OR (provider_id = ?2 AND account_name = ?1) + )", + (&account_name, &provider_id), + |row| row.get(0), + ) + }) + .await?) +} + +async fn binding_is_active( + database: &Database, + provider_id: &str, + account_name: &str, + user_id: &str, +) -> Result { + let provider_id = provider_id.to_owned(); + let account_name = account_name.to_owned(); + let user_id = user_id.to_owned(); + Ok(database + .call(move |connection| { + connection.query_row( + "SELECT EXISTS( + SELECT 1 FROM personal_upstream_bindings + WHERE provider_id = ?1 AND account_name = ?2 AND user_id = ?3 AND state = 'active' + )", + (&provider_id, &account_name, &user_id), + |row| row.get(0), + ) + }) + .await?) +} + +async fn insert_binding( + database: &Database, + actor_id: &str, + user_id: &str, + provider_id: &str, + account_name: &str, + state: &str, + action: &str, +) -> Result<(), PersonalUpstreamError> { + let actor_id = actor_id.to_owned(); + let user_id = user_id.to_owned(); + let provider_id = provider_id.to_owned(); + let account_name = account_name.to_owned(); + let state = state.to_owned(); + let action = action.to_owned(); + database + .with_transaction(move |connection| { + connection.execute( + "INSERT INTO personal_upstream_bindings( + provider_id, account_name, user_id, state, actor_id + ) VALUES (?1, ?2, ?3, ?4, ?5)", + (&provider_id, &account_name, &user_id, &state, &actor_id), + )?; + connection.execute( + "INSERT INTO user_admin_audit(actor_id, action, target_kind, target_id) + VALUES (?1, ?2, 'account', ?3)", + (&actor_id, &action, &account_name), + )?; + Ok(()) + }) + .await?; + Ok(()) +} + +async fn withdraw_binding( + database: &Database, + actor_id: &str, + provider_id: &str, + account_name: &str, +) -> Result<(), PersonalUpstreamError> { + let actor_id = actor_id.to_owned(); + let provider_id = provider_id.to_owned(); + let account_name = account_name.to_owned(); + database + .with_transaction(move |connection| { + connection.execute( + "UPDATE personal_upstream_bindings + SET state = 'withdrawn', actor_id = ?1, updated_at = CURRENT_TIMESTAMP + WHERE provider_id = ?2 AND account_name = ?3 AND state = 'active'", + (&actor_id, &provider_id, &account_name), + )?; + connection.execute( + "INSERT INTO user_admin_audit(actor_id, action, target_kind, target_id) + VALUES (?1, 'upstream_remove', 'account', ?2)", + (&actor_id, &account_name), + )?; + Ok(()) + }) + .await?; + Ok(()) +} + +async fn delete_binding( + database: &Database, + provider_id: &str, + account_name: &str, +) -> Result<(), PersonalUpstreamError> { + let provider_id = provider_id.to_owned(); + let account_name = account_name.to_owned(); + database + .call(move |connection| { + connection.execute( + "DELETE FROM personal_upstream_bindings WHERE provider_id = ?1 AND account_name = ?2", + (&provider_id, &account_name), + )?; + Ok(()) + }) + .await?; + Ok(()) +} + +pub fn withdraw_user_bindings( + connection: &rusqlite::Connection, + user_id: &str, +) -> Result<(), rusqlite::Error> { + connection.execute( + "UPDATE personal_upstream_bindings + SET state = 'withdrawn', updated_at = CURRENT_TIMESTAMP + WHERE user_id = ?1 AND state = 'active'", + [user_id], + )?; + Ok(()) +} diff --git a/rust/src/routing/eligibility.rs b/rust/src/routing/eligibility.rs index ef3e9681..7e4a8cae 100644 --- a/rust/src/routing/eligibility.rs +++ b/rust/src/routing/eligibility.rs @@ -32,6 +32,9 @@ pub struct RoutingRequestFacts { pub thinking: Option, pub capability_policy: BTreeMap, pub now: i64, + /// Authenticated principal. Absent for a legacy shared key, which cannot + /// select a personally bound account. + pub principal_user_id: Option, } /// The wall clock routing facts are stamped with. @@ -64,6 +67,7 @@ impl RoutingRequestFacts { thinking: None, capability_policy: BTreeMap::new(), now: 0, + principal_user_id: None, } } @@ -239,6 +243,7 @@ pub fn build_eligible_candidates( facts: &RoutingRequestFacts, policy: &EligibilityPolicy, active_requests: &BTreeMap, + personal_bindings: &crate::personal_upstream::PersonalUpstreamSnapshot, ) -> (Vec, Vec) { let mut eligible = Vec::new(); let mut exclusions = Vec::new(); @@ -248,6 +253,17 @@ pub fn build_eligible_candidates( &facts.capability_policy }; for identity in registry.all() { + if personal_bindings.excludes( + &identity.provider_id, + &identity.account_name, + facts.principal_user_id.as_deref(), + ) { + exclusions.push(RoutingExclusion { + account_name: identity.account_name.clone(), + reason_code: "personal_upstream".into(), + }); + continue; + } let Some(candidate) = candidate_for_account( identity, catalog, diff --git a/rust/src/routing/router.rs b/rust/src/routing/router.rs index 558c1bcc..be8a75be 100644 --- a/rust/src/routing/router.rs +++ b/rust/src/routing/router.rs @@ -103,6 +103,7 @@ struct RoutingState { recovery_clock: Arc f64 + Send + Sync>, recovery_min_interval_s: f64, recovery_callback: Option, + personal_bindings: crate::personal_upstream::PersonalUpstreamSnapshot, } /// Owns the in-memory routing state for one migration generation. @@ -163,6 +164,7 @@ impl RoutingRouter { recovery_clock: Arc::new(move || clock.elapsed().as_secs_f64()), recovery_min_interval_s: 60.0, recovery_callback: None, + personal_bindings: crate::personal_upstream::PersonalUpstreamSnapshot::default(), }), selection_lock: Arc::new(AsyncMutex::new(())), } @@ -173,6 +175,14 @@ impl RoutingRouter { self } + pub fn with_personal_bindings( + mut self, + bindings: crate::personal_upstream::PersonalUpstreamSnapshot, + ) -> Self { + Arc::make_mut(&mut self.state).personal_bindings = bindings; + self + } + pub fn with_quarantine(mut self, quarantine: ModelQuarantine) -> Self { Arc::make_mut(&mut self.state).quarantine = Some(quarantine); self @@ -241,6 +251,7 @@ impl RoutingRouter { facts, &self.state.policy, &active, + &self.state.personal_bindings, ); drop(catalog); self.plan_from_candidates(facts, candidates, exclusions) @@ -413,6 +424,7 @@ impl RoutingRouter { facts, &self.state.policy, &active, + &self.state.personal_bindings, ); candidates.retain(|candidate| !exclude_accounts.contains(&candidate.account_name)); if let Some(preferred_account) = preferred_account { diff --git a/rust/src/runtime.rs b/rust/src/runtime.rs index 0cc2f4ee..cf642310 100644 --- a/rust/src/runtime.rs +++ b/rust/src/runtime.rs @@ -732,7 +732,12 @@ async fn users(path: &Path, command: crate::cli::UsersCommand) -> Result<(), Boo } } crate::cli::UsersCommand::Bootstrap(args) => { - let password = read_user_password(args.password_stdin, true, "Administrator password")?; + let password = read_user_password( + args.password_stdin, + true, + "Administrator password", + "--password-stdin", + )?; let (user, credential) = crate::identity::bootstrap_admin(&database, &args.username, &password) .await @@ -742,8 +747,12 @@ async fn users(path: &Path, command: crate::cli::UsersCommand) -> Result<(), Boo } crate::cli::UsersCommand::Add(args) => { let actor = policy_actor_id(&database, &args.actor).await?; - let password = - read_user_password(args.password_stdin, false, "Temporary member password")?; + let password = read_user_password( + args.password_stdin, + false, + "Temporary member password", + "--password-stdin", + )?; let user = if args.no_profile { crate::identity::create_member_without_profile( &database, @@ -812,7 +821,12 @@ async fn users(path: &Path, command: crate::cli::UsersCommand) -> Result<(), Boo println!("must_change_password: {}", user.must_change_password); } crate::cli::UsersCommand::ResetPassword(args) => { - let password = read_user_password(args.password_stdin, true, "Administrator password")?; + let password = read_user_password( + args.password_stdin, + true, + "Administrator password", + "--password-stdin", + )?; crate::identity::reset_password(&database, &args.username, &password) .await .map_err(|error| command_error(EXIT_VALIDATION, error.to_string()))?; @@ -940,6 +954,140 @@ async fn users(path: &Path, command: crate::cli::UsersCommand) -> Result<(), Boo } } } + crate::cli::UsersCommand::Upstream(command) => { + use crate::cli::UsersUpstreamCommand as Upstream; + use crate::personal_upstream::GrantEffect; + let effect_of = |value: &str| match value { + "allow" => Ok(GrantEffect::Allow), + "deny" => Ok(GrantEffect::Deny), + "inherit" => Ok(GrantEffect::Inherit), + _ => Err(command_error(EXIT_VALIDATION, "invalid upstream grant")), + }; + match command { + Upstream::Default(args) => { + let actor = policy_actor_id(&database, &args.actor).await?; + crate::personal_upstream::set_instance_grant( + &database, + &actor, + effect_of(&args.effect)?, + ) + .await + .map_err(|error| command_error(EXIT_VALIDATION, error.to_string()))?; + println!("Personal upstream self-service default is {}.", args.effect); + } + Upstream::Grant(args) => { + let actor = policy_actor_id(&database, &args.actor).await?; + let user = crate::identity::get_user_by_name(&database, &args.username) + .await + .map_err(|error| command_error(EXIT_VALIDATION, error.to_string()))? + .ok_or_else(|| command_error(EXIT_VALIDATION, "user was not found"))?; + crate::personal_upstream::set_user_grant( + &database, + &actor, + &user.id, + effect_of(&args.effect)?, + ) + .await + .map_err(|error| command_error(EXIT_VALIDATION, error.to_string()))?; + println!( + "Personal upstream self-service for {} is {}.", + user.username, args.effect + ); + } + Upstream::Add(args) => { + let actor = policy_actor_id(&database, &args.actor).await?; + let user = crate::identity::get_user_by_name(&database, &args.username) + .await + .map_err(|error| command_error(EXIT_VALIDATION, error.to_string()))? + .ok_or_else(|| command_error(EXIT_VALIDATION, "user was not found"))?; + let secret = read_user_password( + args.secret_stdin, + false, + "Upstream API key", + "--secret-stdin", + )?; + let env_path = crate::personal_upstream::personal_env_path(path); + crate::personal_upstream::add_personal_account( + &database, + crate::personal_upstream::PersonalAccountWrite { + actor_id: &actor, + user_id: &user.id, + provider_id: &args.provider, + account_name: &args.name, + secret: &secret, + config_path: path, + env_path: &env_path, + require_self_service: false, + }, + ) + .await + .map_err(|error| command_error(EXIT_VALIDATION, error.to_string()))?; + println!( + "Personal upstream account {} on {} is available only to {}.", + args.name, args.provider, user.username + ); + } + Upstream::List(args) => { + let user_id = if let Some(username) = args.username.as_deref() { + Some( + crate::identity::get_user_by_name(&database, username) + .await + .map_err(|error| command_error(EXIT_VALIDATION, error.to_string()))? + .ok_or_else(|| { + command_error(EXIT_VALIDATION, "user was not found") + })? + .id, + ) + } else { + None + }; + let bindings = + crate::personal_upstream::list_bindings(&database, user_id.as_deref()) + .await + .map_err(|error| command_error(EXIT_VALIDATION, error.to_string()))?; + if bindings.is_empty() { + println!("No personal upstream accounts."); + } + for binding in bindings { + println!( + "{} {} {} {} {}", + binding.user_id, + binding.provider_id, + binding.account_name, + binding.state, + binding.env_var + ); + } + } + Upstream::Remove(args) => { + let actor = policy_actor_id(&database, &args.actor).await?; + let user = crate::identity::get_user_by_name(&database, &args.username) + .await + .map_err(|error| command_error(EXIT_VALIDATION, error.to_string()))? + .ok_or_else(|| command_error(EXIT_VALIDATION, "user was not found"))?; + let env_path = crate::personal_upstream::personal_env_path(path); + crate::personal_upstream::remove_personal_account( + &database, + crate::personal_upstream::PersonalAccountWrite { + actor_id: &actor, + user_id: &user.id, + provider_id: &args.provider, + account_name: &args.name, + secret: "", + config_path: path, + env_path: &env_path, + require_self_service: false, + }, + ) + .await + .map_err(|error| command_error(EXIT_VALIDATION, error.to_string()))?; + println!( + "Personal upstream account {} on {} was removed for {}.", + args.name, args.provider, user.username + ); + } + } + } crate::cli::UsersCommand::Budget(command) => { use crate::cli::UsersBudgetCommand as Budget; match command { @@ -1094,6 +1242,7 @@ fn read_user_password( from_stdin: bool, confirm: bool, prompt: &str, + stdin_flag: &str, ) -> Result { let password = if from_stdin { let mut value = String::new(); @@ -1107,7 +1256,7 @@ fn read_user_password( if !io::stdin().is_terminal() { return Err(command_error( EXIT_VALIDATION, - "password input requires a TTY or --password-stdin", + format!("secret input requires a TTY or {stdin_flag}"), )); } let first = rpassword::prompt_password(format!("{prompt}: ")) @@ -2658,8 +2807,8 @@ async fn onboard(path: &Path, args: crate::cli::OnboardArgs) -> Result<(), Boots } let preflight_config = config::Config::from_toml(path).map_err(BootstrapError::from)?; let preflight_database_path = config::Config::runtime_path(&preflight_config.database.path); - let (bootstrap_admin, identity_initialized) = if !preflight_database_path.exists() { - (true, false) + let (bootstrap_admin, access_state) = if !preflight_database_path.exists() { + (true, None) } else { let database = open_operational_database(&preflight_config, true).await?; let access_state = crate::identity::access_state(&database) @@ -2674,28 +2823,17 @@ async fn onboard(path: &Path, args: crate::cli::OnboardArgs) -> Result<(), Boots .map_err(|error| command_error(EXIT_VALIDATION, error.to_string()))?; ( access_state == "fresh_uninitialized" && users.is_empty(), - matches!(access_state.as_str(), "admin_initialized" | "managed"), + Some(access_state), ) }; - if should_generate_legacy_server_key(identity_initialized) - && config_mutation::read_server_key(path) - .map_err(|error| mutation_error(error, EXIT_VALIDATION))? - .is_none() - { - let key = config_mutation::generate_key() - .map_err(|error| mutation_error(error, EXIT_VALIDATION))?; - if config_mutation::write_server_key(path, &key) - .map_err(|error| mutation_error(error, EXIT_VALIDATION))? - { - println!(" Generated server API key"); - } - } + let key_action = apply_onboarding_server_key(path, access_state.as_deref(), bootstrap_admin)?; let admin_password = if bootstrap_admin { println!("Create the local administrator for this new installation."); Some(read_user_password( args.password_stdin, true, "Administrator password", + "--password-stdin", )?) } else { None @@ -2746,6 +2884,14 @@ async fn onboard(path: &Path, args: crate::cli::OnboardArgs) -> Result<(), Boots .map_err(|error| command_error(EXIT_VALIDATION, error.to_string()))?; println!("Administrator {} created.", user.username); print_one_time_secret(&credential.token, args.show_secret); + let listen = format!("{}:{}", setup_config.server.host, setup_config.server.port); + println!( + "{}", + onboarding_credential_guidance( + key_action == OnboardingKeyAction::LeftExisting, + &listen, + ) + ); } println!("\nConnected {connected} provider(s).\n"); let paths = RuntimePaths::resolve(); @@ -2772,8 +2918,65 @@ async fn onboard(path: &Path, args: crate::cli::OnboardArgs) -> Result<(), Boots .await } -fn should_generate_legacy_server_key(identity_initialized: bool) -> bool { - !identity_initialized +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +enum OnboardingKeyAction { + Generated, + LeftExisting, + Skipped, +} + +/// A missing server key is written only when this run leaves the database +/// `legacy_unmigrated`. A run that bootstraps the administrator does not +/// write a key that bootstrap is about to retire. +fn should_generate_legacy_server_key( + access_state: Option<&str>, + will_bootstrap_admin: bool, +) -> bool { + !will_bootstrap_admin && access_state == Some("legacy_unmigrated") +} + +fn apply_onboarding_server_key( + path: &Path, + access_state: Option<&str>, + will_bootstrap_admin: bool, +) -> Result { + let present = config_mutation::read_server_key(path) + .map_err(|error| mutation_error(error, EXIT_VALIDATION))? + .is_some(); + if present { + return Ok(if will_bootstrap_admin { + OnboardingKeyAction::LeftExisting + } else { + OnboardingKeyAction::Skipped + }); + } + if !should_generate_legacy_server_key(access_state, will_bootstrap_admin) { + return Ok(OnboardingKeyAction::Skipped); + } + let key = + config_mutation::generate_key().map_err(|error| mutation_error(error, EXIT_VALIDATION))?; + if config_mutation::write_server_key(path, &key) + .map_err(|error| mutation_error(error, EXIT_VALIDATION))? + { + println!(" Generated server API key"); + } + Ok(OnboardingKeyAction::Generated) +} + +fn onboarding_credential_guidance(existing_server_key: bool, listen: &str) -> String { + let mut lines = vec![ + "Inference uses the personal API credential shown above. Export it as EGGPOOL_API_KEY." + .to_owned(), + format!("Browser sign-in is /login on {listen}."), + ]; + if existing_server_key { + lines.insert( + 1, + "An existing server key remains in the configuration and is not the inference credential." + .to_owned(), + ); + } + lines.join("\n") } async fn serve(path: &Path, args: &ServeArgs) -> Result<(), BootstrapError> { @@ -3887,11 +4090,13 @@ fn format_bytes(value: Option<&Value>) -> String { #[cfg(test)] mod tests { use super::{ - EXIT_VALIDATION, format_compact_duration, format_duration, lifecycle_timeout, - mutation_error, should_generate_legacy_server_key, whole_seconds, + EXIT_VALIDATION, OnboardingKeyAction, apply_onboarding_server_key, format_compact_duration, + format_duration, lifecycle_timeout, mutation_error, onboarding_credential_guidance, + should_generate_legacy_server_key, whole_seconds, }; - use crate::operations::config_mutation::MutationError; + use crate::operations::config_mutation::{self, MutationError}; use serde_json::json; + use std::fs; #[test] fn interruption_bypasses_validation_exit_code() { @@ -3908,9 +4113,90 @@ mod tests { } #[test] - fn onboarding_does_not_create_a_legacy_key_after_admin_initialization() { - assert!(should_generate_legacy_server_key(false)); - assert!(!should_generate_legacy_server_key(true)); + fn onboarding_writes_a_server_key_only_for_a_legacy_database() { + assert!(should_generate_legacy_server_key( + Some("legacy_unmigrated"), + false + )); + assert!(!should_generate_legacy_server_key( + Some("admin_initialized"), + false + )); + assert!(!should_generate_legacy_server_key(Some("managed"), false)); + assert!(!should_generate_legacy_server_key( + Some("fresh_uninitialized"), + true + )); + assert!(!should_generate_legacy_server_key(None, true)); + } + + #[test] + fn fresh_onboarding_does_not_write_a_server_key_before_bootstrap() { + let directory = tempfile::tempdir().expect("temporary config directory"); + let path = directory.path().join("config.toml"); + config_mutation::init_config(&path, false).expect("config initializes"); + let before = fs::read(&path).expect("config reads"); + let action = apply_onboarding_server_key(&path, None, true).expect("key decision"); + assert_eq!(action, OnboardingKeyAction::Skipped); + assert_eq!(fs::read(&path).expect("config rereads"), before); + assert!( + config_mutation::read_server_key(&path) + .expect("key reads") + .is_none() + ); + } + + #[test] + fn initialized_onboarding_does_not_write_a_server_key() { + let directory = tempfile::tempdir().expect("temporary config directory"); + let path = directory.path().join("config.toml"); + config_mutation::init_config(&path, false).expect("config initializes"); + let before = fs::read(&path).expect("config reads"); + let action = + apply_onboarding_server_key(&path, Some("managed"), false).expect("key decision"); + assert_eq!(action, OnboardingKeyAction::Skipped); + assert_eq!(fs::read(&path).expect("config rereads"), before); + } + + #[test] + fn bootstrap_leaves_an_existing_server_key_unchanged() { + let directory = tempfile::tempdir().expect("temporary config directory"); + let path = directory.path().join("config.toml"); + config_mutation::init_config(&path, false).expect("config initializes"); + assert!( + config_mutation::write_server_key(&path, "existing-server-key") + .expect("existing key writes") + ); + let before = fs::read(&path).expect("config reads"); + let action = apply_onboarding_server_key(&path, None, true).expect("key decision"); + assert_eq!(action, OnboardingKeyAction::LeftExisting); + assert_eq!(fs::read(&path).expect("config rereads"), before); + let guidance = onboarding_credential_guidance(true, "127.0.0.1:11300"); + assert!(guidance.contains("/login")); + assert!(guidance.contains("is not the inference credential")); + for line in guidance.lines() { + if line.contains("EGGPOOL_API_KEY") { + assert!( + !line.to_ascii_lowercase().contains("server"), + "guidance must not export the server key: {line}" + ); + } + } + } + + #[test] + fn legacy_onboarding_still_writes_a_missing_server_key() { + let directory = tempfile::tempdir().expect("temporary config directory"); + let path = directory.path().join("config.toml"); + config_mutation::init_config(&path, false).expect("config initializes"); + let action = apply_onboarding_server_key(&path, Some("legacy_unmigrated"), false) + .expect("key decision"); + assert_eq!(action, OnboardingKeyAction::Generated); + assert!( + config_mutation::read_server_key(&path) + .expect("key reads") + .is_some() + ); } #[test] diff --git a/rust/src/runtime_lifecycle/generation.rs b/rust/src/runtime_lifecycle/generation.rs index 70bd0221..a3e8b946 100644 --- a/rust/src/runtime_lifecycle/generation.rs +++ b/rust/src/runtime_lifecycle/generation.rs @@ -667,6 +667,7 @@ impl RuntimeGenerationFactory { model_registry, provider_profiles, Some(accounts), + process.config_path(), ) .await } @@ -679,6 +680,7 @@ impl RuntimeGenerationFactory { affinity, model_registry, provider_profiles, + process.config_path(), ) .await } diff --git a/rust/src/server/auth.rs b/rust/src/server/auth.rs index 64cbcfc1..18c20612 100644 --- a/rust/src/server/auth.rs +++ b/rust/src/server/auth.rs @@ -167,7 +167,7 @@ pub(super) fn member_landing_html(username: &str) -> String { &format!( "

Signed in as {username}.

\
\ -

My account

Your personal details, personal credentials, and budget.

Open my account

\ +

My account

Your personal details and personal credentials. Budget is on Usage.

Open my account

\

My models

The models your profile permits.

Open my models

\

Usage

Your own request and token usage.

Open usage

\
" @@ -580,6 +580,14 @@ fn sign_in_response(status: StatusCode, html: String) -> Response { no_store((status, Html(html)).into_response()) } +/// Send an unauthenticated browser to the existing sign-in page. +/// +/// The redirect carries no password form. `/login` still refuses the form on +/// a connection that is neither loopback nor trusted HTTPS. +pub(super) fn sign_in_handoff_response() -> Response { + no_store(Redirect::to("/login").into_response()) +} + fn sign_in_unavailable() -> Response { sign_in_failure( StatusCode::SERVICE_UNAVAILABLE, diff --git a/rust/src/server/dashboard/admin.rs b/rust/src/server/dashboard/admin.rs index cfc6d6a0..c301cb78 100644 --- a/rust/src/server/dashboard/admin.rs +++ b/rust/src/server/dashboard/admin.rs @@ -6,8 +6,6 @@ use axum::{ response::Redirect, }; use serde::Deserialize; -use tokio_rusqlite::rusqlite::params; - #[derive(Deserialize)] pub(in crate::server) struct CreateUserForm { username: String, @@ -156,6 +154,42 @@ pub(in crate::server) struct AdminRevokeTokensForm { csrf: String, } +#[derive(Deserialize)] +pub(in crate::server) struct UpstreamDefaultForm { + effect: String, + csrf: String, +} + +#[derive(Deserialize)] +pub(in crate::server) struct UpstreamGrantForm { + user_id: String, + effect: String, + csrf: String, +} + +#[derive(Deserialize)] +pub(in crate::server) struct UpstreamRemoveForm { + user_id: String, + provider: String, + name: String, + csrf: String, +} + +#[derive(Deserialize)] +pub(in crate::server) struct MemberUpstreamForm { + provider: String, + name: String, + secret: String, + csrf: String, +} + +#[derive(Deserialize)] +pub(in crate::server) struct MemberUpstreamRemoveForm { + provider: String, + name: String, + csrf: String, +} + fn csrf_valid( session: &crate::web_session::Principal, headers: &HeaderMap, @@ -214,6 +248,20 @@ fn one_time_token_page( response } +fn account_page_for_role( + role: &str, + title: &str, + active_nav: &str, + theme: &str, + body: &str, +) -> String { + if role == "admin" { + dashboard_standalone_page(title, active_nav, theme, body) + } else { + member_standalone_page(title, active_nav, theme, body) + } +} + pub(in crate::server) async fn users_page( State(state): State, Extension(session): Extension, @@ -239,7 +287,70 @@ pub(in crate::server) async fn users_page( Ok(rules) => rules, Err(_) => return degraded("user administration unavailable"), }; - let body = render_users_admin(&users, &profiles, &instance_rules, &csrf); + let assignments = match policy.list_profile_assignments().await { + Ok(assignments) => assignments, + Err(_) => return degraded("user administration unavailable"), + }; + let overrides = match policy.list_user_overrides().await { + Ok(overrides) => overrides, + Err(_) => return degraded("user administration unavailable"), + }; + let budgets = crate::user_budget::UserBudgetService::new(state.database.clone()); + let mut facts = std::collections::BTreeMap::new(); + for user in &users { + let rules = match budgets.rules(&user.id).await { + Ok(rules) => rules, + Err(_) => return degraded("user administration unavailable"), + }; + let credentials = + match crate::identity::list_user_credentials(&state.database, &user.id).await { + Ok(credentials) => credentials, + Err(_) => return degraded("user administration unavailable"), + }; + let upstream_grant = + match crate::personal_upstream::stored_user_grant(&state.database, &user.id).await { + Ok(effect) => effect.as_str().to_owned(), + Err(_) => return degraded("user administration unavailable"), + }; + let upstreams = + match crate::personal_upstream::list_bindings(&state.database, Some(&user.id)).await { + Ok(bindings) => bindings + .into_iter() + .map(|binding| (binding.provider_id, binding.account_name, binding.state)) + .collect(), + Err(_) => return degraded("user administration unavailable"), + }; + facts.insert( + user.id.clone(), + UserAdminFacts { + profile_id: assignments + .iter() + .find(|(user_id, _)| user_id == &user.id) + .map(|(_, profile_id)| profile_id.clone()), + overrides: overrides + .iter() + .filter(|(user_id, _, _)| user_id == &user.id) + .map(|(_, model_id, effect)| (model_id.clone(), effect.clone())) + .collect(), + rules, + credentials, + upstream_grant, + upstreams, + }, + ); + } + let instance_grant = match crate::personal_upstream::instance_grant(&state.database).await { + Ok(effect) => effect.as_str().to_owned(), + Err(_) => return degraded("user administration unavailable"), + }; + let body = render_users_admin( + &users, + &profiles, + &instance_rules, + &facts, + &csrf, + &instance_grant, + ); dashboard_page_with_body( &state.server.dashboard_theme, "Users", @@ -310,42 +421,43 @@ pub(in crate::server) async fn usage_page( Ok(rules) => rules, Err(_) => return degraded("usage unavailable"), }; - let rows = match crate::user_budget::UserBudgetService::new(state.database.clone()) + let budgets = crate::user_budget::UserBudgetService::new(state.database.clone()); + let rows = match budgets .usage(user_id, "0000-01-01", USAGE_ROW_CAP as u16) .await { Ok(rows) => rows, Err(_) => return degraded("usage unavailable"), }; - return html_response(render_my_usage(&session.username, &rules, &rows, theme)); - } - let rows = match state - .database - .call(|connection| { - let mut statement = connection.prepare( - "SELECT u.username, COALESCE(b.model_id, '(all models)'), \ - SUM(b.request_count), SUM(b.token_count), SUM(b.cost_microdollars) \ - FROM user_budget_usage b JOIN users u ON u.id = b.user_id \ - GROUP BY u.id, b.model_id ORDER BY u.username COLLATE NOCASE, b.model_id LIMIT ?1", - )?; - statement - .query_map(params![USAGE_ROW_CAP as i64], |row| { - Ok(( - row.get(0)?, - row.get(1)?, - row.get(2)?, - row.get(3)?, - row.get(4)?, - )) - })? - .collect::, _>>() - }) + let allowance = match budgets.current_allowance(user_id).await { + Ok(allowance) => allowance, + Err(_) => return degraded("usage unavailable"), + }; + let instance_rules = + match crate::instance_budget::InstanceBudgetService::new(state.database.clone()) + .rules() + .await + { + Ok(rules) => rules, + Err(_) => return degraded("usage unavailable"), + }; + return html_response(render_my_usage( + &session.username, + &rules, + &rows, + &allowance, + &instance_rules, + theme, + )); + } + let snapshot = match crate::user_budget::UserBudgetService::new(state.database) + .admin_usage_by_window(USAGE_ROW_CAP as u16) .await { - Ok(rows) => rows, + Ok(snapshot) => snapshot, Err(_) => return degraded("usage unavailable"), }; - html_response(render_usage_admin(&rows, "", theme)) + html_response(render_usage_admin(&snapshot, "", theme)) } #[derive(Debug, Default, serde::Deserialize)] @@ -464,12 +576,35 @@ pub(in crate::server) async fn my_account_page( .as_deref() .unwrap_or(&state.server.dashboard_theme), ); - html_response(dashboard_standalone_page( + let allowed = + match crate::personal_upstream::effective_grant(&state.database, &session.user_id).await { + Ok(crate::personal_upstream::GrantEffect::Allow) => true, + Ok(_) => false, + Err(_) => return degraded("account details unavailable"), + }; + let upstreams = match crate::personal_upstream::list_bindings( + &state.database, + Some(&session.user_id), + ) + .await + { + Ok(bindings) => bindings + .into_iter() + .map(|binding| (binding.provider_id, binding.account_name, binding.state)) + .collect::>(), + Err(_) => return degraded("account details unavailable"), + }; + let providers = crate::provider_profile::bundled_profiles() + .map(|registry| registry.ids().map(str::to_owned).collect::>()) + .unwrap_or_default(); + let upstream = render_member_upstream(allowed, &upstreams, &providers, &csrf); + html_response(account_page_for_role( + &session.role, "My account", "my-account", theme, &format!( - "

My account

Signed in as {}

My usage · My accessible models · Change password

Personal client credentials

{token_flash}
{DASHBOARD_TABLE_OPEN}LabelCreatedLast usedAction{rows}
", + "

My account

Signed in as {}

My usage · My accessible models · Change password

Personal client credentials

{token_flash}
{DASHBOARD_TABLE_OPEN}LabelCreatedLast usedAction{rows}
{upstream}
", html_escape(&session.username), html_escape(&csrf), html_escape(&csrf) @@ -516,9 +651,14 @@ pub(in crate::server) async fn my_models_page( .as_deref() .unwrap_or(&state.server.dashboard_theme), ); - html_response(dashboard_standalone_page( + html_response(account_page_for_role( + &session.role, "My models", - "my-account", + if session.role == "admin" { + "my-account" + } else { + "my-models" + }, theme, &format!( "

My accessible models

{explanation}

    {models}

My account

" @@ -1138,3 +1278,217 @@ pub(in crate::server) async fn revoke_user_tokens( Err(error) => mutation_error(error, "Could not revoke credentials."), } } + +pub(in crate::server) async fn set_upstream_default( + State(state): State, + Extension(session): Extension, + headers: HeaderMap, + Form(form): Form, +) -> Response { + if !csrf_valid(&session, &headers, &form.csrf) { + return (StatusCode::FORBIDDEN, "Invalid request token.").into_response(); + } + if !admin_only(&session) { + return (StatusCode::FORBIDDEN, "Administrator access required.").into_response(); + } + let Some(effect) = grant_effect(&form.effect, false) else { + return bad_request("Instance grant must be allow or deny."); + }; + match crate::personal_upstream::set_instance_grant(&state.database, &session.user_id, effect) + .await + { + Ok(()) => mutation_redirect("/users"), + Err(error) => upstream_failure(error), + } +} + +pub(in crate::server) async fn set_upstream_grant( + State(state): State, + Extension(session): Extension, + headers: HeaderMap, + Form(form): Form, +) -> Response { + if !csrf_valid(&session, &headers, &form.csrf) { + return (StatusCode::FORBIDDEN, "Invalid request token.").into_response(); + } + if !admin_only(&session) { + return (StatusCode::FORBIDDEN, "Administrator access required.").into_response(); + } + let Some(effect) = grant_effect(&form.effect, true) else { + return bad_request("User grant must be allow, deny, or inherit."); + }; + match crate::personal_upstream::set_user_grant( + &state.database, + &session.user_id, + &form.user_id, + effect, + ) + .await + { + Ok(()) => mutation_redirect("/users"), + Err(error) => upstream_failure(error), + } +} + +pub(in crate::server) async fn remove_upstream_account( + State(state): State, + Extension(session): Extension, + headers: HeaderMap, + Form(form): Form, +) -> Response { + if !csrf_valid(&session, &headers, &form.csrf) { + return (StatusCode::FORBIDDEN, "Invalid request token.").into_response(); + } + if !admin_only(&session) { + return (StatusCode::FORBIDDEN, "Administrator access required.").into_response(); + } + let Ok((config_path, env_path)) = upstream_paths(&state) else { + return ( + StatusCode::SERVICE_UNAVAILABLE, + "Server configuration path is unavailable.", + ) + .into_response(); + }; + match crate::personal_upstream::remove_personal_account( + &state.database, + crate::personal_upstream::PersonalAccountWrite { + actor_id: &session.user_id, + user_id: &form.user_id, + provider_id: &form.provider, + account_name: &form.name, + secret: "", + config_path: &config_path, + env_path: &env_path, + require_self_service: false, + }, + ) + .await + { + Ok(()) => mutation_redirect("/users"), + Err(error) => upstream_failure(error), + } +} + +pub(in crate::server) async fn add_member_upstream( + State(state): State, + Extension(session): Extension, + headers: HeaderMap, + Form(form): Form, +) -> Response { + if !csrf_valid(&session, &headers, &form.csrf) { + return (StatusCode::FORBIDDEN, "Invalid request token.").into_response(); + } + let Ok((config_path, env_path)) = upstream_paths(&state) else { + return ( + StatusCode::SERVICE_UNAVAILABLE, + "Server configuration path is unavailable.", + ) + .into_response(); + }; + match crate::personal_upstream::add_personal_account( + &state.database, + crate::personal_upstream::PersonalAccountWrite { + actor_id: &session.user_id, + user_id: &session.user_id, + provider_id: &form.provider, + account_name: &form.name, + secret: &form.secret, + config_path: &config_path, + env_path: &env_path, + require_self_service: true, + }, + ) + .await + { + Ok(()) => mutation_redirect("/my-account"), + Err(error) => upstream_failure(error), + } +} + +pub(in crate::server) async fn remove_member_upstream( + State(state): State, + Extension(session): Extension, + headers: HeaderMap, + Form(form): Form, +) -> Response { + if !csrf_valid(&session, &headers, &form.csrf) { + return (StatusCode::FORBIDDEN, "Invalid request token.").into_response(); + } + let Ok((config_path, env_path)) = upstream_paths(&state) else { + return ( + StatusCode::SERVICE_UNAVAILABLE, + "Server configuration path is unavailable.", + ) + .into_response(); + }; + match crate::personal_upstream::remove_personal_account( + &state.database, + crate::personal_upstream::PersonalAccountWrite { + actor_id: &session.user_id, + user_id: &session.user_id, + provider_id: &form.provider, + account_name: &form.name, + secret: "", + config_path: &config_path, + env_path: &env_path, + require_self_service: true, + }, + ) + .await + { + Ok(()) => mutation_redirect("/my-account"), + Err(error) => upstream_failure(error), + } +} + +fn grant_effect(value: &str, user_scope: bool) -> Option { + let effect = crate::personal_upstream::GrantEffect::parse(value)?; + if !user_scope && matches!(effect, crate::personal_upstream::GrantEffect::Inherit) { + return None; + } + Some(effect) +} + +fn upstream_paths(state: &AppState) -> Result<(std::path::PathBuf, std::path::PathBuf), ()> { + let config_path = state + .config_path() + .map(std::path::Path::to_path_buf) + .ok_or(())?; + let env_path = crate::personal_upstream::personal_env_path(&config_path); + Ok((config_path, env_path)) +} + +fn upstream_failure(error: crate::personal_upstream::PersonalUpstreamError) -> Response { + use crate::personal_upstream::PersonalUpstreamError as Upstream; + let (status, message) = match &error { + Upstream::GrantDenied | Upstream::AdministratorRequired => ( + StatusCode::FORBIDDEN, + "Personal upstream self-service is not granted.", + ), + Upstream::PublicationRestored => ( + StatusCode::BAD_REQUEST, + "The personal account was not published.", + ), + Upstream::RepairRequired => ( + StatusCode::BAD_REQUEST, + "The personal account needs operator repair.", + ), + Upstream::NameCollision => ( + StatusCode::BAD_REQUEST, + "That account name is already in use.", + ), + Upstream::UnknownProvider => (StatusCode::BAD_REQUEST, "That provider is not available."), + Upstream::SecretRejected => (StatusCode::BAD_REQUEST, "The upstream key was rejected."), + Upstream::BindingNotFound => ( + StatusCode::BAD_REQUEST, + "That personal account was not found.", + ), + Upstream::UserNotFound => (StatusCode::BAD_REQUEST, "That user was not found."), + Upstream::Database(_) | Upstream::Configuration(_) => ( + StatusCode::BAD_REQUEST, + "The personal upstream change was not saved.", + ), + }; + tracing::warn!(error = error.kind(), "personal upstream mutation failed"); + (status, message).into_response() +} diff --git a/rust/src/server/dashboard/mod.rs b/rust/src/server/dashboard/mod.rs index d7bc5539..8aead640 100644 --- a/rust/src/server/dashboard/mod.rs +++ b/rust/src/server/dashboard/mod.rs @@ -128,8 +128,9 @@ use api::{ }; use format::*; use render::{ - DASHBOARD_TABLE_OPEN, USAGE_ROW_CAP, dashboard_page_with_body, dashboard_query_inputs, - dashboard_standalone_page, render_dashboard_page_body, render_model_detail, render_my_usage, + DASHBOARD_TABLE_OPEN, USAGE_ROW_CAP, UserAdminFacts, dashboard_page_with_body, + dashboard_query_inputs, dashboard_standalone_page, member_standalone_page, + render_dashboard_page_body, render_member_upstream, render_model_detail, render_my_usage, render_overview, render_profiles_admin, render_usage_admin, render_users_admin, summary_json, }; #[cfg(test)] @@ -144,12 +145,13 @@ use response::{html_response, static_response}; use theme::*; pub(super) use admin::{ - assign_user_profile, audit_export, audit_page, create_personal_token, create_profile, - create_user, delete_profile, issue_admin_token, my_account_page, my_models_page, profiles_page, - remove_instance_budget, remove_profile_rule, remove_user_override, reset_user_password, + add_member_upstream, assign_user_profile, audit_export, audit_page, create_personal_token, + create_profile, create_user, delete_profile, issue_admin_token, my_account_page, + my_models_page, profiles_page, remove_instance_budget, remove_member_upstream, + remove_profile_rule, remove_upstream_account, remove_user_override, reset_user_password, revoke_personal_token, revoke_user_tokens, set_default_member_profile, set_instance_budget, - set_profile_preference, set_profile_rule, set_user_budget, set_user_override, set_user_state, - update_profile, usage_page, users_page, + set_profile_preference, set_profile_rule, set_upstream_default, set_upstream_grant, + set_user_budget, set_user_override, set_user_state, update_profile, usage_page, users_page, }; pub(super) use api::{ grouped_timeseries_api, stats_cache_observability, stats_cache_stability, diff --git a/rust/src/server/dashboard/render/admin.rs b/rust/src/server/dashboard/render/admin.rs index ac0b606a..4b60a2d4 100644 --- a/rust/src/server/dashboard/render/admin.rs +++ b/rust/src/server/dashboard/render/admin.rs @@ -1,10 +1,23 @@ use super::*; +pub(in crate::server::dashboard) struct UserAdminFacts { + pub profile_id: Option, + pub overrides: Vec<(String, String)>, + pub rules: Vec, + pub credentials: Vec, + /// Stored self-service effect: `allow`, `deny`, or `inherit`. + pub upstream_grant: String, + /// Provider, account name, and binding state. No secret and no env var. + pub upstreams: Vec<(String, String, String)>, +} + pub(in crate::server::dashboard) fn render_users_admin( users: &[crate::identity::UserSummary], profiles: &[crate::model_policy::PolicyProfileSummary], instance_rules: &[crate::instance_budget::InstanceBudgetRule], + facts: &std::collections::BTreeMap, csrf: &str, + instance_grant: &str, ) -> String { let default_profile = profiles .iter() @@ -33,6 +46,47 @@ pub(in crate::server::dashboard) fn render_users_admin( .map(|user| { let active = user.state == "active"; let state_label = if active { "Disable" } else { "Reactivate" }; + let Some(facts) = facts.get(&user.id) else { + return format!( + "{}{}{}{}Roster details could not be loaded.", + html_escape(&user.username), + html_escape(&user.role), + html_escape(&user.state), + if user.must_change_password { + "Must change password" + } else { + "—" + }, + ); + }; + let options = profiles + .iter() + .map(|profile| { + let selected = if facts.profile_id.as_deref() == Some(profile.id.as_str()) { + " selected" + } else { + "" + }; + format!( + "", + html_escape(&profile.id), + html_escape(&profile.name) + ) + }) + .collect::(); + let profile_status = match facts.profile_id.as_deref() { + Some(profile_id) => { + let name = profiles + .iter() + .find(|profile| profile.id == profile_id) + .map_or(profile_id, |profile| profile.name.as_str()); + format!("Assigned profile: {}", html_escape(name)) + } + None if user.role == "member" => { + "Unassigned. Models are denied until a profile is assigned.".to_owned() + } + None => "No profile assignment.".to_owned(), + }; let state_form = format!( "
", html_escape(csrf), html_escape(&user.id), !active, state_label @@ -54,15 +108,97 @@ pub(in crate::server::dashboard) fn render_users_admin( html_escape(csrf), html_escape(&user.id) ); let budget_form = format!( - "
Set budget

Hard token rules admit only requests with an explicit caller output cap and reserve a worst-case bound; hard USD rules additionally require an operator tariff in provider configuration. Estimated rules use approximate holds and are never a hard ceiling.

", + "
Set budget

Hard token rules admit only requests with an explicit caller output cap and reserve a worst-case bound; hard USD rules additionally require an operator tariff in provider configuration. Estimated rules use approximate holds and are never a hard ceiling. The stored unit is microdollars.

", html_escape(csrf), html_escape(&user.id) ); + let override_list = if facts.overrides.is_empty() { + "

No overrides.

".to_owned() + } else { + let items = facts + .overrides + .iter() + .map(|(model, effect)| { + format!( + "
  • {} {}
  • ", + html_escape(model), + html_escape(effect) + ) + }) + .collect::(); + format!("
      {items}
    ") + }; + let budget_list = if facts.rules.is_empty() { + "

    No budget rules.

    ".to_owned() + } else { + let items = facts + .rules + .iter() + .map(|rule| { + format!( + "
  • {} {} requests {} tokens {} concurrent {}
  • ", + html_escape(rule.model_id.as_deref().unwrap_or("All models")), + html_escape(rule.window.as_str()), + optional_count(rule.max_requests), + optional_money(rule.max_microdollars), + optional_count(rule.max_concurrent) + ) + }) + .collect::(); + format!("
      {items}
    ") + }; + let credential_list = if facts.credentials.is_empty() { + "

    No personal credentials.

    ".to_owned() + } else { + let items = facts + .credentials + .iter() + .map(|credential| { + format!( + "
  • {} created {} last used {}
  • ", + html_escape(&credential.label), + html_escape(&credential.created_at), + html_escape(credential.last_used_at.as_deref().unwrap_or("never")) + ) + }) + .collect::(); + format!("
      {items}
    ") + }; let token_form = format!( "
    ", html_escape(csrf), html_escape(&user.id), html_escape(csrf), html_escape(&user.id) ); + let upstream_rows = if facts.upstreams.is_empty() { + "

    No personal upstream accounts.

    ".to_owned() + } else { + facts + .upstreams + .iter() + .map(|(provider, account, state)| { + format!( + "
  • {} {} {}
  • ", + html_escape(provider), + html_escape(account), + html_escape(state), + html_escape(csrf), + html_escape(&user.id), + html_escape(provider), + html_escape(account) + ) + }) + .collect::() + }; + let grant = facts.upstream_grant.as_str(); + let grant_form = format!( + "
    ", + html_escape(&user.username), + if grant == "inherit" { " selected" } else { "" }, + if grant == "allow" { " selected" } else { "" }, + if grant == "deny" { " selected" } else { "" }, + html_escape(csrf), + html_escape(&user.id) + ); let actions = format!( - "{state_form}{password_form}{profile_form}{override_form}{remove_override_form}{budget_form}{token_form}" + "

    Profile

    {profile_status}

    {profile_form}

    Overrides

    {override_list}{override_form}{remove_override_form}

    Budget rules

    {budget_list}{budget_form}

    Credentials

    {credential_list}{token_form}

    Personal upstream

      {upstream_rows}
    {grant_form}

    Changing the grant does not remove an account. Adding an account for this user stays a command-line action.

    Account

    {state_form}{password_form}
    " ); format!( "{}{}{}{}{}", @@ -100,8 +236,75 @@ pub(in crate::server::dashboard) fn render_users_admin( "

    Instance budget ceilings

    One instance-wide ceiling intersected with every per-user rule: an admitted call must satisfy all applicable instance and user limits. Absent rules mean no additional cap. Members never see other users' usage here. Hard token rules need an explicit caller output cap; hard USD rules need an operator tariff in provider configuration.

    {DASHBOARD_TABLE_OPEN}ModelWindowModeMax requestsMax tokensMax microdollarsMax concurrentActions{instance_rows}
    Set instance ceiling
    ", html_escape(csrf) ); + let grant_section = format!( + "

    Personal upstream self-service

    The instance default is deny until an administrator changes it. Allow lets that member submit one bundled-provider key from My account. Deny does not withdraw an account that is already bound.

    ", + if instance_grant == "deny" { + " selected" + } else { + "" + }, + if instance_grant == "allow" { + " selected" + } else { + "" + }, + html_escape(csrf) + ); + format!( + "{instance_section}{grant_section}

    Users

    Create local member accounts and assign policy profiles. The instance default applies only to new members; existing assignments are unchanged. There is no default budget template: user and instance budget rules stay independent. Temporary passwords are shown only to the administrator who enters them; users must change them at first login.

    Local accounts

    {DASHBOARD_TABLE_OPEN}UsernameRoleStatePasswordActions{rows}
    ", + html_escape(csrf) + ) +} + +pub(in crate::server::dashboard) fn render_member_upstream( + allowed: bool, + rows: &[(String, String, String)], + providers: &[String], + csrf: &str, +) -> String { + let listed = if rows.is_empty() { + "

    No personal upstream accounts.

    ".to_owned() + } else { + let items = rows + .iter() + .map(|(provider, account, state)| { + let remove = if allowed { + format!( + "
    ", + html_escape(csrf), + html_escape(provider), + html_escape(account) + ) + } else { + String::new() + }; + format!( + "
  • {} {} {}{remove}
  • ", + html_escape(provider), + html_escape(account), + html_escape(state) + ) + }) + .collect::(); + format!("
      {items}
    ") + }; + if !allowed { + return format!( + "

    Personal upstream account

    Personal upstream self-service is not granted. An administrator can add an account from the command line. Changing a grant does not remove an account that is already bound.

    {listed}
    " + ); + } + let options = providers + .iter() + .map(|provider| { + format!( + "", + html_escape(provider), + html_escape(provider) + ) + }) + .collect::(); format!( - "{instance_section}

    Users

    Create local member accounts and assign policy profiles. The instance default applies only to new members; existing assignments are unchanged. There is no default budget template: user and instance budget rules stay independent. Temporary passwords are shown only to the administrator who enters them; users must change them at first login.

    Local accounts

    {DASHBOARD_TABLE_OPEN}UsernameRoleStatePasswordActions{rows}
    ", + "

    Personal upstream account

    The key is written to the operator environment file and is not stored in the database. The account is selectable only by you.

    {listed}
    ", html_escape(csrf) ) } @@ -161,10 +364,40 @@ pub(in crate::server::dashboard) fn usage_truncation_notice(row_count: usize) -> return String::new(); } format!( - "

    Showing the first {USAGE_ROW_CAP} rows. The usage table is truncated: raise the limit in the query to see the rest.

    " + "

    Showing the first {USAGE_ROW_CAP} rows returned by the usage query. The usage table is truncated.

    " ) } +/// USD text for a stored microdollar integer. The stored unit does not change. +pub(in crate::server::dashboard) fn format_microdollar_usd(microdollars: i64) -> String { + let negative = microdollars < 0; + let value = microdollars.unsigned_abs(); + let whole = value / 1_000_000; + let fraction = value % 1_000_000; + let mut text = if fraction == 0 { + whole.to_string() + } else { + let digits = format!("{fraction:06}"); + format!("{whole}.{}", digits.trim_end_matches('0')) + }; + if negative { + text.insert(0, '-'); + } + format!("{text} USD") +} + +fn money_cell(microdollars: i64) -> String { + format!("{microdollars} ({})", format_microdollar_usd(microdollars)) +} + +fn optional_count(value: Option) -> String { + value.map_or_else(|| "—".to_owned(), |value| value.to_string()) +} + +fn optional_money(value: Option) -> String { + value.map_or_else(|| "—".to_owned(), money_cell) +} + /// Wrap one table in the shared keyboard-reachable scroll region. fn scroll_table(label: &str, table: &str) -> String { format!( @@ -174,35 +407,87 @@ fn scroll_table(label: &str, table: &str) -> String { } pub(in crate::server::dashboard) fn render_usage_admin( - rows: &[(String, String, i64, i64, i64)], + snapshot: &crate::user_budget::AdminUsageSnapshot, csrf: &str, theme: &str, ) -> String { - let content = rows.iter().map(|(user, model, requests, tokens, cost)| { - format!("{}{}{requests}{tokens}{cost}", html_escape(user), html_escape(model)) - }).collect::(); - let limits = scroll_table( - "Usage by user and model", - &format!( - "{DASHBOARD_TABLE_OPEN}UserModelRequestsTokensEstimated microdollars{content}" - ), + let current_day = usage_window_table( + "Current UTC day", + snapshot + .rows + .iter() + .filter(|row| { + row.window == crate::user_budget::BudgetWindow::Day + && row.window_start == snapshot.day_start + }) + .collect(), ); - let truncation = usage_truncation_notice(rows.len()); + let current_month = usage_window_table( + "Current UTC month", + snapshot + .rows + .iter() + .filter(|row| { + row.window == crate::user_budget::BudgetWindow::Month + && row.window_start == snapshot.month_start + }) + .collect(), + ); + let historical = usage_window_table( + "Earlier windows", + snapshot + .rows + .iter() + .filter(|row| { + !((row.window == crate::user_budget::BudgetWindow::Day + && row.window_start == snapshot.day_start) + || (row.window == crate::user_budget::BudgetWindow::Month + && row.window_start == snapshot.month_start)) + }) + .collect(), + ); + let truncation = usage_truncation_notice(snapshot.rows.len()); dashboard_standalone_page( "Usage", "usage", theme, &format!( - "

    Usage

    Token and microdollar figures are usage estimates; estimated USD is not an invoice or a hard ceiling for unpriced models.

    {truncation}{limits}
    ", + "

    Usage

    Token and microdollar figures are usage estimates; estimated USD is not an invoice or a hard ceiling for unpriced models. Day and month totals are separate windows and are not added together.

    {truncation}

    Current UTC day

    {current_day}

    Current UTC month

    {current_month}

    Earlier windows

    {historical}
    ", html_escape(csrf) ), ) } +fn usage_window_table(label: &str, rows: Vec<&crate::user_budget::AdminUsageWindowRow>) -> String { + let content = rows + .iter() + .map(|row| { + format!( + "{}{}{}{}{}{}{}", + html_escape(&row.username), + html_escape(&row.model_id), + html_escape(row.window.as_str()), + html_escape(&row.window_start), + row.request_count, + row.token_count, + money_cell(row.cost_microdollars) + ) + }) + .collect::(); + scroll_table( + label, + &format!( + "{DASHBOARD_TABLE_OPEN}UserModelWindowWindow start (UTC)RequestsTokensEstimated microdollars{content}" + ), + ) +} + pub(in crate::server::dashboard) fn render_my_usage( user: &str, rules: &[crate::user_budget::UserBudgetRule], rows: &[crate::user_budget::UserBudgetUsage], + allowance: &[crate::user_budget::UserBudgetAllowance], + instance_rules: &[crate::instance_budget::InstanceBudgetRule], theme: &str, ) -> String { let rule_rows = rules @@ -213,14 +498,10 @@ pub(in crate::server::dashboard) fn render_my_usage( html_escape(rule.model_id.as_deref().unwrap_or("All models")), html_escape(rule.window.as_str()), html_escape(rule.enforcement.as_str()), - rule.max_requests - .map_or_else(|| "—".to_owned(), |value| value.to_string()), - rule.max_tokens - .map_or_else(|| "—".to_owned(), |value| value.to_string()), - rule.max_microdollars - .map_or_else(|| "—".to_owned(), |value| value.to_string()), - rule.max_concurrent - .map_or_else(|| "—".to_owned(), |value| value.to_string()), + optional_count(rule.max_requests), + optional_count(rule.max_tokens), + optional_money(rule.max_microdollars), + optional_count(rule.max_concurrent), ) }) .collect::(); @@ -228,12 +509,13 @@ pub(in crate::server::dashboard) fn render_my_usage( .iter() .map(|row| { format!( - "{}{}{}{}{}", + "{}{}{}{}{}{}", html_escape(&row.model_id), + html_escape(row.window.as_str()), html_escape(&row.window_start), row.request_count, row.token_count, - row.cost_microdollars + money_cell(row.cost_microdollars) ) }) .collect::(); @@ -246,16 +528,62 @@ pub(in crate::server::dashboard) fn render_my_usage( let usage_table = scroll_table( "Settled usage", &format!( - "{DASHBOARD_TABLE_OPEN}ModelWindow start (UTC)RequestsTokensEstimated microdollars{usage_rows}" + "{DASHBOARD_TABLE_OPEN}ModelWindowWindow start (UTC)RequestsTokensEstimated microdollars{usage_rows}" + ), + ); + let remaining_rows = allowance + .iter() + .map(|row| { + format!( + "{}{}{}{}{}{}{}{}{}{}{}", + html_escape(row.model_id.as_deref().unwrap_or("All models")), + html_escape(row.window.as_str()), + html_escape(&row.window_start), + optional_count(row.requests.ceiling), + optional_count(row.requests.remaining), + optional_count(row.tokens.ceiling), + optional_count(row.tokens.remaining), + optional_money(row.microdollars.ceiling), + optional_money(row.microdollars.remaining), + optional_count(row.concurrent.ceiling), + optional_count(row.concurrent.remaining), + ) + }) + .collect::(); + let remaining_table = scroll_table( + "Remaining allowance", + &format!( + "{DASHBOARD_TABLE_OPEN}ModelWindowWindow start (UTC)Request ceilingRequests remainingToken ceilingTokens remainingMicrodollar ceilingMicrodollars remainingConcurrent ceilingConcurrent remaining{remaining_rows}" + ), + ); + let instance_rows = instance_rules + .iter() + .map(|rule| { + format!( + "{}{}{}{}{}{}{}", + html_escape(rule.model_id.as_deref().unwrap_or("All models")), + html_escape(rule.window.as_str()), + html_escape(rule.enforcement.as_str()), + optional_count(rule.max_requests), + optional_count(rule.max_tokens), + optional_money(rule.max_microdollars), + optional_count(rule.max_concurrent), + ) + }) + .collect::(); + let instance_table = scroll_table( + "Instance ceilings", + &format!( + "{DASHBOARD_TABLE_OPEN}ModelWindowModeMax requestsMax tokensMax microdollarsMax concurrent{instance_rows}" ), ); let truncation = usage_truncation_notice(rows.len()); - dashboard_standalone_page( + member_standalone_page( "My usage", "usage", theme, &format!( - "

    My usage

    Account: {}

    Daily/monthly periods use UTC. Rules marked hard enforce a provable worst-case bound (token rules need an explicit caller output cap; USD rules need an operator tariff) and deny otherwise; rules marked estimated use approximate holds and are not a guaranteed cap. Active requests hold budget before dispatch and may reduce admission headroom.

    Configured limits

    {limit_table}

    Settled usage

    {truncation}{usage_table}

    My account

    ", + "

    My usage

    Account: {}

    Daily/monthly periods use UTC. Rules marked hard enforce a provable worst-case bound (token rules need an explicit caller output cap; USD rules need an operator tariff) and deny otherwise; rules marked estimated use approximate holds and are not a guaranteed cap. Active requests hold budget before dispatch and may reduce admission headroom. Remaining allowance is the ceiling minus settled usage minus active holds for that rule. A dimension without a ceiling has no remaining figure.

    Configured limits

    {limit_table}

    Remaining allowance

    {remaining_table}

    Instance ceilings

    The shared ceiling also applies. Other people's consumption is not shown.

    {instance_table}

    Settled usage

    {truncation}{usage_table}

    My account

    ", html_escape(user) ), ) diff --git a/rust/src/server/dashboard/render/layout.rs b/rust/src/server/dashboard/render/layout.rs index 333d4460..7f6e0efa 100644 --- a/rust/src/server/dashboard/render/layout.rs +++ b/rust/src/server/dashboard/render/layout.rs @@ -9,8 +9,8 @@ pub(in crate::server::dashboard) const DASHBOARD_TABLE_OPEN: &str = ""; -/// The shared navigation destinations. Every dashboard surface renders them, -/// so an operator always has a route back to the overview. +/// The shared navigation destinations. Operator pages render them, so an +/// operator always has a route back to the overview. const DASHBOARD_NAVIGATION: [(&str, &str, &str); 17] = [ ("overview", "/", "Overview"), ("reliability", "/reliability", "Reliability"), @@ -31,6 +31,13 @@ const DASHBOARD_NAVIGATION: [(&str, &str, &str); 17] = [ ("runtime", "/runtime", "Runtime"), ]; +const MEMBER_NAVIGATION: [(&str, &str, &str); 4] = [ + ("my-account", "/my-account", "My account"), + ("my-models", "/my-account/models", "My models"), + ("usage", "/usage", "Usage"), + ("account", "/account", "Password"), +]; + /// The theme picker's query parameters, rendered as hidden inputs. /// /// The picker is a GET form, so submitting it sends only the form's own @@ -56,13 +63,38 @@ pub(in crate::server::dashboard) fn dashboard_navigation_markup( period: &str, theme: &str, extra_query: &str, +) -> String { + navigation_markup( + &DASHBOARD_NAVIGATION, + active_nav, + period, + theme, + extra_query, + ) +} + +pub(in crate::server::dashboard) fn member_navigation_markup( + active_nav: &str, + period: &str, + theme: &str, + extra_query: &str, +) -> String { + navigation_markup(&MEMBER_NAVIGATION, active_nav, period, theme, extra_query) +} + +fn navigation_markup( + destinations: &[(&str, &str, &str)], + active_nav: &str, + period: &str, + theme: &str, + extra_query: &str, ) -> String { let query = format!( "period={}&theme={}", query_component(period), query_component(theme) ); - let navigation = DASHBOARD_NAVIGATION + let navigation = destinations .iter() .map(|(key, href, label)| { let class = if *key == active_nav { "active" } else { "" }; @@ -102,20 +134,51 @@ pub(in crate::server::dashboard) fn dashboard_navigation_markup( /// It carries the same navigation chrome, the same dashboard stylesheet and /// the same theme stylesheet as the rest of the dashboard, so a member or an /// administrator who lands on one of these pages sees a complete page rather -/// than a bare fragment, and has a route back to the overview. +/// than a bare fragment. Operator pages keep a route back to the overview. +/// Member pages use the member destinations only. pub(in crate::server::dashboard) fn dashboard_standalone_page( title: &str, active_nav: &str, theme: &str, body: &str, ) -> String { + let theme = selected_theme(theme); + standalone_page( + title, + theme, + &format!("/?period=24h&theme={}", query_component(theme)), + body, + dashboard_navigation_markup(active_nav, "24h", theme, ""), + ) +} + +pub(in crate::server::dashboard) fn member_standalone_page( + title: &str, + active_nav: &str, + theme: &str, + body: &str, +) -> String { + let theme = selected_theme(theme); + standalone_page( + title, + theme, + &format!( + "/my-account?period=24h&theme={}", + query_component(theme) + ), + body, + member_navigation_markup(active_nav, "24h", theme, ""), + ) +} + +fn standalone_page(title: &str, theme: &str, home: &str, body: &str, navigation: String) -> String { let theme = selected_theme(theme); format!( - "{}

    EggPool

    {}
    ", + "{}

    EggPool

    {}
    ", html_escape(title), query_component(theme), - query_component(theme), - dashboard_navigation_markup(active_nav, "24h", theme, ""), + home, + navigation, body ) } diff --git a/rust/src/server/dashboard/tests.rs b/rust/src/server/dashboard/tests.rs index 69c0799c..07eea7c9 100644 --- a/rust/src/server/dashboard/tests.rs +++ b/rust/src/server/dashboard/tests.rs @@ -1169,10 +1169,10 @@ fn the_theme_variable_count_is_pinned() { fn the_standalone_shells_resolve_the_theme() { // The on-prem shells used to link only the dashboard stylesheet, so every // `var()` they relied on was invalid and the page rendered unstyled. - let usage = super::render_usage_admin(&[], "", "Nord"); + let usage = super::render_usage_admin(&empty_usage_snapshot(), "", "Nord"); assert!(usage.contains("/static/dashboard.css")); assert!(usage.contains("/static/theme.css?theme=Nord")); - let my_usage = super::render_my_usage("operator", &[], &[], "Catppuccin Latte"); + let my_usage = super::render_my_usage("operator", &[], &[], &[], &[], "Catppuccin Latte"); assert!(my_usage.contains("/static/theme.css?theme=Catppuccin%20Latte")); let standalone = super::dashboard_standalone_page("Audit", "usage", "Nord", "

    body

    "); assert!(standalone.contains("/static/theme.css?theme=Nord")); @@ -1186,8 +1186,7 @@ fn the_standalone_shells_resolve_the_theme() { #[test] fn the_standalone_shells_carry_the_navigation_chrome() { for html in [ - super::render_usage_admin(&[], "", "Nord"), - super::render_my_usage("operator", &[], &[], "Nord"), + super::render_usage_admin(&empty_usage_snapshot(), "", "Nord"), super::dashboard_standalone_page("Audit", "usage", "Nord", "

    body

    "), ] { assert!( @@ -1198,8 +1197,137 @@ fn the_standalone_shells_carry_the_navigation_chrome() { html.contains("href=\"/?period=24h&theme=Nord\">Overview"), "the shell has no route back to the overview" ); + assert!(html.contains("href=\"/users?")); + assert!(html.contains("href=\"/accounts?")); assert!(html.contains("id=\"dashboard-content\"")); } + let member = super::render_my_usage("operator", &[], &[], &[], &[], "Nord"); + assert!(member.contains("class=\"topnav-menu\"")); + assert!(member.contains("href=\"/my-account?")); + assert!(member.contains("href=\"/usage?")); + assert!(member.contains("href=\"/account?")); + for forbidden in [ + "href=\"/users", + "href=\"/accounts", + "href=\"/profiles", + "href=\"/runtime", + "href=\"/?period=", + ] { + assert!( + !member.contains(forbidden), + "member navigation contains {forbidden}" + ); + } +} + +#[test] +fn the_users_roster_shows_the_current_assignment_without_secrets() { + let mut facts = std::collections::BTreeMap::new(); + facts.insert( + "member".to_owned(), + super::UserAdminFacts { + profile_id: Some("team".to_owned()), + overrides: vec![("model-a".to_owned(), "deny".to_owned())], + rules: vec![crate::user_budget::UserBudgetRule { + id: 1, + model_id: None, + window: crate::user_budget::BudgetWindow::Month, + max_requests: None, + max_tokens: None, + max_microdollars: Some(1_500_000), + max_concurrent: None, + enforcement: crate::user_budget::BudgetEnforcement::Estimated, + version: 1, + }], + credentials: vec![crate::identity::CredentialSummary { + id: "credential-id".to_owned(), + label: "laptop".to_owned(), + created_at: "2026-11-10T00:00:00Z".to_owned(), + last_used_at: None, + expires_at: None, + }], + upstream_grant: "inherit".to_owned(), + upstreams: vec![( + "opencode-go".to_owned(), + "personal-go".to_owned(), + "active".to_owned(), + )], + }, + ); + facts.insert( + "open".to_owned(), + super::UserAdminFacts { + profile_id: None, + overrides: Vec::new(), + rules: Vec::new(), + credentials: Vec::new(), + upstream_grant: "deny".to_owned(), + upstreams: Vec::new(), + }, + ); + let users = vec![ + crate::identity::UserSummary { + id: "member".to_owned(), + username: "member".to_owned(), + role: "member".to_owned(), + state: "active".to_owned(), + must_change_password: false, + }, + crate::identity::UserSummary { + id: "open".to_owned(), + username: "open".to_owned(), + role: "member".to_owned(), + state: "active".to_owned(), + must_change_password: false, + }, + ]; + let profiles = vec![crate::model_policy::PolicyProfileSummary { + id: "team".to_owned(), + name: "Team".to_owned(), + default_effect: "deny".to_owned(), + preferred_model_id: None, + version: 1, + assigned_users: 1, + model_rules: 0, + is_default_member_profile: false, + }]; + let html = super::render_users_admin(&users, &profiles, &[], &facts, "csrf", "deny"); + assert!(html.contains("Assigned profile: Team")); + assert!(html.contains("")); + assert!(html.contains("model-a deny")); + assert!(html.contains("1500000 (1.5 USD)")); + assert!(html.contains("laptop")); + assert!(html.contains("2026-11-10T00:00:00Z")); + assert!(html.contains("Unassigned. Models are denied until a profile is assigned.")); + assert!(!html.contains("credential-id")); + assert!(!html.contains("selector")); + assert!(!html.contains("digest")); + assert!(html.contains("action=\"/admin/users/budget\"")); + assert!(html.contains("name=\"max_microdollars\"")); + assert!(html.contains("action=\"/admin/users/upstream/grant\"")); + assert!(html.contains("action=\"/admin/users/upstream/default\"")); + assert!(html.contains("opencode-go personal-go active")); + assert!(!html.contains("name=\"secret\"")); +} + +#[test] +fn member_upstream_form_hides_the_key_until_self_service_is_allowed() { + let providers = vec!["opencode-go".to_owned()]; + let rows = vec![( + "opencode-go".to_owned(), + "personal-go".to_owned(), + "active".to_owned(), + )]; + let denied = super::render_member_upstream(false, &rows, &providers, "csrf"); + assert!(denied.contains("not granted")); + assert!(denied.contains("opencode-go")); + assert!(!denied.contains("name=\"secret\"")); + assert!(!denied.contains("action=\"/my-account/upstreams\"")); + let allowed = super::render_member_upstream(true, &rows, &providers, "csrf"); + assert!(allowed.contains("name=\"secret\"")); + assert!(allowed.contains("action=\"/my-account/upstreams\"")); + assert!(allowed.contains("value=\"opencode-go\"")); + assert!(!allowed.contains("amazon")); } #[test] @@ -1211,6 +1339,62 @@ fn a_truncated_usage_table_says_so() { let at_cap = super::usage_truncation_notice(super::USAGE_ROW_CAP); assert!(at_cap.contains("truncated")); assert!(at_cap.contains(&super::USAGE_ROW_CAP.to_string())); + assert!( + !at_cap.contains("raise the limit"), + "the notice names the applied cap without telling the reader to edit the query" + ); +} + +fn empty_usage_snapshot() -> crate::user_budget::AdminUsageSnapshot { + crate::user_budget::AdminUsageSnapshot { + day_start: "2026-11-10".to_owned(), + month_start: "2026-11-01".to_owned(), + rows: Vec::new(), + } +} + +#[test] +fn member_usage_names_the_window_and_admin_windows_stay_separate() { + let mut snapshot = empty_usage_snapshot(); + snapshot.rows.push(crate::user_budget::AdminUsageWindowRow { + username: "ada".to_owned(), + model_id: "model-a".to_owned(), + window: crate::user_budget::BudgetWindow::Day, + window_start: snapshot.day_start.clone(), + request_count: 7, + token_count: 11, + cost_microdollars: 1_500_000, + }); + snapshot.rows.push(crate::user_budget::AdminUsageWindowRow { + username: "ada".to_owned(), + model_id: "model-a".to_owned(), + window: crate::user_budget::BudgetWindow::Month, + window_start: snapshot.month_start.clone(), + request_count: 7, + token_count: 11, + cost_microdollars: 1_500_000, + }); + let admin = super::render_usage_admin(&snapshot, "", "Nord"); + assert!(admin.contains("Current UTC day")); + assert!(admin.contains("Current UTC month")); + assert!(!admin.contains(">14<"), "{admin}"); + assert!(admin.contains("1.5 USD")); + let usage = crate::user_budget::UserBudgetUsage { + model_id: "model-a".to_owned(), + window: crate::user_budget::BudgetWindow::Day, + window_start: "2026-11-10".to_owned(), + request_count: 7, + token_count: 11, + cost_microdollars: 0, + provider_reported_microdollars: 0, + local_estimated_microdollars: 0, + reservation_fallback_microdollars: 0, + unknown_token_requests: 0, + unknown_cost_requests: 0, + }; + let member = super::render_my_usage("ada", &[], &[usage], &[], &[], "Nord"); + assert!(member.contains(">day<"), "{member}"); + assert!(member.contains("Other people's consumption is not shown")); } #[test] diff --git a/rust/src/server/health.rs b/rust/src/server/health.rs index e32e9341..632568bd 100644 --- a/rust/src/server/health.rs +++ b/rust/src/server/health.rs @@ -365,9 +365,17 @@ pub(super) async fn user_budget_api( Ok(value) => value, Err(_) => return degraded("user budget unavailable"), }; - // Instance ceilings are admin-visible only: member responses keep their - // existing shape so one member can never observe the shared ceiling or - // infer other users' consumption from it. + let remaining = match budgets.current_allowance(target_id).await { + Ok(value) => value, + Err(_) => return degraded("user budget unavailable"), + }; + let instance = crate::instance_budget::InstanceBudgetService::new(state.database.clone()); + let instance_rules = match instance.rules().await { + Ok(value) => value, + Err(_) => return degraded("user budget unavailable"), + }; + // Instance usage stays on the administrator response. A member can see + // the configured ceilings without seeing who else consumed them. if principal.role.as_deref() != Some("admin") { return json_response( StatusCode::OK, @@ -376,14 +384,11 @@ pub(super) async fn user_budget_api( "cost_basis": "estimated_microdollars", "rules": rules, "usage": usage, + "remaining": remaining, + "instance_rules": instance_rules, }), ); } - let instance = crate::instance_budget::InstanceBudgetService::new(state.database.clone()); - let instance_rules = match instance.rules().await { - Ok(value) => value, - Err(_) => return degraded("user budget unavailable"), - }; let instance_usage = match instance.usage("0000-01-01", 500).await { Ok(value) => value, Err(_) => return degraded("user budget unavailable"), @@ -395,6 +400,7 @@ pub(super) async fn user_budget_api( "cost_basis": "estimated_microdollars", "rules": rules, "usage": usage, + "remaining": remaining, "instance_rules": instance_rules, "instance_usage": instance_usage, }), diff --git a/rust/src/server/middleware.rs b/rust/src/server/middleware.rs index 90a103d2..5262daf1 100644 --- a/rust/src/server/middleware.rs +++ b/rust/src/server/middleware.rs @@ -84,6 +84,12 @@ pub(super) async fn authenticate( } let Some(session_token) = crate::web_session::session_cookie_value(request.headers()) else { + // A presented credential is a machine client. Keep the JSON refusal + // so a personal token cannot be turned into a browser sign-in. + if supplied_key.is_none() && sign_in_handoff_applies(&path, request.method(), &access_state) + { + return super::auth::sign_in_handoff_response(); + } return unauthorized("Sign in required"); }; let principal = match crate::web_session::authenticate(&state.database, &session_token).await { @@ -102,7 +108,9 @@ pub(super) async fn authenticate( | "/my-account/models" | "/usage" ); - let account_surface = account_surface || path.starts_with("/account/tokens"); + let account_surface = account_surface + || path.starts_with("/account/tokens") + || personal_upstream_member_path(&path); if principal.role != "admin" && !account_surface { // A member is refused an administrative path with a page that names // the refusal and points at the member surface the member does have, @@ -182,10 +190,54 @@ fn requires_browser_session(path: &str) -> bool { | "/users" | "/profiles" ) || path.starts_with("/account/tokens") + || personal_upstream_member_path(path) || path.starts_with("/admin/") || path == "/api/admin/audit/export" } +fn personal_upstream_member_path(path: &str) -> bool { + path == "/my-account/upstreams" || path == "/my-account/upstreams/remove" +} + +fn sign_in_handoff_applies(path: &str, method: &http::Method, access_state: &str) -> bool { + *method == http::Method::GET + && matches!(access_state, "admin_initialized" | "managed") + && !path.starts_with("/v1/") + && !path.starts_with("/api/") + && !encoded_api_path(path) + && html_navigation_page(path) +} + +fn html_navigation_page(path: &str) -> bool { + path == "/" + || matches!( + path, + "/accounts" + | "/models" + | "/latency" + | "/events" + | "/timeseries" + | "/bandwidth" + | "/pings" + | "/reliability" + | "/routing" + | "/traces" + | "/runtime" + | "/cache" + | "/account" + | "/account/landing" + | "/account/password" + | "/my-account" + | "/my-account/models" + | "/usage" + | "/users" + | "/profiles" + ) + || path.starts_with("/models/") + || path.starts_with("/account/tokens") + || path.starts_with("/admin/") +} + fn is_unconditionally_public(path: &str) -> bool { path == "/v1/healthz" || path == "/v1/readyz" @@ -230,6 +282,7 @@ pub(super) fn requires_auth(path: &str, method: &http::Method, server: &ServerSt | "/my-account/models" | "/usage" ) || path.starts_with("/account/tokens") + || personal_upstream_member_path(path) || path.starts_with("/admin/") || path == "/api/admin/audit/export" || matches!(path, "/users" | "/profiles") @@ -664,7 +717,7 @@ pub(super) fn is_loopback_host(host: &str) -> bool { mod tests { use super::{ fixed_key, legacy_server_key_allowed, personal_credential_allowed, provided_api_key, - requires_auth, verify_api_key, + requires_auth, sign_in_handoff_applies, verify_api_key, }; use crate::server::ServerState; use axum::http::{HeaderMap, HeaderValue, header}; @@ -679,6 +732,41 @@ mod tests { assert!(!legacy_server_key_allowed(None)); } + #[test] + fn initialized_html_navigation_offers_sign_in_and_machine_routes_stay_json() { + for path in ["/", "/usage", "/my-account", "/accounts", "/users"] { + assert!( + sign_in_handoff_applies(path, &http::Method::GET, "managed"), + "{path}" + ); + assert!( + sign_in_handoff_applies(path, &http::Method::GET, "admin_initialized"), + "{path}" + ); + } + for path in ["/v1/models", "/api/user-budget", "/api/status"] { + assert!( + !sign_in_handoff_applies(path, &http::Method::GET, "managed"), + "{path}" + ); + } + assert!(!sign_in_handoff_applies( + "/", + &http::Method::POST, + "managed" + )); + assert!(!sign_in_handoff_applies( + "/", + &http::Method::GET, + "legacy_unmigrated" + )); + assert!(!sign_in_handoff_applies( + "/", + &http::Method::GET, + "fresh_uninitialized" + )); + } + #[test] fn personal_credentials_are_limited_to_agent_surfaces() { for path in [ diff --git a/rust/src/server/mod.rs b/rust/src/server/mod.rs index 04272fcd..e8d63116 100644 --- a/rust/src/server/mod.rs +++ b/rust/src/server/mod.rs @@ -16,15 +16,16 @@ use auth::{ account_page, login_page, login_submit, logout_submit, member_landing_page, password_change, }; use dashboard::{ - accounts_page, assign_user_profile, audit_export, audit_page, bandwidth_page, cache_page, - create_personal_token, create_profile, create_user, delete_profile, events_page, - grouped_timeseries_api, issue_admin_token, latency_page, model_detail_page, models_page, - my_account_page, my_models_page, overview, pings_page, profiles_page, reliability_page, - remove_instance_budget, remove_profile_rule, remove_user_override, reset_user_password, - revoke_personal_token, revoke_user_tokens, routing_page, runtime_page, - set_default_member_profile, set_instance_budget, set_profile_preference, set_profile_rule, - set_user_budget, set_user_override, set_user_state, static_chart_js, static_css, - static_favicon, static_js, stats_cache_observability, stats_cache_stability, + accounts_page, add_member_upstream, assign_user_profile, audit_export, audit_page, + bandwidth_page, cache_page, create_personal_token, create_profile, create_user, delete_profile, + events_page, grouped_timeseries_api, issue_admin_token, latency_page, model_detail_page, + models_page, my_account_page, my_models_page, overview, pings_page, profiles_page, + reliability_page, remove_instance_budget, remove_member_upstream, remove_profile_rule, + remove_upstream_account, remove_user_override, reset_user_password, revoke_personal_token, + revoke_user_tokens, routing_page, runtime_page, set_default_member_profile, + set_instance_budget, set_profile_preference, set_profile_rule, set_upstream_default, + set_upstream_grant, set_user_budget, set_user_override, set_user_state, static_chart_js, + static_css, static_favicon, static_js, stats_cache_observability, stats_cache_stability, stats_request_segmentation, stats_request_shaping, stats_transcoding, summary, sync_accounts, theme_css, timeseries_api, timeseries_page, traces_page, update_profile, usage_page, users_page, @@ -715,6 +716,12 @@ pub struct AppState { } impl AppState { + pub(crate) fn config_path(&self) -> Option<&std::path::Path> { + self.process + .as_ref() + .and_then(|process| process.config_path()) + } + /// Construct router state around an already published manager. This is /// intended for embedded/test callers; production startup constructs the /// manager in `run_with_digest` before creating `ServerRuntime`. @@ -1236,6 +1243,14 @@ pub fn build_router(state: AppState) -> Router { .route("/admin/users/override", post(set_user_override)) .route("/admin/users/override/remove", post(remove_user_override)) .route("/admin/users/budget", post(set_user_budget)) + .route("/admin/users/upstream/default", post(set_upstream_default)) + .route("/admin/users/upstream/grant", post(set_upstream_grant)) + .route( + "/admin/users/upstream/remove", + post(remove_upstream_account), + ) + .route("/my-account/upstreams", post(add_member_upstream)) + .route("/my-account/upstreams/remove", post(remove_member_upstream)) .route("/admin/budget/instance", post(set_instance_budget)) .route( "/admin/budget/instance/remove", diff --git a/rust/src/user_budget.rs b/rust/src/user_budget.rs index a488f6bd..286b5951 100644 --- a/rust/src/user_budget.rs +++ b/rust/src/user_budget.rs @@ -59,6 +59,43 @@ pub struct UserBudgetRule { pub version: i64, } +#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)] +pub struct BudgetDimensionAllowance { + pub ceiling: Option, + pub settled: i64, + pub held: i64, + pub remaining: Option, +} + +#[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)] +pub struct UserBudgetAllowance { + pub model_id: Option, + pub window: BudgetWindow, + pub window_start: String, + pub requests: BudgetDimensionAllowance, + pub tokens: BudgetDimensionAllowance, + pub microdollars: BudgetDimensionAllowance, + pub concurrent: BudgetDimensionAllowance, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct AdminUsageWindowRow { + pub username: String, + pub model_id: String, + pub window: BudgetWindow, + pub window_start: String, + pub request_count: i64, + pub token_count: i64, + pub cost_microdollars: i64, +} + +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct AdminUsageSnapshot { + pub day_start: String, + pub month_start: String, + pub rows: Vec, +} + #[derive(Debug, Clone, PartialEq, Eq, serde::Serialize)] pub struct UserBudgetUsage { pub model_id: String, @@ -383,6 +420,219 @@ impl UserBudgetService { .await .map_err(UserBudgetError::Database) } + + /// Current-window headroom for one user's own rules. + /// + /// Rules, settled rows, and active holds are read on one SQLite call so a + /// concurrent settlement cannot be subtracted twice. + pub async fn current_allowance( + &self, + user_id: &str, + ) -> Result, UserBudgetError> { + let user_id = user_id.to_owned(); + self.database + .call(move |connection| { + let (day_start, month_start): (String, String) = connection.query_row( + "SELECT date('now'), strftime('%Y-%m-01', 'now')", + [], + |row| Ok((row.get(0)?, row.get(1)?)), + )?; + let mut statement = connection.prepare( + "SELECT model_id, window, max_requests, max_tokens, + max_microdollars, max_concurrent + FROM user_budget_rules WHERE user_id = ?1 + ORDER BY model_id IS NOT NULL, model_id, window", + )?; + let rules = statement + .query_map([&user_id], |row| { + Ok(( + row.get::<_, Option>(0)?, + row.get::<_, String>(1)?, + row.get::<_, Option>(2)?, + row.get::<_, Option>(3)?, + row.get::<_, Option>(4)?, + row.get::<_, Option>(5)?, + )) + })? + .collect::, _>>()?; + drop(statement); + let mut allowances = Vec::with_capacity(rules.len()); + for ( + model_id, + window, + max_requests, + max_tokens, + max_microdollars, + max_concurrent, + ) in rules + { + let window_start = if window == "day" { + day_start.clone() + } else { + month_start.clone() + }; + let (settled_requests, settled_tokens, settled_cost) = settled_window( + connection, + &user_id, + model_id.as_deref(), + &window, + &window_start, + )?; + let (held_requests, held_tokens, held_cost, active_count) = held_window( + connection, + &user_id, + model_id.as_deref(), + &window, + &window_start, + )?; + allowances.push(UserBudgetAllowance { + window: parse_window(&window), + window_start, + model_id, + requests: dimension(max_requests, settled_requests, held_requests), + tokens: dimension(max_tokens, settled_tokens, held_tokens), + microdollars: dimension(max_microdollars, settled_cost, held_cost), + concurrent: dimension(max_concurrent, 0, active_count), + }); + } + Ok(allowances) + }) + .await + .map_err(UserBudgetError::Database) + } + + /// Usage totals grouped inside one window kind and one window start. + pub async fn admin_usage_by_window( + &self, + limit: u16, + ) -> Result { + if limit == 0 || limit > 500 { + return Err(UserBudgetError::InvalidRule); + } + self.database + .call(move |connection| { + let (day_start, month_start): (String, String) = connection.query_row( + "SELECT date('now'), strftime('%Y-%m-01', 'now')", + [], + |row| Ok((row.get(0)?, row.get(1)?)), + )?; + let mut statement = connection.prepare( + "SELECT u.username, COALESCE(b.model_id, '(all models)'), b.window, + b.window_start, SUM(b.request_count), SUM(b.token_count), + SUM(b.cost_microdollars) + FROM user_budget_usage b JOIN users u ON u.id = b.user_id + GROUP BY u.id, b.model_id, b.window, b.window_start + ORDER BY b.window, b.window_start DESC, u.username COLLATE NOCASE, b.model_id + LIMIT ?1", + )?; + let rows = statement + .query_map([i64::from(limit)], |row| { + let window: String = row.get(2)?; + Ok(AdminUsageWindowRow { + username: row.get(0)?, + model_id: row.get(1)?, + window: parse_window(&window), + window_start: row.get(3)?, + request_count: row.get(4)?, + token_count: row.get(5)?, + cost_microdollars: row.get(6)?, + }) + })? + .collect::, _>>()?; + Ok(AdminUsageSnapshot { + day_start, + month_start, + rows, + }) + }) + .await + .map_err(UserBudgetError::Database) + } +} + +fn dimension(ceiling: Option, settled: i64, held: i64) -> BudgetDimensionAllowance { + BudgetDimensionAllowance { + remaining: ceiling.map(|limit| limit.saturating_sub(settled).saturating_sub(held)), + ceiling, + settled, + held, + } +} + +fn settled_window( + connection: &tokio_rusqlite::rusqlite::Connection, + user_id: &str, + model_id: Option<&str>, + window: &str, + window_start: &str, +) -> Result<(i64, i64, i64), tokio_rusqlite::rusqlite::Error> { + if let Some(model_id) = model_id { + connection.query_row( + "SELECT coalesce(sum(request_count), 0), coalesce(sum(token_count), 0), + coalesce(sum(cost_microdollars), 0) + FROM user_budget_usage WHERE user_id = ?1 AND model_id = ?2 + AND window = ?3 AND window_start = ?4", + params![user_id, model_id, window, window_start], + |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), + ) + } else { + connection.query_row( + "SELECT coalesce(sum(request_count), 0), coalesce(sum(token_count), 0), + coalesce(sum(cost_microdollars), 0) + FROM user_budget_usage WHERE user_id = ?1 AND window = ?2 AND window_start = ?3", + params![user_id, window, window_start], + |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?)), + ) + } +} + +fn held_window( + connection: &tokio_rusqlite::rusqlite::Connection, + user_id: &str, + model_id: Option<&str>, + window: &str, + window_start: &str, +) -> Result<(i64, i64, i64, i64), tokio_rusqlite::rusqlite::Error> { + let sql = if model_id.is_some() { + "SELECT coalesce(sum(CASE WHEN (?3 = 'day' AND day_start = ?4) + OR (?3 = 'month' AND month_start = ?4) + THEN held_requests ELSE 0 END), 0), + coalesce(sum(CASE WHEN (?3 = 'day' AND day_start = ?4) + OR (?3 = 'month' AND month_start = ?4) + THEN held_tokens ELSE 0 END), 0), + coalesce(sum(CASE WHEN (?3 = 'day' AND day_start = ?4) + OR (?3 = 'month' AND month_start = ?4) + THEN held_microdollars ELSE 0 END), 0), + coalesce(sum(CASE WHEN (?3 = 'day' AND day_start = ?4) + OR (?3 = 'month' AND month_start = ?4) + THEN 1 ELSE 0 END), 0) + FROM user_budget_reservations WHERE user_id = ?1 AND model_id = ?2 AND status = 'active'" + } else { + "SELECT coalesce(sum(CASE WHEN (?2 = 'day' AND day_start = ?3) + OR (?2 = 'month' AND month_start = ?3) + THEN held_requests ELSE 0 END), 0), + coalesce(sum(CASE WHEN (?2 = 'day' AND day_start = ?3) + OR (?2 = 'month' AND month_start = ?3) + THEN held_tokens ELSE 0 END), 0), + coalesce(sum(CASE WHEN (?2 = 'day' AND day_start = ?3) + OR (?2 = 'month' AND month_start = ?3) + THEN held_microdollars ELSE 0 END), 0), + coalesce(sum(CASE WHEN (?2 = 'day' AND day_start = ?3) + OR (?2 = 'month' AND month_start = ?3) + THEN 1 ELSE 0 END), 0) + FROM user_budget_reservations WHERE user_id = ?1 AND status = 'active'" + }; + if let Some(model_id) = model_id { + connection.query_row( + sql, + params![user_id, model_id, window, window_start], + |row| Ok((row.get(0)?, row.get(1)?, row.get(2)?, row.get(3)?)), + ) + } else { + connection.query_row(sql, params![user_id, window, window_start], |row| { + Ok((row.get(0)?, row.get(1)?, row.get(2)?, row.get(3)?)) + }) + } } #[derive(Debug, Clone)] diff --git a/rust/tests/build_manifest.rs b/rust/tests/build_manifest.rs index 470856b2..27de3fb0 100644 --- a/rust/tests/build_manifest.rs +++ b/rust/tests/build_manifest.rs @@ -28,7 +28,7 @@ fn semantically_equivalent_reformatted_manifest_is_accepted() { let reformatted = serde_json::to_string(&value).expect("compact JSON"); let parsed = build_support::parse_checksums(&reformatted); - assert_eq!(parsed.len(), 65); + assert_eq!(parsed.len(), 66); assert_eq!( parsed.get("0001_initial.sql").map(String::as_str), Some("2aa5800147fc3ef8cc35591c44564244dba138b4dbc92fc1779e4f88813912ad") @@ -55,7 +55,7 @@ fn rust_owned_runtime_assets_are_complete_and_hash_locked() { serde_json::from_str(include_str!("../assets/runtime-manifest.json")) .expect("runtime asset manifest is valid JSON"); assert_eq!(manifest.manifest_version, "runtime-assets.v1"); - assert_eq!(manifest.schema_migration_count, 65); + assert_eq!(manifest.schema_migration_count, 66); assert!(manifest.schema_change); let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")); diff --git a/rust/tests/database_compatibility.rs b/rust/tests/database_compatibility.rs index d7743a0d..4ac27f81 100644 --- a/rust/tests/database_compatibility.rs +++ b/rust/tests/database_compatibility.rs @@ -40,8 +40,8 @@ async fn fresh_database_migrates_idempotently_and_preserves_pragmas() { .run() .await .expect("migrations apply"); - assert_eq!(first.applied_versions.len(), 65); - assert_eq!(first.applied_this_run.len(), 65); + assert_eq!(first.applied_versions.len(), 66); + assert_eq!(first.applied_this_run.len(), 66); let default_member_profile: Option = database .call(|connection| { connection.query_row( @@ -270,7 +270,7 @@ async fn python_historical_fixture_upgrades_and_repositories_round_trip() { .await .expect("current migrations apply"); assert_eq!(state.applied_this_run.first(), Some(&12)); - assert_eq!(state.applied_this_run.last(), Some(&65)); + assert_eq!(state.applied_this_run.last(), Some(&66)); let account = AccountRepository::new(&database) .get_by_name("historical-account") @@ -640,13 +640,13 @@ async fn schema54_image_upgrades_with_legacy_state_preserved() { .archive; BackupService::validate_archive(&archive).expect("pre-upgrade archive validates"); - // Forward-only production upgrade: exactly migrations 55..65. + // Forward-only production upgrade: exactly migrations 55..66. let state = MigrationRunner::new(&database) .run() .await .expect("production upgrade applies"); assert_eq!(state.applied_this_run.first(), Some(&55)); - assert_eq!(state.applied_this_run.last(), Some(&65)); + assert_eq!(state.applied_this_run.last(), Some(&66)); assert_eq!(state.applied_this_run.len(), 11); database .quick_check() @@ -1067,8 +1067,8 @@ async fn the_v64_migration_removes_the_legacy_rows_and_constrains_the_null_scope ); assert_eq!( state.applied_versions.last(), - Some(&65), - "the migration chain is contiguous and ends at v65" + Some(&66), + "the migration chain is contiguous and ends at v66" ); database diff --git a/rust/tests/on_prem_admin_ui.rs b/rust/tests/on_prem_admin_ui.rs index e7a0cbfb..249a090c 100644 --- a/rust/tests/on_prem_admin_ui.rs +++ b/rust/tests/on_prem_admin_ui.rs @@ -381,6 +381,19 @@ async fn two_user_browser_journey_fences_admin_data_and_personal_credentials() { .await; assert!(user_page.starts_with("HTTP/1.1 200"), "{user_page}"); assert!(user_page.contains("member"), "{user_page}"); + assert!( + user_page.contains(""), + "{user_page}" + ); + assert!( + user_page.contains("Unassigned. Models are denied until a profile is assigned."), + "{user_page}" + ); + assert!( + !user_page.contains("M006 temporary member password") + && !user_page.contains("M006+temporary+member+password"), + "{user_page}" + ); // M008: the budget form distinguishes hard versus estimated enforcement // instead of labeling every dimension an estimate. assert!(user_page.contains("name=\"enforcement\""), "{user_page}"); @@ -1334,6 +1347,19 @@ async fn a_member_lands_on_the_member_landing_page_and_reaches_the_member_surfac for path in ["/my-account", "/my-account/models", "/usage"] { let page = http_request(address, "GET", path, "", Some(&member_cookies), None, None).await; assert!(page.starts_with("HTTP/1.1 200"), "{path}: {page}"); + for forbidden in [ + "href=\"/users", + "href=\"/accounts", + "href=\"/profiles", + "href=\"/runtime", + ] { + assert!( + !page.contains(forbidden), + "{path} navigation contains {forbidden}: {page}" + ); + } + assert!(page.contains("href=\"/my-account"), "{path}: {page}"); + assert!(page.contains("href=\"/usage"), "{path}: {page}"); } shutdown(handle, task).await; @@ -1472,3 +1498,246 @@ async fn an_operator_who_must_change_their_password_is_still_redirected_to_the_a shutdown(handle, task).await; database.close().await.unwrap(); } + +#[tokio::test] +async fn personal_upstream_browser_grant_never_echoes_the_key() { + let (directory, database) = database().await; + identity::mark_fresh_uninitialized(&database).await.unwrap(); + let (admin, admin_token) = + identity::bootstrap_admin(&database, "admin", "M006 strong admin password passphrase") + .await + .unwrap(); + identity::enable_managed(&database, &admin.id) + .await + .unwrap(); + let member = identity::create_member( + &database, + &admin.id, + "member", + "temporary member password 123", + ) + .await + .unwrap(); + database + .call(|connection| { + connection.execute( + "UPDATE users SET must_change_password = 0 WHERE username = 'member'", + [], + )?; + Ok(()) + }) + .await + .unwrap(); + let config_path = directory.path().join("config.toml"); + std::fs::write(&config_path, include_str!("../config.example.toml")).unwrap(); + let env_path = directory.path().join(".env"); + let secret = "sk-personal-browser-sentinel"; + + let process = + ProcessRuntime::with_config_path(database.clone(), &config_path).expect("process runtime"); + let mut config = Config::default(); + config.server.host = "127.0.0.1".to_owned(); + config.server.api_key = None; + config.dashboard.enabled = true; + let candidate = + RuntimeGenerationFactory::prepare(&process, config.clone(), "upstream-ui".into(), 1) + .await + .expect("runtime generation"); + let manager = Arc::new(RuntimeManager::new( + candidate.transfer().expect("generation transfer"), + )); + process + .install_initial_tasks((*manager).clone(), &config) + .await + .expect("tasks install"); + let runtime = ServerRuntime::new(process, manager, config); + let handle = runtime.handle(); + let listener = TcpListener::bind(("127.0.0.1", 0)).await.unwrap(); + let address = listener.local_addr().unwrap(); + let task = tokio::spawn(async move { + let _ = runtime.serve_listener(listener).await; + }); + let origin = format!("http://{address}"); + + let member_login = http_request( + address, + "POST", + "/login", + "username=member&password=temporary+member+password+123", + None, + Some(&origin), + None, + ) + .await; + assert!(member_login.starts_with("HTTP/1.1 303"), "{member_login}"); + let (_, member_csrf, member_cookies) = session_pair(&member_login); + let denied_page = http_request( + address, + "GET", + "/my-account", + "", + Some(&member_cookies), + None, + None, + ) + .await; + assert!(denied_page.contains("not granted"), "{denied_page}"); + assert!(!denied_page.contains("name=\"secret\"")); + let denied_post = http_request( + address, + "POST", + "/my-account/upstreams", + &format!("provider=opencode-go&name=personal-browser&secret={secret}&csrf={member_csrf}"), + Some(&member_cookies), + Some(&origin), + None, + ) + .await; + assert!(denied_post.starts_with("HTTP/1.1 403"), "{denied_post}"); + assert!(!denied_post.contains(secret)); + assert!(!env_path.exists()); + assert!( + eggpool::personal_upstream::list_bindings(&database, Some(&member.id)) + .await + .unwrap() + .is_empty() + ); + + let admin_login = http_request( + address, + "POST", + "/login", + "username=admin&password=M006+strong+admin+password+passphrase", + None, + Some(&origin), + None, + ) + .await; + let (_, admin_csrf, admin_cookies) = session_pair(&admin_login); + let users = http_request( + address, + "GET", + "/users", + "", + Some(&admin_cookies), + None, + None, + ) + .await; + assert!(users.contains("action=\"/admin/users/upstream/grant\"")); + assert!(!users.contains("name=\"secret\"")); + let granted = http_request( + address, + "POST", + "/admin/users/upstream/grant", + &format!("user_id={}&effect=allow&csrf={admin_csrf}", member.id), + Some(&admin_cookies), + Some(&origin), + None, + ) + .await; + assert!(granted.starts_with("HTTP/1.1 303"), "{granted}"); + + let allowed_page = http_request( + address, + "GET", + "/my-account", + "", + Some(&member_cookies), + None, + None, + ) + .await; + assert!(allowed_page.contains("name=\"secret\""), "{allowed_page}"); + assert!(allowed_page.contains("value=\"opencode-go\"")); + assert!(!allowed_page.contains(secret)); + let added = http_request( + address, + "POST", + "/my-account/upstreams", + &format!("provider=opencode-go&name=personal-browser&secret={secret}&csrf={member_csrf}"), + Some(&member_cookies), + Some(&origin), + None, + ) + .await; + assert!(added.starts_with("HTTP/1.1 303"), "{added}"); + assert!(!added.contains(secret)); + let env_text = std::fs::read_to_string(&env_path).unwrap(); + let config_text = std::fs::read_to_string(&config_path).unwrap(); + assert!(env_text.contains(secret)); + assert!(!config_text.contains(secret)); + let account_page = http_request( + address, + "GET", + "/my-account", + "", + Some(&member_cookies), + None, + None, + ) + .await; + assert!(account_page.contains("personal-browser")); + assert!(!account_page.contains(secret)); + let stored = database + .call(|connection| { + let text: String = connection.query_row( + "SELECT group_concat(effect || ' ' || provider_id || ' ' || account_name || ' ' || state || ' ' || action || ' ' || target_id, ' ') + FROM personal_upstream_grants, personal_upstream_bindings, user_admin_audit", + [], + |row| row.get(0), + )?; + Ok(text) + }) + .await + .unwrap(); + assert!(!stored.contains(secret)); + + let denied_again = http_request( + address, + "POST", + "/admin/users/upstream/grant", + &format!("user_id={}&effect=deny&csrf={admin_csrf}", member.id), + Some(&admin_cookies), + Some(&origin), + None, + ) + .await; + assert!(denied_again.starts_with("HTTP/1.1 303"), "{denied_again}"); + assert_eq!( + eggpool::personal_upstream::list_bindings(&database, Some(&member.id)) + .await + .unwrap() + .len(), + 1 + ); + assert!(std::fs::read_to_string(&env_path).unwrap().contains(secret)); + let hidden = http_request( + address, + "GET", + "/my-account", + "", + Some(&member_cookies), + None, + None, + ) + .await; + assert!(!hidden.contains("name=\"secret\"")); + assert!(!hidden.contains(secret)); + + let token_post = http_request( + address, + "POST", + "/my-account/upstreams", + &format!("provider=opencode-go&name=other-browser&secret={secret}&csrf={member_csrf}"), + None, + Some(&origin), + Some(&admin_token.token), + ) + .await; + assert!(token_post.starts_with("HTTP/1.1 401"), "{token_post}"); + assert!(!token_post.contains(secret)); + + shutdown(handle, task).await; + database.close().await.unwrap(); +} diff --git a/rust/tests/on_prem_budgets.rs b/rust/tests/on_prem_budgets.rs index df8f4a09..0f1f1117 100644 --- a/rust/tests/on_prem_budgets.rs +++ b/rust/tests/on_prem_budgets.rs @@ -1747,3 +1747,99 @@ async fn backup_during_active_reservation_captures_hold_verbatim() { assert_eq!(hold_status(&reopened, request_id).await.0, "released"); reopened.close().await.expect("restored database closes"); } + +#[tokio::test] +async fn usage_windows_are_not_added_and_remaining_subtracts_holds() { + let fixture = fixture().await; + fixture + .database + .call(|connection| { + connection.execute( + "INSERT INTO users(id, username, normalized_username, role, password_hash) + VALUES ('budget-other', 'budget-other', 'budget-other', 'member', 'test-hash')", + [], + )?; + connection.execute( + "INSERT INTO user_budget_usage( + user_id, model_id, window, window_start, request_count) + VALUES ('budget-member', 'model-a', 'day', date('now'), 40), + ('budget-member', 'model-a', 'month', strftime('%Y-%m-01', 'now'), 40), + ('budget-member', 'model-a', 'day', '2000-01-01', 40), + ('budget-other', 'model-a', 'day', date('now'), 99)", + [], + )?; + for _ in 0..10 { + connection.execute( + "INSERT INTO requests(account_id, model_id, status) VALUES (1, 'model-a', 'pending')", + [], + )?; + connection.execute( + "INSERT INTO user_budget_reservations( + request_id, user_id, model_id, policy_version, day_start, month_start, + held_requests, held_tokens, held_microdollars, status, expires_at) + VALUES (last_insert_rowid(), 'budget-member', 'model-a', 1, date('now'), + strftime('%Y-%m-01', 'now'), 1, 0, 0, 'active', '2999-01-01')", + [], + )?; + } + Ok(()) + }) + .await + .expect("usage fixture inserts"); + let budgets = UserBudgetService::new(fixture.database.clone()); + budgets + .set_rule( + "budget-admin", + "budget-member", + Some("model-a"), + BudgetWindow::Day, + BudgetLimits { + requests: Some(100), + tokens: None, + microdollars: None, + concurrent: None, + enforcement: BudgetEnforcement::Estimated, + }, + ) + .await + .expect("request ceiling is recorded"); + let allowance = budgets + .current_allowance("budget-member") + .await + .expect("allowance reads"); + assert_eq!(allowance.len(), 1); + assert_eq!(allowance[0].requests.settled, 40); + assert_eq!(allowance[0].requests.held, 10); + assert_eq!(allowance[0].requests.remaining, Some(50)); + assert_eq!(allowance[0].tokens.ceiling, None); + assert_eq!(allowance[0].tokens.remaining, None); + let other = budgets + .current_allowance("budget-other") + .await + .expect("other allowance reads"); + assert!(other.is_empty()); + let snapshot = budgets + .admin_usage_by_window(500) + .await + .expect("admin windows read"); + let current_day: i64 = snapshot + .rows + .iter() + .filter(|row| { + row.window == BudgetWindow::Day + && row.window_start == snapshot.day_start + && row.username == "budget-member" + }) + .map(|row| row.request_count) + .sum(); + let current_month: i64 = snapshot + .rows + .iter() + .filter(|row| row.window == BudgetWindow::Month && row.window_start == snapshot.month_start) + .map(|row| row.request_count) + .sum(); + assert_eq!(current_day, 40); + assert_eq!(current_month, 40); + assert_ne!(current_day + current_month, current_day); + fixture.database.close().await.unwrap(); +} diff --git a/rust/tests/on_prem_global_budgets.rs b/rust/tests/on_prem_global_budgets.rs index 710f68d1..10c24274 100644 --- a/rust/tests/on_prem_global_budgets.rs +++ b/rust/tests/on_prem_global_budgets.rs @@ -1388,3 +1388,68 @@ async fn paired_gate_observations_across_identities_and_rules() { println!("M010_GATE_OBSERVATION {{\"rss_kb_after_suite\":{rss}}}"); } } + +#[tokio::test] +async fn member_allowance_excludes_other_users_and_instance_usage() { + let fixture = fixture().await; + let budgets = UserBudgetService::new(fixture.database.clone()); + let limits = BudgetLimits { + requests: Some(20), + ..BudgetLimits::default() + }; + for user in ["budget-member", "budget-member-2"] { + budgets + .set_rule("budget-admin", user, None, BudgetWindow::Day, limits) + .await + .expect("member rule"); + } + InstanceBudgetService::new(fixture.database.clone()) + .set_rule("budget-admin", None, BudgetWindow::Day, limits) + .await + .expect("instance ceiling"); + fixture + .database + .call(|connection| { + connection.execute( + "INSERT INTO user_budget_usage( + user_id, model_id, window, window_start, request_count) + VALUES ('budget-member', 'model-a', 'day', date('now'), 4), + ('budget-member-2', 'model-a', 'day', date('now'), 9)", + [], + )?; + connection.execute( + "INSERT INTO instance_budget_usage( + model_id, window, window_start, request_count) + VALUES ('model-a', 'day', date('now'), 80)", + [], + )?; + Ok(()) + }) + .await + .expect("usage rows insert"); + let first = budgets + .current_allowance("budget-member") + .await + .expect("first allowance"); + let second = budgets + .current_allowance("budget-member-2") + .await + .expect("second allowance"); + assert_eq!(first[0].requests.settled, 4); + assert_eq!(first[0].requests.remaining, Some(16)); + assert_eq!(second[0].requests.settled, 9); + assert_eq!(second[0].requests.remaining, Some(11)); + let encoded = serde_json::to_string(&first).expect("allowance encodes"); + assert!(!encoded.contains("instance_usage")); + assert!(!encoded.contains("budget-member-2")); + let instance = InstanceBudgetService::new(fixture.database.clone()); + let rules = instance.rules().await.expect("ceilings"); + assert_eq!(rules, instance.rules().await.expect("ceilings again")); + assert_eq!(rules[0].max_requests, Some(20)); + let usage = instance + .usage("0000-01-01", 50) + .await + .expect("instance usage"); + assert!(usage.iter().any(|row| row.request_count == 80)); + fixture.database.close().await.unwrap(); +} diff --git a/rust/tests/on_prem_identity.rs b/rust/tests/on_prem_identity.rs index 1771b264..2d17cd10 100644 --- a/rust/tests/on_prem_identity.rs +++ b/rust/tests/on_prem_identity.rs @@ -226,3 +226,160 @@ async fn password_reset_revokes_api_credentials_and_rejects_bad_passwords() { ); database.close().await.unwrap(); } + +#[tokio::test] +async fn personal_upstream_grant_defaults_to_deny_and_a_failed_publish_is_not_shared() { + let database = database().await; + identity::mark_fresh_uninitialized(&database).await.unwrap(); + let (admin, _) = identity::bootstrap_admin(&database, "admin", "correct horse battery staple") + .await + .unwrap(); + let member = identity::create_member( + &database, + &admin.id, + "member", + "temporary member password 123", + ) + .await + .unwrap(); + assert_eq!( + eggpool::personal_upstream::instance_grant(&database) + .await + .unwrap(), + eggpool::personal_upstream::GrantEffect::Deny + ); + assert_eq!( + eggpool::personal_upstream::effective_grant(&database, &member.id) + .await + .unwrap(), + eggpool::personal_upstream::GrantEffect::Deny + ); + let directory = std::env::temp_dir().join(format!( + "eggpool-upstream-{}-{}", + std::process::id(), + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap() + .as_nanos() + )); + std::fs::create_dir_all(&directory).unwrap(); + let config_path = directory.join("config.toml"); + let env_path = directory.join(".env"); + let original = include_str!("../config.example.toml"); + std::fs::write(&config_path, original).unwrap(); + let secret = "sk-personal-sentinel-value"; + let failed = eggpool::personal_upstream::add_personal_account_publishing( + &database, + eggpool::personal_upstream::PersonalAccountWrite { + actor_id: &admin.id, + user_id: &member.id, + provider_id: "opencode-go", + account_name: "personal-go", + secret, + config_path: &config_path, + env_path: &env_path, + require_self_service: false, + }, + eggpool::personal_upstream::PublishMode::Fail, + ) + .await; + assert!( + matches!( + failed, + Err(eggpool::personal_upstream::PersonalUpstreamError::PublicationRestored) + ), + "{failed:?}" + ); + assert_eq!(std::fs::read_to_string(&config_path).unwrap(), original); + assert!(!env_path.exists()); + assert!( + eggpool::personal_upstream::list_bindings(&database, None) + .await + .unwrap() + .is_empty() + ); + + eggpool::personal_upstream::add_personal_account( + &database, + eggpool::personal_upstream::PersonalAccountWrite { + actor_id: &admin.id, + user_id: &member.id, + provider_id: "opencode-go", + account_name: "personal-go", + secret, + config_path: &config_path, + env_path: &env_path, + require_self_service: false, + }, + ) + .await + .expect("personal account publishes when the server is not running"); + let config_text = std::fs::read_to_string(&config_path).unwrap(); + let env_text = std::fs::read_to_string(&env_path).unwrap(); + assert!(env_text.contains(secret)); + assert!(!config_text.contains(secret)); + assert!(config_text.contains("EGGPOOL_UPSTREAM_")); + let stored = database + .call(|connection| { + let grants: String = connection.query_row( + "SELECT group_concat(effect, ' ') FROM personal_upstream_grants", + [], + |row| row.get(0), + )?; + let bindings: String = connection.query_row( + "SELECT group_concat(provider_id || ' ' || account_name || ' ' || user_id || ' ' || state, ' ') + FROM personal_upstream_bindings", + [], + |row| row.get(0), + )?; + let audit: String = connection.query_row( + "SELECT group_concat(action || ' ' || target_id, ' ') FROM user_admin_audit", + [], + |row| row.get(0), + )?; + Ok(format!("{grants} {bindings} {audit}")) + }) + .await + .unwrap(); + assert!(!stored.contains(secret)); + let snapshot = eggpool::personal_upstream::load_snapshot(&database) + .await + .unwrap(); + assert!(!snapshot.excludes("opencode-go", "personal-go", Some(&member.id))); + assert!(snapshot.excludes("opencode-go", "personal-go", Some("other-user"))); + assert!(snapshot.excludes("opencode-go", "personal-go", None)); + let collision = eggpool::personal_upstream::add_personal_account( + &database, + eggpool::personal_upstream::PersonalAccountWrite { + actor_id: &admin.id, + user_id: &member.id, + provider_id: "opencode-go", + account_name: "personal-go", + secret, + config_path: &config_path, + env_path: &env_path, + require_self_service: false, + }, + ) + .await; + assert!(matches!( + collision, + Err(eggpool::personal_upstream::PersonalUpstreamError::NameCollision) + )); + identity::set_user_enabled(&database, &admin.id, &member.id, false) + .await + .unwrap(); + let withdrawn = eggpool::personal_upstream::load_snapshot(&database) + .await + .unwrap(); + assert!(withdrawn.excludes("opencode-go", "personal-go", Some(&member.id))); + identity::set_user_enabled(&database, &admin.id, &member.id, true) + .await + .unwrap(); + let still_withdrawn = eggpool::personal_upstream::load_snapshot(&database) + .await + .unwrap(); + assert!(still_withdrawn.excludes("opencode-go", "personal-go", Some(&member.id))); + let _ = std::fs::remove_dir_all(&directory); + database.close().await.unwrap(); +} diff --git a/rust/tests/on_prem_sessions.rs b/rust/tests/on_prem_sessions.rs index 69e7788f..7c12d0f8 100644 --- a/rust/tests/on_prem_sessions.rs +++ b/rust/tests/on_prem_sessions.rs @@ -358,6 +358,49 @@ fn cookie(response: &str, name: &str) -> String { .expect("cookie is set") } +#[tokio::test] +async fn legacy_public_dashboard_stays_available_without_a_sign_in_redirect() { + let (_directory, database) = database().await; + let process = ProcessRuntime::new(database.clone()).expect("process runtime"); + let mut config = Config::default(); + config.server.host = "127.0.0.1".to_owned(); + config.server.api_key = Some("legacy-server-key-0123456789".to_owned()); + config.dashboard.enabled = true; + config.dashboard.public = true; + let candidate = RuntimeGenerationFactory::prepare( + &process, + config.clone(), + "legacy-dashboard-test".to_owned(), + 1, + ) + .await + .expect("initial generation"); + let manager = Arc::new(RuntimeManager::new( + candidate.transfer().expect("generation transfer"), + )); + let runtime = ServerRuntime::new(process, manager, config); + let handle = runtime.handle(); + let listener = TcpListener::bind(("127.0.0.1", 0)).await.expect("listener"); + let address = listener.local_addr().unwrap(); + let task = tokio::spawn(async move { runtime.serve_listener(listener).await }); + + let dashboard = http_request( + address, + &format!("GET / HTTP/1.1\r\nHost: {address}\r\nConnection: close\r\n\r\n"), + ) + .await; + assert!(dashboard.starts_with("HTTP/1.1 200"), "{dashboard}"); + assert!(dashboard.contains("Overview"), "{dashboard}"); + assert!( + !dashboard.to_ascii_lowercase().contains("location: /login"), + "{dashboard}" + ); + + handle.request_shutdown(ShutdownReason::Requested); + task.await.unwrap().unwrap(); + database.close().await.unwrap(); +} + #[tokio::test] async fn managed_browser_login_account_csrf_and_logout_work_over_loopback() { let (_directory, database) = database().await; @@ -394,9 +437,60 @@ async fn managed_browser_login_account_csrf_and_logout_work_over_loopback() { ) .await; assert!( - public_dashboard.starts_with("HTTP/1.1 401"), + public_dashboard.starts_with("HTTP/1.1 303"), + "{public_dashboard}" + ); + assert!( + public_dashboard + .to_ascii_lowercase() + .contains("location: /login"), + "{public_dashboard}" + ); + assert!( + public_dashboard + .to_ascii_lowercase() + .contains("cache-control: no-store"), + "{public_dashboard}" + ); + assert!( + !public_dashboard.contains("name=\"password\""), "{public_dashboard}" ); + let usage_handoff = http_request( + address, + &format!("GET /usage HTTP/1.1\r\nHost: {address}\r\nConnection: close\r\n\r\n"), + ) + .await; + assert!(usage_handoff.starts_with("HTTP/1.1 303"), "{usage_handoff}"); + assert!( + usage_handoff + .to_ascii_lowercase() + .contains("location: /login"), + "{usage_handoff}" + ); + let models = http_request( + address, + &format!("GET /v1/models HTTP/1.1\r\nHost: {address}\r\nConnection: close\r\n\r\n"), + ) + .await; + assert!(models.starts_with("HTTP/1.1 401"), "{models}"); + assert!(models.contains("\"detail\""), "{models}"); + let budget = http_request( + address, + &format!("GET /api/user-budget HTTP/1.1\r\nHost: {address}\r\nConnection: close\r\n\r\n"), + ) + .await; + assert!(budget.starts_with("HTTP/1.1 401"), "{budget}"); + assert!(budget.contains("\"detail\""), "{budget}"); + let posted = http_request( + address, + &format!( + "POST /account HTTP/1.1\r\nHost: {address}\r\nContent-Length: 0\r\nConnection: close\r\n\r\n" + ), + ) + .await; + assert!(posted.starts_with("HTTP/1.1 401"), "{posted}"); + assert!(!posted.starts_with("HTTP/1.1 303"), "{posted}"); let agent_to_account = http_request(address, &format!( "GET /account HTTP/1.1\r\nHost: {address}\r\nAuthorization: Bearer {agent_token}\r\nConnection: close\r\n\r\n" )).await; @@ -686,9 +780,10 @@ async fn browser_sessions_can_read_scoped_user_budget_api() { "{member_response}" ); assert!( - !member_response.contains("instance_rules") + member_response.contains("instance_rules") + && !member_response.contains("instance_usage") && !member_response.contains("\"max_requests\":10"), - "members see neither instance ceilings nor another user's rules: {member_response}" + "members see the shared ceiling configuration and not another user's rules or instance usage: {member_response}" ); let denied = http_request( @@ -714,7 +809,7 @@ async fn browser_sessions_can_read_scoped_user_budget_api() { "{admin_response}" ); assert!( - admin_response.contains("instance_rules"), + admin_response.contains("instance_rules") && admin_response.contains("instance_usage"), "{admin_response}" ); assert!( diff --git a/rust/tests/routing_domain.rs b/rust/tests/routing_domain.rs index 57982887..4489c428 100644 --- a/rust/tests/routing_domain.rs +++ b/rust/tests/routing_domain.rs @@ -591,3 +591,74 @@ async fn an_authentication_failure_still_produces_no_timed_backoff() { assert_eq!(policy.base_delay, 0.0); assert_eq!(policy.cap, 0.0); } + +#[tokio::test(flavor = "current_thread")] +async fn a_personal_binding_is_selectable_only_by_its_owner() { + let (database, path) = database("personal-binding").await; + database + .call(|connection| { + connection.execute( + "INSERT INTO personal_upstream_bindings(provider_id, account_name, user_id, state) + VALUES ('provider-a', 'account-a', 'owner-user', 'active')", + [], + )?; + Ok(()) + }) + .await + .unwrap(); + let snapshot = eggpool::personal_upstream::load_snapshot(&database) + .await + .unwrap(); + let (router, _) = health_router(); + let router = router.with_personal_bindings(snapshot); + let mut owner = routing_facts("model-a"); + owner.principal_user_id = Some("owner-user".into()); + let claim = router + .select_and_claim(&owner, &BTreeSet::new()) + .await + .unwrap() + .expect("the owner can select the bound account"); + assert_eq!(claim.account_name(), "account-a"); + drop(claim); + let mut other = routing_facts("model-a"); + other.principal_user_id = Some("other-user".into()); + assert!( + router + .select_and_claim(&other, &BTreeSet::new()) + .await + .unwrap() + .is_none() + ); + assert!( + router + .select_and_claim(&routing_facts("model-a"), &BTreeSet::new()) + .await + .unwrap() + .is_none() + ); + database + .call(|connection| { + connection.execute( + "UPDATE personal_upstream_bindings SET state = 'withdrawn'", + [], + )?; + Ok(()) + }) + .await + .unwrap(); + let withdrawn = eggpool::personal_upstream::load_snapshot(&database) + .await + .unwrap(); + let (router, _) = health_router(); + let router = router.with_personal_bindings(withdrawn); + assert!( + router + .select_and_claim(&owner, &BTreeSet::new()) + .await + .unwrap() + .is_none(), + "a withdrawn account is selected for nobody" + ); + database.close().await.unwrap(); + fs::remove_file(path).unwrap(); +} From 520909fa71617adfee23797377c5a117ac226937 Mon Sep 17 00:00:00 2001 From: CI Test Date: Tue, 10 Nov 2026 22:53:29 +0000 Subject: [PATCH 2/2] Close on-prem member access after the serial suite and release build. The suite required the schema-54 upgrade to count v66, and the member page to stop embedding the fixture username. Co-authored-by: Cursor --- AGENTS.md | 2 +- architecture/overview.md | 14 +- .../on-prem-member-access/001-status.md | 135 ++++++++++++++++ .../on-prem-member-access/002-status.md | 128 +++++++++++++++ .../on-prem-member-access/003-status.md | 127 +++++++++++++++ .../on-prem-member-access/004-status.md | 152 ++++++++++++++++++ .../on-prem-member-access/005-status.md | 133 +++++++++++++++ ...-solo-sign-in-and-onboarding-credential.md | 2 +- .../002-usage-windows-and-member-limits.md | 2 +- .../003-member-navigation-and-admin-roster.md | 2 +- ...4-personal-upstream-custody-and-routing.md | 2 +- .../005-personal-upstream-browser-grant.md | 2 +- plans/registry.md | 24 +-- .../on-prem-member-access-roadmap.md | 17 +- plans/subsystems/persistence-roadmap.md | 2 +- rust/src/server/dashboard/render/admin.rs | 2 +- rust/tests/database_compatibility.rs | 4 +- 17 files changed, 716 insertions(+), 34 deletions(-) create mode 100644 plans/closure/on-prem-member-access/001-status.md create mode 100644 plans/closure/on-prem-member-access/002-status.md create mode 100644 plans/closure/on-prem-member-access/003-status.md create mode 100644 plans/closure/on-prem-member-access/004-status.md create mode 100644 plans/closure/on-prem-member-access/005-status.md diff --git a/AGENTS.md b/AGENTS.md index d26972b5..687448cf 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -33,7 +33,7 @@ providers/transport → `deep-dive-providers.md`; reload/restart → `wire/` protocol codecs, `routing/` + `accounts/` + `catalog/` + `quota/` + `health/` selection, `model_router.rs` affinity, `identity.rs` + `web_session.rs` + `user_budget.rs` + `instance_budget.rs` + - `model_policy.rs` on-prem user access, `providers/` transport, + `model_policy.rs` + `personal_upstream.rs` on-prem user access, `providers/` transport, `runtime_lifecycle/` generations + `reload.rs` + `task_supervisor.rs`, `operations/` local lifecycle, `db/` + `rust/assets/db/migrations/` v1–v66 immutable. diff --git a/architecture/overview.md b/architecture/overview.md index 36df49b2..aac08f0c 100644 --- a/architecture/overview.md +++ b/architecture/overview.md @@ -155,7 +155,8 @@ operation, not a Responses alias); discovery and health at `/v1/models`, `/api/stats/canonical-request-segmentation`, `/api/stats/cache-stability`, `/api/stats/request-shaping`, `/api/timeseries`, `/api/timeseries/grouped`); managed-user at `/login`, `/logout`, `/account`, `/account/landing`, -`/account/password`, `/my-account`, `/my-account/models`, `/account/tokens`, +`/account/password`, `/my-account`, `/my-account/models`, +`/my-account/upstreams`, `/my-account/upstreams/remove`, `/account/tokens`, `/account/tokens/revoke`, `/usage`, `/api/user-budget`; dashboard pages at `/`, `/accounts`, `/models`, `/models/{*model_id}`, `/latency`, `/events`, `/timeseries`, `/bandwidth`, `/pings`, `/reliability`, `/routing`, @@ -165,6 +166,8 @@ admin actions at `/admin/users/create`, `/admin/users/state`, `/admin/users/password`, `/admin/users/token`, `/admin/users/revoke-tokens`, `/admin/users/profile`, `/admin/users/override`, `/admin/users/override/remove`, `/admin/users/budget`, +`/admin/users/upstream/default`, `/admin/users/upstream/grant`, +`/admin/users/upstream/remove`, `/admin/budget/instance`, `/admin/budget/instance/remove`, `/admin/profiles/create`, `/admin/profiles/default`, `/admin/profiles/update`, `/admin/profiles/delete`, `/admin/profiles/rule`, @@ -481,8 +484,11 @@ scopes: daily and monthly rules with explicit `estimated`/`hard` enforcement, worst-case holds for `hard`, checks and holds in the same publication transaction as the request reservation, and settlement of one daily and one monthly bucket at terminalization. `rust/src/server/dashboard/admin.rs` owns -the admin and member HTML surfaces as thin CSRF-validated adapters. The -subsystem owns no router, no upstream dispatch, and no second database +the admin and member HTML surfaces as thin CSRF-validated adapters. +`rust/src/personal_upstream.rs` owns personal upstream grants and bindings. +The plaintext secret stays in the config-adjacent environment file, and +routing eligibility excludes a bound account from every principal except its +owner. The subsystem owns no router, no upstream dispatch, and no second database writer; `server/middleware.rs` keeps the route-role gate, `coordinator/` keeps publication and settlement, and `routing/`, `quota/`, and `health/` keep owning upstream accounts, provider quota, and provider health. @@ -591,7 +597,7 @@ Deep dives: [Core](deep-dive-core.md), [Deployment](deep-dive-deployment.md). | Operations CLI surface | `rust/src/runtime.rs`, `rust/src/cli.rs`, `rust/src/operations/` (local operator commands; `runtime.rs` dispatches and renders, `operations/` owns the local services) | [Core](deep-dive-core.md), [Control](deep-dive-control.md), [Metrics](deep-dive-metrics.md) | | Config, reload policy, reload | `rust/src/config.rs`, `rust/src/config_reload_policy.rs`, `rust/src/reload.rs`, `rust/build.rs`, `rust/build_support.rs` | [Core](deep-dive-core.md), [Control](deep-dive-control.md), [Runtime](deep-dive-runtime.md) | | HTTP adapters | `rust/src/server/` | [Request lifecycle](deep-dive-request-lifecycle.md), [Dashboard](deep-dive-dashboard.md), [Runtime](deep-dive-runtime.md) | -| On-prem user access | `rust/src/identity.rs`, `rust/src/web_session.rs`, `rust/src/model_policy.rs`, `rust/src/user_budget.rs`, `rust/src/instance_budget.rs`, `rust/src/server/auth.rs`, `rust/src/server/dashboard/admin.rs` | [On-prem user access](deep-dive-on-prem-user-access.md) | +| On-prem user access | `rust/src/identity.rs`, `rust/src/web_session.rs`, `rust/src/model_policy.rs`, `rust/src/user_budget.rs`, `rust/src/instance_budget.rs`, `rust/src/personal_upstream.rs`, `rust/src/server/auth.rs`, `rust/src/server/dashboard/admin.rs` | [On-prem user access](deep-dive-on-prem-user-access.md) | | Admission | `rust/src/request/` | [Request lifecycle](deep-dive-request-lifecycle.md), [Transcoder](deep-dive-transcoder.md) | | Coordinator finite/streaming | `rust/src/coordinator/`, `rust/src/coordinator/streaming/` | [Request lifecycle](deep-dive-request-lifecycle.md), [Retry](deep-dive-retry.md) | | Publication/finalization/failure | `rust/src/coordinator/publication.rs`, `rust/src/coordinator/finalization.rs`, `rust/src/coordinator/failure.rs`, `rust/src/coordinator/attempt.rs`, `rust/src/coordinator/wire_resolver.rs` | [Request lifecycle](deep-dive-request-lifecycle.md), [Retry](deep-dive-retry.md) | diff --git a/plans/closure/on-prem-member-access/001-status.md b/plans/closure/on-prem-member-access/001-status.md new file mode 100644 index 00000000..fc61f667 --- /dev/null +++ b/plans/closure/on-prem-member-access/001-status.md @@ -0,0 +1,135 @@ +# On-Prem Member Access Milestone 001 — Closure Status + +Status: closed + +Source implementation plan: + +- `plans/implementation/on-prem-member-access/001-solo-sign-in-and-onboarding-credential.md` + +Source subsystem roadmap: + +- `plans/subsystems/on-prem-member-access-roadmap.md#milestone-1--solo-sign-in-and-onboarding-credential` + +Repository baseline reviewed: `9da5e2d383c73035850c37f8125c145b8b7ff9ff` + +Implementation commits or pull requests: + +- `0767576c4b23b53b3125f0dbe75adb731048d9ab` — Implement on-prem member access M001–M005 +- The closure commit that adds this record corrects two suite defects found while gathering this evidence. Neither changes the onboarding credential decision. + +## 1. Executive finding + +Milestone 001 is closed. A fresh onboard no longer writes a server key that the same run retires, and an unauthenticated browser on a managed instance is sent to the existing sign-in page. Machine routes stay JSON 401. + +`apply_onboarding_server_key` writes `[server].api_key` only when the database is `legacy_unmigrated` and the key is absent. A new configuration, a missing access state, `fresh_uninitialized`, `admin_initialized`, and `managed` skip the write. An existing key is left in place. The printed guidance names `/login`. A line that mentions `EGGPOOL_API_KEY` does not call that value the server key. + +An unauthenticated `GET` of an HTML navigation page on `admin_initialized` or `managed` is a `303` to `/login` with `Cache-Control: no-store` and no password form. `GET /v1/models` and `GET /api/user-budget` without a credential stay JSON 401. `POST /account` stays 401. A personal API token does not authorize `/account` or `/api/status`. A `legacy_unmigrated` public dashboard is still `200` and is not redirected. + +No migration, dependency, or authentication-mode change belongs to this milestone. + +## 2. Requirement-to-evidence matrix + +| Requirement | Evidence | Result | Notes | +|---|---|---|---| +| A new configuration passed through the fresh bootstrap path writes no `[server].api_key` | `rust/src/runtime.rs` — `fresh_onboarding_does_not_write_a_server_key_before_bootstrap`, `initialized_onboarding_does_not_write_a_server_key`, `onboarding_writes_a_server_key_only_for_a_legacy_database` | pass | The fresh path compares the file bytes before and after and reads the key back as absent. | +| Guidance names `/login` and does not export the server key | `bootstrap_leaves_an_existing_server_key_unchanged` | pass | An existing key is left byte-identical. Guidance that contains `EGGPOOL_API_KEY` must not contain "server". | +| A browser `GET` of a managed dashboard without a cookie can follow one redirect to `/login` | `rust/tests/on_prem_sessions.rs` — `managed_browser_login_account_csrf_and_logout_work_over_loopback` | pass | `GET /` and `GET /usage` are `303` to `/login`, `no-store`, and contain no password field. | +| `curl` of `/v1/models` without a key still receives JSON 401 | same HTTP test | pass | `/v1/models` and `/api/user-budget` are `401` and contain `"detail"`. `POST /account` is `401` and is not a `303`. | +| A pre-existing legacy database still authenticates with its server key | `legacy_onboarding_still_writes_a_missing_server_key`; `legacy_public_dashboard_stays_available_without_a_sign_in_redirect`; `legacy_server_key_is_valid_only_before_identity_cutover` | pass | The key is generated only for `legacy_unmigrated`. The legacy public dashboard stays `200`. The server key is accepted only in that access state. | +| The handoff does not apply to `/v1`, `/api`, or an unsafe method | `initialized_html_navigation_offers_sign_in_and_machine_routes_stay_json` | pass | `/v1/models`, `/api/user-budget`, and `/api/status` are excluded. `POST /` is excluded. `fresh_uninitialized` and `legacy_unmigrated` are excluded. | +| No migration, dependency, or auth-mode change | This milestone adds no file under `rust/assets/db/migrations/` and no dependency. `Cargo.lock` is unchanged by the implementation commit. | pass | v66 belongs to milestone 004. | + +## 3. Production implementation evidence + +- `rust/src/runtime.rs` — `should_generate_legacy_server_key`, `apply_onboarding_server_key`, and `onboarding_credential_guidance`. +- `rust/src/server/auth.rs` — `sign_in_handoff_response` is a `no-store` redirect to `/login` and embeds no password form. +- `rust/src/server/middleware.rs` — `sign_in_handoff_applies` is limited to `GET` of an HTML navigation page when the access state is `admin_initialized` or `managed`. +- `rust/config.example.toml`, `README.md`, and `docs/deployment.md` describe the fresh-onboard credential. +- `architecture/deep-dive-on-prem-user-access.md` records the handoff. + +## 4. Verification executed + +Local, on the developer machine. These commands are not a hosted CI result. The pull request `check` job is the CI truth for the closure commit. + +### Commands run + +```bash +cargo fmt --manifest-path rust/Cargo.toml --all -- --check +cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets -- -D warnings +cargo check --manifest-path rust/Cargo.toml --workspace --all-targets --no-default-features +cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets --no-default-features -- -D warnings +cargo test --manifest-path rust/Cargo.toml --workspace --all-targets -- --test-threads=1 +cargo build --manifest-path rust/Cargo.toml --locked --release +uv run ruff format --check scripts/ tests/tooling/ +uv run ruff check scripts/ tests/tooling/ +uv run pyright scripts/ +uv run pytest tests/tooling/ -q --tb=short +uv run python scripts/validate_release_docs.py +uv run python scripts/validate_release_workflow.py \ + .github/workflows/release.yml \ + .github/workflows/qualification-release-artifacts.yml \ + .github/workflows/qualification-public-release.yml +``` + +### Results + +| Command | Result | +|---|---| +| `cargo fmt --all -- --check` | clean | +| default `cargo clippy --workspace --all-targets -- -D warnings` | clean | +| `cargo check --workspace --all-targets --no-default-features` | passes | +| no-default `cargo clippy --workspace --all-targets -- -D warnings` | clean | +| `cargo test --workspace --all-targets -- --test-threads=1` | **1257 passed, 0 failed, 2 ignored**, 95 targets, exit 0 | +| `cargo build --manifest-path rust/Cargo.toml --locked --release` | `Finished release profile` in 2m 21s | +| `ruff format --check` | 72 files already formatted | +| `ruff check` | all checks passed | +| `pyright scripts/` | 0 errors, 0 warnings, 0 informations | +| `pytest tests/tooling/` | **253 passed, 2 skipped** | +| `validate_release_docs.py` | pass, 7 documents, version 0.8.3 | +| `validate_release_workflow.py` | pass for all three workflows | + +The two ignored tests are pre-existing manual qualifications and are outside this milestone: `qualify_dashboard_ttft_query_plans_and_serialized_write_delay` and `qualified_ollama_model_returns_live_embedding_vectors_through_eggpool`. + +The first full-suite invocation stopped in `database_compatibility` because the schema-54 upgrade still expected 11 migrations after v66. The assertion now expects 12, migrations 55 through 66 inclusive. That correction belongs to milestone 004. The second invocation stopped in `on_prem_admin_ui` because the denied-member sentence contained the substring `admin`, which is the fixture username. The sentence now says "The instance operator". That correction belongs to milestone 005. The counts above are the rerun after both corrections. + +An earlier locked release invocation failed because the release `libsqlite3-sys` build directory was missing `bindgen.rs`. `cargo clean -p libsqlite3-sys --release` and the same locked release build then finished. That was a stale build directory, not a product failure. + +The first tooling run failed two census guards: `AGENTS.md` did not name `personal_upstream.rs`, and the persistence roadmap still said the current chain was v1–v65. Both documents now state the current facts. The pytest count above is the rerun. + +## 5. Invariant review + +- The server key remains the legacy shared credential. It is still accepted only while the access state is `legacy_unmigrated`. +- Fresh, initialized, and managed installs do not gain a newly written server key. +- `/v1` and `/api` do not receive the HTML redirect. A missing credential there is still a JSON 401. +- The sign-in form is still the `/login` document. The redirect does not embed a password form, so the transport gate in `rust/src/server/auth.rs` is unchanged. +- Personal API tokens remain limited to the agent surfaces already enforced by `personal_credential_allowed`. + +## 6. Failure and recovery review + +Onboard writes the key only for the legacy missing-key case and leaves an existing file byte-identical otherwise. A failed key decision does not create a second disclosure path. The redirect is a single `303` to `/login`; `POST` is not redirected. No new persistence step was added. + +## 7. Migration and compatibility review + +No schema, checksum, or dependency change belongs to this milestone. A legacy database that still has no server key still receives one. A legacy public dashboard is not redirected. Existing managed sign-in, CSRF, and logout behavior in the same HTTP test still completes. + +## 8. Security review + +The handoff does not authenticate the caller and does not accept a credential. It does not open an unauthenticated inference path. The redirect body contains no password field and is `no-store`. The server key is not printed as the token to export. + +## 9. Documentation and operations + +`README.md`, `docs/deployment.md`, `rust/config.example.toml`, and `architecture/deep-dive-on-prem-user-access.md` describe the fresh-onboard credential and the sign-in handoff. `validate_release_docs.py` passed. + +## 10. Unresolved findings + +| Severity | Finding | Impact | Required action | +|---|---|---|---| +| — | None | — | — | + +## 11. Roadmap disposition + +Milestone 001 is closed. Milestones 002–005 are closed in the same commit by their own records. The on-prem member-access roadmap is closed. No successor is registered. On-prem user access M001–M024 stay closed. + +## 12. Registry updates + +`plans/registry.md` moves M001–M005 out of the active table and records the roadmap closed. The roadmap status table links this record. diff --git a/plans/closure/on-prem-member-access/002-status.md b/plans/closure/on-prem-member-access/002-status.md new file mode 100644 index 00000000..edbac14a --- /dev/null +++ b/plans/closure/on-prem-member-access/002-status.md @@ -0,0 +1,128 @@ +# On-Prem Member Access Milestone 002 — Closure Status + +Status: closed + +Source implementation plan: + +- `plans/implementation/on-prem-member-access/002-usage-windows-and-member-limits.md` + +Source subsystem roadmap: + +- `plans/subsystems/on-prem-member-access-roadmap.md#milestone-2--usage-windows-and-member-limits` + +Repository baseline reviewed: `9da5e2d383c73035850c37f8125c145b8b7ff9ff` + +Implementation commits or pull requests: + +- `0767576c4b23b53b3125f0dbe75adb731048d9ab` — Implement on-prem member access M001–M005 + +## 1. Executive finding + +Milestone 002 is closed. A member's current day and current month are separate totals, and remaining for a window is that window's ceiling minus its settled usage minus its active holds. + +The budget fixture writes 40 settled requests into the member's current day and 40 into the current month, plus an old day bucket and another user's 99. The current day total is 40 and the current month total is 40. They are not added. With a day ceiling of 100 and 10 active holds, remaining is 50. The other user's allowance is empty. The member usage page names the day window and says other people's consumption is not shown. The administrator page renders the two windows under separate headings and does not render a summed 14. + +The member `/api/user-budget` payload adds `remaining` and `instance_rules`. It still omits `instance_usage`. An instance usage row of 80 stays readable through `InstanceBudgetService` and is still present on the administrator payload. Settlement functions in `rust/src/user_budget.rs` were not edited. This milestone adds no migration. The v66 checksum in the same implementation commit belongs to milestone 004. + +## 2. Requirement-to-evidence matrix + +| Requirement | Evidence | Result | Notes | +|---|---|---|---| +| One settled request appears once in the current day and once in the current month, and those totals are not added | `rust/tests/on_prem_budgets.rs` — `usage_windows_are_not_added_and_remaining_subtracts_holds` | pass | Both window totals are 40. The test asserts they are not equal to their sum. | +| A member page names day and month on each usage row | `rust/src/server/dashboard/tests.rs` — `member_usage_names_the_window_and_admin_windows_stay_separate` | pass | The member page contains `>day<`. The admin page contains "Current UTC day" and "Current UTC month" and does not contain a summed `>14<`. | +| Remaining matches ceiling minus settled minus active holds | same budget test | pass | Ceiling 100, settled 40, held 10, remaining 50. An absent token ceiling stays `None`. | +| A member response excludes instance usage and other users | `rust/tests/on_prem_global_budgets.rs` — `member_allowance_excludes_other_users_and_instance_usage` | pass | Member one settled 4, remaining 16. Member two settled 9, remaining 11. The encoded allowance contains neither `instance_usage` nor the other username. | +| Instance ceiling configuration is visible and instance usage stays admin-only | `rust/src/server/health.rs` — `user_budget_api`; the same global-budget test | pass | Members receive `instance_rules`. `instance_usage` is added only when the principal role is `admin`. The instance service still reads the row of 80. | +| An administrator can still read instance usage | `user_budget_api` administrator branch; `InstanceBudgetService::usage` | pass | The administrator JSON still includes `instance_usage`. | +| Settlement code and schema checksums did not change for this milestone | `git diff` of `rust/src/user_budget.rs` adds `current_allowance`, `admin_usage_by_window`, and read helpers. No settlement function is in the diff. No migration file belongs to this milestone. | pass | v66 is milestone 004. | + +## 3. Production implementation evidence + +- `rust/src/user_budget.rs` — `current_allowance` and `admin_usage_by_window` read one window at a time. Holds are subtracted inside that window. +- `rust/src/server/health.rs` — member JSON gains `remaining` and `instance_rules` and still withholds `instance_usage`. +- `rust/src/server/dashboard/render/admin.rs` — separate day and month tables, USD text via `format_microdollar_usd`. +- `docs/model-limits.md`, `docs/api-reference.md`, and `architecture/deep-dive-on-prem-user-access.md` describe the projection. + +## 4. Verification executed + +Local, on the developer machine. These commands are not a hosted CI result. The pull request `check` job is the CI truth for the closure commit. + +### Commands run + +```bash +cargo fmt --manifest-path rust/Cargo.toml --all -- --check +cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets -- -D warnings +cargo check --manifest-path rust/Cargo.toml --workspace --all-targets --no-default-features +cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets --no-default-features -- -D warnings +cargo test --manifest-path rust/Cargo.toml --workspace --all-targets -- --test-threads=1 +cargo build --manifest-path rust/Cargo.toml --locked --release +uv run ruff format --check scripts/ tests/tooling/ +uv run ruff check scripts/ tests/tooling/ +uv run pyright scripts/ +uv run pytest tests/tooling/ -q --tb=short +uv run python scripts/validate_release_docs.py +uv run python scripts/validate_release_workflow.py \ + .github/workflows/release.yml \ + .github/workflows/qualification-release-artifacts.yml \ + .github/workflows/qualification-public-release.yml +``` + +### Results + +| Command | Result | +|---|---| +| `cargo fmt --all -- --check` | clean | +| default `cargo clippy --workspace --all-targets -- -D warnings` | clean | +| `cargo check --workspace --all-targets --no-default-features` | passes | +| no-default `cargo clippy --workspace --all-targets -- -D warnings` | clean | +| `cargo test --workspace --all-targets -- --test-threads=1` | **1257 passed, 0 failed, 2 ignored**, 95 targets, exit 0 | +| `cargo build --manifest-path rust/Cargo.toml --locked --release` | `Finished release profile` in 2m 21s | +| `ruff format --check` | 72 files already formatted | +| `ruff check` | all checks passed | +| `pyright scripts/` | 0 errors, 0 warnings, 0 informations | +| `pytest tests/tooling/` | **253 passed, 2 skipped** | +| `validate_release_docs.py` | pass, 7 documents, version 0.8.3 | +| `validate_release_workflow.py` | pass for all three workflows | + +The two ignored tests are pre-existing manual qualifications and are outside this milestone: `qualify_dashboard_ttft_query_plans_and_serialized_write_delay` and `qualified_ollama_model_returns_live_embedding_vectors_through_eggpool`. + +The first two full-suite invocations failed before this passing run. The schema-54 upgrade count and the denied-member sentence were corrected in the closure commit. Those corrections belong to milestones 004 and 005. The counts above are the rerun. + +An earlier locked release invocation failed because the release `libsqlite3-sys` build directory was missing `bindgen.rs`. `cargo clean -p libsqlite3-sys --release` and the same locked release build then finished. That was a stale build directory, not a product failure. + +## 5. Invariant review + +- Day and month remain two enforcement buckets. The projection does not delete or merge the month bucket. +- Remaining is computed inside one window. Holds in that window reduce remaining. Another user's rows do not. +- Instance usage stays off the member payload. Instance ceiling configuration is the rule list, not a remaining shared headroom figure. +- The single SQLite gate is unchanged. The new reads use the existing `Database::call` path. + +## 6. Failure and recovery review + +A failed allowance or instance-rule read returns the existing degraded user-budget response. No new write, reservation, or settlement step was added, so there is no new partial-persistence path. An old day bucket is excluded from the current-day total by the window start. + +## 7. Migration and compatibility review + +No table, column, or checksum change belongs to this milestone. `rules` and `usage` remain on `/api/user-budget`. The added fields are `remaining` and, for members, `instance_rules`. Administrator responses still include `instance_rules` and `instance_usage`. + +## 8. Security review + +A non-administrator still cannot query another user's id: the existing owner-or-admin check in `user_budget_api` is unchanged. The member payload used in the fixture does not contain the other username or `instance_usage`. USD text is a rendering of the stored integer microdollars. The budget form still posts `max_microdollars` as that integer. + +## 9. Documentation and operations + +`docs/model-limits.md`, `docs/api-reference.md`, and `architecture/deep-dive-on-prem-user-access.md` describe the separate windows and the member payload. `validate_release_docs.py` passed. + +## 10. Unresolved findings + +| Severity | Finding | Impact | Required action | +|---|---|---|---| +| — | None | — | — | + +## 11. Roadmap disposition + +Milestone 002 is closed. Milestones 001 and 003–005 are closed in the same commit by their own records. The on-prem member-access roadmap is closed. No successor is registered. + +## 12. Registry updates + +`plans/registry.md` moves M001–M005 out of the active table and records the roadmap closed. The roadmap status table links this record. diff --git a/plans/closure/on-prem-member-access/003-status.md b/plans/closure/on-prem-member-access/003-status.md new file mode 100644 index 00000000..7571e6d7 --- /dev/null +++ b/plans/closure/on-prem-member-access/003-status.md @@ -0,0 +1,127 @@ +# On-Prem Member Access Milestone 003 — Closure Status + +Status: closed + +Source implementation plan: + +- `plans/implementation/on-prem-member-access/003-member-navigation-and-admin-roster.md` + +Source subsystem roadmap: + +- `plans/subsystems/on-prem-member-access-roadmap.md#milestone-3--member-navigation-and-admin-roster` + +Repository baseline reviewed: `9da5e2d383c73035850c37f8125c145b8b7ff9ff` + +Implementation commits or pull requests: + +- `0767576c4b23b53b3125f0dbe75adb731048d9ab` — Implement on-prem member access M001–M005 + +## 1. Executive finding + +Milestone 003 is closed. A member page links only the member destinations, and the administrator users page shows the current assignment, overrides, budget rules in USD, and credential labels without secrets. + +`MEMBER_NAVIGATION` is My account, My models, Usage, and Password. `the_standalone_shells_carry_the_navigation_chrome` renders a member usage page with those member links and without `/users`, `/accounts`, `/profiles`, `/runtime`, or the operator overview. The same test still renders those operator links on the administrator shells. The browser journey reaches My account and asserts "My accessible models", and the member's create-user and instance-budget posts are still `403`. + +The users roster fixture shows the assigned profile, the selected option, the `model-a deny` override, `1500000 (1.5 USD)`, the credential label, and the creation time. It shows the unassigned member as denied until a profile is assigned. The HTML does not contain the credential id, the selector, the digest, or a secret field. The budget form still posts `max_microdollars`. + +The member role gate gained only `/my-account/upstreams` and `/my-account/upstreams/remove`, which milestone 005 uses. `/users`, `/profiles`, and every `/admin/` path stay off that set, so a non-administrator is still refused with the existing HTML refusal. + +## 2. Requirement-to-evidence matrix + +| Requirement | Evidence | Result | Notes | +|---|---|---|---| +| A member session's My account, My models, and Usage pages link to member destinations only | `the_standalone_shells_carry_the_navigation_chrome`; `MEMBER_NAVIGATION` in `rust/src/server/dashboard/render/layout.rs` | pass | The member shell forbids the operator routes named above. | +| An administrator session still reaches Users, Profiles, and Accounts | same test, administrator shell loop | pass | The admin shell contains `/users` and `/accounts` and the overview link. | +| The users page shows the current profile, overrides, budget rules with USD text, and credential labels | `the_users_roster_shows_the_current_assignment_without_secrets` | pass | Assigned and unassigned members are both rendered. | +| The roster HTML contains no password, token, or digest | same roster test | pass | The credential id, the word `digest`, and `name="secret"` are absent. The label and timestamp are present. | +| Existing admin form actions still succeed for an administrator and fail for a member | `rust/tests/on_prem_admin_ui.rs` — `two_user_browser_journey_fences_admin_data_and_personal_credentials` | pass | The member create and instance-budget posts are `403`. The journey still completes the administrator's earlier profile and budget actions before that assertion. | +| Middleware role gates were not widened onto administrative routes | `rust/src/server/middleware.rs` account-surface set | pass | The only added member paths are the two personal-upstream paths from milestone 005. | + +## 3. Production implementation evidence + +- `rust/src/server/dashboard/render/layout.rs` — `MEMBER_NAVIGATION`, `member_navigation_markup`, and `member_standalone_page`. +- `rust/src/server/dashboard/admin.rs` — member pages use `member_standalone_page`. +- `rust/src/server/dashboard/render/admin.rs` — roster facts for profile, overrides, USD, credentials, and the upstream grant label. The secret field is not on the roster. +- `architecture/deep-dive-dashboard.md` and `architecture/deep-dive-on-prem-user-access.md` describe the member navigation. + +## 4. Verification executed + +Local, on the developer machine. These commands are not a hosted CI result. The pull request `check` job is the CI truth for the closure commit. + +### Commands run + +```bash +cargo fmt --manifest-path rust/Cargo.toml --all -- --check +cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets -- -D warnings +cargo check --manifest-path rust/Cargo.toml --workspace --all-targets --no-default-features +cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets --no-default-features -- -D warnings +cargo test --manifest-path rust/Cargo.toml --workspace --all-targets -- --test-threads=1 +cargo build --manifest-path rust/Cargo.toml --locked --release +uv run ruff format --check scripts/ tests/tooling/ +uv run ruff check scripts/ tests/tooling/ +uv run pyright scripts/ +uv run pytest tests/tooling/ -q --tb=short +uv run python scripts/validate_release_docs.py +uv run python scripts/validate_release_workflow.py \ + .github/workflows/release.yml \ + .github/workflows/qualification-release-artifacts.yml \ + .github/workflows/qualification-public-release.yml +``` + +### Results + +| Command | Result | +|---|---| +| `cargo fmt --all -- --check` | clean | +| default `cargo clippy --workspace --all-targets -- -D warnings` | clean | +| `cargo check --workspace --all-targets --no-default-features` | passes | +| no-default `cargo clippy --workspace --all-targets -- -D warnings` | clean | +| `cargo test --workspace --all-targets -- --test-threads=1` | **1257 passed, 0 failed, 2 ignored**, 95 targets, exit 0 | +| `cargo build --manifest-path rust/Cargo.toml --locked --release` | `Finished release profile` in 2m 21s | +| `ruff format --check` | 72 files already formatted | +| `ruff check` | all checks passed | +| `pyright scripts/` | 0 errors, 0 warnings, 0 informations | +| `pytest tests/tooling/` | **253 passed, 2 skipped** | +| `validate_release_docs.py` | pass, 7 documents, version 0.8.3 | +| `validate_release_workflow.py` | pass for all three workflows | + +The two ignored tests are pre-existing manual qualifications and are outside this milestone: `qualify_dashboard_ttft_query_plans_and_serialized_write_delay` and `qualified_ollama_model_returns_live_embedding_vectors_through_eggpool`. + +The passing suite is the rerun after the schema-54 count correction and the member-sentence correction recorded under milestones 004 and 005. + +## 5. Invariant review + +- Operator navigation is intact on administrator shells. +- Member shells do not link `/users`, `/accounts`, `/profiles`, `/runtime`, or the operator overview. +- The integer posted to the budget action is still `max_microdollars`. USD is display text beside that integer. +- A non-administrator outside the account surface still receives the member refusal. + +## 6. Failure and recovery review + +The roster is a render of already-stored facts. It adds no write. A member who posts an administrative form is refused before the handler. The browser journey still refuses those posts with `403`. + +## 7. Migration and compatibility review + +No schema, configuration, or published inference API change belongs to this milestone. Administrator form actions and their paths are unchanged. + +## 8. Security review + +The roster fixture contains no password, token, credential id, or digest. Credential display is the label and the timestamps. The member navigation change does not add an administrative path to the member allow list. + +## 9. Documentation and operations + +`architecture/deep-dive-dashboard.md` and `architecture/deep-dive-on-prem-user-access.md` describe the separate member navigation. No CLI change belongs to this milestone. + +## 10. Unresolved findings + +| Severity | Finding | Impact | Required action | +|---|---|---|---| +| — | None | — | — | + +## 11. Roadmap disposition + +Milestone 003 is closed. Milestones 001, 002, 004, and 005 are closed in the same commit by their own records. The on-prem member-access roadmap is closed. No successor is registered. + +## 12. Registry updates + +`plans/registry.md` moves M001–M005 out of the active table and records the roadmap closed. The roadmap status table links this record. diff --git a/plans/closure/on-prem-member-access/004-status.md b/plans/closure/on-prem-member-access/004-status.md new file mode 100644 index 00000000..e64ae184 --- /dev/null +++ b/plans/closure/on-prem-member-access/004-status.md @@ -0,0 +1,152 @@ +# On-Prem Member Access Milestone 004 — Closure Status + +Status: closed + +Source implementation plan: + +- `plans/implementation/on-prem-member-access/004-personal-upstream-custody-and-routing.md` + +Source subsystem roadmap: + +- `plans/subsystems/on-prem-member-access-roadmap.md#milestone-4--personal-upstream-custody-and-routing` + +Repository baseline reviewed: `9da5e2d383c73035850c37f8125c145b8b7ff9ff` + +Implementation commits or pull requests: + +- `0767576c4b23b53b3125f0dbe75adb731048d9ab` — Implement on-prem member access M001–M005 +- The closure commit corrects the schema-54 upgrade count from 11 migrations to 12 so the chain through v66 is what the test asserts. + +Governing decision: + +- `plans/adrs/ADR-0010-personal-upstream-account-custody.md` (accepted 2026-11-10, in the implementation commit above) + +## 1. Executive finding + +Milestone 004 is closed. An administrator can attach one bundled-provider account to one user. The secret is written only to the config-adjacent `.env` with mode `0600`. The TOML stanza names `EGGPOOL_UPSTREAM_` plus the first 8 bytes of SHA-256 over `provider`, a NUL, and the account name. The database row stores ids and state and the audit row stores the account name. Neither stored text contains the secret. + +Routing excludes that account for every principal except the bound user. A withdrawn binding is excluded for the owner as well. An account with no binding is not excluded. A failed publication restores the original config, removes a newly created `.env`, and deletes the binding, so the account does not become shared. The instance grant inserted by the migration is `deny`. User disable withdraws active bindings, and re-enable does not restore them. + +Amazon Bedrock is not a bundled provider and is not added. v1–v65 migration files are unchanged. v66 is `0066_personal_upstream.sql`, checksum `5f37ccad85c006e3e535322155d52a3bb75cc2fad649af54021c9905db742e4c`. + +This is the custody and CLI consumer. The member-facing grant is milestone 005. + +## 2. Requirement-to-evidence matrix + +| Requirement | Evidence | Result | Notes | +|---|---|---|---| +| ADR-0010 is accepted | `plans/adrs/ADR-0010-personal-upstream-account-custody.md` status `accepted`, date 2026-11-10 | pass | Accepted in `0767576c` with the named canonical amendments. | +| Before any binding, an account is not excluded | `PersonalUpstreamSnapshot::excludes` returns false when the key is absent | pass | The eligibility loop consults that predicate before scoring. | +| An administrator can add an `opencode-go` account for one user | `rust/tests/on_prem_identity.rs` — `personal_upstream_grant_defaults_to_deny_and_a_failed_publish_is_not_shared` | pass | The secret is in `.env`, absent from the TOML, and the TOML names `EGGPOOL_UPSTREAM_`. | +| The database row and the audit row have no secret | same test, concatenated grants, bindings, and `user_admin_audit` | pass | The stored text does not contain `sk-personal-sentinel-value`. | +| That user can be routed to the account. Another user and an unattributed caller cannot | `rust/tests/routing_domain.rs` — `a_personal_binding_is_selectable_only_by_its_owner`; snapshot asserts in the identity test | pass | The owner receives `account-a`. The other user and a missing principal get no claim. | +| A withdrawn account is routed to nobody | same routing test after `state = 'withdrawn'` | pass | The owner is also excluded. | +| A failed rehash does not leave the account shared | identity test with `PublishMode::Fail` | pass | The error is `PublicationRestored`. The config bytes match the original, `.env` is absent, and the binding list is empty. | +| Self-service default is deny | migration insert and `instance_grant` / `effective_grant` in the identity test | pass | Both reads are `GrantEffect::Deny`. | +| The CLI can set allow, deny, and inherit | `UsersUpstreamCommand::Grant` value parser `allow`, `deny`, `inherit`; `runtime.rs` dispatches to `set_user_grant` | pass | See the low finding in §10. The browser allow and deny path is milestone 005. | +| User disable withdraws the binding and re-enable does not restore it | identity test after `set_user_enabled` | pass | The snapshot excludes the owner after disable and still excludes the owner after enable. | +| A second add of the same name is a collision | identity test | pass | `PersonalUpstreamError::NameCollision`. | +| Amazon Bedrock is not added | `bundled_provider` rejects an id that is not in the bundled asset; `member_upstream_form_hides_the_key_until_self_service_is_allowed` asserts the select does not contain `amazon` | pass | No Bedrock profile was added. | +| Migration v66 and its checksum | `0066_personal_upstream.sql`; `checksums.json`; `MigrationRunner::migrations().len() == 66` | pass | The schema-54 upgrade now asserts 12 applied versions, 55 through 66 inclusive. | +| No-default clippy | see §4 | pass | `--no-default-features` check and clippy are clean. | +| Account add/remove diagnostics do not record the secret | `account_env_name` in `config_reload_policy.rs` | pass | The change record stores the env-var name. The account transition stays non-reloadable. No new reload-key list was added. | + +## 3. Production implementation evidence + +- `rust/assets/db/migrations/0066_personal_upstream.sql` — `personal_upstream_grants` and `personal_upstream_bindings`. No secret column. The instance row is `deny`. +- `rust/src/personal_upstream.rs` — grants, bindings, snapshot, env-var name, and the add/remove service. +- `rust/src/operations/config_mutation.rs` — `.env` is written mode `0600` before credential validation. A validation or config-write failure restores the previous `.env`. +- `rust/src/accounts/registry.rs` — `CredentialStore::from_config_near` reads the config-adjacent env file. +- `rust/src/routing/eligibility.rs` — `build_eligible_candidates` excludes on `personal_bindings.excludes` before the account is scored. +- `rust/src/cli.rs` and `rust/src/runtime.rs` — `eggpool users upstream` default, grant, add, list, and remove. Add reads the secret from stdin. +- `docs/cli-reference.md`, `docs/providers.md`, `docs/backup-restore.md`, `architecture/deep-dive-routing.md`, and `architecture/deep-dive-on-prem-user-access.md`. + +## 4. Verification executed + +Local, on the developer machine. These commands are not a hosted CI result. The pull request `check` job is the CI truth for the closure commit. + +### Commands run + +```bash +cargo fmt --manifest-path rust/Cargo.toml --all -- --check +cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets -- -D warnings +cargo check --manifest-path rust/Cargo.toml --workspace --all-targets --no-default-features +cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets --no-default-features -- -D warnings +cargo test --manifest-path rust/Cargo.toml --workspace --all-targets -- --test-threads=1 +cargo build --manifest-path rust/Cargo.toml --locked --release +uv run ruff format --check scripts/ tests/tooling/ +uv run ruff check scripts/ tests/tooling/ +uv run pyright scripts/ +uv run pytest tests/tooling/ -q --tb=short +uv run python scripts/validate_release_docs.py +uv run python scripts/validate_release_workflow.py \ + .github/workflows/release.yml \ + .github/workflows/qualification-release-artifacts.yml \ + .github/workflows/qualification-public-release.yml +``` + +### Results + +| Command | Result | +|---|---| +| `cargo fmt --all -- --check` | clean | +| default `cargo clippy --workspace --all-targets -- -D warnings` | clean | +| `cargo check --workspace --all-targets --no-default-features` | passes | +| no-default `cargo clippy --workspace --all-targets -- -D warnings` | clean | +| `cargo test --workspace --all-targets -- --test-threads=1` | **1257 passed, 0 failed, 2 ignored**, 95 targets, exit 0 | +| `cargo build --manifest-path rust/Cargo.toml --locked --release` | `Finished release profile` in 2m 21s | +| `ruff format --check` | 72 files already formatted | +| `ruff check` | all checks passed | +| `pyright scripts/` | 0 errors, 0 warnings, 0 informations | +| `pytest tests/tooling/` | **253 passed, 2 skipped** | +| `validate_release_docs.py` | pass, 7 documents, version 0.8.3 | +| `validate_release_workflow.py` | pass for all three workflows | + +The two ignored tests are pre-existing manual qualifications: `qualify_dashboard_ttft_query_plans_and_serialized_write_delay` and `qualified_ollama_model_returns_live_embedding_vectors_through_eggpool`. + +The first full-suite invocation failed in `schema54_image_upgrades_with_legacy_state_preserved`: `applied_this_run.len()` was 12 and the assertion still expected 11. The closure commit expects 12 and says the range is migrations 55 through 66 inclusive. The passing count above is the rerun after that correction and the milestone 005 sentence correction. + +An earlier locked release invocation failed because the release `libsqlite3-sys` build directory was missing `bindgen.rs`. `cargo clean -p libsqlite3-sys --release` and the same locked release build then finished. That was a stale build directory, not a product failure. + +The tooling census required `personal_upstream.rs` in the `AGENTS.md` layout section and `v1–v66` in the persistence roadmap's current-chain sentence. Both are updated in the closure commit. The persistence roadmap still authorizes no schema change of its own. v66 was added by this milestone. + +## 5. Invariant review + +- One SQLite writer. Grants and bindings use `Database::call` and `with_transaction`. +- No second routing lock. Exclusion is a membership test on the candidate loop that already existed. +- Selector decisions are unchanged. The filter runs inside account eligibility and cannot pin an account that failed the predicate. +- Attempt preparation is unchanged. The snapshot is generation state, read during candidate build. +- Reload classification stays in `classify_transition`. Account add and remove remain non-reloadable. The diagnostic value is the env-var name, not the secret. +- Credentials stay out of SQLite, audit rows, and the reload diagnostic. + +## 6. Failure and recovery review + +`PublishMode::Fail` restores the config bytes, does not leave `.env`, and leaves no binding. Credential validation runs after the `.env` write and restores that file on failure. Remove withdraws the binding before the config and env omission. A withdrawn row stays withdrawn across user re-enable. A name collision does not insert a second row. In-flight requests keep the generation they started on; the snapshot is replaced with the generation. + +## 7. Migration and compatibility review + +v66 is append-only. v1–v65 files and checksums are unchanged. Fresh databases apply 66 migrations. A schema-54 image applies 55 through 66 inclusive and then passes `quick_check`. Existing accounts with no binding stay eligible for every principal. `Cargo.lock` gained no dependency. The locked release build passed. + +Rollback of a failed add restores the files and deletes the binding. A failed remove after the binding is withdrawn reports repair rather than republishing the account as shared. + +## 8. Security review + +The secret is not a CLI argument. Add requires `--secret-stdin`. The env file mode is `0600` on Unix. SQLite has no secret column. The identity test dumps grants, bindings, and audit text and asserts the sentinel is absent. The env-var name is a hash prefix, not the secret. Self-service remains deny until a grant changes it. Grant denial does not, by itself, withdraw a binding; that withdraw path is disable, or an explicit remove. + +## 9. Documentation and operations + +`docs/cli-reference.md`, `docs/providers.md`, `docs/backup-restore.md`, `architecture/deep-dive-routing.md`, and `architecture/deep-dive-on-prem-user-access.md` describe the binding, the env file, and the exclusion filter. `AGENTS.md` names `personal_upstream.rs`. `architecture/overview.md` lists the module and the new routes. The persistence roadmap's current-chain sentence now says v1–v66. `validate_release_docs.py` passed. + +## 10. Unresolved findings + +| Severity | Finding | Impact | Required action | +|---|---|---|---| +| low | `eggpool users upstream grant` accepts `allow`, `deny`, and `inherit` in clap and dispatches to `set_user_grant`. No test spawns the CLI process for those three effects. | The service and the browser allow/deny path are tested. A parser regression that dropped `inherit` would not be caught by a process test. | None for closure. A later CLI contract test can cover the three effects if that surface grows. | + +## 11. Roadmap disposition + +Milestone 004 is closed. Milestone 005's interface matches the shipped binding: grant denial blocks member add and remove and leaves an existing binding selectable. Milestones 001–003 and 005 are closed in the same commit by their own records. The roadmap is closed. No successor is registered. + +## 12. Registry updates + +`plans/registry.md` moves M001–M005 out of the active table and records the roadmap closed. The roadmap status table links this record. diff --git a/plans/closure/on-prem-member-access/005-status.md b/plans/closure/on-prem-member-access/005-status.md new file mode 100644 index 00000000..d7674e77 --- /dev/null +++ b/plans/closure/on-prem-member-access/005-status.md @@ -0,0 +1,133 @@ +# On-Prem Member Access Milestone 005 — Closure Status + +Status: closed + +Source implementation plan: + +- `plans/implementation/on-prem-member-access/005-personal-upstream-browser-grant.md` + +Source subsystem roadmap: + +- `plans/subsystems/on-prem-member-access-roadmap.md#milestone-5--personal-upstream-browser-grant` + +Repository baseline reviewed: `9da5e2d383c73035850c37f8125c145b8b7ff9ff` + +Implementation commits or pull requests: + +- `0767576c4b23b53b3125f0dbe75adb731048d9ab` — Implement on-prem member access M001–M005 +- The closure commit rewords the denied-member sentence so it does not contain the fixture username `admin`. + +## 1. Executive finding + +Milestone 005 is closed. A member who has not been granted self-service sees no secret field and receives `403` on add. An administrator can allow that member from `/users`. The member can then submit one bundled-provider key from My account. The secret is in `.env`, absent from the config, absent from the HTML responses, and absent from the stored grants, bindings, and audit text. A personal API token cannot call the mutation. Setting the grant back to deny hides the field and leaves the existing binding and the env entry in place. + +The provider select offers `opencode-go` and does not offer Amazon Bedrock. The handlers call the milestone 004 service. Grant denial does not withdraw the binding. + +The denied sentence now says "The instance operator can add an account from the command line." The previous wording, "An administrator...", made the member-page fence test fail because the fixture username is `admin`. + +## 2. Requirement-to-evidence matrix + +| Requirement | Evidence | Result | Notes | +|---|---|---|---| +| Default deny: My account has no upstream secret field | `member_upstream_form_hides_the_key_until_self_service_is_allowed`; `personal_upstream_browser_grant_never_echoes_the_key` | pass | The denied page contains "not granted" and does not contain `name="secret"`. The denied POST is `403`. `.env` is not created. | +| An administrator can allow one user | same browser test, `POST /admin/users/upstream/grant` with `effect=allow` | pass | The response is `303`. The users page contains the grant form and does not contain `name="secret"`. | +| That user can add an OpenCode Go account in the browser | same test, `POST /my-account/upstreams` | pass | The response is `303`. `.env` contains the sentinel. The config does not. The following My account page names `personal-browser` and does not contain the sentinel. | +| The secret is absent from the response and the database | same test | pass | The add response, the account page, and the concatenated grant, binding, and audit text do not contain the sentinel. | +| Deny again hides the field and keeps the binding | same test, second grant POST with `effect=deny` | pass | The binding list still has one row. `.env` still contains the sentinel. The page has no secret field. | +| A personal API token cannot add or remove an upstream account | same test, `POST /my-account/upstreams` with the admin token and no session cookie | pass | The response is `401` and does not contain the sentinel. | +| CSRF | the new posts include the session CSRF field; `requires_browser_session` includes the two member paths and every `/admin/` path | pass | The existing missing-cookie mutation test still refuses an account mutation. The new posts are browser-session posts, not token posts. | +| Amazon Bedrock is not offered | `member_upstream_form_hides_the_key_until_self_service_is_allowed` | pass | The allowed form contains `value="opencode-go"` and does not contain `amazon`. | +| Grant denial does not withdraw existing bindings | browser test after the deny POST; milestone 004 `effective_grant` | pass | The 004 service was not changed to treat denial as withdraw. | +| Milestones 001–004 are closed in the same commit | their closure records | pass | This record does not close the roadmap alone. | + +## 3. Production implementation evidence + +- `rust/src/server/dashboard/admin.rs` — `set_upstream_default`, `set_upstream_grant`, `remove_upstream_account`, `add_member_upstream`, `remove_member_upstream`. Each mutation calls `personal_upstream`. +- `rust/src/server/dashboard/render/admin.rs` — `render_member_upstream` and the users-page grant controls. +- `rust/src/server/mod.rs` registers the five routes. +- `rust/src/server/middleware.rs` — the two member paths are on the member account surface and require a browser session. They are not personal-API-token routes. +- `docs/deployment.md` and `architecture/deep-dive-on-prem-user-access.md` describe the grant. +- `architecture/overview.md` lists `/my-account/upstreams`, `/my-account/upstreams/remove`, `/admin/users/upstream/default`, `/admin/users/upstream/grant`, and `/admin/users/upstream/remove`. + +## 4. Verification executed + +Local, on the developer machine. These commands are not a hosted CI result. The pull request `check` job is the CI truth for the closure commit. + +### Commands run + +```bash +cargo fmt --manifest-path rust/Cargo.toml --all -- --check +cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets -- -D warnings +cargo check --manifest-path rust/Cargo.toml --workspace --all-targets --no-default-features +cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets --no-default-features -- -D warnings +cargo test --manifest-path rust/Cargo.toml --workspace --all-targets -- --test-threads=1 +cargo build --manifest-path rust/Cargo.toml --locked --release +uv run ruff format --check scripts/ tests/tooling/ +uv run ruff check scripts/ tests/tooling/ +uv run pyright scripts/ +uv run pytest tests/tooling/ -q --tb=short +uv run python scripts/validate_release_docs.py +uv run python scripts/validate_release_workflow.py \ + .github/workflows/release.yml \ + .github/workflows/qualification-release-artifacts.yml \ + .github/workflows/qualification-public-release.yml +``` + +### Results + +| Command | Result | +|---|---| +| `cargo fmt --all -- --check` | clean | +| default `cargo clippy --workspace --all-targets -- -D warnings` | clean | +| `cargo check --workspace --all-targets --no-default-features` | passes | +| no-default `cargo clippy --workspace --all-targets -- -D warnings` | clean | +| `cargo test --workspace --all-targets -- --test-threads=1` | **1257 passed, 0 failed, 2 ignored**, 95 targets, exit 0 | +| `cargo build --manifest-path rust/Cargo.toml --locked --release` | `Finished release profile` in 2m 21s | +| `ruff format --check` | 72 files already formatted | +| `ruff check` | all checks passed | +| `pyright scripts/` | 0 errors, 0 warnings, 0 informations | +| `pytest tests/tooling/` | **253 passed, 2 skipped** | +| `validate_release_docs.py` | pass, 7 documents, version 0.8.3 | +| `validate_release_workflow.py` | pass for all three workflows | + +The two ignored tests are pre-existing manual qualifications: `qualify_dashboard_ttft_query_plans_and_serialized_write_delay` and `qualified_ollama_model_returns_live_embedding_vectors_through_eggpool`. + +The second full-suite invocation failed `two_user_browser_journey_fences_admin_data_and_personal_credentials` because the denied-member copy contained `administrator` and the fixture username is `admin`. The closure commit uses "The instance operator". `personal_upstream_browser_grant_never_echoes_the_key` had already passed in that invocation. The passing count above is the rerun. + +## 5. Invariant review + +- Custody and eligibility stay in milestone 004. These handlers do not write `.env` or TOML themselves. +- A grant of deny does not withdraw a binding. +- Member navigation stays on the member destinations. The secret form is a section of My account, not a new operator link. +- Personal API tokens remain excluded from browser mutations. The token POST is `401`. +- The provider list is the bundled profile ids. The rendered select used in the test does not contain `amazon`. + +## 6. Failure and recovery review + +A denied member POST does not create `.env` or a binding. A failed add uses the 004 rollback. The browser test's successful add is followed by a deny that preserves the binding. CSRF failures follow the existing browser-session check before the handler. The token attempt is refused before a write. + +## 7. Migration and compatibility review + +No migration belongs to this milestone. The routes are HTML form actions. `/api/user-budget` is unchanged by this milestone. Existing administrator user actions in the browser journey still complete. + +## 8. Security review + +The secret is a password input on the granted member form only. It is not rendered back. The users page has grant controls and no secret input. The stored grant, binding, and audit text in the browser test do not contain the sentinel. The member paths require a browser session. A personal token is not a session. + +## 9. Documentation and operations + +`docs/deployment.md` and `architecture/deep-dive-on-prem-user-access.md` describe the browser grant. The route topology in `architecture/overview.md` lists the five new paths. `validate_release_docs.py` passed. + +## 10. Unresolved findings + +| Severity | Finding | Impact | Required action | +|---|---|---|---| +| — | None | — | — | + +## 11. Roadmap disposition + +Milestone 005 is closed. Milestones 001–004 are closed in the same commit by their own records, which is the condition this milestone set for closing the roadmap. The on-prem member-access roadmap is closed. No successor is registered. Nothing else was blocked on this roadmap. + +## 12. Registry updates + +`plans/registry.md` moves M001–M005 out of the active table and records the roadmap closed. The roadmap status table links this record. The unblock audit records that no other plan is promoted. diff --git a/plans/implementation/on-prem-member-access/001-solo-sign-in-and-onboarding-credential.md b/plans/implementation/on-prem-member-access/001-solo-sign-in-and-onboarding-credential.md index 4a2300fb..2f8f7309 100644 --- a/plans/implementation/on-prem-member-access/001-solo-sign-in-and-onboarding-credential.md +++ b/plans/implementation/on-prem-member-access/001-solo-sign-in-and-onboarding-credential.md @@ -1,6 +1,6 @@ # On-Prem Member Access Milestone 001 — Solo sign-in and onboarding credential -Status: active +Status: implemented Repository baseline: `9da5e2d383c73035850c37f8125c145b8b7ff9ff` diff --git a/plans/implementation/on-prem-member-access/002-usage-windows-and-member-limits.md b/plans/implementation/on-prem-member-access/002-usage-windows-and-member-limits.md index 98587a96..04327fe8 100644 --- a/plans/implementation/on-prem-member-access/002-usage-windows-and-member-limits.md +++ b/plans/implementation/on-prem-member-access/002-usage-windows-and-member-limits.md @@ -1,6 +1,6 @@ # On-Prem Member Access Milestone 002 — Usage windows and member limits -Status: active +Status: implemented Repository baseline: `9da5e2d383c73035850c37f8125c145b8b7ff9ff` diff --git a/plans/implementation/on-prem-member-access/003-member-navigation-and-admin-roster.md b/plans/implementation/on-prem-member-access/003-member-navigation-and-admin-roster.md index 24a07347..da836a44 100644 --- a/plans/implementation/on-prem-member-access/003-member-navigation-and-admin-roster.md +++ b/plans/implementation/on-prem-member-access/003-member-navigation-and-admin-roster.md @@ -1,6 +1,6 @@ # On-Prem Member Access Milestone 003 — Member navigation and admin roster -Status: active +Status: implemented Repository baseline: `9da5e2d383c73035850c37f8125c145b8b7ff9ff` diff --git a/plans/implementation/on-prem-member-access/004-personal-upstream-custody-and-routing.md b/plans/implementation/on-prem-member-access/004-personal-upstream-custody-and-routing.md index fb441553..bad986ba 100644 --- a/plans/implementation/on-prem-member-access/004-personal-upstream-custody-and-routing.md +++ b/plans/implementation/on-prem-member-access/004-personal-upstream-custody-and-routing.md @@ -1,6 +1,6 @@ # On-Prem Member Access Milestone 004 — Personal upstream custody and routing -Status: active +Status: implemented Repository baseline: `9da5e2d383c73035850c37f8125c145b8b7ff9ff` diff --git a/plans/implementation/on-prem-member-access/005-personal-upstream-browser-grant.md b/plans/implementation/on-prem-member-access/005-personal-upstream-browser-grant.md index 5d8825c7..1501963f 100644 --- a/plans/implementation/on-prem-member-access/005-personal-upstream-browser-grant.md +++ b/plans/implementation/on-prem-member-access/005-personal-upstream-browser-grant.md @@ -1,6 +1,6 @@ # On-Prem Member Access Milestone 005 — Personal upstream browser grant -Status: active +Status: implemented Repository baseline: `9da5e2d383c73035850c37f8125c145b8b7ff9ff` diff --git a/plans/registry.md b/plans/registry.md index 6d9b4fc3..286fa8f2 100644 --- a/plans/registry.md +++ b/plans/registry.md @@ -16,11 +16,12 @@ New optional application-interoperability planning (2026-11-03): [ADR-0007](adrs Downstream application boundary (2026-11-10): [ADR-0009](adrs/ADR-0009-downstream-application-boundary.md) is accepted and supersedes ADR-0007's gateway and hosted-execution decisions. Ordinary inference still returns tool calls to the client. Application-boundary M001–M003 are closed and M004 is conditionally closed with disposition `not measured`. The MCP gateway and hosted runner are withdrawn, the content-free audit export is in place, and the local metadata profile is opt-in. Retrieval R002 is closed and supersedes R001 as an execution handoff. Embeddings stay. Tool-integration M003 and M004 evidence conditions are vacated rather than collected. No successor is registered. -On-prem member access (2026-11-10, baseline `9da5e2d383c73035850c37f8125c145b8b7ff9ff`): a review of solo install and small-team use found a fresh onboard that writes a server key the same run retires, usage totals that add day and month buckets, member pages that link into administrator 403s, and no way for a member to add an upstream account that only they can spend. [On-prem member access](subsystems/on-prem-member-access-roadmap.md) is the successor. On-prem user access M001–M024 stay closed and are not reopened. [ADR-0010](adrs/ADR-0010-personal-upstream-account-custody.md) is accepted with its named canonical amendments. M001–M005 are implemented in the working tree and are not closed. +On-prem member access (2026-11-10, baseline `9da5e2d383c73035850c37f8125c145b8b7ff9ff`): a review of solo install and small-team use found a fresh onboard that writes a server key the same run retires, usage totals that add day and month buckets, member pages that link into administrator 403s, and no way for a member to add an upstream account that only they can spend. [On-prem member access](subsystems/on-prem-member-access-roadmap.md) is the successor and is closed. On-prem user access M001–M024 stay closed and are not reopened. [ADR-0010](adrs/ADR-0010-personal-upstream-account-custody.md) is accepted with its named canonical amendments. M001–M005 are closed: [001](closure/on-prem-member-access/001-status.md), [002](closure/on-prem-member-access/002-status.md), [003](closure/on-prem-member-access/003-status.md), [004](closure/on-prem-member-access/004-status.md), [005](closure/on-prem-member-access/005-status.md). No successor is registered. Legacy archive (pre-251, immutable, top level): `plans/001-*` through `plans/250-*` plus `python_hotpath_dispatch_compression_optimization.md`. -Most recently closed: Request Admission and Wire M008 (remote compaction capability +Most recently closed: On-prem member access M001–M005 (solo sign-in, separate usage windows, member navigation, personal upstream custody, and the browser grant; `plans/closure/on-prem-member-access/`), +Request Admission and Wire M008 (remote compaction capability contract; a compact request against an installation with no eligible provider surface fails with a typed capability outcome and consumes no provider attempt; `plans/closure/request-admission-wire/008-status.md`), @@ -106,7 +107,7 @@ No new runtime, schema or performance claim lands with these plans. | Deployment and packaging | active | `plans/subsystems/deployment-packaging-roadmap.md` | M008 and M009 closed | M009 resolves audited dependencies and adapts bounded backup member-name parsing; serial suites and locked release build passed. | | Dashboard | closed | `plans/subsystems/dashboard-roadmap.md` | M014 closed — operator surface presentation and accessibility corrective | Reopened on evidence at baseline `e6822d8f78`: M001–M013 remain closed. M014 is closed; the paired browser disposition needs the frozen oracle worktree and a browser, and the stale on-prem browser reference artifact has to be regenerated on hardware. | | On-prem user access | closed | `plans/subsystems/on-prem-user-access-roadmap.md` | M024 closed — browser session CSRF delivery and member account surface corrective | Reopened on evidence at baseline `d04ad6831c6e030b7f5fc8a56501fdfecab982bd`: M001–M023 remain closed. `plans/adrs/ADR-0004-browser-session-csrf-delivery-and-account-scoped-sign-in-throttling.md` was accepted on 2026-10-23, and M024 implements that decision; it is closed. The 2026-11-10 solo and small-team gaps are a new roadmap, not a reopening. | -| On-prem member access | active | [on-prem member access roadmap](subsystems/on-prem-member-access-roadmap.md) | M001–M005 active, not closed | ADR-0010 is accepted. Closure still needs the serial suite, the no-default gates, the locked release build, and a closure record. | +| On-prem member access | closed | [on-prem member access roadmap](subsystems/on-prem-member-access-roadmap.md) | M001–M005 closed | ADR-0010 is accepted. Closure records are [001](closure/on-prem-member-access/001-status.md) through [005](closure/on-prem-member-access/005-status.md). No successor is registered. | | On-prem concurrency performance | active | `plans/subsystems/on-prem-concurrency-performance-roadmap.md` | M002 closed — ordinary-server synthetic baseline recorded | M001's Pi/microSD solo tail attribution stays conditionally closed; M002 authorizes no WAL/SQLite topology change. | | Operations CLI | active | `plans/subsystems/operations-cli-roadmap.md` | M003 closed — watchdog start-guard ownership correction | New subsystem roadmap opened at baseline `e6822d8f78` for `rust/src/operations/` and `rust/src/runtime.rs`, which no other roadmap claims as a primary owner. M001 is closed and M002 is closed through M003; no successor is registered in this subsystem. | | Request admission and wire | active | `plans/subsystems/request-admission-wire-roadmap.md` | M008 closed — remote compaction capability contract | ADR-0003 accepted; M001–M007 and M009 remain closed; M008 is closed; no successor is registered in this subsystem. | @@ -328,11 +329,10 @@ persistence roadmap. | Subsystem | Milestone | Status | Implementation plan | Handoff note | |---|---|---|---|---| -| On-prem member access | M001 — solo sign-in and onboarding credential | active | [001](implementation/on-prem-member-access/001-solo-sign-in-and-onboarding-credential.md) | Implemented. Not closed. Does not implement ADR-0010. | -| On-prem member access | M002 — usage windows and member limits | active | [002](implementation/on-prem-member-access/002-usage-windows-and-member-limits.md) | Implemented. Not closed. Projection only; settlement stays. | -| On-prem member access | M003 — member navigation and admin roster | active | [003](implementation/on-prem-member-access/003-member-navigation-and-admin-roster.md) | Implemented. Not closed. | -| On-prem member access | M004 — personal upstream custody and routing | active | [004](implementation/on-prem-member-access/004-personal-upstream-custody-and-routing.md) | Implemented. Not closed. ADR-0010 is accepted. | -| On-prem member access | M005 — personal upstream browser grant | active | [005](implementation/on-prem-member-access/005-personal-upstream-browser-grant.md) | Implemented. Not closed. Calls the M004 service. | + +None. + +Unblock audit (on-prem member access, 2026-11-10): M001–M005 are closed by their own records. ADR-0010 stays accepted. Searched the member-access roadmap, its implementation plans, and the ready, active, and blocked tables. No successor is registered. Nothing else was waiting on this roadmap, so nothing is promoted. On-prem user access M001–M024 stay closed. ## Blocked work @@ -341,8 +341,6 @@ persistence roadmap. None. -Unblock audit (on-prem member access, 2026-11-10): ADR-0010 is accepted with the named canonical amendments. M001–M005 are implemented in the working tree and sit in the active table. They are not closed. On-prem user access M001–M024 stay closed. Nothing else was waiting on this roadmap. - Unblock audit (application boundary, 2026-11-10, baseline `e049025274a397d7799c3ae21ed106947c2a1572`): ADR-0009 supersedes ADR-0007's gateway and hosted-execution decisions. Retrieval R001 is no longer a blocked handoff; R002 is the successor and is documentation only. Tool-integration M003 and M004 stay conditionally closed as historical records, and their open evidence conditions are vacated rather than promoted into new tool-integration work. Nothing else on the blocked table was waiting on R001. M004's missing shared host is an allowed `not measured` closure, not a registry block. The same-day closure audit above records M001–M003 and R002 closed and M004 conditionally closed. Nothing further is promoted. Unblock audit (on-prem user access reopening after M012 closure, baseline @@ -375,6 +373,12 @@ Historical M007 blocker assessment at baseline `7e241ad` (`plans/closure/persist ## Recently closed | Subsystem / plan | Disposition | Evidence | +|---|---|---| +| On-prem member access M001 — solo sign-in and onboarding credential | closed — a fresh onboard writes no server key; a managed browser GET redirects to `/login`; `/v1` and `/api` stay JSON 401; a legacy database still receives a missing server key | `plans/closure/on-prem-member-access/001-status.md`; implementation `0767576c` | +| On-prem member access M002 — usage windows and member limits | closed — current day and current month stay separate totals; remaining is ceiling minus settled minus holds in that window; members receive instance ceilings and not instance usage | `plans/closure/on-prem-member-access/002-status.md`; implementation `0767576c` | +| On-prem member access M003 — member navigation and admin roster | closed — member shells link only member destinations; the users roster shows assignment, overrides, USD, and credential labels without secrets; administrative routes stay off the member allow list | `plans/closure/on-prem-member-access/003-status.md`; implementation `0767576c` | +| On-prem member access M004 — personal upstream custody and routing | closed — v66 bindings store no secret; the secret is in the config-adjacent `.env`; routing admits a bound account only for its owner; a failed publish restores the files and deletes the binding; ADR-0010 accepted | `plans/closure/on-prem-member-access/004-status.md`; implementation `0767576c` | +| On-prem member access M005 — personal upstream browser grant | closed — default deny hides the secret field; a granted member adds an OpenCode Go account in the browser; deny leaves the binding; a personal API token is refused | `plans/closure/on-prem-member-access/005-status.md`; implementation `0767576c` | | Application boundary M001 — withdraw MCP gateway and hosted execution | closed — routes unmounted, true execution switches fail closed, tool scopes and tool CLI commands removed, v65 tables kept, default and no-default serial suites pass | `plans/closure/application-boundary/001-status.md` | | Application boundary M002 — content-free gateway audit export | closed — administrator JSON-lines export, member and agent-token denial, per-section cap, no migration, prompt columns not selected | `plans/closure/application-boundary/002-status.md` | | Application boundary M003 — local metadata profile and doctor | closed — `rust/config.local.example.toml` and opt-in `check-config --local`; defaults unchanged; provider catalog is not an EggPool metadata source | `plans/closure/application-boundary/003-status.md` | diff --git a/plans/subsystems/on-prem-member-access-roadmap.md b/plans/subsystems/on-prem-member-access-roadmap.md index 23823bf1..061109d8 100644 --- a/plans/subsystems/on-prem-member-access-roadmap.md +++ b/plans/subsystems/on-prem-member-access-roadmap.md @@ -1,6 +1,6 @@ # On-Prem Member Access Roadmap -Status: active +Status: closed Long-term references: @@ -311,10 +311,7 @@ suite is closure evidence, not a substitute for the focused tests. ## 10. Risks and decision points -ADR-0010 is accepted, with the named canonical amendments. The five -milestones are implemented in the working tree and are not closed: the full -serial suite, the no-default gates, and the locked release build are still -outstanding, and no closure record has been written. +ADR-0010 is accepted, with the named canonical amendments. M001–M005 are closed. Their records are `plans/closure/on-prem-member-access/001-status.md` through `005-status.md`. The serial suite, the no-default check and clippy, and the locked release build are recorded there. Showing instance ceiling values to members reveals the cap and does not reveal other people's consumption. Showing remaining shared headroom would. @@ -335,8 +332,8 @@ Bedrock provider is implied. | Milestone | Status | Implementation plan | Closure record | Blockers | |---|---|---|---|---| -| 1 | active | [001](../implementation/on-prem-member-access/001-solo-sign-in-and-onboarding-credential.md) | — | closure suite outstanding | -| 2 | active | [002](../implementation/on-prem-member-access/002-usage-windows-and-member-limits.md) | — | closure suite outstanding | -| 3 | active | [003](../implementation/on-prem-member-access/003-member-navigation-and-admin-roster.md) | — | closure suite outstanding | -| 4 | active | [004](../implementation/on-prem-member-access/004-personal-upstream-custody-and-routing.md) | — | closure suite outstanding | -| 5 | active | [005](../implementation/on-prem-member-access/005-personal-upstream-browser-grant.md) | — | closure suite outstanding | +| 1 | closed | [001](../implementation/on-prem-member-access/001-solo-sign-in-and-onboarding-credential.md) | [001](../closure/on-prem-member-access/001-status.md) | none | +| 2 | closed | [002](../implementation/on-prem-member-access/002-usage-windows-and-member-limits.md) | [002](../closure/on-prem-member-access/002-status.md) | none | +| 3 | closed | [003](../implementation/on-prem-member-access/003-member-navigation-and-admin-roster.md) | [003](../closure/on-prem-member-access/003-status.md) | none | +| 4 | closed | [004](../implementation/on-prem-member-access/004-personal-upstream-custody-and-routing.md) | [004](../closure/on-prem-member-access/004-status.md) | none | +| 5 | closed | [005](../implementation/on-prem-member-access/005-personal-upstream-browser-grant.md) | [005](../closure/on-prem-member-access/005-status.md) | none | diff --git a/plans/subsystems/persistence-roadmap.md b/plans/subsystems/persistence-roadmap.md index 2e835584..e31cb3b0 100644 --- a/plans/subsystems/persistence-roadmap.md +++ b/plans/subsystems/persistence-roadmap.md @@ -482,7 +482,7 @@ Exit conditions: ## 8. Cross-cutting requirements -Storage and migration: no schema change. WAL/NORMAL and the current schema (migration chain v1–v65) remain authoritative. +Storage and migration: no schema change. WAL/NORMAL and the current schema (migration chain v1–v66) remain authoritative. Protocol and compatibility: no HTTP, wire, CLI, config, or public Rust API change. diff --git a/rust/src/server/dashboard/render/admin.rs b/rust/src/server/dashboard/render/admin.rs index 4b60a2d4..8a5d35f6 100644 --- a/rust/src/server/dashboard/render/admin.rs +++ b/rust/src/server/dashboard/render/admin.rs @@ -290,7 +290,7 @@ pub(in crate::server::dashboard) fn render_member_upstream( }; if !allowed { return format!( - "

    Personal upstream account

    Personal upstream self-service is not granted. An administrator can add an account from the command line. Changing a grant does not remove an account that is already bound.

    {listed}
    " + "

    Personal upstream account

    Personal upstream self-service is not granted. The instance operator can add an account from the command line. Changing a grant does not remove an account that is already bound.

    {listed}
    " ); } let options = providers diff --git a/rust/tests/database_compatibility.rs b/rust/tests/database_compatibility.rs index 4ac27f81..3210fcb5 100644 --- a/rust/tests/database_compatibility.rs +++ b/rust/tests/database_compatibility.rs @@ -640,14 +640,14 @@ async fn schema54_image_upgrades_with_legacy_state_preserved() { .archive; BackupService::validate_archive(&archive).expect("pre-upgrade archive validates"); - // Forward-only production upgrade: exactly migrations 55..66. + // Forward-only production upgrade: migrations 55 through 66 inclusive. let state = MigrationRunner::new(&database) .run() .await .expect("production upgrade applies"); assert_eq!(state.applied_this_run.first(), Some(&55)); assert_eq!(state.applied_this_run.last(), Some(&66)); - assert_eq!(state.applied_this_run.len(), 11); + assert_eq!(state.applied_this_run.len(), 12); database .quick_check() .await