Skip to content

feat(auth): add read-only viewer role for fleet inspection and console - #1809

Draft
bheemreddy-samsara wants to merge 1 commit into
callstackincubator:mainfrom
bheemreddy-samsara:bheemreddy-samsara/viewer-role
Draft

bheemreddy-samsara wants to merge 1 commit into
callstackincubator:mainfrom
bheemreddy-samsara:bheemreddy-samsara/viewer-role

Conversation

@bheemreddy-samsara

@bheemreddy-samsara bheemreddy-samsara commented Nov 23, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Add a read-only viewer token and daemon session role so web console users and monitoring scripts can inspect fleet state, events, usage, redacted configuration and live device screens without full operator (admin) privileges.

Workflow

flowchart LR
  T["Token or socket hello"] -->|"role: viewer"| S["Session role: viewer"]
  S -->|"roleAllows(viewer, opRole)"| D["Dispatcher"]
  D -->|"any or viewer op"| R["Read fleet state and screens"]
  D -->|"agent or admin op"| F1["403 FORBIDDEN"]
  S -->|"lease sub-route"| H["findOwnedLease(access)"]
  H -->|"read (GET lease, stream)"| R
  H -->|"hold (files, events, input, tunnel)"| F2["403 FORBIDDEN"]
  S -->|"GET /v1/identity"| UI["Console UI"]
  UI -->|"role !== admin"| RO["Read-only badge, actions hidden"]
Loading

What changed

  • Contract & protocol (102 -> 103): Modeled roles as a lattice (agent, viewer, admin) with OperationRole = Role | "any", roleAllows, and readsEveryLease in src/contract/roles.ts. Moved fleet reads (worker.list, list.get, events.*, usage.get, inbox.get, token.list, redacted config.get) to "viewer" and shared reads (identity.get, catalog.get, status.get, lease.list, lease.get, component.list, baseline.list) to "any". Kept all mutations, lease ops, device.exec, driver.passthrough, doctor.run, cleanup.run, and config.get { showSecrets: true } refused for viewer.
  • Auth & SQLite: Added viewer to TokenRole, Identity, resolveHelloRole, and simlock token create --role viewer; migrated tokens table v2 -> v3 preserving row order, STRICT, hash UNIQUE, worker_id, and tokens_worker_id.
  • HTTP, modules & stream: Exhaustive toRole; required "read" | "hold" on findOwnedLease (refusing viewer with 403 on /files, /events, /input, /tunnel, and default-deny module lease routes; only stream opts in via viewerLeaseRoute: true); exhaustive stream role mapping sharing readsEveryLease.
  • Console UI: Accepted viewer tokens into the console, gated mutating menus/writes centrally in useActions() (plus search palette filtering), and displayed Read-only in the sidebar.
  • Docs & ADR: Added ADR 0090, updated narrowed ADR statuses, module manuals, OpenAPI route roles, and website docs. Proxy SSO role mapping (http.proxyAuth) is deferred to a follow-up PR so SSO operators keep an elevation path.

Validation

Head: e8517712

@coderabbitai

coderabbitai Bot commented Nov 23, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@bheemreddy-samsara
bheemreddy-samsara force-pushed the bheemreddy-samsara/viewer-role branch from b1a5cea to dc1416c Compare November 23, 2026 21:58
Add a read-only `viewer` token and daemon session role so console users
and monitoring scripts can inspect fleet state, events, usage, redacted
configuration and live device screens without full `operator` (`admin`)
privileges.

- Model daemon roles as a lattice (`agent`, `viewer`, `admin`) with
  `OperationRole = Role | "any"`, `roleAllows`, and `readsEveryLease` in
  `src/contract/roles.ts`; bump `PROTOCOL_VERSION_RANGE` to `103`.
- Keep all mutating operations, lease mutations, `device.exec`,
  `driver.passthrough`, `doctor.run`, `cleanup.run`, and
  `config.get { showSecrets: true }` refused (`FORBIDDEN`) for `viewer`.
- Require explicit `"read" | "hold"` access on `findOwnedLease` so
  holder-only sub-routes (`GET /v1/leases/{id}/events`,
  `/v1/leases/{id}/files*`, and module lease routes without
  `viewerLeaseRoute: true`) refuse `viewer` with `403` before calling
  `lease.get`; opt `stream` in via `viewerLeaseRoute` and share
  `readsEveryLease` across worker/gateway stream links with exhaustive
  role mapping.
- Migrate SQLite `tokens` table from v2 to v3 to accept `viewer` tokens
  while preserving row order, worker pins, and `tokens_worker_id`.
- Allow `viewer` tokens in `simlock token create --role viewer` and the
  web console, gating mutating menus/writes centrally in `useActions()`
  (and filtering search palette actions) while showing `Read-only` in
  the sidebar when `identity.role === "viewer"`.
- Record ADR 0090, update narrowed ADR statuses, module manuals, OpenAPI
  route roles, and website docs.

Co-authored-by: Cursor <cursoragent@cursor.com>

This branch has not been deployed

No deployments
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