molecule-core/canvas/src/components
Hongming Wang f72fa4cd70 feat(auth): organization-scoped API keys for admin access
Adds user-facing API keys with full-org admin scope. Replaces the
single ADMIN_TOKEN env var with named, revocable, audited tokens
that users can mint/rotate from the canvas UI without ops
intervention.

Designed for the beta growth phase — one token tier (full admin).
Future work will split into scoped roles (admin / workspace-write
/ read-only) and per-workspace bindings. See docs/architecture/
org-api-keys.md for the design + follow-up roadmap.

## Surface

  POST   /org/tokens        mint (plaintext returned once)
  GET    /org/tokens        list live keys (prefix-only)
  DELETE /org/tokens/:id    revoke (idempotent)

All AdminAuth-gated. Bootstrap path: mint the first token via
ADMIN_TOKEN or canvas session; tokens can mint more tokens after.

## Validation as a new AdminAuth tier (2a)

AdminAuth evaluation order:
  Tier 0  lazy-bootstrap fail-open (only when no live tokens AND
          no ADMIN_TOKEN env)
  Tier 1  verified WorkOS session via /cp/auth/tenant-member
  Tier 2a org_api_tokens SELECT — NEW
  Tier 2b ADMIN_TOKEN env (bootstrap / CLI break-glass)
  Tier 3  any live workspace token (deprecated, only when ADMIN_TOKEN
          unset)

Tier 2a runs ONE indexed lookup (partial index on
token_hash WHERE revoked_at IS NULL) + an async last_used_at
bump. No measurable latency cost on the hot path.

## UI

New "Org API Keys" tab in the settings panel. Label field for
human-readable naming. Plaintext shown once + clipboard copy.
Revoke with confirm dialog. Mirrors the existing workspace-
TokensTab flow so users who've used one get the other for free.

## Security properties

  - Plaintext never stored. sha256 hash + 8-char display prefix.
  - Revocation is immediate: partial index on revoked_at IS NULL
    means the next request validates or fails in microseconds.
  - created_by audit field captures provenance: "org-token:<short>"
    when a token mints another, "session" for browser-UI mints,
    "admin-token" for the ADMIN_TOKEN bootstrap path.
  - Validate() collapses all failure shapes into ErrInvalidToken
    so response-shape can't distinguish "never existed" from
    "revoked".

## Tests

  - internal/orgtoken: 9 unit tests (hash storage, empty field
    null-ing, validation happy path, empty plaintext, unknown hash,
    revoked filtering, list ordering, revoke idempotency, has-any-
    live short-circuit).
  - AdminAuth tier-2a integration covered by existing middleware
    tests unchanged (fail-open + bearer paths).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-04-20 14:01:41 -07:00
