From 45c38023a7554253a11163bb3f8dae9069e2e69b Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Tue, 24 Nov 2026 09:30:31 -0500 Subject: [PATCH] docs(grpc-data): A1 placements/keys/ids evidence, public API and deviations --- docs/plans/evidence/grpc-data-ext/A1-keys.md | 83 ++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 docs/plans/evidence/grpc-data-ext/A1-keys.md diff --git a/docs/plans/evidence/grpc-data-ext/A1-keys.md b/docs/plans/evidence/grpc-data-ext/A1-keys.md new file mode 100644 index 000000000..1f54f6eea --- /dev/null +++ b/docs/plans/evidence/grpc-data-ext/A1-keys.md @@ -0,0 +1,83 @@ +# A1 (placements / keys / ids) — progress log and evidence + +Phase A1 of `docs/plans/2026-11-23-grpc-data-connections-history-alarms-plan.md` (rev. 7), the **placements / keys / ids** +slice only, 2026-11-24. The condition-state machinery (NM snapshot, `state_known`, signals, `ConditionStateHub`) is a parallel +branch and is not touched here (no NM, `OpcUaPublishActor`, driver or scripted-alarm-engine edits). + +## Progress log + +- [x] `ImportedConditionIds` (`c1.` identifier, child ids, condition namespace) + tests +- [x] `ConditionKeys` derivation + `DataConnections:ConditionKeySecret` option/validation/registration + tests +- [x] Realm-local condition placement enumeration in `LocalExportCatalog` (+ coordinator listing) + tests (UNS-only property test, + with a red control: leaking `plan.NodeId` into a UNS placement's Subject turns the property test red) +- [x] `A1` manifest key (Abstractions, Runtime, Host); gates below +- Next (not this slice): A2 consumes `TryListConditions` with `DataOperations.AlarmSubscribe` once that bit is understood, puts + `condition_key` + `ConditionInfo.placements` on the wire, and resolves method placements through + `TryResolveConditionPlacement`; the core branch's `ConditionStateHub` maps a condition to its placements via `PlacementsOf`. + +## Public API (for the core agent and A2) + +| Where | API | +|---|---| +| `Core.Abstractions/DataConnections/ImportedConditionIds.cs` | `NamespaceUri` (`https://zb.com/otopcua/mapped/conditions`), `IsConditionNamespace(uri)`, `Identifier(connectionId, conditionKey)` ⇒ `c1.`+base64url(JSON{ConnectionId,ConditionKey}), `TryDecodeIdentifier(id, out connectionId, out conditionKey)` (bare condition, canonical only), `ChildIdentifier(conditionId, browsePath)`, `TryParse(id, out conditionIdentifier, out connectionId, out conditionKey, out browsePath?)` (splits at the first `/`), `IsValidBrowsePath`, `IsWellFormedConditionKey` (43 base64url chars = 32 bytes), `ConditionKeyLength`, `ChildSeparator` | +| `Runtime/DataConnections/ConditionKeys.cs` | `ConditionKeys.FromSecret(secret)` (absent ⇒ `Unavailable`; weak ⇒ `ArgumentException`), `Unavailable`, `IsAvailable`, `UnavailableReason`, `Derive(originClusterId, AddressSpaceRealm, conditionId)`, `SecretProblem(secret)`, `IsProvisioned`, `MinimumSecretBytes` (32), `DerivationInfo` | +| `Runtime/DataConnections/ConditionPlacements.cs` | `ConditionSourceKind {Native=1, Scripted=2}`, `OriginConditionRef(AddressSpaceRealm Realm, string ConditionId)` (origin-internal; the NM realm key), `LocalConditionPlacement(View, Parent, Scope, BrowseName, SourceKind, Condition, EntityKind, EntityId)` (origin-internal) + `ToView()`, `ConditionPlacementView(View, Parent, BrowseName)` and `ExportedCondition(ConditionKey, SourceKind, Placements)` (peer-safe) | +| `LocalExportCatalog` | `ConditionPlacements`, `TryResolveConditionPlacement(view, out placement)` (unmapped address+realm; Subject ignored), `PlacementsOf(OriginConditionRef)`, `ListConditions(principal, root, operation, keys)`, internal `AllowsConditionPlacement(principal, placement, operation)`; ctor gained optional `conditionPlacements` | +| `LocalCatalogCoordinator` | `ConditionKeys { get; init; }` (default `Unavailable`; the host wires the configured one), `TryListConditions(principal, root, operation, out conditions)` (false while no catalog is served or no secret) | +| Host | `DataConnectionOptions.ConditionKeySecret`; `ConditionKeys` singleton; one Information log of the fail-closed diagnostic when absent | + +## Placements (§5.2) + +- **Raw**: every alarm-bearing raw tag (`RawTagPlan.Alarm != null`): View = raw ns at the RawPath, Parent = its device/group + folder, Scope = the raw tag's ACL subject, Condition = `(Raw, RawPath)`. +- **UNS native**: every `UnsTagReference` (in the cluster) to an alarm-bearing tag: View = uns ns at the reserved id + `V3NodeIds.UnsChild(V3NodeIds.Uns(area, line, equipment), effectiveName)` — the same derivation the composer skips for #896; + Subject = that id; Parent = the equipment's catalog view (identifier = EquipmentId); Scope = `DataScopeSubjects.Owned(equipment + scope)`; Condition = `(Raw, RawPath)` (internal only). +- **UNS scripted**: every **enabled** `EquipmentScriptedAlarmPlan` (the producer the NM materialises from): View = uns ns at the + ScriptedAlarmId, Subject = equipment path + alarm name, Parent = equipment, Scope = equipment-owned, Condition = `(Uns, ScriptedAlarmId)`. +- Listing (`ListConditions`): placements in the root's realm whose parent is under the root and that pass the principal's export + rule for the operation, grouped by condition, keyed with `condition_key`; ordered by key, placements by identifier. + +## Decisions / deviations + +1. **Realm byte in the key input.** The plan's formula is `HMAC(K, originClusterId ‖ 0x00 ‖ ConditionId)`. Implemented as + `HMAC(K, upper(originClusterId) ‖ 0x00 ‖ realm(1=Raw|2=Uns) ‖ ConditionId)`: a native ConditionId (RawPath) and a scripted one + (ScriptedAlarmId) live in the NM's realm-keyed map and nothing prevents equal strings, so the realm keeps two conditions from + sharing a key. Cluster ids are upper-cased (they compare OrdinalIgnoreCase everywhere). HKDF uses an empty salt; output 32 bytes. +2. **Missing secret is not a startup error** (§5.2 "fail closed, with a diagnostic"): `ConditionKeys.Unavailable` + one Information + log line. A **provisioned** secret that is < 32 UTF-8 bytes, blank, contains control characters or still holds an unexpanded + `${secret:` is a `DataConnectionOptionsValidator` error (startup), only while `DataConnections:Enabled`. Messages never echo + the value. No dev literal added to docker-dev / grpc-data rig (A1 is invisible; A2/A3 will need one on the rig's origins). +3. **Operation-parameterised listing.** `ListConditions` takes the required export bit. A2 passes `AlarmSubscribe`; today + `DataOperationSets.Understood` masks it out of every export rule, so production listings are empty until A2 — tests use + `Subscribe`. No wire, proto or v1-listing change. +4. **Placements are a separate index, not catalog nodes.** A Raw placement shares its address with the v1 raw tag node (#917); + UNS placements have no node (#896). They are not counted in `maximumNodes` (a v1 catalog that compiled before still compiles). + An address claimed by two placements is dropped (fail closed for conditions) rather than failing the compile. +5. **Composer now gets the cluster's scripted alarms** (`LocalExportCatalog.Compile` passed `[]` before) so scripted placements + come from the same `EquipmentScriptedAlarms` the NM materialises; a test pins that the v1 node set is identical with and + without them. +6. **UNS native placement scope** = equipment-owned subject (§5.2 "authorized against that placement's origin ACL subject (the + equipment scope)"), not the reference's tag-level path. +7. `ImportedConditionIds` is **not** added to `ProjectedDataIds.IsMappedNamespace` (that would change v1 classifiers/NM); the core + branch must dispatch `IsConditionNamespace` before `RealmOf` (guard test is theirs/A3's). + +## Questions (tracked, not asked) + +- Q-A1k-1: should the plan text adopt the realm byte (deviation 1)? A2 golden tests should pin the exact derivation. +- Q-A1k-2: rig provisioning — A2 needs `DataConnections__ConditionKeySecret` on both `source-*` services in + `scripts/validation/grpc-data/compose.yml` (a dev literal, identical on the pair). + +## Gates + +| Gate | Result | +|---|---| +| `dotnet build ZB.MOM.WW.OtOpcUa.slnx` | 0 errors / 0 warnings | +| `run-unit-phase.py A1` (Abstractions 7 + Runtime 8 + `GrpcDataLocalExportCatalogTests` + Host 7 + `GrpcDataV1RealOriginCompatibilityTests`) | passed | +| `run-unit-phase.py X0`, `H2` | passed | +| `test_unit_phase_runner.py` | 30 passed | +| Runtime.Tests (`Category!=E2E&Category!=LiveIntegration`) | 1923 passed, 3 skipped, 0 failed | +| Core.Abstractions.Tests (full) | 860 passed | +| Host.Tests `.DataConnections.` | 196 passed | +| Red control | UNS placement Subject = RawPath ⇒ the property test fails (reverted) |