Review 2026-12-02 Phase 0: Authorization and auth throttling #251

Closed
opened 2026-12-02 16:07:37 -05:00 by dohertj2 · 2 comments
Owner

Phase 0 — Authorization and auth throttling (p0)

These are real trust-boundary gaps. The SES-002, SES-003 and DSH-001 code paths were re-checked by hand.

# Finding(s) Change Test
0.1 SES-002 Add an EnsureOwner(session, identity) helper next to ResolveSession in Grpc/MxAccessGatewayService.cs and call it from Invoke and CloseSession, returning PermissionDenied (same ordinal compare as EventStreamService.cs:58). Decide whether an admin-scoped key may override, and record that in docs/Authorization.md and docs/DesignDecisions.md. Internal ISessionManager callers (alarm monitor, dashboard) are unaffected. Key B → Invoke(DrainEvents/Write) and CloseSession on key A's session gives PermissionDenied, and A's session stays Ready.
0.2 SES-003 Add an AddBufferedItem case to ApplyConstraintsAsync that calls EnforceReadTagAsync(command.AddBufferedItem.ItemDefinition). Also make the switch fail closed: maintain an explicit allow-list of command kinds that carry no tag, and send any new tag-bearing kind to the check (a test enumerates MxCommandKind). Out-of-scope AddBufferedItem gives PermissionDenied plus an audited denial, and no worker command is sent. Enum-coverage test.
0.3 DSH-001 Replace RouteView with AuthorizeRouteView (with NotAuthorized content) in Dashboard/Components/Routes.razor. Check /admin/secrets (Secrets.Ui) under the same path. bUnit or integration test: anonymous-localhost principal navigating in-circuit to /alarms gets NotAuthorized.
0.4 SEC-001 Partition the failure limiter on the remote IP only (strip the port from context.Peer, or use HttpContext.Connection.RemoteIpAddress). Two connections from the same IP with different ports share one partition.
0.5 SEC-002, SEC-003 Move a valid-secret cache hit ahead of the aggregate throttle, so a holder of the correct secret is never denied by spray against the key id. Stop the success path from wiping the cross-peer aggregate; let entries decay by window instead. Spray with bad secrets for key X, then the valid secret for X still succeeds. An active key still accrues aggregate failures.
0.6 SEC-004, DSH-006 Key revocation or deletion cancels that key's open server streams: register stream CTSs by key id, and the revoke path cancels them. For the dashboard, re-validate the hub-token / cookie expiry and the role on a timer per hub connection and circuit, and abort when expired. Revoke a key mid-StreamEvents and the stream ends with Unauthenticated. Hub connection is closed after the token expires.

Verify: dotnet build src/ZB.MOM.WW.MxGateway.NonWindows.slnx; filtered tests MxAccessGatewayService*, GatewayGrpcScope*, *FailureLimiter*, Dashboard*Authorization*; full gateway suite once.

High findings filed separately:


Source: code-reviews/2026-12-02-perf-bugs/README.md and code-reviews/2026-12-02-perf-bugs/PLAN.md (commit f200bda6 on local branch docs/review-2026-12-02-perf-bugs, not yet pushed). Reviewed at 54367e74.

