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.
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Shouldly;
|
||||
using Xunit;
|
||||
using ZB.MOM.WW.OtOpcUa.Cluster;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Interfaces;
|
||||
using ZB.MOM.WW.OtOpcUa.Commons.Messages.Admin;
|
||||
|
||||
namespace ZB.MOM.WW.OtOpcUa.Host.IntegrationTests;
|
||||
|
||||
/// <summary>
|
||||
/// lmxopcua#1003: Akka untrusted-mode is ON by default. On the full two-node harness — the shipped bootstrap with every
|
||||
/// ControlPlane singleton and proxy, the cluster-scoped redundancy singleton, the runtime actors and DistributedPubSub —
|
||||
/// a deployment through the AdminOperations proxy, the diagnostics selection to each node's driver host, and node B
|
||||
/// leaving and rejoining (singleton proxies re-identifying) leave NO untrusted-mode drop on either node.
|
||||
/// </summary>
|
||||
public sealed class UntrustedModeHarnessTests
|
||||
{
|
||||
private static CancellationToken Ct => TestContext.Current.CancellationToken;
|
||||
|
||||
[Fact]
|
||||
public async Task The_full_two_node_stack_runs_under_untrusted_mode_without_a_single_dropped_message()
|
||||
{
|
||||
await using var harness = await TwoNodeClusterHarness.StartAsync();
|
||||
harness.NodeASystem.Settings.Config.GetBoolean("akka.remote.untrusted-mode").ShouldBeTrue("the default, effective");
|
||||
harness.NodeBSystem.Settings.Config.GetBoolean("akka.remote.untrusted-mode").ShouldBeTrue();
|
||||
await harness.SeedDefaultClusterAsync();
|
||||
|
||||
// Deploy from EACH node: one of them reaches the singletons through a cross-node proxy.
|
||||
foreach (var node in new[] { harness.NodeA, harness.NodeB })
|
||||
{
|
||||
await using var scope = node.Services.CreateAsyncScope();
|
||||
var adminOps = scope.ServiceProvider.GetRequiredService<IAdminOperationsClient>();
|
||||
var deploy = await adminOps.StartDeploymentAsync(createdBy: "alice@test", Ct);
|
||||
deploy.Outcome.ShouldBeOneOf(StartDeploymentOutcome.Accepted, StartDeploymentOutcome.NoChanges,
|
||||
StartDeploymentOutcome.AnotherDeploymentInFlight); // any of these is the singleton answering
|
||||
}
|
||||
|
||||
// The diagnostics selection (/user/driver-host) to both nodes, from node A.
|
||||
await using (var scope = harness.NodeA.Services.CreateAsyncScope())
|
||||
{
|
||||
var diagnostics = scope.ServiceProvider.GetRequiredService<IFleetDiagnosticsClient>();
|
||||
foreach (var member in Akka.Cluster.Cluster.Get(harness.NodeASystem).State.Members)
|
||||
{
|
||||
var nodeId = Commons.Types.NodeId.Parse($"{member.Address.Host}:{member.Address.Port}");
|
||||
(await diagnostics.GetDiagnosticsAsync(nodeId, Ct)).NodeId.ShouldBe(nodeId, "answered, not the empty fallback");
|
||||
}
|
||||
}
|
||||
|
||||
// Node B leaves and rejoins: hand-over / re-identification on the remaining managers and proxies.
|
||||
await harness.RestartNodeBAsync();
|
||||
await using (var scope = harness.NodeB.Services.CreateAsyncScope())
|
||||
{
|
||||
var adminOps = scope.ServiceProvider.GetRequiredService<IAdminOperationsClient>();
|
||||
var deploy = await adminOps.StartDeploymentAsync(createdBy: "alice@test", Ct);
|
||||
deploy.Outcome.ShouldBeOneOf(StartDeploymentOutcome.Accepted, StartDeploymentOutcome.NoChanges,
|
||||
StartDeploymentOutcome.AnotherDeploymentInFlight); // any of these is the singleton answering
|
||||
}
|
||||
|
||||
var drops = RemotingHardening.DroppedFor(harness.NodeASystem).Concat(RemotingHardening.DroppedFor(harness.NodeBSystem)).ToArray();
|
||||
drops.ShouldBeEmpty($"untrusted-mode dropped: {string.Join(", ", drops)}");
|
||||
|
||||
// Positive control — the empty list above is not vacuous: the drop monitor runs on this stack and records a
|
||||
// selection to a path that is not trusted.
|
||||
var addressA = Akka.Cluster.Cluster.Get(harness.NodeASystem).SelfAddress;
|
||||
harness.NodeBSystem.ActorSelection($"{addressA}/user/not-a-trusted-path").Tell(new Akka.Actor.Identify(1));
|
||||
var deadline = DateTime.UtcNow + TimeSpan.FromSeconds(10);
|
||||
while (!RemotingHardening.DroppedFor(harness.NodeASystem).Contains("/user/not-a-trusted-path") && DateTime.UtcNow < deadline)
|
||||
await Task.Delay(100, Ct);
|
||||
RemotingHardening.DroppedFor(harness.NodeASystem).ShouldContain("/user/not-a-trusted-path");
|
||||
}
|
||||
}
|
||||
+63
@@ -0,0 +1,63 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user