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
+1 -1
View File
@@ -1401,7 +1401,7 @@ public enum NodePermissions : int
}
```
The three Write tiers map to Galaxy's v1 `SecurityClassification` — `FreeAccess`/`Operate` → `WriteOperate`, `Tune` → `WriteTune`, `Configure` → `WriteConfigure`. `VerifiedWrite` / `ViewOnly` classifications remain read-only from OPC UA regardless of grant; `SecuredWrite` is too unless the Galaxy driver opts in to `MxAccess.SecuredWrites = ApiKeyIdentity`, which writes it as the calling OPC UA session's key's own Galaxy identity (#1017). A secured write arriving over a **gRPC data connection** needs a second, default-off opt-in, `MxAccess.SecuredWritesOverDataConnections` (#1074); without it such a write is refused `BadUserAccessDenied` before the wire, as before. ⚠️ With it on, the identity is the **connection's** key — and a consumer OtOpcUa cluster forwarding its OPC UA clients' writes (projected-node write-through) presents its link's service key, so every consumer-side client allowed to write the projected node writes secured attributes as that key's Galaxy identity (the audit names the link's account, not the person). The driver tells the planes apart by `WriteCaller.Origin`, stamped by the runtime at the receiving seam (an unstated origin gets no identity). See [Galaxy § Secured writes](drivers/Galaxy.md#secured-writes-under-the-callers-galaxy-identity-1017).
The three Write tiers map to Galaxy's v1 `SecurityClassification` — `FreeAccess`/`Operate` → `WriteOperate`, `Tune` → `WriteTune`, `Configure` → `WriteConfigure`. `VerifiedWrite` / `ViewOnly` classifications remain read-only from OPC UA regardless of grant; `SecuredWrite` is too unless the Galaxy driver opts in to `MxAccess.SecuredWrites = ApiKeyIdentity`, which writes it as the calling OPC UA session's key's own Galaxy identity (#1017). A secured write arriving over a **gRPC data connection** needs two more default-off opt-ins: the driver's `MxAccess.SecuredWritesOverDataConnections` (#1074) AND, on the origin, the `DataExport.AllowSecuredWrites` of an export that grants the connection's principal `Write` on the node (#1084). Without the export flag the origin hands the driver no caller at all; without the driver option the driver refuses a data-connection caller; either way the write is refused `BadUserAccessDenied` before the wire and reported to the gRPC caller as a definite failure (#1091). ⚠️ With both on, the identity is the **connection's** key — and a consumer OtOpcUa cluster forwarding its OPC UA clients' writes (projected-node write-through) presents its link's service key, so every consumer-side client allowed to write the projected node writes secured attributes as that key's Galaxy identity (the audit names the link's account, not the person). That is why the export flag exists: it scopes the delegation to one peer and one root, so leave it off on an export to another OtOpcUa cluster unless that delegation is intended. The driver tells the planes apart by `WriteCaller.Origin`, stamped by the runtime at the receiving seam (an unstated origin gets no identity). See [Galaxy § Secured writes](drivers/Galaxy.md#secured-writes-under-the-callers-galaxy-identity-1017).
`HistoryUpdate` (bit 12) is a **separate** permission from `HistoryRead` so a read-only grant cannot also authorize OPC UA HistoryUpdate operations. `TriePermissionEvaluator` maps `OpcUaOperation.HistoryUpdate` to this bit. It is **not** included in any composite bundle (`ReadOnly` / `Operator` / `Engineer` / `Admin`) — it must be granted explicitly, and it is offered as its own checkbox in the AdminUI ACL editor (`AclEdit.razor`). The HistoryUpdate service itself is now implemented (SQL Server historian backend only) — see the next section.