fix(grpc): owner-scope Invoke and CloseSession like StreamEvents (SES-002, #241)

A foreign API key holding the matching scope could Invoke(DrainEvents) another
key's session (dequeuing its events), write through it, or close it. Invoke and
CloseSession now apply the same ordinal owner compare as the StreamEvents
attach and return PermissionDenied. No admin override (D2): operators use the
dashboard, which calls ISessionManager directly.
This commit is contained in:
Joseph Doherty
2026-12-03 09:40:41 -05:00
parent d12fd4f5a0
commit cf00f6fc86
7 changed files with 229 additions and 5 deletions
+26
View File
@@ -277,6 +277,32 @@ that drops on full, so per-item events let a single low-privilege key flush
every other pending audit record with one large bulk command. Secured values
and raw credentials are never logged.
## Session Ownership
Scopes say what verbs a key may use; they do not say whose sessions it may use
them on. Every session-scoped RPC is therefore also **owner-scoped**.
`OpenSession` records the caller's key id as `GatewaySession.OwnerKeyId`, and
`StreamEvents`, `Invoke` (every command kind) and `CloseSession` refuse a caller
whose key id differs with `PermissionDenied`, before the session manager or the
worker is reached. The compare is ordinal, and a `null` owner (a session opened
with authentication disabled) matches only a `null` caller key.
`MxAccessGatewayService.EnsureOwner` holds the check for `Invoke` and
`CloseSession`; `EventStreamService` holds the same check for the stream attach.
Without the owner rule, knowing a session id plus a matching scope would be
enough. Session ids appear on the dashboard Sessions pages and in logs, so an
`events:read` key could call `Invoke(DrainEvents)` on another key's session and
dequeue its events (which the owner's stream then never sees), and an
`invoke:write` key could write through it.
There is **no `admin` override**: an `admin`-scoped key is refused like any
other foreign key. Operators close or kill other keys' sessions from the
dashboard, which calls `ISessionManager` directly. Internal callers (the alarm
monitor, the dashboard live read) go through `ISessionManager` as well and are
not affected. The session-less alarm RPCs (`AcknowledgeAlarm`, `StreamAlarms`,
`QueryActiveAlarms`) and the Galaxy Repository RPCs have no session and so no
owner to check.
## Scope Catalog
`GatewayScopes` is the single source of truth for scope strings. Every entry is currently mapped by either the resolver or another security component: