fix(acl): authorize scripted alarm commands at their owning equipment's scope (#797)
Scripted condition NodeIds are opaque ScriptedAlarmIds, so splitting them as a topology path could never match an Equipment grant: a narrow equipment grant was denied while a Cluster grant passed. - OtOpcUaNodeManager binds each LIVE scripted condition instance to the EquipmentId it was materialised under (only when it hangs under that folder); dropped on remove / drop-recreate / equipment-subtree removal / rebuild; a same-id re-materialise under another equipment re-parents and re-binds. - DataPlaneAuthoritySnapshot carries EquipmentScopePaths (EquipmentId -> [uns, Area, Line, Equipment]) decoded from the artifact by the same AclScopePathResolver call that plants Equipment grants. - DataPlaneAuthorizer.AuthorizeScriptedCondition re-reads key, grant and generation per call (uncached) and evaluates at the owner path; unbound, replaced or unplaceable owners deny under every grant. No id-split or realm-root fallback. - Native conditions (RawPath) and the ACL-off role gate are unchanged. NodeIds and AlarmCommand.AlarmId are unchanged. Sdk2OpaqueScriptedScopeBaselineTests deliberately flipped: it pinned the denial and now pins owner-grant allow / sibling deny / cluster allow. Follow-up #808 (folder ids + Server-object event visibility for narrow UNS grants).
This commit is contained in:
@@ -283,6 +283,35 @@ public sealed class DataPlaneAuthorityStateTests
|
||||
snapshot.DroppedGrants.ShouldBeEmpty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gitea #797 — the owner lookup for scripted alarm conditions: a UNS equipment path yields its segments
|
||||
/// below the realm; anything that does not name an equipment (absent id, a bare realm root, a raw path)
|
||||
/// yields nothing, so the caller denies rather than evaluating at some broader scope.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void The_equipment_owner_lookup_returns_only_real_uns_equipment_paths()
|
||||
{
|
||||
var sut = new DataPlaneAuthorityState();
|
||||
var snapshot = sut.Apply("cluster-a", "rev-1", [], [], NoScopes, new Dictionary<string, NodeAclPath>
|
||||
{
|
||||
["EQ-1"] = new(["uns", "Area", "Line", "Pump"]),
|
||||
["EQ-root"] = new(["uns"]),
|
||||
["EQ-raw"] = new(["raw", "Plant", "dev1"]),
|
||||
});
|
||||
|
||||
snapshot.TryGetEquipmentUnsSegments("EQ-1", out var segments).ShouldBeTrue();
|
||||
segments.ShouldBe(["Area", "Line", "Pump"]);
|
||||
snapshot.TryGetEquipmentUnsSegments("eq-1", out _).ShouldBeTrue("ids are identifiers: OrdinalIgnoreCase");
|
||||
snapshot.TryGetEquipmentUnsSegments("EQ-root", out _).ShouldBeFalse("a bare realm root is not an equipment");
|
||||
snapshot.TryGetEquipmentUnsSegments("EQ-raw", out _).ShouldBeFalse("a raw path is not a UNS equipment");
|
||||
snapshot.TryGetEquipmentUnsSegments("EQ-unknown", out _).ShouldBeFalse();
|
||||
snapshot.TryGetEquipmentUnsSegments("", out _).ShouldBeFalse();
|
||||
|
||||
// A later generation without the equipment forgets it — the lookup is per generation.
|
||||
sut.Apply("cluster-a", "rev-2", [], [], NoScopes).TryGetEquipmentUnsSegments("EQ-1", out _).ShouldBeFalse();
|
||||
DataPlaneAuthoritySnapshot.Empty.TryGetEquipmentUnsSegments("EQ-1", out _).ShouldBeFalse();
|
||||
}
|
||||
|
||||
private static NodeAcl Acl(string id, string principal, NodePermissions flags) => new()
|
||||
{
|
||||
NodeAclId = id,
|
||||
|
||||
Reference in New Issue
Block a user