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.
72 lines
4.2 KiB
C#
72 lines
4.2 KiB
C#
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");
|
|
}
|
|
}
|