fix(opcua): drop the reflective folder-event verdict invalidation; deny the SDK channel under enforcement (#878)
v2-ci / unit-tests (push) Waiting to run

The SDK memoizes INodeManager3.ValidateEventRolePermissions per (item, event type,
SourceNode). #826 kept it fresh by reflecting into the private
MonitoredNode2.InvalidatePermissionCaches (plus a detach/re-attach fallback). Since #855
condition events never take that channel, and the search for #878 found nothing
production-raised that does except a condition's SDK method audits, which reach it only
with auditing on, SignAndEncrypt and a SecurityAdmin session (nothing grants that role).

Under enforcement the channel verdict is now a flat deny for items on our nodes, so no
cached verdict depends on a grant, and InvalidateFolderEventVerdicts, the reflection,
the fallback, its counter and the guard test are removed. Method audits still reach
Server-object items, decided per event.

Tests: FolderEventVerdictInvalidationTests -> FolderEventVerdictFreshnessTests; new
revoked-grant test (positive control: a still-granted session) and method-audit test
(SecurityAdmin mapped for the test; positive controls: Server-object item, flag off);
the plain-event test runs each mode on a fresh server. Mutation-checked.

Claude-Session: https://claude.ai/code/session_01GT67ACmpMR7b9LGRPLijMi
This commit is contained in:
Joseph Doherty
2026-11-12 11:38:11 -05:00
parent 3a312ffdd1
commit fa811feb3d
5 changed files with 414 additions and 394 deletions
+16 -14
View File
@@ -185,20 +185,22 @@ Two things to know before relying on any of this:
`AclScopePathResolver.ResolveTagRawPath`), and `IsConditionVisibleTo(item, ConditionVisibilityScopes(c))` — the
Server-object rule, whose wired folders are ALSO generation-filtered now. ConditionRefresh on a direct item no
longer calls the base (it uses the non-virtual base check, which bypasses the re-implementation): `RefreshDirectItems`
mirrors the base loop plus the same decision. ⚠️ **The SDK memoizes that verdict per `(item, eventType,
SourceNode)`** until the monitored node's permission generation moves — `InvalidateFolderEventVerdicts` (one
`MonitoredNode2.InvalidatePermissionCacheForSession` per notifier×session) must run whenever the inputs change:
the authority/authorizer setters, `RevalidateMonitoredItems` (deploy `Changed` + timer tick) and
`CompleteAddressSpaceApply` — and is SKIPPED while enforcement is off (the authorizer setter forces it across an
on/off transition). Without it a cached allow survives the deploy (caught by the native wire test's restore leg /
`t2`). A rebuild tombstones the monitored nodes, so their caches go with them. ⚠️ (review) It clears each node's
cache WHOLE through the SDK's private `MonitoredNode2.InvalidatePermissionCaches` (reflection, pinned by
`FolderEventVerdictInvalidationTests.The_sdks_node_wide…`): the public `InvalidatePermissionCacheForSession`
misses ORPHANED subscriptions (session closed without deleting subs ⇒ `Session` null), which then queued a moved
alarm's events and delivered them on `TransferSubscriptions`, and rescanned the cache per item. Fallback if the SDK
drops it: per-session drop + `Remove`/`Add` of each session-less item. ⚠️ The verdict is decided on the LIVE
instance holding the event's condition NodeId, never the event's own instance — the SDK key has no instance
identity, so denying a replaced instance's late event cached a deny the new instance inherited.
mirrors the base loop plus the same decision. Since #855 condition events at our notifiers are served per item,
per event, UNCACHED by `DeliverToNotifierItems` (the same three checks, resolved once per hop), never through the
SDK channel. ⚠️ **#878: the SDK channel's verdict is a flat DENY under enforcement.** The SDK memoizes whatever
`INodeManager3.ValidateEventRolePermissions` returns per `(item, eventType, SourceNode)` until the monitored node's
permission generation moves (item add/remove, rebind, namespace default-permission change — NOT a deploy or grant
change); #826 kept it fresh with reflection into the SDK's private `MonitoredNode2.InvalidatePermissionCaches`
(`InvalidateFolderEventVerdicts`, a detach/re-attach fallback, a guard test). All of it is DELETED: its only caller
in SDK 2.0.1 is `MonitoredNode2.GetOrAddEventPermissionAsync`, and only a condition's SDK-raised method AUDITS ride
that channel (auditing on + SignAndEncrypt + `SecurityAdmin`, the one role the SDK type check admits to audit types
— nothing grants it) or a hand-made `folder.ReportEvent` (none in src). Denying them all keeps the cached verdict
grant-independent. **Do not reintroduce a grant-dependent decision on that path** — it would need the invalidation
back. Residual: a flag-OFF allow survives the switch to ON (authorizer wired just after server start). Mutation
record: with the invalidation disabled only its own counter test and a flag-off→on plain-event test failed (347
integration tests). Tests: `FolderEventVerdictFreshnessTests`. ⚠️ The verdict is decided on the LIVE instance
holding the event's condition NodeId, never the event's own instance (a replaced instance's late event is treated as
the live one's).
`TagReferencingEquipment` holds ALARM-BEARING tags only (`TagConfigIntent.Alarm`). ⚠️ A hand-built
authority (rigs) must pass `tagReferencingEquipment` or native alarms stop reaching equipment-folder items under
enforcement (`ServerEventRig.TagReferences()`); null ⇒ none (fail closed). Tests: