Merge #941/#942/#943: gRPC data consumer skips unbuildable browse kinds; DataExportRootAlarmBearing deploy/authoring gate; outside-grant addresses answer NotFound (GetMetadata/Read/Subscribe/condition admission)
This commit is contained in:
@@ -174,6 +174,15 @@ public static class DataConnectionValidator
|
||||
"VirtualTag" => draft.VirtualTags.FirstOrDefault(x => Same(x.VirtualTagId, entityId)) is { } virtualTag ? EquipmentOwner(virtualTag.EquipmentId) : null,
|
||||
_ => null
|
||||
};
|
||||
bool AlarmBearing(string? tagId) => draft.Tags.FirstOrDefault(x => Same(x.TagId, tagId)) is { } tag
|
||||
&& TagConfigIntent.Parse(tag.TagConfig).Alarm is not null;
|
||||
bool AlarmBearingRoot(string? kind, string? entityId) => kind switch
|
||||
{
|
||||
"RawTag" => AlarmBearing(entityId),
|
||||
"UnsTagReference" => draft.UnsTagReferences.FirstOrDefault(x => Same(x.UnsTagReferenceId, entityId)) is { } reference
|
||||
&& AlarmBearing(reference.TagId),
|
||||
_ => false
|
||||
};
|
||||
string? DeviceOwner(string deviceId)
|
||||
{
|
||||
var device = draft.Devices.FirstOrDefault(x => Same(x.DeviceId, deviceId));
|
||||
@@ -332,6 +341,17 @@ public static class DataConnectionValidator
|
||||
// must stay false; a deployed row from a newer central that carries both is tolerated (the flag is inert here).
|
||||
if (export.AllowGalaxyServiceAck && !export.AllowedOperations.HasFlag(DataOperations.AlarmAcknowledge))
|
||||
Add("DataExportGalaxyAckInvalid", id, "Galaxy service acknowledgement can be allowed only on an export that grants AlarmAcknowledge.");
|
||||
// #942: an alarm-bearing tag is never a value (#917: an unsupported value node, hidden from Browse; #896: no UNS
|
||||
// variable), and its condition placements sit under the tag's folder / the referencing equipment, never under the
|
||||
// tag. So an export rooted at the tag (RawTag) grants nothing at all, and one rooted at a reference to it
|
||||
// (UnsTagReference) names a node the origin never compiles — the node's catalog compile then refuses the whole
|
||||
// export set. Refused at authoring and at the deploy gate only: a node re-validating an already-deployed artifact
|
||||
// (deployed) keeps its tolerant behaviour.
|
||||
if (!deployed && AlarmBearingRoot(export.RootKind, export.RootEntityId))
|
||||
Add("DataExportRootAlarmBearing", id,
|
||||
"An export cannot be rooted at an alarm-bearing tag or a reference to one: the tag carries no value and its " +
|
||||
"alarm is exported as a condition under the tag's folder (Raw) or the referencing equipment (UNS). Root the " +
|
||||
"export at that folder, device or equipment instead.");
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
+3
-1
@@ -61,7 +61,9 @@ public sealed partial class LocalDataServices
|
||||
if (catalog is null || !Ready(catalog) || !RoleAllows(target, catalog.Serving)) return DataItemStatus.Unavailable;
|
||||
if (!string.Equals(catalog.Serving.Role, "Primary", StringComparison.OrdinalIgnoreCase)) return DataItemStatus.Unavailable;
|
||||
if (context.AuthorityEpoch != catalog.AuthorityEpoch || !_policy.IsCallerUsable(Caller(context))) return DataItemStatus.Denied;
|
||||
if (!catalog.TryResolve(view, out var node)) return catalog.ContainsAddress(view) ? DataItemStatus.Denied : DataItemStatus.NotFound;
|
||||
// #943: a root outside the caller's grant is answered exactly like a missing one (no existence oracle).
|
||||
if (!catalog.DisclosesAddress(context.PrincipalId, view)) return DataItemStatus.NotFound;
|
||||
if (!catalog.TryResolve(view, out var node)) return DataItemStatus.Denied;
|
||||
var root = node.Metadata.View;
|
||||
if (catalog.ConditionLimitFor(context.PrincipalId, root) is not { } limit) return DataItemStatus.Denied;
|
||||
var serving = catalog.Serving;
|
||||
|
||||
@@ -154,7 +154,9 @@ public sealed partial class LocalDataServices : IDataConnectionFactory
|
||||
target.Mode == DataTargetMode.Node && !string.Equals(target.ExpectedNodeId, catalog.Serving.NodeId, StringComparison.OrdinalIgnoreCase))
|
||||
return DataItemStatus.Unavailable;
|
||||
if (!_policy.IsCallerUsable(Caller(context))) return DataItemStatus.Denied;
|
||||
if (!catalog.TryResolve(view, out var node)) return catalog.ContainsAddress(view) ? DataItemStatus.Denied : DataItemStatus.NotFound;
|
||||
// #943: an address outside the caller's grant is answered exactly like a missing one (no existence oracle).
|
||||
if (!catalog.DisclosesAddress(context.PrincipalId, view)) return DataItemStatus.NotFound;
|
||||
if (!catalog.TryResolve(view, out var node)) return DataItemStatus.Denied;
|
||||
if (!Allowed(catalog, context, node, DataOperations.Subscribe)) return DataItemStatus.Denied;
|
||||
var source = node.Source;
|
||||
if (!node.Supported || source is null) return DataItemStatus.Unsupported;
|
||||
@@ -263,7 +265,9 @@ public sealed partial class LocalDataServices : IDataConnectionFactory
|
||||
var view = request.Views[i]; view.Validate();
|
||||
var status = !Ready(catalog) || Expired(start, request.Budget) ? DataItemStatus.Unavailable
|
||||
: !_policy.IsCallerUsable(Caller(context)) ? DataItemStatus.Denied
|
||||
: !catalog.TryResolveAddress(view, out _) ? catalog.ContainsAddress(view) ? DataItemStatus.Denied : DataItemStatus.NotFound
|
||||
// #943: an address outside the caller's grant is answered exactly like a missing one (no existence oracle).
|
||||
: !catalog.DisclosesAddress(context.PrincipalId, view) ? DataItemStatus.NotFound
|
||||
: !catalog.TryResolveAddress(view, out _) ? DataItemStatus.Denied
|
||||
: DataItemStatus.Good;
|
||||
DataMetadata? metadata = null;
|
||||
MetadataLease? itemLease = null;
|
||||
@@ -323,8 +327,9 @@ public sealed partial class LocalDataServices : IDataConnectionFactory
|
||||
new(item.CorrelationId, status, readiness, null, null, null);
|
||||
if (!Ready(catalog) || Expired(start, request.Budget)) { results.Add(Empty(DataItemStatus.Unavailable)); continue; }
|
||||
if (!_policy.IsCallerUsable(Caller(context))) { results.Add(Empty(DataItemStatus.Denied)); continue; }
|
||||
if (!catalog.TryResolve(item.View, out var node))
|
||||
{ results.Add(Empty(catalog.ContainsAddress(item.View) ? DataItemStatus.Denied : DataItemStatus.NotFound)); continue; }
|
||||
// #943: an address outside the caller's grant is answered exactly like a missing one (no existence oracle).
|
||||
if (!catalog.DisclosesAddress(context.PrincipalId, item.View)) { results.Add(Empty(DataItemStatus.NotFound)); continue; }
|
||||
if (!catalog.TryResolve(item.View, out var node)) { results.Add(Empty(DataItemStatus.Denied)); continue; }
|
||||
if (!Allowed(catalog, context, node, DataOperations.Read)) { results.Add(Empty(DataItemStatus.Denied)); continue; }
|
||||
if (!node.Supported) { results.Add(Empty(DataItemStatus.Unsupported)); continue; }
|
||||
if (!node.SourceEnabled) { results.Add(Empty(DataItemStatus.Unavailable)); continue; }
|
||||
@@ -399,10 +404,11 @@ public sealed partial class LocalDataServices : IDataConnectionFactory
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
if (Expired(start, request.Budget)) return Task.FromResult(Empty(DataItemStatus.Unavailable));
|
||||
var child = children[offset++];
|
||||
// #917: an unsupported value node (an alarm-bearing tag, or a data type v1 cannot carry) is never listed. Every
|
||||
// consumer build applies a browse page all-or-nothing and cannot materialise one, so listing it made the whole
|
||||
// #917: an unsupported value node (an alarm-bearing tag, or a data type v1 cannot carry) is never listed. Consumer
|
||||
// builds before #941 apply a browse page all-or-nothing and cannot materialise one, so listing it made the whole
|
||||
// folder unbrowsable on the consumer (BadNoCommunication). It stays addressable (GetMetadata/Read/Subscribe on it
|
||||
// answer Unsupported). An export rooted at it still compiles but grants nothing. A skipped node is not counted
|
||||
// answer Unsupported). A deployed export rooted at it still compiles but grants nothing (authoring and the deploy
|
||||
// gate refuse an alarm-bearing root, #942). A skipped node is not counted
|
||||
// against the scan bound (it costs one check; the budget timeout above still bounds the call), so the skip never
|
||||
// yields an empty Complete=false page.
|
||||
if (child.Source is not null && !child.Supported) continue;
|
||||
|
||||
+3
-2
@@ -139,8 +139,9 @@ public sealed partial class LocalExportCatalog
|
||||
// #917: an alarm-bearing tag never gets a value (DriverHostActor keeps it out of the value fan-out; #896 gives it
|
||||
// no UNS variable), so it is an unsupported value node: Browse does not list it (LocalDataServices) and every
|
||||
// value operation answers Unsupported, instead of a Variable a consumer would wait on forever. The node is KEPT so
|
||||
// an export rooted at it still compiles, but such a root grants nothing: its values are unsupported and its
|
||||
// condition placement sits under its folder, not under the tag. The alarm is forwarded as a condition (A1–A4).
|
||||
// a deployed export rooted at it still compiles, but such a root grants nothing: its values are unsupported and its
|
||||
// condition placement sits under its folder, not under the tag — so authoring and the deploy gate refuse that root
|
||||
// (#942, DataConnectionValidator "DataExportRootAlarmBearing"). The alarm is forwarded as a condition (A1–A4).
|
||||
var supported = plan.Alarm is null && kind != DataValueKind.Unspecified
|
||||
&& (!plan.IsArray || DataValue.IsSupportedArrayElementKind(kind));
|
||||
var rawView = View(DataRealm.Raw, plan.NodeId, scope);
|
||||
|
||||
@@ -147,7 +147,26 @@ public sealed partial class LocalExportCatalog
|
||||
}
|
||||
private DataAddress LocalAddress(DataAddress address) => string.Equals(address.OriginClusterId, ClusterId, StringComparison.OrdinalIgnoreCase)
|
||||
? address with { OriginClusterId = ClusterId } : address;
|
||||
internal bool ContainsAddress(DataView view) => _nodes.ContainsKey((LocalAddress(view.Address), view.Realm));
|
||||
/// <summary>
|
||||
/// #943: whether a per-item refusal for <paramref name="view"/> may say "exists": the node at the view's address (in
|
||||
/// its realm, whatever the view's other fields claim) is inside the principal's grant — some export rule of the
|
||||
/// principal with at least one operation covers it (its root contains it, or it is a browsable ancestor of the root).
|
||||
/// When this is false the address must be answered exactly like a missing one, so a peer granted one subtree cannot
|
||||
/// probe guessed addresses elsewhere and learn which exist (the existence oracle).
|
||||
/// </summary>
|
||||
internal bool DisclosesAddress(string principal, DataView view)
|
||||
{
|
||||
if (!_nodes.TryGetValue((LocalAddress(view.Address), view.Realm), out var node)) return false;
|
||||
var target = node.Metadata.View;
|
||||
foreach (var rule in _exports)
|
||||
{
|
||||
if (!string.Equals(principal, rule.Principal, StringComparison.OrdinalIgnoreCase) || rule.Realm != target.Realm
|
||||
|| rule.Operations == DataOperations.None) continue;
|
||||
if (rule.WholeRealm || IsAncestor(rule.Root!, target)
|
||||
|| ((rule.Operations & DataOperations.Browse) != 0 && IsAncestor(target, rule.Root!))) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
internal bool TryResolveAddress(DataView view, out LocalDataNode node)
|
||||
{
|
||||
if (view.MappingId is null && view.MappingRevision == 0 && _nodes.TryGetValue((LocalAddress(view.Address), view.Realm), out var found))
|
||||
|
||||
@@ -131,6 +131,26 @@ public sealed class ProjectedCatalogCache
|
||||
}
|
||||
};
|
||||
internal static bool IsValueNode(DataMetadata metadata) => metadata.NodeKind is "Variable" or "Tag";
|
||||
|
||||
/// <summary>
|
||||
/// #941: whether this build can materialise an origin browse item at all — a <c>Folder</c>, or a <c>Variable</c> /
|
||||
/// <c>Tag</c> whose scalar (or array element) kind has an OPC UA built-in type here. Mirrors the kind/type checks of
|
||||
/// <c>OtOpcUaNodeManager.TryEnsureProjectedVariable</c> (its <c>typeName</c> switch): Guid and Bytes have none. An item
|
||||
/// that is not materialisable (an <c>UnsupportedVariable</c> from a pre-#917 origin, a node kind a newer origin adds, a
|
||||
/// value type the consumer cannot represent) is SKIPPED by the resolver; it used to fail the whole page, making the
|
||||
/// folder <c>BadNoCommunication</c>. A malformed item of a supported kind (rank / dimensions / element kind that do
|
||||
/// not agree) still fails the page closed — that is a protocol violation, not an unknown kind.
|
||||
/// </summary>
|
||||
internal static bool IsMaterialisable(DataMetadata metadata) => metadata.NodeKind switch
|
||||
{
|
||||
"Folder" => true,
|
||||
"Variable" or "Tag" => HasBuiltInType(metadata.ValueKind == DataValueKind.Array ? metadata.ArrayElementKind : metadata.ValueKind),
|
||||
_ => false
|
||||
};
|
||||
|
||||
private static bool HasBuiltInType(DataValueKind? kind) => kind is DataValueKind.Boolean or DataValueKind.Int8 or DataValueKind.UInt8
|
||||
or DataValueKind.Int16 or DataValueKind.UInt16 or DataValueKind.Int32 or DataValueKind.UInt32 or DataValueKind.Int64
|
||||
or DataValueKind.UInt64 or DataValueKind.Float or DataValueKind.Double or DataValueKind.String or DataValueKind.Timestamp;
|
||||
private static long Bytes(ProjectedNodeProof proof) => ProjectedProofSize.Estimate(proof);
|
||||
private static long KeyBytes(ParentKey k) => checked(256L + 2L * (k.Mapping.Length + k.Parent.Subject.Length +
|
||||
k.Parent.Address.OriginClusterId.Length + k.Parent.Address.NamespaceUri.Length + k.Parent.Address.IdentifierKind.Length +
|
||||
|
||||
@@ -254,6 +254,10 @@ public sealed class RemoteNamespaceResolver : IFederatedProjectionCatalog, IDisp
|
||||
var results = new List<ProjectedNodeProof>(); var seenNames = new HashSet<string>(StringComparer.Ordinal);
|
||||
foreach (var item in branch.Items)
|
||||
{
|
||||
// #941: an item this build cannot materialise is skipped, not a reason to fail the whole page (the applier and
|
||||
// the node manager apply a page all-or-nothing). It never enters the snapshot, the cache or the address space,
|
||||
// and its browse name does not count against the page's duplicate check.
|
||||
if (!ProjectedCatalogCache.IsMaterialisable(item)) continue;
|
||||
item.Validate();
|
||||
if (item.Serving != serving || item.View.MappingId is not null || item.View.Realm != request.Parent.Realm ||
|
||||
item.CatalogRevision != serving.CatalogEpoch || !string.Equals(item.View.Address.OriginClusterId, originParent.View.Address.OriginClusterId, StringComparison.OrdinalIgnoreCase) ||
|
||||
|
||||
Reference in New Issue
Block a user