Files
lmxopcua/src/Core/ZB.MOM.WW.OtOpcUa.Cluster/AkkaRemotingOptions.cs
T
Joseph Doherty ef4e1668de feat(cluster): #1003 Akka remoting hardening — untrusted-mode on by default, mutual TLS opt-in
Follow-up of #973 (review 2026-12-02 A-1). New Cluster:Remoting section (AkkaRemotingOptions):

- UntrustedMode (default ON): akka.remote.untrusted-mode with trusted-selection-paths =
  every path this code base reaches by ActorSelection across nodes, enumerated from the Akka
  1.5.62 sources + src/: cluster core daemon + heartbeat receiver, remote-watcher, the DPS
  mediator, /user/{s} + /user/{s}/{s} for each ControlPlane singleton, /user/driver-host.
  Remote deployment and peer PoisonPill/Kill are dropped. Receive-side only, so a mixed
  old/new pair keeps working through a rolling upgrade. Drops (Akka logs them at Debug)
  become a Warning per path + otopcua.cluster.remoting.untrusted_drops.
  AdditionalTrustedSelectionPaths / UntrustedMode=false are the escape hatches.
- Tls (default OFF): mutual TLS on the DotNetty transport (PFX or store cert, mutual auth
  on by default, thumbprint pinning or chain validation, optional hostname check). Seeds and
  the diagnostics selection follow the transport scheme (akka.ssl.tcp); the bootstrap guard
  parses it. Validated at boot.

Proven on real clusters: pair formation, singleton via proxy + hand-over on leave, DPS, zero
drops; untrusted selection dropped (and delivered with the mode off); pinned TLS peers form,
an unpinned node cannot join; full two-node Host harness (deploys from both nodes,
diagnostics, node restart) with zero drops + positive control. Guards fail when a new
singleton or ActorSelection appears without its trusted path.
2026-12-03 15:35:56 -05:00

80 lines
4.5 KiB
C#

namespace ZB.MOM.WW.OtOpcUa.Cluster;
/// <summary>
/// Hardening of the Akka remoting endpoint every node listens on (<c>Cluster:Remoting</c>, lmxopcua#1003, review
/// 2026-12-02 A-1 follow-up). Two independent controls:
/// <list type="bullet">
/// <item><see cref="UntrustedMode"/> — <b>on by default</b>: inbound <c>ActorSelection</c> is delivered only to the
/// paths this code base actually addresses across nodes (<see cref="RemotingHardening.TrustedSelectionPaths"/>),
/// remote deployment is refused, and <c>PoisonPill</c>/<c>Kill</c>-class messages from a peer are dropped. A
/// receive-side filter only — the wire format is unchanged, so a mixed old/new pair keeps working.</item>
/// <item><see cref="Tls"/> — <b>off by default</b> (opt-in): TLS with mutual authentication on the remoting
/// transport, so only a peer presenting an accepted certificate can associate (and therefore join the mesh).
/// All-or-nothing per mesh: a TLS node and a plain node cannot talk.</item>
/// </list>
/// </summary>
public sealed class AkkaRemotingOptions
{
/// <summary>
/// Gets or sets whether Akka's <c>untrusted-mode</c> is on. Default <see langword="true"/>. Set
/// <see langword="false"/> only as an escape hatch while reporting a missing path (the drop is logged as a Warning
/// naming it; <see cref="AdditionalTrustedSelectionPaths"/> is the targeted fix).
/// </summary>
public bool UntrustedMode { get; set; } = true;
/// <summary>
/// Gets or sets extra actor paths (<c>/user/…</c> or <c>/system/…</c>, no address) a peer may reach with an
/// <c>ActorSelection</c>, on top of <see cref="RemotingHardening.TrustedSelectionPaths"/>.
/// </summary>
public string[] AdditionalTrustedSelectionPaths { get; set; } = [];
/// <summary>Gets or sets the transport TLS settings (opt-in).</summary>
public AkkaRemotingTlsOptions Tls { get; set; } = new();
}
/// <summary>
/// TLS on the Akka remoting transport (<c>Cluster:Remoting:Tls</c>). Opt-in; see <c>docs/security.md</c> §"Akka
/// remoting" for the rollout (both nodes of a pair, and every node a central admin dials for diagnostics, together).
/// </summary>
public sealed class AkkaRemotingTlsOptions
{
/// <summary>Gets or sets whether the remoting transport runs TLS. Default <see langword="false"/>.</summary>
/// <remarks>
/// Changes the address scheme from <c>akka.tcp</c> to <c>akka.ssl.tcp</c>. <c>Cluster:SeedNodes</c> may keep
/// either spelling: the scheme is rewritten to match this switch at startup.
/// </remarks>
public bool Enabled { get; set; }
/// <summary>Gets or sets the node certificate as a PKCS#12 (<c>.pfx</c>) file, with its private key. Absolute path.</summary>
public string? CertificatePath { get; set; }
/// <summary>Gets or sets the PFX password — supply it as <c>${secret:…}</c> or an environment variable, never committed.</summary>
public string? CertificatePassword { get; set; }
/// <summary>Gets or sets the node certificate's SHA-1 thumbprint in a certificate store (alternative to <see cref="CertificatePath"/>).</summary>
public string? CertificateThumbprint { get; set; }
/// <summary>Gets or sets the store name for <see cref="CertificateThumbprint"/>. Default <c>My</c>.</summary>
public string CertificateStoreName { get; set; } = "My";
/// <summary>Gets or sets the store location for <see cref="CertificateThumbprint"/>. Default <c>LocalMachine</c>.</summary>
public string CertificateStoreLocation { get; set; } = "LocalMachine";
/// <summary>
/// Gets or sets whether an inbound peer must present a certificate too. Default <see langword="true"/> — without it
/// the transport is encrypted but any host can still associate (and join), which is the threat this exists for.
/// </summary>
public bool RequireMutualAuthentication { get; set; } = true;
/// <summary>Gets or sets whether the peer certificate's CN/SAN must match the host it was dialled at. Default off.</summary>
public bool ValidateCertificateHostname { get; set; }
/// <summary>
/// Gets or sets the SHA-1 thumbprints of the peer certificates this node accepts (its pair partner, its own, and —
/// on a node an admin node dials for diagnostics — the admin nodes'). When non-empty, a peer is accepted on its
/// pinned thumbprint alone (self-signed certificates work; no CA needed). When empty, the peer's chain must
/// validate against the machine's trust store.
/// </summary>
public string[] AllowedThumbprints { get; set; } = [];
}