Merge Galaxy gRPC write follow-ups: per-export AllowSecuredWrites opt-in (migration AddDataExportAllowSecuredWrites) required alongside the driver option (#1084); Galaxy reports gRPC write outcomes definitively + caller-aware write interfaces guarded by the analyzer (#1091)
This commit is contained in:
@@ -31,5 +31,13 @@ public sealed class DataExport
|
||||
/// <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; } = [];
|
||||
}
|
||||
|
||||
+1984
File diff suppressed because it is too large
Load Diff
+32
@@ -0,0 +1,32 @@
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class AddDataExportAllowSecuredWrites : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
// #1084: the export-level opt-in for secured (caller-identity) writes over a data connection. Non-null with a
|
||||
// false default, so every existing export keeps refusing them and no row needs a backfill. No check constraint:
|
||||
// "only with Write" is a validator rule (DataExportSecuredWriteInvalid), like AllowGalaxyServiceAck's.
|
||||
migrationBuilder.AddColumn<bool>(
|
||||
name: "AllowSecuredWrites",
|
||||
table: "DataExport",
|
||||
type: "bit",
|
||||
nullable: false,
|
||||
defaultValue: false);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "AllowSecuredWrites",
|
||||
table: "DataExport");
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
@@ -500,6 +500,9 @@ namespace ZB.MOM.WW.OtOpcUa.Configuration.Migrations
|
||||
b.Property<bool>("AllowGalaxyServiceAck")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("AllowSecuredWrites")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<int>("AllowedOperations")
|
||||
.HasColumnType("int");
|
||||
|
||||
|
||||
@@ -349,6 +349,10 @@ 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.");
|
||||
// #1084: the secured-write (caller-identity) opt-in qualifies the Write grant and means nothing without it. Checked
|
||||
// at authoring, at the deploy gate and on a deployed row alike (a deployed row breaking it fails closed).
|
||||
if (export.AllowSecuredWrites && !export.AllowedOperations.HasFlag(DataOperations.Write))
|
||||
Add("DataExportSecuredWriteInvalid", id, "Secured writes can be allowed only on an export that grants Write.");
|
||||
// #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
|
||||
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
namespace ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
||||
|
||||
/// <summary>
|
||||
/// #1091 — <see cref="IWriteOutcomeCapability" /> on behalf of a caller: the gRPC data-connection write path's
|
||||
/// explicit-outcome overload for a driver that also acts on the caller's identity (<see cref="ICallerAwareWritable" />;
|
||||
/// the Galaxy driver's SecuredWrite attributes). The runtime calls it when the admitted write carries a
|
||||
/// <see cref="WriteCaller" /> (the connection's key, and only when an export covering the node opts in to secured writes,
|
||||
/// #1084); a write without one goes to <see cref="IWriteOutcomeCapability.WriteWithOutcomesAsync" />. Either way the
|
||||
/// driver reports each write's outcome definitively where it can (e.g. a refused secured write is
|
||||
/// <see cref="DataWriteState.DriverConfirmedFailure" /> + <c>BadUserAccessDenied</c>, not <c>OutcomeUnknown</c>).
|
||||
/// </summary>
|
||||
public interface ICallerAwareWriteOutcomeCapability : IWriteOutcomeCapability
|
||||
{
|
||||
/// <summary>Write a batch on behalf of <paramref name="caller" />; one outcome per request, in order.</summary>
|
||||
/// <param name="writes">Pairs of full reference + value to write.</param>
|
||||
/// <param name="caller">Who issued the write.</param>
|
||||
/// <param name="cancellationToken">Cancellation token; the driver should abort the batch if cancelled.</param>
|
||||
/// <returns>One <see cref="DataWriteOutcome" /> per requested write, in the same order.</returns>
|
||||
Task<IReadOnlyList<DataWriteOutcome>> WriteWithOutcomesAsync(
|
||||
IReadOnlyList<WriteRequest> writes, WriteCaller caller, CancellationToken cancellationToken);
|
||||
}
|
||||
@@ -29,10 +29,16 @@ public sealed record WriteItem(string CorrelationId, string OperationId, DataVie
|
||||
/// recheck the original key's current principal and credential version against authority and its
|
||||
/// original expiry even when the epoch is unchanged. ApiKeyId and CredentialVersion are non-secret
|
||||
/// identifiers, never the bearer credential.
|
||||
/// <para>
|
||||
/// <paramref name="AllowsSecuredWrite"/> (#1084): whether an export covering the node opts in to secured (caller-identity)
|
||||
/// writes (<c>DataExport.AllowSecuredWrites</c>). Only then does the runtime hand the driver the connection's caller; false
|
||||
/// (the default — fail closed) dispatches the write with no caller, so a caller-aware driver refuses an identity-bearing
|
||||
/// write exactly as it would an anonymous one.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public sealed record DataWriteAdmission(string PrincipalId, DataView View, long AuthorityEpoch, long CatalogRevision,
|
||||
string ServingIncarnation, string DriverIncarnation, string OperationId, long MonotonicExpiry,
|
||||
string ApiKeyId, DateTimeOffset? CredentialExpiresUtc, string CredentialVersion)
|
||||
string ApiKeyId, DateTimeOffset? CredentialExpiresUtc, string CredentialVersion, bool AllowsSecuredWrite = false)
|
||||
{
|
||||
public void Validate()
|
||||
{
|
||||
|
||||
@@ -39,8 +39,9 @@ public enum WriteCallerOrigin
|
||||
/// attributes, written under the calling API key's Galaxy account). The runtime calls this overload instead
|
||||
/// of <see cref="IWritable.WriteAsync" /> whenever the write carries a <see cref="WriteCaller" />. Both data planes
|
||||
/// supply one: an OPC UA write from its session, a gRPC data-connection write from the connection's authenticated
|
||||
/// key (#1074) — except through <c>IWriteOutcomeCapability</c>, which takes precedence on the gRPC path and carries
|
||||
/// no caller. It must keep
|
||||
/// key (#1074), and only when the origin export opts in (<c>DataExport.AllowSecuredWrites</c>, #1084). On the gRPC path
|
||||
/// a driver that also implements <c>IWriteOutcomeCapability</c> is called through that instead — with a caller, through
|
||||
/// <c>ICallerAwareWriteOutcomeCapability</c> (#1091). It must keep
|
||||
/// every other behaviour of <see cref="IWritable.WriteAsync" />; a caller the driver cannot map is refused
|
||||
/// per write (e.g. <c>BadUserAccessDenied</c>), never silently written under another identity.
|
||||
/// </summary>
|
||||
|
||||
@@ -4,6 +4,7 @@ using Microsoft.Extensions.Logging.Abstractions;
|
||||
using ZB.MOM.WW.MxGateway.Client;
|
||||
using ZB.MOM.WW.MxGateway.Contracts.Proto;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Browse;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Config;
|
||||
using ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Health;
|
||||
@@ -38,7 +39,7 @@ namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy;
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
public sealed class GalaxyDriver
|
||||
: IDriver, ITagDiscovery, IReadable, IWritable, ICallerAwareWritable, ISubscribable, IRediscoverable, IHostConnectivityProbe, IAlarmSource, IAlarmInitialStateSignal, IAlarmAcknowledgePreflight, IAlarmAcknowledgeConfirmation, ISkippedTagReporter, IDisposable, IAsyncDisposable
|
||||
: IDriver, ITagDiscovery, IReadable, IWritable, ICallerAwareWritable, ICallerAwareWriteOutcomeCapability, ISubscribable, IRediscoverable, IHostConnectivityProbe, IAlarmSource, IAlarmInitialStateSignal, IAlarmAcknowledgePreflight, IAlarmAcknowledgeConfirmation, ISkippedTagReporter, IDisposable, IAsyncDisposable
|
||||
{
|
||||
/// <summary>Authored tags this driver could not dial — a TagConfig with no usable
|
||||
/// <c>attributeRef</c> has no MXAccess address to bind.</summary>
|
||||
@@ -2438,6 +2439,42 @@ public sealed class GalaxyDriver
|
||||
dialledWrites, attributeRef => ResolveSecurity(ToRawPath(attributeRef)), securedCredential, cancellationToken);
|
||||
}
|
||||
|
||||
// ===== IWriteOutcomeCapability (#1091) — the gRPC data-connection write path =====
|
||||
|
||||
/// <summary>
|
||||
/// #1091 — <see cref="WriteAsync(IReadOnlyList{WriteRequest}, CancellationToken)"/> reported as explicit outcomes for
|
||||
/// the gRPC data-connection write path (<see cref="GalaxyWriteOutcomes.From"/>): a refusal is a definite
|
||||
/// <see cref="DataWriteState.DriverConfirmedFailure"/> carrying its status (a refused secured write ⇒
|
||||
/// <c>BadUserAccessDenied</c>), where the legacy path reported every non-Good result as <c>OutcomeUnknown</c>.
|
||||
/// </summary>
|
||||
/// <param name="writes">Pairs of full reference (RawPath) + value.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>One outcome per request, in order.</returns>
|
||||
public Task<IReadOnlyList<DataWriteOutcome>> WriteWithOutcomesAsync(
|
||||
IReadOnlyList<WriteRequest> writes, CancellationToken cancellationToken)
|
||||
=> WithOutcomesAsync(writes, caller: null, cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// #1091 — <see cref="WriteAsync(IReadOnlyList{WriteRequest}, WriteCaller, CancellationToken)"/> (the caller's Galaxy
|
||||
/// identity for SecuredWrite attributes, under the same origin rules) reported as explicit outcomes.
|
||||
/// </summary>
|
||||
/// <param name="writes">Pairs of full reference (RawPath) + value.</param>
|
||||
/// <param name="caller">Who issued the write.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>One outcome per request, in order.</returns>
|
||||
public Task<IReadOnlyList<DataWriteOutcome>> WriteWithOutcomesAsync(
|
||||
IReadOnlyList<WriteRequest> writes, WriteCaller caller, CancellationToken cancellationToken)
|
||||
=> WithOutcomesAsync(writes, caller ?? throw new ArgumentNullException(nameof(caller)), cancellationToken);
|
||||
|
||||
private async Task<IReadOnlyList<DataWriteOutcome>> WithOutcomesAsync(
|
||||
IReadOnlyList<WriteRequest> writes, WriteCaller? caller, CancellationToken cancellationToken)
|
||||
{
|
||||
var results = await WriteCoreAsync(writes, caller, cancellationToken).ConfigureAwait(false);
|
||||
var outcomes = new DataWriteOutcome[results.Count];
|
||||
for (var i = 0; i < results.Count; i++) outcomes[i] = GalaxyWriteOutcomes.From(results[i]);
|
||||
return outcomes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #1074 — which data planes a SecuredWrite may run under the caller's identity on. An OPC UA session always
|
||||
/// (the #1017 opt-in alone); a gRPC data connection only with <c>MxAccess.SecuredWritesOverDataConnections</c>
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
using ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Driver.Galaxy.Runtime;
|
||||
|
||||
/// <summary>
|
||||
/// #1091 — how a Galaxy <see cref="WriteResult"/> reads as a gRPC data-connection <see cref="DataWriteOutcome"/>. Only a
|
||||
/// status that can arise solely from a definite verdict is reported as one; everything ambiguous stays
|
||||
/// <see cref="DataWriteState.OutcomeUnknown"/>, because a caller treats a definite failure as "the value did not change".
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <list type="bullet">
|
||||
/// <item><b>Good</b> ⇒ <see cref="DataWriteState.AcceptedUnconfirmed"/> (as the legacy path reported it): the writer
|
||||
/// reports a provisional Good off an EMPTY gateway statuses array (the completion wait timed out), which the result
|
||||
/// cannot tell apart from a confirmed one.</item>
|
||||
/// <item><b>Definite refusals</b> ⇒ <see cref="DataWriteState.DriverConfirmedFailure"/> with the status:
|
||||
/// <c>BadUserAccessDenied</c> — a local secured/verified-write refusal (no identity, origin not allowed, identity
|
||||
/// unresolvable), a failed <c>AuthenticateUser</c> (no <c>WriteSecured</c> sent), the gateway refusing the caller
|
||||
/// (<c>PermissionDenied</c>/<c>Unauthenticated</c>, nothing executed) or MXAccess's own access verdict (1008/1012/
|
||||
/// 1013/1016/1017); and the MXAccess <c>OnWriteComplete</c> verdicts <c>BadNotWritable</c>, <c>BadTypeMismatch</c>,
|
||||
/// <c>BadOutOfRange</c> and <c>BadConfigurationError</c>, which no transport/exception path of the writer produces.</item>
|
||||
/// <item><b>Everything else</b> ⇒ <see cref="DataWriteState.OutcomeUnknown"/> with the status:
|
||||
/// <c>BadCommunicationError</c> (protocol failure, exception, failed advise), <c>BadTimeout</c>, Uncertain
|
||||
/// (Pending/Warning), <c>BadInternalError</c>, generic Bad and any other code.</item>
|
||||
/// </list>
|
||||
/// </remarks>
|
||||
internal static class GalaxyWriteOutcomes
|
||||
{
|
||||
/// <summary>Maps one write result.</summary>
|
||||
/// <param name="result">The writer's result.</param>
|
||||
/// <returns>The data-connection outcome.</returns>
|
||||
public static DataWriteOutcome From(WriteResult result)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(result);
|
||||
var status = result.StatusCode;
|
||||
if (status == StatusCodeMap.Good) return new(DataWriteState.AcceptedUnconfirmed, status, null);
|
||||
return status switch
|
||||
{
|
||||
StatusCodeMap.BadUserAccessDenied => new(DataWriteState.DriverConfirmedFailure, status, "Write refused: access denied."),
|
||||
StatusCodeMap.BadNotWritable => new(DataWriteState.DriverConfirmedFailure, status, "Write refused: not writable."),
|
||||
StatusCodeMap.BadTypeMismatch => new(DataWriteState.DriverConfirmedFailure, status, "Write refused: type mismatch."),
|
||||
StatusCodeMap.BadOutOfRange => new(DataWriteState.DriverConfirmedFailure, status, "Write refused: out of range."),
|
||||
StatusCodeMap.BadConfigurationError => new(DataWriteState.DriverConfirmedFailure, status, "Write refused: configuration error."),
|
||||
_ => new(DataWriteState.OutcomeUnknown, status, "Write outcome unknown."),
|
||||
};
|
||||
}
|
||||
}
|
||||
+1
@@ -123,6 +123,7 @@ else
|
||||
<label class="form-label" for="export-history-bytes">History response bytes</label><input id="export-history-bytes" type="number" min="@DataConnectionValidator.MinHistoryResponseBytesLimit" max="@DataConnectionValidator.MaxHistoryResponseBytesLimit" class="form-control mb-2" @bind="e.MaxHistoryResponseBytes" /><div class="form-text">Larger answers are sent in bounded chunks.</div>
|
||||
<label class="form-label" for="export-max-conditions">Conditions per alarm subscription</label><input id="export-max-conditions" type="number" min="1" max="@DataConnectionValidator.MaxConditionsLimit" class="form-control mb-2" @bind="e.MaxConditions" /><div class="form-text">A remote AlarmSubscribe scope with more conditions than this is refused (ConditionCapacity) before anything is imported.</div>
|
||||
<label class="d-block"><input id="export-galaxy-ack" type="checkbox" @bind="e.AllowGalaxyServiceAck" disabled="@(!e.AllowedOperations.HasFlag(DataOperations.AlarmAcknowledge) && !e.AllowGalaxyServiceAck)" /> Allow remote acknowledge of Galaxy alarms</label><div class="form-text">Galaxy-sourced alarms are acknowledged under this peer's API-key Galaxy ack identity (provision <code>otopcua/apikeys/<keyId>/galaxy-ack-user</code> and <code>…/galaxy-ack-password</code> on this cluster). Requires AlarmAcknowledge.</div>
|
||||
<label class="d-block"><input id="export-secured-writes" type="checkbox" @bind="e.AllowSecuredWrites" disabled="@(!e.AllowedOperations.HasFlag(DataOperations.Write) && !e.AllowSecuredWrites)" /> Allow secured writes under this peer's key identity</label><div class="form-text">Galaxy SecuredWrite attributes written through this export run as this peer's API-key Galaxy identity (the same <code>otopcua/apikeys/<keyId>/galaxy-ack-*</code> secrets). Also needs the Galaxy driver's "Also for gRPC data-connection writes". If the peer is another OtOpcUa cluster, every client it forwards writes for writes as that one identity. Requires Write.</div>
|
||||
<label><input type="checkbox" @bind="e.Enabled" /> Enabled in next deployment</label>@Actions(e, e.DataExportRowId != Guid.Empty)
|
||||
</div></section>
|
||||
}
|
||||
|
||||
@@ -144,7 +144,10 @@ internal sealed class DataWriteExecutor(DataAuthenticatedContext context, Func<L
|
||||
var issued = clock.GetTimestamp();
|
||||
var admission = new DataWriteAdmission(context.PrincipalId, node.Metadata.View, current.AuthorityEpoch,
|
||||
current.Serving.CatalogEpoch, current.Serving.Incarnation, target.DriverIncarnation, item.OperationId,
|
||||
expiration, context.ApiKeyId, context.CredentialExpiresUtc, context.CredentialVersion);
|
||||
expiration, context.ApiKeyId, context.CredentialExpiresUtc, context.CredentialVersion,
|
||||
// #1084: decided here, from the same catalog generation that admitted the write (the dispatch gate's commit
|
||||
// re-checks that generation), never from the request.
|
||||
AllowsSecuredWrite: current.AllowsSecuredWrite(context.PrincipalId, node));
|
||||
var scope = new FrozenWriteScope(node.Scope.ClusterId, node.Scope.Kind, node.Scope.Segments.ToImmutableArray());
|
||||
var proof = new WriteRouteProof(admission, scope, node.EntityKind, node.EntityId, node.Source,
|
||||
target.DriverInstanceId, target.DriverReference, target.RouteGeneration, target.PrimaryGeneration, current.Serving);
|
||||
|
||||
@@ -22,7 +22,7 @@ public sealed partial class LocalExportCatalog
|
||||
private sealed record ExportRule(string Identity, string Principal, DataRealm Realm, DataView? Root, bool WholeRealm,
|
||||
DataOperations Operations, int Batch, int Page, int Items, int Streams,
|
||||
int HistoryReads = 4, int HistoryValuesPerPage = 10_000, int HistoryResponseBytes = 4 * 1024 * 1024,
|
||||
int Conditions = 1000, bool GalaxyServiceAck = false);
|
||||
int Conditions = 1000, bool GalaxyServiceAck = false, bool SecuredWrites = false);
|
||||
|
||||
public LocalExportCatalog(string clusterId, ServingIdentity serving, IDataMappedCatalogAuthority activation,
|
||||
IEnumerable<LocalDataNode> nodes, IEnumerable<DataExport> exports, int maximumNodes = 100_000,
|
||||
@@ -100,7 +100,9 @@ public sealed partial class LocalExportCatalog
|
||||
export.AllowedOperations & DataOperationSets.Understood, export.MaxBatchItems, export.MaxPageItems, export.MaxMonitoredItems, export.MaxStreams,
|
||||
export.MaxConcurrentHistoryReads, export.MaxHistoryValuesPerPage, export.MaxHistoryResponseBytes, export.MaxConditions,
|
||||
// A2b (§6, Q2): the Galaxy service-ack opt-in counts only with the AlarmAcknowledge grant it qualifies.
|
||||
export.AllowGalaxyServiceAck && (export.AllowedOperations & DataOperations.AlarmAcknowledge) != 0));
|
||||
export.AllowGalaxyServiceAck && (export.AllowedOperations & DataOperations.AlarmAcknowledge) != 0,
|
||||
// #1084: the secured-write (caller-identity) opt-in counts only with the Write grant it qualifies.
|
||||
export.AllowSecuredWrites && (export.AllowedOperations & DataOperations.Write) != 0));
|
||||
if (UnknownOperationDrops.Unknown(export.AllowedOperations) is var unknown && unknown != DataOperations.None)
|
||||
dropped[export.DataExportId] = unknown;
|
||||
}
|
||||
@@ -201,6 +203,25 @@ public sealed partial class LocalExportCatalog
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// #1084: whether <paramref name="principal"/> holds an export of the node's realm that grants Write on it AND opts in to
|
||||
/// secured writes (<c>DataExport.AllowSecuredWrites</c>) — i.e. a write admitted for this node may carry the connection's
|
||||
/// caller to a caller-aware driver (Galaxy SecuredWrite under the key's Galaxy identity). Any one such export suffices,
|
||||
/// exactly as for <see cref="AllowsExport"/>; with none the write is still admitted (on the Write grant) but goes to the
|
||||
/// driver without a caller, so an identity-bearing write is refused there.
|
||||
/// </summary>
|
||||
internal bool AllowsSecuredWrite(string principal, LocalDataNode node)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(node);
|
||||
foreach (var rule in _exports)
|
||||
{
|
||||
if (!rule.SecuredWrites || !string.Equals(principal, rule.Principal, StringComparison.OrdinalIgnoreCase)
|
||||
|| rule.Realm != node.Metadata.View.Realm || (rule.Operations & DataOperations.Write) == 0) continue;
|
||||
if (rule.WholeRealm || IsAncestor(rule.Root!, node.Metadata.View)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
internal string SubscriptionExportScope(string principal, LocalDataNode node)
|
||||
{
|
||||
var ids = _exports.Where(rule => string.Equals(principal, rule.Principal, StringComparison.OrdinalIgnoreCase) &&
|
||||
|
||||
@@ -1510,14 +1510,18 @@ public sealed class DriverInstanceActor : ReceiveActor, IWithTimers
|
||||
{
|
||||
// #1074: a gRPC data-connection write carries its caller like an OPC UA write does (#1017) —
|
||||
// the admission's principal + API key id, bound from the authenticated transport context
|
||||
// (never from the request payload) and re-checked by the dispatch gate's commit above. A
|
||||
// caller-aware driver (Galaxy SecuredWrite under the key's Galaxy identity) gets it; every
|
||||
// other driver is unchanged. No driver is both IWriteOutcomeCapability and
|
||||
// ICallerAwareWritable today; one that were would need a caller-aware outcome overload.
|
||||
if (driver is IWriteOutcomeCapability rich)
|
||||
// (never from the request payload) and re-checked by the dispatch gate's commit above. #1084:
|
||||
// only when an export covering the node opts in (AllowsSecuredWrite); otherwise there is no
|
||||
// caller and a caller-aware driver gets the caller-less call (identity-bearing writes refused).
|
||||
// Precedence (#1091): the explicit-outcome path wins over the legacy one, and within each the
|
||||
// caller-aware overload is used whenever there is a caller.
|
||||
var caller = RichCaller(msg.Ticket.Proof.Admission);
|
||||
if (caller is not null && driver is ICallerAwareWriteOutcomeCapability richCaller)
|
||||
_ = ObserveRichDriver(richCaller.WriteWithOutcomesAsync(request, caller, ct), physical);
|
||||
else if (driver is IWriteOutcomeCapability rich)
|
||||
_ = ObserveRichDriver(rich.WriteWithOutcomesAsync(request, ct), physical);
|
||||
else if (driver is ICallerAwareWritable callerAware)
|
||||
_ = ObserveLegacyDriver(callerAware.WriteAsync(request, RichCaller(msg.Ticket.Proof.Admission), ct), physical);
|
||||
else if (caller is not null && driver is ICallerAwareWritable callerAware)
|
||||
_ = ObserveLegacyDriver(callerAware.WriteAsync(request, caller, ct), physical);
|
||||
else
|
||||
_ = ObserveLegacyDriver(((IWritable)driver).WriteAsync(request, ct), physical);
|
||||
}
|
||||
@@ -1583,11 +1587,17 @@ public sealed class DriverInstanceActor : ReceiveActor, IWithTimers
|
||||
/// Both are mandatory on an admission (<see cref="DataWriteAdmission.Validate"/>) and carry no secret. Marked
|
||||
/// <see cref="WriteCallerOrigin.DataConnection"/> so a driver can hold this plane to its own opt-in (Galaxy
|
||||
/// <c>MxAccess.SecuredWritesOverDataConnections</c>, default off).
|
||||
/// <para>
|
||||
/// #1084: null unless the admission says an export covering the node opts in to secured writes
|
||||
/// (<c>DataExport.AllowSecuredWrites</c>, default off). The driver option alone is therefore not enough: a
|
||||
/// forwarding consumer cluster's link gets no caller identity unless the origin's export for it says so.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
internal static WriteCaller RichCaller(DataWriteAdmission admission) =>
|
||||
new(string.IsNullOrWhiteSpace(admission.PrincipalId) ? null : admission.PrincipalId,
|
||||
string.IsNullOrWhiteSpace(admission.ApiKeyId) ? null : admission.ApiKeyId,
|
||||
WriteCallerOrigin.DataConnection);
|
||||
internal static WriteCaller? RichCaller(DataWriteAdmission admission) =>
|
||||
!admission.AllowsSecuredWrite ? null
|
||||
: new(string.IsNullOrWhiteSpace(admission.PrincipalId) ? null : admission.PrincipalId,
|
||||
string.IsNullOrWhiteSpace(admission.ApiKeyId) ? null : admission.ApiKeyId,
|
||||
WriteCallerOrigin.DataConnection);
|
||||
|
||||
private static async Task ObserveRichDriver(Task<IReadOnlyList<DataWriteOutcome>> task,
|
||||
TaskCompletionSource<DataWriteOutcome> physical)
|
||||
|
||||
@@ -79,6 +79,11 @@ public sealed class UnwrappedCapabilityCallAnalyzer : DiagnosticAnalyzer
|
||||
// work and so must run under the invoker's timeout/breaker/telemetry.
|
||||
"ZB.MOM.WW.OtOpcUa.Core.Abstractions.IAcknowledgedAcquisitionSource",
|
||||
"ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections.IWriteOutcomeCapability",
|
||||
// #1091: the caller-aware overloads. Each DERIVES from a guarded interface but declares its own member, and a
|
||||
// derived interface's new member is not an implementation of the base's — so `callerAware.WriteAsync(w, caller, ct)`
|
||||
// on an ICallerAwareWritable receiver used to pass unflagged. They must be listed themselves.
|
||||
"ZB.MOM.WW.OtOpcUa.Core.Abstractions.ICallerAwareWritable",
|
||||
"ZB.MOM.WW.OtOpcUa.Core.Abstractions.DataConnections.ICallerAwareWriteOutcomeCapability",
|
||||
];
|
||||
|
||||
/// <summary>
|
||||
@@ -109,7 +114,7 @@ public sealed class UnwrappedCapabilityCallAnalyzer : DiagnosticAnalyzer
|
||||
category: "OtOpcUa.Resilience",
|
||||
defaultSeverity: DiagnosticSeverity.Warning,
|
||||
isEnabledByDefault: true,
|
||||
description: "Phase 6.1 Stream A requires every IReadable/IWritable/ITagDiscovery/ISubscribable/IHostConnectivityProbe/IAlarmSource/IAcknowledgedAcquisitionSource/IWriteOutcomeCapability call to route through the shared Polly pipeline. Direct calls skip the pipeline + lose per-host isolation, retry semantics, and telemetry. If the caller is Core/Server/Driver dispatch code, wrap the call in CapabilityInvoker.ExecuteAsync. If the caller is a unit test invoking the driver directly to test its wire-level behavior, either suppress with a pragma or move the suppression into a NoWarn for the test project.");
|
||||
description: "Phase 6.1 Stream A requires every IReadable/IWritable/ITagDiscovery/ISubscribable/IHostConnectivityProbe/IAlarmSource/IAcknowledgedAcquisitionSource/IWriteOutcomeCapability/ICallerAwareWritable/ICallerAwareWriteOutcomeCapability call to route through the shared Polly pipeline. Direct calls skip the pipeline + lose per-host isolation, retry semantics, and telemetry. If the caller is Core/Server/Driver dispatch code, wrap the call in CapabilityInvoker.ExecuteAsync. If the caller is a unit test invoking the driver directly to test its wire-level behavior, either suppress with a pragma or move the suppression into a NoWarn for the test project.");
|
||||
|
||||
/// <inheritdoc />
|
||||
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(Rule);
|
||||
|
||||
Reference in New Issue
Block a user