fix(acl): place opaque-id UNS folders, virtual tags and scripted conditions for every operation (#808)

UNS Area/Line/Equipment folders are minted under their opaque entity ids
(s=UA-/UL-/EQ-...), virtual tags under s=EQ-.../Name and scripted conditions
(+ #629 children) under s=<ScriptedAlarmId>[/...], while every UNS grant is
planted at a NAME path. DataPlaneAuthorizer split those ids, so with
Security:Acl:Enabled a narrow (Area/Line/Equipment) grant could not Browse,
Read, subscribe or HistoryRead them, and Server-object delivery never reached
it — so a narrow key never held the EventId Ack/Confirm/AddComment need.

- The generation carries UnsFolderScopes (folderId -> path + id chain), built
  by DeploymentArtifact from the same AclScopePathResolver as the grants; ids
  two entity kinds share are dropped; plumbed through IDataPlaneAuthoritySink.
- OtOpcUaNodeManager.ResolveUnsAclSubject reports live facts (folder id
  ancestry / scripted owner binding); attached by the Authorizer setter.
- Evaluate places the subject against the CURRENT generation before the
  decision cache, which now caches the walk keyed on the resolved scope.
  Folders require live chain == generation chain (a moved equipment is denied
  under old and new line until the rebuild). Owned nodes (vtags, conditions,
  children) get owner path + a reserved segment, so Tag grants and their
  Browse transit never expose them. Conditions share TryPlaceScriptedCondition
  with the #797 command gate.
- Server-object visibility of a scripted condition is decided on the
  condition alone, so a moved alarm cannot reach its old owner there.

Tests: UnsFolderScopeWireTests (opaque ids, end-to-end browse -> EventId ->
Acknowledge on an Equipment grant; sibling denied; Tag-only grant; moved alarm
and moved equipment stale windows). Rig tests now install folder scopes
explicitly (ServerEventRig.FolderScopes); the #797 recreate test deliberately
asserts the moved alarm is invisible to the Cluster observer in the window.
This commit is contained in:
Joseph Doherty
2026-11-10 23:12:46 -05:00
parent 308b1b3b56
commit af5c9744b7
15 changed files with 1095 additions and 60 deletions
@@ -87,7 +87,8 @@ public sealed class AclEventSubscriptionEnforcementTests
await WaitUntilAsync(() => collector.Has(onA, "t1") && collector.Has(onB, "t1"));
// The next deployment carries only EqB's grant.
state.Apply(Cluster, "rev-2", [], [EquipmentGrant(EqB)], ScopePaths());
state.Apply(Cluster, "rev-2", [], [EquipmentGrant(EqB)], ScopePaths(),
ServerEventRig.EquipmentOwnerPaths(), ServerEventRig.ScriptedAlarmOwners(), ServerEventRig.FolderScopes());
rig.AttachedEventItems.ShouldBe(1);
rig.Transition("t2", active: false);
@@ -98,7 +99,8 @@ public sealed class AclEventSubscriptionEnforcementTests
collector.Has(onA, "t2").ShouldBeFalse("the revoked item must not receive events after the deployment");
// A deployment that restores the grant brings the feed back on its own.
state.Apply(Cluster, "rev-3", [], [EquipmentGrant(EqA), EquipmentGrant(EqB)], ScopePaths());
state.Apply(Cluster, "rev-3", [], [EquipmentGrant(EqA), EquipmentGrant(EqB)], ScopePaths(),
ServerEventRig.EquipmentOwnerPaths(), ServerEventRig.ScriptedAlarmOwners(), ServerEventRig.FolderScopes());
rig.AttachedEventItems.ShouldBe(2);
rig.Transition("t3", active: true);
@@ -140,7 +142,8 @@ public sealed class AclEventSubscriptionEnforcementTests
await WaitUntilAsync(() => collector.Has(onA, "t1") && collector.Has(onB, "t1"));
rig.AttachedEventItems.ShouldBe(2);
state.Apply(Cluster, "rev-2", [], [EquipmentGrant(EqB)], ScopePaths());
state.Apply(Cluster, "rev-2", [], [EquipmentGrant(EqB)], ScopePaths(),
ServerEventRig.EquipmentOwnerPaths(), ServerEventRig.ScriptedAlarmOwners(), ServerEventRig.FolderScopes());
rig.AttachedEventItems.ShouldBe(1);
subscription.RemoveItem(onA);
@@ -149,7 +152,8 @@ public sealed class AclEventSubscriptionEnforcementTests
// A restoring deployment must not re-attach the deleted item. The client could never see that
// happen — it has deleted the item — so the server-side fan-out is what is asserted.
state.Apply(Cluster, "rev-3", [], [EquipmentGrant(EqA), EquipmentGrant(EqB)], ScopePaths());
state.Apply(Cluster, "rev-3", [], [EquipmentGrant(EqA), EquipmentGrant(EqB)], ScopePaths(),
ServerEventRig.EquipmentOwnerPaths(), ServerEventRig.ScriptedAlarmOwners(), ServerEventRig.FolderScopes());
rig.AttachedEventItems.ShouldBe(1, "the deleted item must not be resurrected onto EqA's fan-out");
rig.Transition("t2", active: false);
@@ -405,14 +409,16 @@ public sealed class AclEventSubscriptionEnforcementTests
rig.Transition("t1", active: true);
await WaitUntilAsync(() => events.Has(item, "t1") && controlEvents.Has(controlItem, "t1"));
state.Apply(Cluster, "rev-2", [key], [ClusterGrant(KeyPrincipal, "acl-key")], ScopePaths());
state.Apply(Cluster, "rev-2", [key], [ClusterGrant(KeyPrincipal, "acl-key")], ScopePaths(),
ServerEventRig.EquipmentOwnerPaths(), ServerEventRig.ScriptedAlarmOwners(), ServerEventRig.FolderScopes());
rig.Transition("t2", active: false);
await WaitUntilAsync(() => controlEvents.Has(controlItem, "t2"));
await Task.Delay(TimeSpan.FromMilliseconds(700), ct);
events.Has(item, "t2").ShouldBeFalse("the revoked session must not receive alarms after the deployment");
state.Apply(Cluster, "rev-3", [key], [EquipmentGrant(EqA), ClusterGrant(KeyPrincipal, "acl-key")], ScopePaths());
state.Apply(Cluster, "rev-3", [key], [EquipmentGrant(EqA), ClusterGrant(KeyPrincipal, "acl-key")], ScopePaths(),
ServerEventRig.EquipmentOwnerPaths(), ServerEventRig.ScriptedAlarmOwners(), ServerEventRig.FolderScopes());
rig.Transition("t3", active: true);
await WaitUntilAsync(() => events.Has(item, "t3") && controlEvents.Has(controlItem, "t3"));
@@ -885,6 +891,10 @@ public sealed class AclEventSubscriptionEnforcementTests
PermissionFlags = NodePermissions.Read | NodePermissions.Browse | NodePermissions.Subscribe,
};
// Gitea #808: every Apply above also installs the placements the generation now carries — the equipment owner
// paths + scripted-alarm owners (#797) and the UNS folder scopes (#808). This rig's folders are synthetic
// root-level ids (EqA ⇒ [uns, EqA]), shared with ServerEventRig; production-shaped opaque ids are covered by
// UnsFolderScopeWireTests. Without them every UNS folder and the scripted condition deny under EVERY grant.
private static IReadOnlyDictionary<AclScopeRef, IReadOnlyList<NodeAclPath>> ScopePaths() =>
new Dictionary<AclScopeRef, IReadOnlyList<NodeAclPath>>
{
@@ -1038,7 +1048,8 @@ public sealed class AclEventSubscriptionEnforcementTests
public DataPlaneAuthorityState Enforce(bool enabled, ApiKey[] keys, params NodeAcl[] grants)
{
var state = new DataPlaneAuthorityState();
state.Apply(Cluster, "rev-1", keys, grants, ScopePaths());
state.Apply(Cluster, "rev-1", keys, grants, ScopePaths(),
ServerEventRig.EquipmentOwnerPaths(), ServerEventRig.ScriptedAlarmOwners(), ServerEventRig.FolderScopes());
Nm.DataPlaneAuthority = state;
Nm.Authorizer = new DataPlaneAuthorizer(