ef4e1668de
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.
64 lines
3.0 KiB
C#
64 lines
3.0 KiB
C#
using System.Reflection;
|
|
using System.Text.RegularExpressions;
|
|
using Shouldly;
|
|
using Xunit;
|
|
using ZB.MOM.WW.OtOpcUa.Cluster;
|
|
|
|
namespace ZB.MOM.WW.OtOpcUa.Host.Tests.Configuration;
|
|
|
|
/// <summary>
|
|
/// lmxopcua#1003: Akka untrusted-mode is ON by default, so a cross-node <c>ActorSelection</c> to a path missing from
|
|
/// <see cref="RemotingHardening.TrustedSelectionPaths"/> is dropped. These guards keep the trusted set in step with the
|
|
/// code: every cluster singleton the ControlPlane registers, the driver host actor's name, and the one application-level
|
|
/// selection in <c>src/</c>.
|
|
/// </summary>
|
|
public sealed class RemotingTrustedPathsCoverageTests
|
|
{
|
|
[Fact]
|
|
public void Every_registered_cluster_singleton_is_trusted()
|
|
{
|
|
var names = typeof(ZB.MOM.WW.OtOpcUa.ControlPlane.ServiceCollectionExtensions)
|
|
.GetFields(BindingFlags.Public | BindingFlags.Static)
|
|
.Where(f => f.IsLiteral && f.Name.EndsWith("SingletonName", StringComparison.Ordinal))
|
|
.Select(f => (string)f.GetRawConstantValue()!)
|
|
.ToArray();
|
|
names.ShouldNotBeEmpty("positive control: the constants are found");
|
|
foreach (var name in names)
|
|
{
|
|
RemotingHardening.SingletonNames.ShouldContain(name,
|
|
$"singleton '{name}' must be added to RemotingHardening.SingletonNames or its proxy/hand-over selections are dropped");
|
|
}
|
|
}
|
|
|
|
[Fact]
|
|
public void The_driver_host_path_is_the_runtime_actor_name()
|
|
=> RemotingHardening.DriverHostPath.ShouldBe("/user/" + ZB.MOM.WW.OtOpcUa.Runtime.ServiceCollectionExtensions.DriverHostActorName);
|
|
|
|
/// <summary>
|
|
/// The only <c>ActorSelection</c> in <c>src/</c> is the diagnostics client (which targets <c>/user/driver-host</c>).
|
|
/// A new one must come with its path in the trusted set — then add its file here.
|
|
/// </summary>
|
|
[Fact]
|
|
public void No_new_cross_node_actor_selection_appears_without_a_trusted_path()
|
|
{
|
|
var allowed = new HashSet<string>(StringComparer.Ordinal) { "FleetDiagnosticsClient.cs" };
|
|
var call = new Regex(@"\.ActorSelection\s*\(", RegexOptions.Compiled);
|
|
var offenders = Directory.EnumerateFiles(Path.Combine(SolutionRoot(), "src"), "*.cs", SearchOption.AllDirectories)
|
|
.Where(f => !f.Contains($"{Path.DirectorySeparatorChar}obj{Path.DirectorySeparatorChar}", StringComparison.Ordinal))
|
|
.Where(f => File.ReadLines(f).Any(l => !l.TrimStart().StartsWith("//", StringComparison.Ordinal) && call.IsMatch(l)))
|
|
.Select(Path.GetFileName)
|
|
.Where(n => !allowed.Contains(n!))
|
|
.ToArray();
|
|
offenders.ShouldBeEmpty();
|
|
}
|
|
|
|
private static string SolutionRoot()
|
|
{
|
|
var dir = new DirectoryInfo(AppContext.BaseDirectory);
|
|
while (dir is not null && !File.Exists(Path.Combine(dir.FullName, "ZB.MOM.WW.OtOpcUa.slnx")))
|
|
dir = dir.Parent;
|
|
dir.ShouldNotBeNull("Could not find solution root (ZB.MOM.WW.OtOpcUa.slnx).");
|
|
return dir!.FullName;
|
|
}
|
|
}
|