Files
lmxopcua/src/Core/ZB.MOM.WW.OtOpcUa.Configuration/Entities/DataExport.cs
T
Joseph Doherty 8e2a793000 feat(grpc-data): #1084 secured writes over a data connection need an export-level opt-in; #1091 Galaxy reports gRPC write outcomes definitively
#1084 - DataExport.AllowSecuredWrites (default false; migration AddDataExportAllowSecuredWrites, a bit NOT NULL DEFAULT 0
column, no constraint => no MigrationPreChecks twin; the preflight's legacy-schema tolerance covers the missing column).
- Valid only with Write: validator code DataExportSecuredWriteInvalid at authoring, the deploy gate and on a deployed
  row (an artifact row breaking it fails closed), modelled on AllowGalaxyServiceAck.
- LocalExportCatalog keeps it per rule (counts only with Write) and answers AllowsSecuredWrite(principal, node): an
  export of the principal, in the node's realm, granting Write, opted in, whose root contains the node.
- DataWriteExecutor stamps DataWriteAdmission.AllowsSecuredWrite (new, default false) from the catalog generation that
  admitted the write (re-checked by the dispatch gate's commit), never from the request.
- DriverInstanceActor.RichCaller returns null without it, so the driver gets NO caller: the driver option
  MxAccess.SecuredWritesOverDataConnections alone no longer lets a forwarding consumer cluster's link key write
  SecuredWrite attributes. Fail closed by default.
- AdminUI export editor: "Allow secured writes under this peer's key identity" checkbox (enabled only with Write).

#1091 (a) - GalaxyDriver implements IWriteOutcomeCapability + ICallerAwareWriteOutcomeCapability. GalaxyWriteOutcomes
maps BadUserAccessDenied and the OnWriteComplete verdicts BadNotWritable/BadTypeMismatch/BadOutOfRange/
BadConfigurationError to DriverConfirmedFailure, Good to AcceptedUnconfirmed (a provisional Good is indistinguishable),
everything else to OutcomeUnknown. A refused secured write is now a definite BadUserAccessDenied, not OutcomeUnknown.
- RunRichWriteAsync precedence: caller-aware outcome overload (caller present) -> outcome overload -> ICallerAwareWritable
  (caller present) -> IWritable. Both earlier behaviours kept; the OPC UA path is unchanged.

Tests (each failed before its fix where applicable):
- End to end through the runtime path (artifact -> catalog -> DataWriteRuntime executor -> ActorDataWriteRoute ->
  DriverInstanceActor behind the real dispatch gate -> real GalaxyDriver): export opt-in x driver option matrix; only
  both commit as the key's identity, either alone refuses BadUserAccessDenied definitively with no identity lookup.
  Ignoring the flag in RichCaller fails 3 tests.
- Catalog scope (root containment, Write, principal), artifact round-trip + fail-closed row, validator, migration SQL +
  no pending model changes, AdminUI checkbox enable/save (bUnit), actor precedence, Galaxy outcome mapping.
- ScriptForeignKeysAndExternalIdUniquenessMigrationTests now migrate to THEIR migration, not the latest.

Docs: DataConnections.md (two-gate table), Galaxy.md, security.md, rules/drivers.md.
2026-12-04 14:58:16 -05:00

44 lines
2.7 KiB
C#

using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
namespace ZB.MOM.WW.OtOpcUa.Configuration.Entities;
/// <summary>Origin-local export grant for a named authenticated peer principal.</summary>
public sealed class DataExport
{
public Guid DataExportRowId { get; set; }
public string DataExportId { get; set; } = "";
public string ClusterId { get; set; } = "";
public long Revision { get; set; } = 1;
public bool Enabled { get; set; }
public DataRealm Realm { get; set; }
public string RootKind { get; set; } = "";
public string RootEntityId { get; set; } = "";
public string PrincipalId { get; set; } = "";
public DataOperations AllowedOperations { get; set; }
public int MaxBatchItems { get; set; } = 1000;
public int MaxPageItems { get; set; } = 500;
public int MaxMonitoredItems { get; set; } = 10000;
public int MaxStreams { get; set; } = 100;
/// <summary>H2: concurrent remote HistoryRead requests admitted per principal (past it ⇒ BadTooManyOperations).</summary>
public int MaxConcurrentHistoryReads { get; set; } = 4;
/// <summary>H2: per-node page ceiling of a remote raw read (an uncapped read pages at this and returns a continuation).</summary>
public int MaxHistoryValuesPerPage { get; set; } = 10000;
/// <summary>H2: response-byte cap; a larger answer is split into bounded chunks (chunk_continues).</summary>
public int MaxHistoryResponseBytes { get; set; } = 4 * 1024 * 1024;
/// <summary>A2: conditions one remote condition scope (subscription root) may carry; a larger scope is refused with
/// <c>Unavailable(ConditionCapacity)</c> before anything is materialised (plan §5.5).</summary>
public int MaxConditions { get; set; } = 1000;
/// <summary>A2 (used by A2b): per-export opt-in for remote acknowledgement of Galaxy conditions, which execute as the
/// origin's service identity (plan §5.6, Q2). Valid only with <c>AlarmAcknowledge</c>.</summary>
public bool AllowGalaxyServiceAck { get; set; }
/// <summary>
/// #1084: per-export opt-in for writes that act under the connection key's own identity (Galaxy SecuredWrite attributes,
/// written as the key's <c>/api-keys</c> Galaxy account). Without it the origin hands the driver NO caller for a write
/// admitted through this export, so a caller-aware driver refuses an identity-bearing write exactly as it would an
/// anonymous one — even with the driver's own <c>MxAccess.SecuredWritesOverDataConnections</c> on. Both are needed.
/// Valid only with <c>Write</c>. Default false (fail closed).
/// </summary>
public bool AllowSecuredWrites { get; set; }
public byte[] RowVersion { get; set; } = [];
}