main moved cron jobs into the cron-jobs plugin (#37) and retired the core Send later doors for the scheduled-conversations plugin's commands (#36), both touching the core MCP files this branch moves into the hub-mcp plugin. - The MCP stays out of core: backend/mcpserver/, cli/mcp_tools.py, cli/mcp_server.py, their tests and business/aiApps/ stay deleted (main's edits to them — no schedule group, no cron / schedule tools — are the plugin's to apply). - Cron and Send later follow main: backend/cron/routes.py gone (its by-name worker pick is runs.start's at fire time now), no ai-agent later / scheduled / unschedule — so a worker's narrowed CLI drops them from its command lists (workers/cli.py) and schedules nothing; Full reaches the plugin's commands. - authz: neither runs.schedule nor mcp.connect. - Settings: neither Scheduled jobs nor AI apps in the registry; both old addresses redirect to their plugin's page. - Regenerated openapi.json, src/generated, rolesCatalog.json, matrix.golden.txt and telemetry features.json. - cli/test_library_surface.py: parse_when left with `ai-agent later`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
9.8 KiB
Permissions — roles, relations, narrowed credentials
Since 2026-11-23. Analysis and research: the homelab's
data/log/2026-11-23-ai-agent-permission-model.md. Gabriel's calls: form
ai-agent-permissions-redesign_7n3ne1 (every recommendation taken). Code:
backend/authz/. Related: security.md,
multi-user.md.
The model in one line
RBAC for people, relationships for resources, attenuated credentials for everything that acts on someone's behalf — written by hand in Python, no policy server.
effective(request) = role(person) ∪ allow − deny ← RBAC + overrides
∩ scope(credential) ← attenuation
then, per object, relation(person, object) ← whose conversation, which grant
Why not the alternatives: plain RBAC can't say "this conversation is yours" (ownership is a relation; a role per project per person is role explosion); a policy language (Cedar, OPA) or a Zanzibar server (OpenFGA, SpiceDB) is a new dependency — or a new container — for 1 owner, ~10 guests and a small team; capabilities everywhere don't suit people at a browser. The catalog / role / relation split maps 1:1 onto Cedar's principal / action / resource if non-developers ever have to edit policies.
The pieces
| piece | file | what it is |
|---|---|---|
| catalog | authz/catalog.py |
42 named permissions in groups, each a route permission (the gate checks it) or a feature one (a handler or the run's scope reads it), in a tier: person, admin, host |
| roles | authz/roles.py |
named bundles; built-ins Operator (everything, the owner, locked), Admin (person + admin tiers; assignable with team mode), Member, Guest, Viewer; custom ones by cloning (person tier only). Edits and customs in roles.json (ROLES_PATH) |
| a person | authz/policy.py |
users.json role + allow / deny overrides (person tier only; core permissions can't be denied) |
| scopes | authz/scopes.py |
what a credential acting for someone keeps: cli, worker.read, worker.run, bot, phone. A scope only removes — route permissions it lists (all methods, or safe ones only); feature permissions pass through |
| route table | authz/routes.py |
(method, path template) → permission for every /api route, or public (signing in) |
| matrix | authz/matrix.py + authz/matrix.golden.txt |
route × caller (anon, viewer, guest, member, cli, w.read, w.run, bot, phone, owner), checked in |
| API | authz/api.py |
GET/POST /api/roles, PUT/DELETE /api/roles/{id}, POST /api/roles/{id}/reset (users.manage) |
| UI | frontend/src/business/users/ |
Settings → Roles (pages/Roles.tsx), a person's Access tab → Role & permissions (components/RolePermissions.tsx), helpers in roles.ts |
Tiers
- person — anyone in
users.jsonmay hold it (role or override). - admin — the hub's administration (people, security, every
conversation, dashboards). Only the Admin role holds it, and nobody can be
given Admin yet: ~100 handlers still tell the owner from a guest by identity
(
caller.is_owner), so it arrives with team mode, together with converting those checks tocaller.has(...). - host — running code on the machine: the
.claudeeditor (hooks), workers, Claude logins, cron agents, webhooks, unscoped runs. Operator only — the machine's owner. No other role can ever hold one.
Who is the caller, then may they
core/auth.py resolves who (a guest session, the edge's Authelia user, a
read-only key, a host caller and the narrower identity it asks for), then
asks one question for everyone: caller.allows(TABLE[route], method). A
refusal is a perm_denied line in the Security log (once per caller × route
per 10 min) — a guest sees your role doesn't include "…" — ask Gabriel.
| caller | identity | permissions |
|---|---|---|
| guest / member / viewer (session cookie) | their record | role ∪ allow − deny |
their run's ai-agent CLI (guard broker) |
the session's runAs |
theirs ∩ cli |
a plugin acting for them (hub.api + X-AIA-As-User — the hub-mcp plugin's AI-app connections) |
the named guest, while the plugin is theirs | theirs ∩ cli |
a worker's ai-agent CLI, switch Read / Read + run here |
the owner + one profile | all ∩ worker.read / worker.run |
a worker's ai-agent CLI, switch Full |
the owner | all |
READONLY_USERS (the claude bot) |
the owner, read-only | Admin's reads minus people, security and the machine |
READONLY_API_KEY (the desk phone) |
the owner, read-only | notifications.ledger reads |
METRICS_TOKEN bearer (Prometheus' scrape) |
the owner, read-only | metrics.read (GET /api/metrics) only |
Authelia OWNER_USERS, the host token, loopback |
the owner | everything |
The cli scope keeps a run off the person's devices, drafts and settings and
never lets it answer forms or questions (inbox.answer): the human
answers.
Relations stay in the handlers
The table says may they call this route; the handler decides on which
objects: users/access.py (a conversation's owner / participants; 404,
never 403, for one they can't see; conversations.all = see every one),
Caller.can(slug, level) (a project's view < chat < ship), each module's
owner field (computers, cron jobs, forms).
The mock's copy of the catalog
frontend/src/mock/rolesCatalog.json is /api/roles with no edits; after
changing authz/catalog.py or authz/roles.py, regenerate it:
docker run --rm --entrypoint python -v "$PWD:/svc" -w /svc/backend --tmpfs /data:uid=1000 \
homelab-ai-agent -c "import json, os; from authz import catalog, roles; \
json.dump({**catalog.public(), 'tiers': list(catalog.TIERS), \
'roles': [roles.public(r) for r in roles.store().all()]}, \
open('/svc/frontend/src/mock/rolesCatalog.json', 'w'), indent=1, ensure_ascii=False); os._exit(0)"
(It runs as root: chown the file back, and remove any root-owned
__pycache__ it leaves in backend/.)
Adding a route
- Add
(method, path) → permissiontoTABLEinauthz/routes.py— the narrowest existing permission, or a new catalog entry (label, help, tier). - Filter by relation inside the handler if it touches someone's objects.
UPDATE_GOLDEN=1 python -m unittest test_authz_matrixand read the diff: it is the list of callers who now reach the route.
test_authz_matrix fails on a route missing from the table, on an entry no
route has, and on any matrix change; test_authz covers roles, overrides,
the migration, scopes, the gate, the Roles API and the loopback audit.
The migration (2026-11-23)
UsersStore turns each record's old switches into a role + overrides that
allow exactly what they did (policy.migrate, marked authz: 1, a
users.json.bak-authz-<stamp> copy first): cli → cli.use, mcp →
mcp.connect (retired 2026-11-28 with mcp.manage: connecting AI apps is the
hub-mcp plugin's managed grant), createProjects → projects.create
(retired 2026-11-25: New project is the new-project plugin's managed grant
now, and a migrating record just drops the switch — authz/catalog.RETIRED:
a record still naming one reads without it and is never refused),
scratchBash →
runs.scratch.bash, codeMode → runs.codemode, computers.enabled →
computers.pair (computers.max stays). The API still accepts the old
booleans (each becomes an override relative to the role) and still shows
them (read off the permissions).
What changed for whom, route by route (the old regex lists against the
table): guests may now rename / archive their own conversations from the
browser (their CLI already could); the CLI and MCP-guest scope reads its
person's projects' files, conversation details and forms (it could list
them); a worker-bound connection reads conversation details and plan usage
of its profile and managed its worker's scheduled turns (until 2026-11-28:
the runs.schedule permission and /api/scheduled went, and the bound
connection itself with the hub-mcp plugin — a worker's narrowed CLI
schedules nothing; conversation-meta checks the profile); the claude bot no longer reads people, security, accounts or
host-level pages; the phone's key reads its notifications and nothing else.
A route with a malformed id now reaches its handler (400/404) instead of a
gate 403 — the gate checks permissions, not id shapes.
Loopback is not a credential — audit mode
Every host caller should present the host token (INTERNAL_API_TOKEN) as
X-Internal-Auth or Authorization: Bearer. The ai-agent and notify
CLIs read it from AI_AGENT_TOKEN or ~/.config/ai-agent/token (0600,
written by the homelab deploy); the hub's own MCP calls send it. A loopback
or docker-gateway call without it is still the owner this round, but
logged as loopback_tokenless (Security → Access; once per method × route ×
peer × user agent an hour, never pushed). When that list is empty for a
week, refuse them (a one-line change in _evaluate_gate).
Left
- Team mode (the devbox hub, conv
01a2090a): Admin assignable (theis_owner→has()pass), a Tailscale identity provider in the gate, members on their own Claude login with no fallback, per-uid runs. - Refuse tokenless loopback once the audit list is empty.
- Per-run tokens: an opaque token per run (
{subject, scope, expiry}, dying with the run) instead of the brokeredX-AIA-As-Sessionheader. - MCP scopes as real OAuth scopes (the 2026-07-28 MCP authorization
revision:
insufficient_scope+ step-up) instead ofread/full. - The guest UI could hide what a role lacks beyond Settings (a Viewer still
sees a composer; sending explains the refusal). Settings already does: the
registry reads
me.perms(settings.md).