Skip to content

feat(server): reader / editor / admin roles for signed-in users #559

Closed

Description

@LeMyst

Follow-up to #534 (opt-in sign-in for cook server), from this discussion.

Problem

With sign-in on, #534 knows only two kinds of visitor: a guest, who can read everything and change nothing, and a signed-in user, who can change everything. A shared household or family server often needs more in between:

  • someone who signs in and reads, but never edits (for example a guest account on a public instance);
  • someone who ticks off the shopping list and updates the pantry, but doesn't edit recipes;
  • keeping the cook.md sync controls and the editor's language server (/api/ws/lsp) to one administrator.

Proposal

Add a role to each user in users.toml:

Role Read Shopping list / pantry Recipes & menus (create, edit, delete, title picture) Sync controls, /api/ws/lsp
guest (not signed in) ✅ ❌ ❌ ❌
reader ✅ ❌ ❌ ❌
editor ✅ ✅ ✅ ❌
admin ✅ ✅ ✅ ✅

Whether the shopping list and pantry need their own role (e.g. shopper) or are part of editor can be decided here.

Users file

Stay backwards compatible: a plain hash string still means today's behaviour (admin, i.e. everything), and a table adds a role:

[users]
alice = "$argon2id$…"                            # admin, as today
bob   = { hash = "$argon2id$…", role = "editor" }
guest = { hash = "$argon2id$…", role = "reader" }

Parsed as an untagged enum. deny_unknown_fields stays, so an older server refuses a newer file instead of ignoring the roles in it, and an unknown role name stops the server from starting (it fails closed, like a bad hash does today).

CLI

cook server user add bob --role editor     # default: admin (or editor?), to be decided
cook server user role bob reader
cook server user list                      # shows each user's role

These edits go through toml_edit like the existing commands, so comments survive.

Server

  • Viewer carries the role. can_edit() is replaced by capability checks (can_edit_recipes(), can_edit_lists(), can_admin()) that the templates use to hide controls.
  • auth::middleware::requires_user becomes "which capability does this request need": the path prefix maps to a capability, writes stay denied by default, and a new write route still needs the highest capability unless it is listed.
  • Roles are read from the live users file on every request, as the user list already is, so changing a role applies at once without signing anyone out.
  • A signed-in user without the capability gets 403 (not 401, which means "sign in"), and pages are rendered without the controls they can't use.

Out of scope

Per-folder or per-recipe access (private recipes, folders visible to some users) is a separate, much larger change. It needs enforcement where files are read and listed, not in the middleware; see the linked comment for the list of paths a recipe can leak through. The roles above shouldn't depend on it, but shouldn't prevent it either.

Tests

  • Unit: parsing both value forms, unknown role, a capability for each route (extending the requires_user table tests).
  • End-to-end (tests/server_auth_test.rs): a reader gets 401/403 on every write; an editor can edit recipes and the list but not reach /api/sync/… or /api/ws/lsp; a role changed in the file applies without a restart.

Activity

  1. added a commit that references this issue on Sep 28, 2026
    45e6ae1
  2. added a commit that references this issue on Oct 3, 2026
    2c82f28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions