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
+25 -11
View File
@@ -14,7 +14,7 @@ The deployed configuration uses three entities:
| Entity | Operator choices |
|---|---|
| `DataConnection` | Owning cluster, explicit consumer nodes, expected remote cluster/node, Node or Cluster target, endpoint set, consistency, secret reference, operation subset and finite call limits. |
| `DataExport` | Origin-owned Raw or UNS root, authenticated peer principal, operation grants and export limits. |
| `DataExport` | Origin-owned Raw or UNS root, authenticated peer principal, operation grants, export limits and the default-off identity opt-ins `AllowGalaxyServiceAck` and `AllowSecuredWrites` (#1084, migration `AddDataExportAllowSecuredWrites`). |
| `RemoteNamespaceMapping` | Connection, consumer subset, local parent and branch name, same-realm remote root/address, operations, optional write-through, projection limits and freshness settings. |
New connections, exports and mappings are disabled by default; write-through also defaults off.
@@ -799,16 +799,30 @@ not see these bits; see "Mixed versions" above.
`otopcua/apikeys/<serviceKeyId>/galaxy-ack-user` and `…/galaxy-ack-password` in the **origin's** secrets store; without
them the #765 preflight refuses `BadUserAccessDenied`.
**Galaxy secured writes over a data connection (#1074) — opt-in, default off.** A write carries the connection's
principal, API key id and `Origin = DataConnection` to the driver. A Galaxy driver in `MxAccess.SecuredWrites =
ApiKeyIdentity` mode still refuses a SecuredWrite from a data connection (`BadUserAccessDenied`, before the wire, as
before) unless it also sets `MxAccess.SecuredWritesOverDataConnections = true`. Then it writes as the **connection key's**
Galaxy identity (the same `galaxy-ack-*` secrets as above; no fallback account). ⚠️ For a forwarding consumer cluster that
key is the link's service key, so every consumer-side client allowed to write the projected node would write secured
attributes as it. Unlike `AllowGalaxyServiceAck` there is no export-level switch; the driver option, the export's Write
grant and the origin ACL are the gates. A refused secured write reaches the caller as `OutcomeUnknown`, because the
Galaxy driver reports through the legacy write path. See
[Galaxy § Secured writes](drivers/Galaxy.md#secured-writes-under-the-callers-galaxy-identity-1017).
**Galaxy secured writes over a data connection (#1074, #1084) — two opt-ins, both default off.** A SecuredWrite
attribute written through a data connection runs as the **connection key's** Galaxy identity (the same `galaxy-ack-*`
secrets as above; no fallback account) only when BOTH hold:
| Gate | Where | Default | Without it |
|---|---|---|---|
| **`DataExport.AllowSecuredWrites`** (#1084; AdminUI export editor "Allow secured writes under this peer's key identity") | origin ConfigDb, per export; valid only with `Write` (validator code `DataExportSecuredWriteInvalid`, authoring, deploy gate and deployed row) | `false` | the origin dispatches the write to the driver with **no caller** — it is still admitted on the Write grant, but a caller-aware driver refuses an identity-bearing write exactly as an anonymous one |
| **`MxAccess.SecuredWritesOverDataConnections`** (#1074) | Galaxy driver config (with `SecuredWrites = ApiKeyIdentity`) | `false` | the driver refuses a caller whose `Origin = DataConnection` |
- The export flag counts only on an export of the connection's principal that grants `Write` AND whose root contains the
node (`LocalExportCatalog.AllowsSecuredWrite`); any one such export suffices, as for every grant. The origin decides it
when it admits the write, from the same catalog generation (`DataWriteAdmission.AllowsSecuredWrite`) — never from the
request — and the dispatch gate's commit re-checks that generation, so a deploy that clears it reaches the next write.
- Why two switches: the driver option applies to every connection that can write the driver's nodes, including a
**forwarding consumer cluster**, whose link key stands for every consumer-side client allowed to write the projected
node. The export flag scopes the delegation to one peer principal and one root. Turn it on for a direct client (e.g.
ScadaBridge with its own key); leave it off on an export to another OtOpcUa cluster unless delegating to the link's
identity is intended.
- The remaining gates are unchanged: the export's Write grant, the origin ACL for the connection's principal and, on a
consumer, its own write grants.
- **A refusal is reported definitively (#1091):** the Galaxy driver reports gRPC writes through `IWriteOutcomeCapability`
(+ the caller-aware `ICallerAwareWriteOutcomeCapability`), so a refused secured write is `DriverConfirmedFailure` +
`BadUserAccessDenied` (it used to be `OutcomeUnknown`). See
[Galaxy § Secured writes](drivers/Galaxy.md#secured-writes-under-the-callers-galaxy-identity-1017).
### Condition methods (`CallConditionMethod`)