..
__tests__ test: add BatchActionBar unit tests (7 tests) 2026-04-18 02:21:31 -07:00
canvas initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
settings feat(auth): organization-scoped API keys for admin access 2026-04-20 14:01:41 -07:00
tabs fix: ChatTab comment path for workspace-server rename 2026-04-18 01:48:59 -07:00
ui feat(canvas): wire live metrics API in WorkspaceUsage (#592) 2026-04-17 06:00:14 +00:00
A2ATopologyOverlay.tsx feat(canvas): A2A topology overlay with animated delegation edges (issue #744) 2026-04-17 15:45:34 +00:00
ApprovalBanner.tsx fix(a11y): WCAG ARIA fixes for time-sensitive components (Fixes #Fix1/#Fix2/#Fix3) 2026-04-16 05:40:40 -07:00
AuditTrailPanel.tsx feat(canvas): audit trail visualization panel (issue #753) 2026-04-17 16:03:28 +00:00
AuthGate.tsx fix(canvas): UIUX Cycle 15 dark-theme & a11y sweep (C1-C5, A1-A4, F1, M1) 2026-04-16 10:35:32 +00:00
BatchActionBar.tsx feat(canvas): batch operations — multi-select + restart/pause/delete (Phase 20.3) 2026-04-18 01:16:55 -07:00
BundleDropZone.tsx fix(a11y): WCAG ARIA fixes for time-sensitive components (Fixes #Fix1/#Fix2/#Fix3) 2026-04-16 05:40:40 -07:00
Canvas.tsx feat(canvas): batch operations — multi-select + restart/pause/delete (Phase 20.3) 2026-04-18 01:16:55 -07:00
CommunicationOverlay.tsx fix(canvas): address all code review findings on PR #482 2026-04-16 07:48:47 -07:00
ConfirmDialog.tsx fix(canvas): WCAG critical — ARIA live toasts, dialog focus trap, keyboard nav 2026-04-15 08:31:06 +00:00
ContextMenu.tsx fix(canvas): hydration error UI (#554), radio arrow-key nav (#556), zoom-to-team context menu (#557) (#565) 2026-04-17 00:35:54 +00:00
ConversationTraceModal.tsx fix(a11y): add aria-label to Dialog.Content in ConversationTraceModal (Issue M) 2026-04-17 23:31:20 +00:00
CookieConsent.tsx feat(canvas): cookie consent banner with privacy-preserving default 2026-04-15 13:01:48 -07:00
CreateWorkspaceDialog.tsx fix(canvas): WCAG SC 1.3.1 — programmatic label/input association in InputField 2026-04-17 06:07:08 +00:00
EmptyState.tsx fix(canvas): add role=alert to deploy error in EmptyState 2026-04-17 21:16:14 +00:00
ErrorBoundary.tsx test: 100% coverage of extracted helpers + ConfirmDialog singleButton 2026-04-13 17:08:33 -07:00
Legend.tsx fix(canvas): address all code review findings on PR #482 2026-04-16 07:48:47 -07:00
MemoryInspectorPanel.tsx fix(gate-6): merge main into fix/a11y-audit-902-905 — resolve 7 conflicts 2026-04-18 01:34:00 +00:00
MissingKeysModal.tsx fix(wcag): sweep text-zinc-600→zinc-500 across 9 components with small text 2026-04-16 07:53:00 +00:00
OnboardingWizard.tsx fix(canvas): add ARIA landmark and live region to OnboardingWizard 2026-04-17 21:17:32 +00:00
PricingTable.tsx feat(canvas): /pricing route with plan selector + Stripe checkout 2026-04-15 13:41:44 -07:00
ProvisioningTimeout.tsx initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
SearchDialog.tsx fix(canvas): address all code review findings on PR #482 2026-04-16 07:48:47 -07:00
SidePanel.tsx Merge pull request #888 from Molecule-AI/fix/canvas-a11y-sidepanel-resize-keyboard 2026-04-18 01:20:02 +00:00
Spinner.tsx fix(canvas): address all code review findings on PR #482 2026-04-16 07:48:47 -07:00
StatusDot.tsx fix(canvas): address all code review findings on PR #482 2026-04-16 07:48:47 -07:00
TemplatePalette.tsx fix(canvas): address all code review findings on PR #482 2026-04-16 07:48:47 -07:00
TermsGate.tsx feat(canvas): ToS gate modal + us-east-2 data residency notice 2026-04-19 07:44:47 -07:00
Toaster.tsx fix(canvas): WCAG critical — ARIA live toasts, dialog focus trap, keyboard nav 2026-04-15 08:31:06 +00:00
Toolbar.tsx fix(canvas): add aria-label to Toolbar buttons and status pills 2026-04-17 21:17:05 +00:00
Tooltip.tsx initial commit — Molecule AI platform 2026-04-13 11:55:37 -07:00
WorkspaceNode.tsx Merge pull request #949 from Molecule-AI/feat/canvas-batch-operations 2026-04-20 08:48:26 -07:00
WorkspaceUsage.tsx feat(canvas): wire live metrics API in WorkspaceUsage (#592) 2026-04-17 06:00:14 +00:00