fix(grpc): check AddBufferedItem read constraints; fail closed on unclassified command kinds (SES-003, #242)

AddBufferedItem carries an item_definition but fell into the default branch of
ApplyConstraintsAsync, so a read-constrained key could add and advise an
out-of-scope tag. It now runs EnforceReadTagAsync. The switch also fails
closed: kinds are explicitly classified as constraint-checked or tag-free, any
other kind is refused with PermissionDenied and an audited denial, and a test
enumerates MxCommandKind so a new kind must be classified.
This commit is contained in:
Joseph Doherty
2026-12-03 09:41:50 -05:00
parent cf00f6fc86
commit 97e4d96afa
3 changed files with 237 additions and 4 deletions
+20 -4
View File
@@ -249,10 +249,26 @@ page create dialog (see
[Gateway Dashboard Design](./GatewayDashboardDesign.md#api-keys-page)). The
dashboard API Keys page also renders each key's effective constraints.
The service checks read constraints for `AddItem`, `AddItem2`, `AddItemBulk`,
`SubscribeBulk`, `AdviseItemBulk`, and `ReadBulk`. It checks write constraints
for `Write`, `Write2`, `WriteSecured`, `WriteSecured2`, `WriteBulk`,
`Write2Bulk`, `WriteSecuredBulk`, and `WriteSecured2Bulk`. Bulk commands run
The service checks read constraints for `AddItem`, `AddItem2`,
`AddBufferedItem`, `AddItemBulk`, `SubscribeBulk`, `AdviseItemBulk`, and
`ReadBulk`. It checks write constraints for `Write`, `Write2`, `WriteSecured`,
`WriteSecured2`, `WriteBulk`, `Write2Bulk`, `WriteSecuredBulk`, and
`WriteSecured2Bulk`. Handle-only commands (`Advise`, `RemoveItem`, the
un-advise and remove bulks) and commands with no tag at all (`Register`,
`Ping`, `DrainEvents`, ...) are on an explicit no-tag allow-list
(`MxAccessGatewayService.UnconstrainedCommandKinds`); single `Advise` relies on
the add that produced the handle having been checked.
The command-kind switch fails closed. A kind that is on neither the checked list
(`ConstrainedCommandKinds`) nor the allow-list is refused with
`PermissionDenied` and one audited `constraint-denied` event, for every key,
constrained or not. Today that covers the gateway-internal alarm kinds
(`SubscribeAlarms`, `UpdateAlarmWatchList`, `AcknowledgeAlarmByName`, ...),
which the gateway's alarm monitor sends through `ISessionManager` and which the
public `Invoke` could only ever deliver without a payload, and any kind added
to the contract later. A unit test enumerates `MxCommandKind` and fails until a
new kind is classified, so a new tag-bearing kind cannot reach the worker
unchecked the way `AddBufferedItem` once did (SES-003). Bulk commands run
through `BulkConstraintPlan` (`ReadBulkConstraintPlan`,
`WriteBulkConstraintPlan`, `SubscribeBulkConstraintPlan`), which preserves the
caller's input order: each entry is evaluated against the constraint surface,