From 83e607d4375744a5d64fef2acc35c5d2a61ed0ec Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 24 Nov 2026 16:08:07 -0500 Subject: [PATCH] =?UTF-8?q?docs(grpc-data):=20A2b=20security=20review=20fi?= =?UTF-8?q?xes=20=E2=80=94=20findings,=20resolutions,=20red/green,=20gates?= =?UTF-8?q?,=20live=20conditions=5Fsmoke=20a2s1-cond-1=20PASS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/plans/evidence/grpc-data-ext/A2.md | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/plans/evidence/grpc-data-ext/A2.md b/docs/plans/evidence/grpc-data-ext/A2.md index 5d338197e..e0cc8df89 100644 --- a/docs/plans/evidence/grpc-data-ext/A2.md +++ b/docs/plans/evidence/grpc-data-ext/A2.md @@ -1,5 +1,41 @@ # A2 — progress log and evidence +## Security review (A2b) fixes — progress log + +- Commit `91f1f729` on `a2-wire` (code + tests), then this evidence. Not merged, not pushed. + +| # | Finding | Resolution | Test | Red on revert | +|---|---|---|---|---| +| 1 | Exception after apply reported as "nothing applied", claim leaked, audit skipped | Only `OriginConditionSourceUnavailableException` (new, thrown by `DeferredOriginConditionSource` when the server is down) counts as nothing-applied. Any other exception from the port ⇒ claim marked dispatched + completed `OutcomeUnknown` (`BadInternalError`), joiners get the same. A `finally` always finishes the claim, and the outer `finally` always writes the audit record (`OutcomeUnknown` if no result), with the audit call guarded so it cannot throw | `An_exception_after_dispatch_answers_OutcomeUnknown_finishes_the_claim_and_is_audited`; `A_node_manager_that_is_not_running_is_nothing_applied_and_retains_no_entry` | **yes**: catch widened back to `InvalidOperationException` ⇒ the first test is red (M1) | +| 2 | One principal can exhaust the 4096-entry registry | `WriteOperationRegistry` gains `maxEntriesPerPrincipal` (case-insensitive per-principal count) and `ReleaseUndispatched` (removes only an entry completed as rejected before dispatch). Facade/NM refusals release their entry, and refusals before the claim never touch the registry. Limits: `DataConnections:MaxConditionMethodOperations` (4096) / `MaxConditionMethodOperationsPerPrincipal` (256), validated (1..65536, per-principal ≤ total), via `LocalDataRuntimeLimits` → `LocalDataServices.ConditionMethodMaxOperations[PerPrincipal]`. The write path keeps its old behaviour (per-principal cap defaults to the global cap) | `One_principal_cannot_exhaust_the_registry_for_another`, `The_global_registry_cap_holds_across_principals`, `Refusals_retain_no_registry_capacity`, registry unit `A2b_the_per_principal_cap_…_release_frees_the_slot` | **yes**: per-principal check removed ⇒ 2 red (M2); global check removed ⇒ global test red (M3); release removed ⇒ refusal + not-running tests red (M4) | +| 3 | Audit category unused, default logger possibly NullLogger | `DataConnectionRegistration.AddDataConnectionAuditLog` registers `IDataConnectionAuditLog` = `LoggerDataConnectionAuditLog.Create(ILoggerFactory)` (category `ZB.MOM.WW.OtOpcUa.DataConnections.Audit`). `LocalDataRuntimeComposition` takes it and sets `Services.Audit` | Host `The_registered_audit_log_writes_on_its_own_category_from_the_real_logger_factory` (real registered graph + capturing provider: the composition's `Audit` is the DI instance, and one line lands on the audit category) | **yes**: composition ignoring the passed audit ⇒ red (M7) | +| 4 | Only `on_behalf_of` sanitised | The audit entry is built with every caller-supplied string sanitised (`OperationId`, placement cluster/namespace/identifier kind/identifier/subject/mapping id, principal, key id), max 512 UTF-16 units each. `LoggerDataConnectionAuditLog` sanitises again (defence in depth). No other log site prints these strings | `Every_caller_supplied_audit_string_is_sanitised` (CR/LF/BEL/U+2028/NUL in op id and placement) | **yes**: field sanitiser → identity ⇒ red (M6) | +| 5 | Activation sequence restarts at 0 for a re-created condition | `_activationSequenceSource`: one monotonic counter for the node-manager lifetime (= `ConditionIncarnation`'s lifetime). Every fresh `ActivationEntry` and every bump draws `++counter`, and rebuild carry-over keeps its value. A sequence now only grows, by any step (the T3 test asserts "moves", not "+1") | `A_condition_removed_and_re_created_never_accepts_a_marker_of_its_previous_incarnation` (remove + re-materialise + same-shape raise ⇒ the old marker gets `BadEventIdUnknown`, nothing routed) | **yes**: per-entry `0` + `Sequence++` ⇒ red (M10) | +| 6 | Mutation-test gaps | Cross-principal join: `Principal_B_reusing_principal_As_operation_id_never_joins_As_operation`. Native AddComment off-Primary, plus scripted AddComment off-Primary: `AddComment_is_refused_off_Primary_for_a_native_and_a_scripted_condition`. Scripted AddComment on Warm Standby: `A_scripted_AddComment_is_refused_on_a_Warm_Standby`. Capacity, incarnation and exception-after-dispatch: rows 1, 2, 5 | see left | cross-principal: **yes** (registry key ignoring principal ⇒ red, M5). AddComment off-Primary: **yes** (NM Primary gate disabled ⇒ red, M11). Warm Standby AddComment: **no for one layer** (the TryExecute standby check alone is masked by the handler's `HandleAlarmCommand` standby check, M12), **yes with both layers disabled** (M12b) | +| 7 (nit) | AddComment status text | A native AddComment now says "AcceptedUnconfirmed: the comment was applied at the origin (not sent to the driver) …". It is not driver-routed, and the old "routed to the driver" text was wrong. State unchanged (`AcceptedUnconfirmed`) | covered by existing facade tests | text only, no mutation test | +| 8 (nit) | Sanitiser: lone surrogates / private-use / format | Drops Cc, Cf, Co (BMP **and** planes 15/16), Cn, Zl, Zp and lone surrogates. Never splits a pair at the cap, so the output is always well-formed UTF-16 | `SanitizeAuditText_drops_private_use_and_lone_surrogates_and_stays_well_formed` (strict UTF-8 round trip) | **yes**: PrivateUse dropped from the set ⇒ red (M8) | +| 9 (nit) | TOCTOU between authorization and apply | Documented on `CallConditionMethodAsync` (``). The window is one synchronous hop with no I/O, the same as a local client's call. Revocation stops later calls. Serving-identity changes are re-checked under `Lock` (Primary, Warm Standby), and the activation marker refuses a re-created condition. Not closed: a grant revoked inside that hop is not re-checked | — | doc | +| 10 (nit) | Unbounded origin wait on NM `Lock` | `TryExecuteConditionMethod` uses `Monitor.TryEnter(Lock, ConditionMethodLockTimeout)` (default 5 s = the consumer's default `ConditionMethodTimeoutMilliseconds`). Not acquired ⇒ `BadTimeout`, nothing applied | `A_remote_call_waits_a_bounded_time_for_the_Lock_and_is_refused_unapplied` (Lock held on another thread, 100 ms bound) | **yes**: `Monitor.Enter` ⇒ red after the 30 s holder (M13) | +| 11 (nit) | Consumer cancel after send must be OutcomeUnknown | The `OperationCanceledException` rethrow is removed: any failure after the request reaches the transport, a caller cancel included, answers `OutcomeUnknown` (`BadCommunicationError`) | `A_caller_cancel_after_the_request_was_sent_is_OutcomeUnknown_not_a_clean_failure` | **no**: Grpc.Net.Client surfaces a caller cancel as `RpcException(Cancelled)` (the channel does not set `ThrowOperationCanceledOnCancellation`), which was already mapped to `OutcomeUnknown`. The removed rethrow was reachable only by a bare `OperationCanceledException`. The test pins the behaviour but is green with the rethrow restored (M9) | + +**Mutation record (all restored, tree clean afterwards):** M1–M8, M10, M11, M12b, M13 each turned their target test(s) red. M9 and M12 (single layer) stayed green, as explained above. M5 also reddened the existing registry test `Hash_is_copied_and_conflicting_payload_or_stale_incarnation_cannot_dispatch`. + +New configuration keys (Host, `DataConnections` section): `MaxConditionMethodOperations` (default 4096) and +`MaxConditionMethodOperationsPerPrincipal` (default 256). Both are validated at startup. AdminUI and Configuration were +not touched. + +### Security review (A2b) — gates + +| Gate | Result | +|---|---| +| `dotnet build ZB.MOM.WW.OtOpcUa.slnx` | 0 warnings, 0 errors | +| `run-unit-phase.py` A2 / A1 / H2 / X0 (one at a time) | passed / passed / passed / passed | +| Host.Tests `.DataConnections.` + options (both v1 gates) | 206 passed; `git diff master -- '*Goldens.cs'` empty (never re-recorded) | +| Runtime.Tests (`Category!=E2E&Category!=LiveIntegration`) | 2022 passed, 3 skipped | +| OpcUaServer.Tests (same filter) | 1451 passed, 1 skipped | +| AdminUI.Tests / Configuration.Tests | not run (neither project nor what they cover was touched) | +| Live `conditions_smoke.py` | **PASS**, run `a2s1-cond-1` at `91f1f729` (clean tree, `source_tree_hash` `452965d34713…`): up `--conditions` → seed → ~85 s → deploy → smoke → down. source-1 (Primary): ops 31 without the header, 479 with it; snapshot v3 active/unacked marker `f708524d:2`, which is the node-manager-wide sequence and no longer starts at 1. Remote ack `DriverConfirmedSuccess` (2); the duplicate joins and is equal; header-less ⇒ `FailedPrecondition`; deltas v4/v5 acked, comment "A2b remote ack", `clientUserId` fixture-consumer, v6 inactive; no RawPath. source-2 (Secondary): ack refused "not the redundancy Primary"; ops 87. Origin subscriber: 4 ScalarHigh events, exactly one Active+Acknowledged. Audit lines on source-1: the ack and the same line `(joined)`. `rig.py down`: no run-labelled containers, volumes or networks left | + ## Review round 1 (Fable, A2a range `68a9d518..81cee9b5e`, approve-with-changes) — progress log - Commits on `a2-wire` after `95d90c19`: `fbf9f7b8` (A1 F5 diagnostic defect), `69014cc4` (B1), `7694eb67` (N3),