## Phase 0 — Authorization and auth throttling (p0) These are real trust-boundary gaps. The SES-002, SES-003 and DSH-001 code paths were re-checked by hand. | # | Finding(s) | Change | Test | |---|---|---|---| | 0.1 | SES-002 | Add an `EnsureOwner(session, identity)` helper next to `ResolveSession` in `Grpc/MxAccessGatewayService.cs` and call it from `Invoke` and `CloseSession`, returning `PermissionDenied` (same ordinal compare as `EventStreamService.cs:58`). Decide whether an `admin`-scoped key may override, and record that in `docs/Authorization.md` and `docs/DesignDecisions.md`. Internal `ISessionManager` callers (alarm monitor, dashboard) are unaffected. | Key B → `Invoke(DrainEvents/Write)` and `CloseSession` on key A's session gives `PermissionDenied`, and A's session stays `Ready`. | | 0.2 | SES-003 | Add an `AddBufferedItem` case to `ApplyConstraintsAsync` that calls `EnforceReadTagAsync(command.AddBufferedItem.ItemDefinition)`. Also make the switch fail closed: maintain an explicit allow-list of command kinds that carry no tag, and send any new tag-bearing kind to the check (a test enumerates `MxCommandKind`). | Out-of-scope `AddBufferedItem` gives `PermissionDenied` plus an audited denial, and no worker command is sent. Enum-coverage test. | | 0.3 | DSH-001 | Replace `RouteView` with `AuthorizeRouteView` (with `NotAuthorized` content) in `Dashboard/Components/Routes.razor`. Check `/admin/secrets` (Secrets.Ui) under the same path. | bUnit or integration test: anonymous-localhost principal navigating in-circuit to `/alarms` gets NotAuthorized. | | 0.4 | SEC-001 | Partition the failure limiter on the remote IP only (strip the port from `context.Peer`, or use `HttpContext.Connection.RemoteIpAddress`). | Two connections from the same IP with different ports share one partition. | | 0.5 | SEC-002, SEC-003 | Move a valid-secret cache hit ahead of the aggregate throttle, so a holder of the correct secret is never denied by spray against the key id. Stop the success path from wiping the cross-peer aggregate; let entries decay by window instead. | Spray with bad secrets for key X, then the valid secret for X still succeeds. An active key still accrues aggregate failures. | | 0.6 | SEC-004, DSH-006 | Key revocation or deletion cancels that key's open server streams: register stream CTSs by key id, and the revoke path cancels them. For the dashboard, re-validate the hub-token / cookie expiry and the role on a timer per hub connection and circuit, and abort when expired. | Revoke a key mid-`StreamEvents` and the stream ends with `Unauthenticated`. Hub connection is closed after the token expires. | **Verify:** `dotnet build src/ZB.MOM.WW.MxGateway.NonWindows.slnx`; filtered tests `MxAccessGatewayService*`, `GatewayGrpcScope*`, `*FailureLimiter*`, `Dashboard*Authorization*`; full gateway suite once. **High findings filed separately:** - [ ] #241 SES-002 - [ ] #242 SES-003 - [ ] #243 DSH-001 - [ ] #244 SEC-001 - [ ] #245 SEC-002 --- Source: `code-reviews/2026-12-02-perf-bugs/README.md` and `code-reviews/2026-12-02-perf-bugs/PLAN.md` (commit `f200bda6` on local branch `docs/review-2026-12-02-perf-bugs`, not yet pushed). Reviewed at `54367e74`.
Author
Owner

Decision (2026-12-03, recorded as D2/D3/D10 in code-reviews/2026-12-02-perf-bugs/PLAN.md): see the comments on #241 and #243. Medium/Low findings stay as rows in these phase issues; no separate issues unless split out, deferred or grown.

Decision (2026-12-03, recorded as D2/D3/D10 in `code-reviews/2026-12-02-perf-bugs/PLAN.md`): see the comments on #241 and #243. Medium/Low findings stay as rows in these phase issues; no separate issues unless split out, deferred or grown.
Author
Owner

Merged to main at 68043411 (pushed 2026-12-03). Gateway suite 1610 passed / 0 failed (macOS); windev worker CI 836 passed / 0 failed on that SHA.

All rows 0.1–0.6 done. Known gaps (documented): apikey CLI revocation doesn't end open streams (separate process); LDAP group removal / sign-out elsewhere takes effect at the 8 h cookie limit or reconnect. Behaviour change: key rotate also ends that key's streams.

Merged to `main` at `68043411` (pushed 2026-12-03). Gateway suite 1610 passed / 0 failed (macOS); windev worker CI 836 passed / 0 failed on that SHA. All rows 0.1–0.6 done. Known gaps (documented): `apikey` CLI revocation doesn't end open streams (separate process); LDAP group removal / sign-out elsewhere takes effect at the 8 h cookie limit or reconnect. Behaviour change: key rotate also ends that key's streams.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dohertj2/mxaccessgw#251