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
@@ -114,10 +114,19 @@ internal sealed class ServerEventRig : IAsyncDisposable
/// <summary>Wires the authorizer over the given keys, scope paths and grants, enforcing or not.</summary>
public DataPlaneAuthorityState Enforce(
bool enabled, ApiKey[] keys, IReadOnlyDictionary<AclScopeRef, IReadOnlyList<NodeAclPath>> scopePaths,
params NodeAcl[] grants)
params NodeAcl[] grants) =>
Enforce(enabled, keys, scopePaths, EquipmentOwnerPaths(), grants);
/// <summary>
/// Wires the authorizer over the given keys, scope paths, equipment owner paths (the scripted-alarm owner
/// lookup, Gitea #797) and grants, enforcing or not.
/// </summary>
public DataPlaneAuthorityState Enforce(
bool enabled, ApiKey[] keys, IReadOnlyDictionary<AclScopeRef, IReadOnlyList<NodeAclPath>> scopePaths,
IReadOnlyDictionary<string, NodeAclPath> equipmentOwnerPaths, params NodeAcl[] grants)
{
var state = new DataPlaneAuthorityState();
state.Apply(Cluster, "rev-1", keys, grants, scopePaths);
state.Apply(Cluster, "rev-1", keys, grants, scopePaths, equipmentOwnerPaths);
Nm.DataPlaneAuthority = state;
Nm.Authorizer = new DataPlaneAuthorizer(
state, new TriePermissionEvaluator(state.Tries), enabled, NullLogger.Instance, TimeProvider.System);
@@ -160,6 +169,18 @@ internal sealed class ServerEventRig : IAsyncDisposable
[new AclScopeRef(NodeAclScopeKind.Equipment, $"eq-{EqB}")] = [new NodeAclPath([NodeAclRealms.Uns, EqB])],
};
/// <summary>
/// The rig's equipment owner paths: its equipment folders' ids ARE their EquipmentIds, sitting directly at
/// <c>[uns, EqA]</c> / <c>[uns, EqB]</c> — the same nodes <see cref="ScopePaths"/> plants the Equipment
/// grants at.
/// </summary>
public static IReadOnlyDictionary<string, NodeAclPath> EquipmentOwnerPaths() =>
new Dictionary<string, NodeAclPath>
{
[EqA] = new NodeAclPath([NodeAclRealms.Uns, EqA]),
[EqB] = new NodeAclPath([NodeAclRealms.Uns, EqB]),
};
/// <summary>The native condition, wired as an event source of both equipment folders.</summary>
public void MaterialiseNative()
{