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.
This commit is contained in:
Joseph Doherty
2026-12-04 14:58:16 -05:00
parent 2f22003061
commit 8e2a793000
23 changed files with 2704 additions and 53 deletions
+21 -6
View File
@@ -224,6 +224,12 @@ from the transport's `DataAuthenticatedContext` (never from the request payload)
at the commit point — plus `Origin = DataConnection`. The OPC UA node manager stamps `Origin = OpcUaSession`. The
runtime sets the origin from where it RECEIVED the write; nothing parses it out of the principal or key. No wire change.
**…and the origin's export must opt in too (#1084): `DataExport.AllowSecuredWrites`** (default `false`, valid only with
`Write`; AdminUI export editor "Allow secured writes under this peer's key identity"). The origin decides at admission
whether an export of the connection's principal that grants Write on the node opts in; if none does, the runtime hands
the driver **no caller** (`DriverInstanceActor.RichCaller` returns null) and the write takes the caller-less path — so the
driver option alone is not enough. See [DataConnections § Galaxy secured writes](../DataConnections.md).
The driver gives a caller an identity source only when `SecuredWrites = ApiKeyIdentity` **and** the origin is allowed:
| Origin | Identity source |
@@ -232,7 +238,7 @@ The driver gives a caller an identity source only when `SecuredWrites = ApiKeyId
| `DataConnection` | only with `MxAccess.SecuredWritesOverDataConnections = true` (default `false`; AdminUI "Also for gRPC data-connection writes") |
| `Unspecified` (the `WriteCaller` default) | never — fail closed, so a future call site that forgets to say where a write came from gets nothing |
**Off (default):** a SecuredWrite arriving over a data connection is refused exactly as before #1074 — no identity
**Off (default — either switch):** a SecuredWrite arriving over a data connection is refused exactly as before #1074 — no identity
lookup, the writer's local `BadUserAccessDenied`, nothing on the wire — even when the same key writes it successfully
over OPC UA. **On:** it runs as the connection key's own `/api-keys` Galaxy identity, as an OPC UA session with that key
would; no identity (or a broken one) ⇒ refused. The option is ignored in `Refuse` mode. Read before turning it on:
@@ -244,9 +250,17 @@ would; no identity (or a broken one) ⇒ refused. The option is ignored in `Refu
names the link's account, not the person. The remaining gates are the export's Write grant, the origin ACL for the
service principal and the consumer's own write grants. A direct client (e.g. ScadaBridge with its own key) is the case
the option is meant for; do not map an identity to a link's service key you do not want to delegate.
- **A refusal is not reported as one over gRPC.** The Galaxy driver is a plain `IWritable` (no
`IWriteOutcomeCapability`), so the rich write path reports any non-Good result, `BadUserAccessDenied` included, as
`OutcomeUnknown` — the same as every legacy driver's Bad (pre-existing; #1074 follow-up).
- **The forwarded-write case is why the export flag exists (#1084):** set `AllowSecuredWrites` on the export for a direct
client's principal and leave it off on an export to another OtOpcUa cluster's link unless delegating to it is intended.
- **gRPC write outcomes are definite where they can be (#1091).** The driver implements `IWriteOutcomeCapability` and the
caller-aware `ICallerAwareWriteOutcomeCapability` (`DriverInstanceActor.RunRichWriteAsync` precedence: caller-aware
outcome overload when the write carries a caller → plain outcome overload → `ICallerAwareWritable` → `IWritable`; the OPC
UA path is unchanged). `GalaxyWriteOutcomes` maps each result: `BadUserAccessDenied` (every secured/verified refusal, a
failed `AuthenticateUser`, a gateway `PermissionDenied`, MXAccess's access verdicts) and the `OnWriteComplete` verdicts
`BadNotWritable` / `BadTypeMismatch` / `BadOutOfRange` / `BadConfigurationError` ⇒ `DriverConfirmedFailure` with that
status; Good ⇒ `AcceptedUnconfirmed` (the writer cannot tell a confirmed Good from the provisional one an empty statuses
array produces); everything else (`BadCommunicationError`, `BadTimeout`, Uncertain, …) ⇒ `OutcomeUnknown`. Before
#1091 every non-Good result was `OutcomeUnknown`.
**The wire sequence** (`GatewayGalaxyDataWriter.WriteSecuredOneAsync`): the writer's own item handle for the secured
path (separate from the raw path's supervisory-advised handle — MXAccess allows one advise mode per handle), plain
@@ -275,8 +289,9 @@ wrong password ⇒ `BadUserAccessDenied` naming the user, password absent from e
attribute's permission ⇒ `BadUserAccessDenied` (1016); a VerifiedWrite attribute ⇒ `BadUserAccessDenied` with no
gateway traffic; a raw (FreeAccess) write on the same attribute's object still commits (the two handles coexist);
a gateway reconnect re-adds + re-advises the secured handle; the same write over a gRPC data connection with that
key ⇒ `BadUserAccessDenied`-refused (reported `OutcomeUnknown`, nothing in the gateway log) until
`SecuredWritesOverDataConnections = true`, then it commits as the mapped user (#1074).
key ⇒ `BadUserAccessDenied`-refused (reported `DriverConfirmedFailure`, #1091; nothing in the gateway log) until BOTH
`SecuredWritesOverDataConnections = true` and the origin export's `AllowSecuredWrites = true` (#1084) — check each alone
still refuses — then it commits as the mapped user (#1074).
Full per-field descriptions live in `Config/GalaxyDriverOptions.cs`. The full JSON skeleton is reproduced in [docs/v2/driver-specs.md §1](../v2/driver-specs.md).