From 808e1fe9852a4bd21733545394e4662bcf81ae81 Mon Sep 17 00:00:00 2001 From: Joseph Doherty Date: Mon, 23 Nov 2026 23:19:21 -0500 Subject: [PATCH] fix(grpc-data): H2 review2-7a - no aggregates or resolution for a peer without a HistoryRead grant The history field still marks that the origin has a historian (negotiation rule unchanged), but a principal with no HistoryRead export sees no aggregate names and resolution 0 (undisclosed). --- .../DataConnections/DataContracts.cs | 5 +++-- .../DataConnections/LocalDataServices.History.cs | 4 +++- .../DataConnections/GrpcDataHistoryWireTests.cs | 5 +++++ 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Core/ZB.MOM.WW.OtOpcUa.Core.Abstractions/DataConnections/DataContracts.cs b/src/Core/ZB.MOM.WW.OtOpcUa.Core.Abstractions/DataConnections/DataContracts.cs index bd301cb88..a30f1e559 100644 --- a/src/Core/ZB.MOM.WW.OtOpcUa.Core.Abstractions/DataConnections/DataContracts.cs +++ b/src/Core/ZB.MOM.WW.OtOpcUa.Core.Abstractions/DataConnections/DataContracts.cs @@ -291,7 +291,7 @@ public sealed record DataLimits(int MaxPageItems, int MaxBatchItems, int MaxMess /// HistoryRead-Processed (at least one aggregate served). /// HistoryRead-AtTime. /// The served aggregates, as stable HistoryAggregateType names. -/// The backend's stored timestamp resolution (QuestDB µs = 10); 1 = 100 ns. +/// The backend's stored timestamp resolution (QuestDB µs = 10); 1 = 100 ns; 0 = undisclosed (no grant). /// The origin's per-node page ceiling for this caller. /// The origin's concurrent history reads admitted per principal. /// How long an untaken origin continuation lives. @@ -301,7 +301,8 @@ public sealed record DataHistoryCapabilities(bool Raw, bool Processed, bool AtTi public void Validate() { ArgumentNullException.ThrowIfNull(Aggregates); - if (TimestampResolutionTicks <= 0 || MaxValuesPerPage <= 0 || MaxConcurrentReads <= 0 || ContinuationIdle <= TimeSpan.Zero + // Resolution 0 = undisclosed (the caller holds no HistoryRead grant on any export). + if (TimestampResolutionTicks < 0 || MaxValuesPerPage <= 0 || MaxConcurrentReads <= 0 || ContinuationIdle <= TimeSpan.Zero || Aggregates.Any(string.IsNullOrWhiteSpace)) throw new ArgumentOutOfRangeException(nameof(MaxValuesPerPage), "History capabilities must be positive."); } diff --git a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/LocalDataServices.History.cs b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/LocalDataServices.History.cs index 46962383d..fb9ba2f42 100644 --- a/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/LocalDataServices.History.cs +++ b/src/Server/ZB.MOM.WW.OtOpcUa.Runtime/DataConnections/LocalDataServices.History.cs @@ -63,7 +63,9 @@ public sealed partial class LocalDataServices internal DataHistoryCapabilities? HistoryCapabilitiesFor(LocalExportCatalog? catalog, DataAuthenticatedContext context) { if (HistoryServing is not { } serving) return null; - var limits = catalog?.HistoryLimitsFor(context.PrincipalId) ?? (4, 10_000, 4 * 1024 * 1024); + // Without a HistoryRead grant on some export the peer learns that history exists here, and nothing about it. + if (catalog?.HistoryLimitsFor(context.PrincipalId) is not { } limits) + return new DataHistoryCapabilities(false, false, false, [], 0, 10_000, 4, PeerHistoryIdle); return new DataHistoryCapabilities(true, serving.Aggregates.Count > 0, true, serving.Aggregates, serving.TimestampResolutionTicks, limits.ValuesPerPage, limits.ConcurrentReads, PeerHistoryIdle); } diff --git a/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataHistoryWireTests.cs b/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataHistoryWireTests.cs index a3a464a91..e6d22dc68 100644 --- a/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataHistoryWireTests.cs +++ b/tests/Server/ZB.MOM.WW.OtOpcUa.Host.Tests/DataConnections/GrpcDataHistoryWireTests.cs @@ -287,6 +287,11 @@ public sealed class GrpcDataHistoryWireTests await using var ungranted = new RealOrigin(exportOperations: DataOperationSets.V1, grantHistory: false); var denied = await Should.ThrowAsync(() => ungranted.HistoryAsync(Raw(I("a", RealOriginRequests.Flow)), History)); denied.StatusCode.ShouldBe(StatusCode.PermissionDenied); + // ...and its probe names no aggregates or resolution: nothing about the historian leaks to an ungranted peer. + var bare = W.CapabilitiesResponse.Parser.ParseFrom(Convert.FromHexString(await ungranted.DriveAsync("GetCapabilities", History))); + bare.History.ShouldNotBeNull(); + bare.History.Aggregates.ShouldBeEmpty(); + bare.History.TimestampResolutionTicks.ShouldBe(0); } [Fact]