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:
Joseph Doherty
2026-11-10 21:23:57 -05:00
parent b36e688f0a
commit 3d1b86b451
16 changed files with 1511 additions and 37 deletions
@@ -180,4 +180,49 @@ public sealed class DeploymentArtifactScopePathTests
projection.Grants.ShouldHaveSingleItem();
projection.ScopePaths.ShouldBeEmpty();
}
/// <summary>
/// Gitea #797 — the artifact also yields every equipment's OWN path (the scripted-alarm owner lookup), and
/// it is identical to the path the same artifact plants an Equipment grant at. That equality is what makes
/// a narrow equipment grant authorize the equipment's scripted alarms: if the two were produced by
/// different rules, the owner binding would silently authorize at a node no grant can reach.
/// </summary>
[Fact]
public void Every_equipment_owner_path_equals_the_path_its_equipment_grant_is_planted_at()
{
var projection = DeploymentArtifact.ParseDataPlaneAuthority(Encoding.UTF8.GetBytes(Artifact), NodeId);
projection.EquipmentScopePaths.ShouldContainKey("EQ-mixer");
var owner = projection.EquipmentScopePaths["EQ-mixer"];
owner.Segments.ShouldBe(["uns", "West", "L1", "Mixer"]);
projection.ScopePaths[new AclScopeRef(NodeAclScopeKind.Equipment, "EQ-mixer")]
.ShouldHaveSingleItem().Segments.ShouldBe(owner.Segments);
// Keyed by identifier (OrdinalIgnoreCase), like every other id lookup on the authorization path.
projection.EquipmentScopePaths.ContainsKey("eq-MIXER").ShouldBeTrue();
// A grant naming an equipment the artifact does not carry yields no owner path either.
projection.EquipmentScopePaths.ContainsKey("EQ-gone").ShouldBeFalse();
var snapshot = new DataPlaneAuthorityState().Apply(
"c1", "rev-1", projection.Keys, projection.Grants, projection.ScopePaths, projection.EquipmentScopePaths);
snapshot.TryGetEquipmentUnsSegments("EQ-mixer", out var segments).ShouldBeTrue();
segments.ShouldBe(["West", "L1", "Mixer"]);
}
/// <summary>An equipment whose UNS chain does not resolve (dangling line) has no owner path.</summary>
[Fact]
public void An_equipment_with_a_dangling_line_has_no_owner_path()
{
var projection = DeploymentArtifact.ParseDataPlaneAuthority(
Encoding.UTF8.GetBytes("""
{
"UnsAreas": [{"UnsAreaId":"UA-w","ClusterId":"c1","Name":"West"}],
"Equipment": [{"EquipmentId":"EQ-orphan","UnsLineId":"UL-missing","Name":"Orphan"}],
"NodeAcls":[{"NodeAclId":"a","ClusterId":"c1","Principal":"p","ScopeKind":0,"PermissionFlags":1}]
}
"""),
NodeId);
projection.EquipmentScopePaths.ShouldBeEmpty();
}
}