feat(sessions): groupLabels: label sessions by owning group for dashboard badges

Merged
KH
5d ago
+153-6

What

  • Policy: optional groupLabels, keyed by gid in decimal: "groupLabels": {"22": {"label": "pit", "description": "..."}}. Label is 1-24 chars of letters, digits, space, ., _, - (starts with a letter or digit, no trailing space); description optional, <=200 chars, never sent to readers. Every key must be a defined group. Validated by parsePolicy, so both the loader and POST /admin/v1/policy/validate (and Control-owned policies) enforce it. No defaults. The field is .optional(), so the policy hash of an existing policy is unchanged.
  • Sessions proxy: on reads that already passed the check, each session owned by a labeled group gets relaygate: {"gid": <n>, "label": "<label>"}:
    • every item of GET /sessions/v1/sessions (which relaygate already re-serialises after filtering);
    • the top-level object of GET /sessions/v1/sessions/:id/metadata and .../catalog (the dashboard's detail header reads catalog through relay-control).
  • Unlabeled sessions get no key; other views are untouched; a single-session view with no label passes byte for byte. A relaygate key coming from Sessions is dropped so only relaygate can say it. The owner is never named.
  • Docs: contract "Group labels" section + route table; README note; examples/policy.pit.json labels gid 22.

Why

So the dashboard (relay-web, via relay-control) can show a group badge such as "pit" on sessions. Companion PRs follow in relay-control (pass the field through the catalog route) and relay-web (badge + filter).

Tests

npm run typecheck, npx vitest run (151 pass): list labeling only for readable labeled sessions, metadata/catalog labeling, byte-for-byte passthrough when unlabeled, forged upstream key dropped, no labels without groupLabels, validator cases (unknown gid, bad label charset/length, leading-zero key, unknown fields), admin validate route.

🤖 Generated with Claude Code


Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.


Summary by cubic

Adds optional groupLabels to policies so the dashboard can badge sessions by their owning group, without changing any access decisions.

  • New policy field groupLabels, keyed by gid in decimal, with a 1-24 character label and optional description (never sent to readers). Validated by the loader and POST /admin/v1/policy/validate; unknown gids, bad label characters, and unknown fields are rejected.
  • On reads that pass the check, relaygate adds relaygate: {"gid", "label"} to each session a labeled group owns: every item of GET /sessions/v1/sessions and the top-level object of .../metadata and .../catalog. Unlabeled sessions and other views pass unchanged; a relaygate key from Sessions is dropped so only relaygate can write it.