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`)
+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).
+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.