Skip to content

Desktop: the Admin tab in the new layout, with server storage (after the navigation PR and #38) - #49

Open
Skyfuller1303 wants to merge 218 commits into
itrycodinganditsbad:mainfrom
Skyfuller1303:desktop-admin
Open

Skyfuller1303 wants to merge 218 commits into
itrycodinganditsbad:mainfrom
Skyfuller1303:desktop-admin

Conversation

@Skyfuller1303

Copy link
Copy Markdown

Merge after #46 (the navigation PR) and #38. The diff of this PR alone: desktop-nav...desktop-admin. The compare also lists the commits of #38 that this branch merges.

The Admin tab moves to the new layout and shows the server's storage. Desktop crate only; the server fields it displays come from the storage capacity PR (#38), which this branch contains as a merge.

What

  • Admin sections Accounts, Storage and Audit log in a segmented switcher (the audit log opens inside it); the accounts as a table (role, computers, stored against quota with a small bar, two-factor, state, Manage) with the existing search and New account.
  • Server storage: the stored bytes against the capacity, with free space; the server disk (used and total, the database size as a sub-line) and the store. A disk store is measured by its filesystem and the configured capacity is a second measure; an S3 store shows stored bytes against the configured capacity, or a hint to set [storage] capacity. A warning tag shows at 90 % or more. Every missing value (older server, Postgres, S3 without a capacity) degrades to a dash or a one-line hint.
  • Account detail, New account, invite and confirmation panels in the new layout, reusing every existing flow and text. An action names its account and says whether it is destructive. Panel pairs follow their content down and are kept per account.

Testing

  • cargo fmt --all -- --check and cargo clippy --workspace --all-targets --locked -- -D warnings pass.
  • cargo test --workspace --locked --no-fail-fast (Postgres 17, SeaweedFS 4.48, backends required) at this head: 1836 passed, 0 failed, 2 ignored.
  • Tests for the storage block: disk with and without capacity, S3 with and without capacity, an older server, Postgres, and the warning threshold. Snapshots for each page in light and dark and at the smallest window.

Skyfuller1303 and others added 30 commits November 3, 2026 22:55
`craft-cloud-server healthcheck [--addr 127.0.0.1:8080]` sends GET /api/info
over a plain TcpStream and exits 0 only on a 200 status line, within 3 s.
Otherwise it exits 1 with one line on stderr. It prints nothing on stdout and
adds no dependency. A container image without a shell or curl can use it as
its health check.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ment

packaging/docker holds a Dockerfile (Debian trixie build, distroless cc
runtime as uid 65532, base images pinned by digest) and a Compose deployment:
the server behind Caddy for TLS (acme, internal or custom certificates), with
SQLite and the local disk by default and overlays for Postgres and S3.

Secrets never reach a service's environment. A one-shot secrets-init service
renders config.toml from a template and writes the secret files into a volume;
every other service mounts only its own directory read-only. Every service has
a read-only root, no capabilities and no-new-privileges. Caddy has a fixed
address that the config lists in trusted_proxies.

install.sh writes .env with random passwords, builds the image, starts the
stack and creates the first admin from a password read on stdin. The Docker
section in docs/server.md covers use, TLS, Postgres, S3, upgrading and what is
not covered. The Dockerfile uses the healthcheck subcommand.

Derived from the deployment in Skyfuller1303/craftcloud (deploy/compose),
written by the same author, MIT OR Apache-2.0, adapted to this repository's
TOML-only configuration.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Migration 0007 gives a device its client kind, platform and app version
and, once revoked, the time and the reason, and gives a user the time of
the last password change (plus a disabled time nothing reads yet). All
of it is additive, BIGINT on Postgres, and the flag stays the check.

Meta gets create_device_with and redeem_with, rename_device,
revoke_device_as, revoke_other_devices, revoke_all_devices, account,
change_password and reset_password. Flag, time and reason are set
together and only by the first revoke. A password change or reset sets
the hash, revokes the devices and deletes the account's invite and
pairings in one transaction.

Tests run on both databases, including the migration from 0006.

Co-Authored-By: Claude <noreply@anthropic.com>
New: GET /account, POST /account/password, PATCH /devices/{id} and
POST /devices/revoke-others. Sign-in and join take an optional client
kind, platform and app version, checked before a try is counted. The
device list shows them with the time and reason of a revoke; all new
fields are optional on the wire.

Changing the password answers a wrong current password with 403
wrong_password, never 401, since the agent reads every 401 on a
signed-in route as a revoked device. It is limited to five tries per
account in 15 minutes, takes a password-check slot, and ends the revoked
devices' live connections at once. Password and name bodies are read up
to the new TINY_JSON_BYTES (4 KiB).

wrong_password and forbidden move into the shared error codes; the local
API refers to them. The agent, app and desktop only change where they
build the extended types.

Co-Authored-By: Claude <noreply@anthropic.com>
user reset-password now revokes every device of the account (reason
reset) and deletes its open invite and pairings, so a stolen token does
not outlive the old password. --keep-devices restores the old behaviour
for the devices. device revoke-all signs out an account's devices
without touching the password. Both print how many devices they ended;
device revoke records the admin as the reason.

Co-Authored-By: Claude <noreply@anthropic.com>
The API table and error codes in the design document, the password and
sign-out commands, the live-connection delay of the command line and the
rollout note (an older server refuses the newer database) in the
server guide.

Co-Authored-By: Claude <noreply@anthropic.com>
…evice

A /changes long-poll that was waiting when its device was signed out
through the API now ends at once, and one that wakes for any other reason
looks the device up again before it answers, so a device signed out by
the command line gets 401 instead of the next change set.

The live endpoint listens for revocations and looks the device up before
the upgrade, so a revoke between the sign-in check and the subscription
is not missed.

Co-Authored-By: Claude <noreply@anthropic.com>
change_password checks, inside its transaction, that the calling device
is still signed in (it may have been revoked while the password was
hashed) and answers 401 if not. A password that changed meanwhile is now
409 conflict instead of 400 invalid. Both are new MetaError variants
mapped in the server.

set_password_hash had no caller outside a test and is removed. A new test
breaks the pairing deletes with a trigger and checks that a password
change, an admin reset and a revoke-others undo everything on SQLite and
Postgres.

Co-Authored-By: Claude <noreply@anthropic.com>
The request used bare line feeds instead of CRLF, and an answer that is not
HTTP at all was reported as a bad status. Send CRLF line endings and report
"not an HTTP answer" unless the first word is an HTTP version.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The long-poll now listens for revocations and looks its device up before
it waits, so a revoke between the sign-in check and the wait is not
missed, and looks it up once more after the change set is fetched, as
the last step before the answer, so a revoke during the fetch is not
answered with changes.

Co-Authored-By: Claude <noreply@anthropic.com>
…changes a password

change_password locked the caller's device row and then the user's row,
while revoke_other_devices from another device locked its own device and
then the user's, and reset_password locked the user before the devices.
On Postgres two of them at once could deadlock and fail with a database
error. All of them now take the user's row first (a no-op update), then
the devices, then the pairings.

A new scenario runs password changes, sign-outs and an admin reset at the
same moment, over and over, on both databases and expects only successes,
conflicts and signed-out callers. The test trigger helper also drops its
Postgres function.

Co-Authored-By: Claude <noreply@anthropic.com>
An answer that stopped inside the status line ("HTTP/1.1 200" and then EOF) or
filled the 64 byte buffer without a line end counted as healthy or as a bad
status. Now only a status line that ends in CRLF is read, and the other cases
are errors. Tests cover a truncated line, a line that does not end and a bare
line feed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
When the server is down, Caddy's error log entry for a failed request carried
the full request URI and headers, so an invite code (/join/<code>), a query
or a bearer token could end up in the log. The default log now drops
request>uri and request>headers. Caddy also skips installing its internal CA
into the container, which only produced an error line.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
db-init exported PGPASSWORD, which put the superuser password in the
environment of the shell and of psql. It now writes a mode 0600 password file
on a tmpfs, passes only PGPASSFILE and removes the file on exit. The
db-init service gets a small noexec tmpfs for it.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…docs

The server started before Caddy and was given 172.29.215.2, the address
reserved for Caddy, so Caddy failed to start. The frontend network now hands
out dynamic addresses from CC_FRONTEND_POOL (the upper half by default). The
docs name the new setting, the error of a data directory with the wrong owner
and what was tried with S3.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
render-config.sh read only the first line of a secret file, so a database
password with a second line passed the check while db-init, which reads the
whole file, set a different password than the one in config.toml. The whole
file is read now, one trailing line feed is allowed and any other line feed is
refused. The tests cover a second line, an empty second line and the allowed
trailing line feed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Compose gives a container its secrets from .env when it is created. After
`docker compose run --rm secrets-init`, a later `up -d db-init` started the
original secrets-init container again, which wrote the old values back. The
docs and the script comment now say to recreate it (`up -d --force-recreate
secrets-init`) before restarting the services that read the files.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
…-in adds a device

redeem consumed the invite and then updated the user, while a password
reset locks the user and then deletes the invite, so the two could
deadlock on Postgres. redeem now finds the invite or pairing with a plain
read, locks the account, and consumes the code again under the lock; a
code that is gone by then is invalid_code. create_pairing locks the
account first too.

A password sign-in verified the password outside any transaction, so a
reset or change that committed meanwhile could be followed by a new
device. sign_in_device locks the account and compares the stored hash
again before it creates the device; if it differs, login answers as for
a wrong password.

New scenarios run redeems, a sign-in, a pairing and a reset at the same
moment on both databases and expect no database error and no live device
once the reset is done.

Co-Authored-By: Claude <noreply@anthropic.com>
The invite delete and the pairing update now name the account the plain
read found, so a code hash removed and made again for another account
between that read and the lock is refused as invalid_code instead of
adding a device to the wrong account.

Co-Authored-By: Claude <noreply@anthropic.com>
The admin API's server overview shows whether blobs are on disk, in S3 or in memory. A backend that does not say is reported as other, so nothing outside the store crate has to change.

Co-Authored-By: Claude <noreply@anthropic.com>
New request and answer types for the routes under /api/v1/admin, with a redacting Debug for everything that holds a password or a code, and the error codes account_disabled and last_admin. The confirmation is a body with an optional password today, so an optional totp_code can join it later without breaking a client.

Co-Authored-By: Claude <noreply@anthropic.com>
Migration 0008 adds the purpose of an invite (invite or reset), a quota per space and a removal mark per user. The new Meta methods for the admin API each re-check the acting admin inside their own transaction and take the locks in one order, with a transaction-wide lock before the last-admin count. Disabled accounts are refused by the token check, sign-in, redeem, pairing and device creation, decided under the account's row lock. A reset code always sets a new password, signs every device out and then signs the redeeming computer in. A space's quota replaces the server-wide cap in the preflight check and in the count that follows.

Co-Authored-By: Claude <noreply@anthropic.com>
The require_admin layer and the routes under /api/v1/admin: counters, a paged and searchable user list, creating accounts, changing role and quota, disabling, enabling and removing, invites, password reset codes and a user's devices. Every change asks for the acting admin's password in its body. Sign-in and join answer account_disabled for a disabled account, and a redeemed reset code ends the live connections of the devices it signed out. Documents the API, the confirmation and the rollout in the design document and the server guide.

Co-Authored-By: Claude <noreply@anthropic.com>
Limiter::count added the attempt before comparing it with the maximum, so tries refused at the limit still raised the count. A refund of an attempt that had been accepted at the same moment then left the key above its limit with fewer wrong passwords than allowed. A refused try now leaves the count alone.

Co-Authored-By: Claude <noreply@anthropic.com>
Disabling and enabling an account leaves the password hash as it was, so a sign-in that verified the password before the disable could still create a usable device after the enable. Users get an auth_gen counter (migration 0008) that a disable, an enable, a removal and every password change or reset bump. The sign-in reads it with the hash and sign_in_device compares both under the account's lock. The server's refunds test covers the limiter change.

Co-Authored-By: Claude <noreply@anthropic.com>
Compaction asks a replica for a snapshot of a live document at an older
version. Loro's SnapshotAt export checks the document out at that version,
and on a long text history that needs many GiB: the live_documents test
an_app_that_misbehaves_is_refused_or_dropped_and_the_rest_go_on, whose app
sends 60 updates of 200,000 characters, ran out of a 16 GiB limit (itrycodinganditsbad#15).

snapshot_at now exports the operations up to the version, imports them into
a fresh document and takes that document's snapshot: the same history and
state, with memory linear in the history. A version whose operations need
others past it is refused instead of silently widened, a shallow document
is refused at once (Loro can't fork one at a version), and a scratch
document that Loro panicked in is let go of without being dropped.

Co-Authored-By: Claude <noreply@anthropic.com>
The typed details of a security event, an event, a page of them and the last line of the NDJSON export. Every
field of the details is a closed list of words or a number, and fields a later release adds are ignored.

Co-Authored-By: Claude <noreply@anthropic.com>
Migration 0009 adds audit_events, with no foreign keys so that an event outlives its account. Every change that the
log names writes its event in its own transaction before the commit, so a change whose event cannot be written is
not made. A change that changes nothing writes none. A failed sign-in is one row per account and minute whose
counter goes up, written in a transaction of its own. The values of an event are typed and come from closed
lists, never from what a client typed. Old events are pruned in batches outside those transactions.

Meta methods that had no way to say who asked get one: revoke_device_by takes the origin, and admin_enable_user and
admin_revoke_invite take the time.

Co-Authored-By: Claude <noreply@anthropic.com>
GET /account/activity, GET /admin/audit and the streamed GET /admin/audit/export; a failed sign-in is written
after the answer is decided and never changes it. [audit] retention_days (1 to 3650, default 365) and
audit list and audit prune on the command line. The export reads fixed pages through a bounded channel up to a
fixed end of the log and ends with a line that says complete or truncated, or breaks the connection.

Co-Authored-By: Claude <noreply@anthropic.com>
Other test modules of the app (such as a Security page test module in a
stacked pull request) build their own kittest harnesses. Make shared_wgpu()
visible to them, so all of the app's harnesses render on one device.
The Security page tests (from itrycodinganditsbad#19) built their kittest harness with
.wgpu(), a new wgpu device per test, which crashed the test process with
STATUS_ACCESS_VIOLATION when run in parallel on Windows, like the other UI
tests did before itrycodinganditsbad#35. Use the shared device from itrycodinganditsbad#35 here too.
…ersions

Back from the trash or file versions built a fresh overview, which starts with
the storage usage loading and the admin check unknown, but only asked for the
computers. The usage stayed on "Loading storage usage…" with Refresh disabled
until the app restarted, and the admin pages link stayed hidden.

Both pages now go back through one helper that asks for everything a fresh
overview shows, like signing in does.
Adds [storage] capacity (and init --capacity), cheap filesystem and SQLite
size measurements (fs4), optional fields on AdminStorageOverview, docs and tests.
Adds ui/kit.rs: colour tokens for dark and light, fonts (Archivo, Inter and Geist Mono, bundled under OFL-1.1),
visuals and spacing, and the widgets the screens draw with (buttons, icon button, tag, section label, card, table row,
headline, wordmark). Every existing screen uses it; texts, controls and layout stay as they were. Snapshots redrawn.
…labels and the wordmark

LICENSES.txt now appends the three OFL texts of the bundled fonts; NOTICE, AGENTS.md and the crate docs name them.
Buttons are painted by the kit (focus ring, single accessibility event, own font) and the global button text style
is body text again; the selection colour is per theme; tags and section labels expose their text as written; the
wordmark reads "Craft Cloud".
…ented control, the mockups' sizes

Tags are allocated at their natural size, so a grid cell, a right-to-left layout or a wrapped row never stretches them.
New: table (hairline rows, fixed and flexible columns, its own solid horizontal scroll), joined_cells (shared
hairlines, equal row heights, header strip, footer at the bottom, stacks when narrow), segmented, text_link, and the
badge, tab, text_edit and section_label_fit that the shell had added. Controls are 40 px (44 large), headings 30 px
(34 large), labels 12 px; tabs are regular weight in the muted colour and the locked chosen tab stays readable. The
focus ring keeps a 2 px gap from the control's border. Scroll bars are solid and take their own room.

The light theme's near-black header and footer rules came from eframe's default clear colour, a translucent dark grey
(12, 12, 12, 180), showing through the 1 px gap egui's panels keep for their separator, which is drawn translucent. The
app now clears with the page colour (kit::clear_color).
…ages, and the overview as three cells

The signed-in app was one long column of buttons. It now has a header (the wordmark, the account line and the tabs
Overview, Versions, Trash, Computers, Security, Activity and, for an admin, Admin) and a footer with the agent's state,
Sign out and Quit. The tabs replace the buttons that opened those pages and the Back buttons that left them; the events
stay. A tab asks for what its button asked for, after leaving the page shown the way that page's own way back did.

The overview is the sync, the storage and a short list of the computers side by side (one under the other in a narrow
window); the computers have a tab with the full list and Remove. Controls are 32 points high, the window opens at 960 by
640 and can shrink to 640 by 480.
…alls, a long account line is cut off

Review of the navigation shell:
- The footer's Sign out works on every page of the signed-in window (versions and trash had no overview to carry it),
  and a failed sign out, with the offer to sign out on this computer only, is kept in the model and shown above the
  footer on every page.
- A tab does not leave the security page while a call is under way or recovery codes are shown, nor the admin pages
  while a change waits for the server or a one-time code is shown; the tabs are drawn disabled meanwhile.
- The tab shown does nothing, also on the add-a-computer page, so a click on it no longer cancels the code.
- What the admin check said is forgotten when the signed-in account changes.
- The account line is cut off with an ellipsis instead of pushing a tab out of the window; with too little room the
  tabs get their own row.
- Single-line text fields of the pages are as high as the buttons (kit::text_edit).
The cells sit in ui.columns, whose top-down justified layout makes egui justify wrapped label text, so a long warning stretched single letters apart. The cell body now lays out top-down left-aligned; the wide button sizes itself.
…and footer as designed, trash and versions as tables, names for IDs

Overview: three joined cells with their actions at the bottom, the Sync tag "Online · Up to date", a 28 px headline, the
folder in a well with an icon, the storage figure at 40/20 px without a forced ".0", Refresh in the label row, the
computers with a metadata line, and a compact autostart problem with Details. Under the cells, "02 / Recent activity":
the newest five events (asked for with the overview, through the account-activity call the Activity tab uses), "All
activity" opens that tab.

Header: the wordmark and the nav sit in blocks with a hairline each, the account line takes the free space and keeps
"· host" when the user name is cut. Footer: a 36 px strip with Sign out and Quit as accent mono text links.

Trash and Versions are tables with the kit's helper (a file or folder icon, a Kind tag, a readable size, Restore and a red
Remove). The trash has the kind filter and a search field over the loaded list. Their confirmations are an inline panel
under the table (380 px, at the right): Esc cancels, the focus moves in, Cancel is the first button.

Computers and accounts are shown by name where the app knows them (the devices list, the account answer, the admin's
list), a short ID with the whole one on hover otherwise: in Activity, the audit log and Versions. The audit log's
controls are as high as a button and its truncation notice is a warning, not an error.
…ccount pages in the new layout

The admin landing page gets Accounts, Storage and Audit log tabs. The Storage tab shows the server's room as one number and a
bar, with a row for the server's disk and one for the store, built from the optional capacity fields of the storage overview.
Every number an older server, Postgres or S3 leaves out reads as a dash or a one-line hint. The warning starts at 90 percent,
the line the server uses for an account near its quota. The accounts are a table that scrolls sideways in its own area, and
the account, new account and shown-code pages use the same panels.
…r capacity, and review fixes

A disk store's all storage line and bar now use the store's filesystem numbers, because the accounts' stored total counts per
account and can pass the disk's size. A capacity set on a disk is a second measure with its own warning, and the tags say which
one is near (disk 92 %, capacity 95 %). A store with only a capacity (S3) shows the accounts' total against it, said to be an
upper bound. The bars carry a label with their share, a disk store without numbers stays a disk, the hint about S3 is only shown
for S3, an account shows every state it is in, and the server's own counters stay when the storage call fails.
… names its account and says whether it is destructive
…cells, segmented switcher with the audit log inside, panels for new account, invite, confirmation and account detail, storage table with flexible bars and over-capacity)
…w their content down and are kept per account
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant