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:
+58
@@ -254,4 +254,62 @@ public sealed class DeploymentArtifactScopePathTests
|
||||
owner.ShouldBe("EQ-mixer");
|
||||
snapshot.TryGetScriptedAlarmOwner("scripted-no-owner", out _).ShouldBeFalse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gitea #808 — the artifact yields every UNS Area / Line / Equipment folder's placement: the SAME path a grant
|
||||
/// on that entity is planted at, plus the folder-id chain the address space nests it under. The path equality
|
||||
/// is what lets a narrow grant reach the opaque-id folder it names; the chain is what the authorizer compares
|
||||
/// the live folder against.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void Every_uns_folder_scope_equals_its_entity_grant_path_and_carries_its_id_chain()
|
||||
{
|
||||
var projection = DeploymentArtifact.ParseDataPlaneAuthority(Encoding.UTF8.GetBytes(Artifact), NodeId);
|
||||
|
||||
var folders = projection.UnsFolderScopes;
|
||||
folders.Keys.Order(StringComparer.Ordinal).ShouldBe(["EQ-mixer", "UA-w", "UL-1"]);
|
||||
folders["UA-w"].Path.Segments.ShouldBe(["uns", "West"]);
|
||||
folders["UA-w"].IdChain.ShouldBe(["UA-w"]);
|
||||
folders["UL-1"].Path.Segments.ShouldBe(["uns", "West", "L1"]);
|
||||
folders["UL-1"].IdChain.ShouldBe(["UA-w", "UL-1"]);
|
||||
folders["EQ-mixer"].IdChain.ShouldBe(["UA-w", "UL-1", "EQ-mixer"]);
|
||||
folders["EQ-mixer"].Path.Segments.ShouldBe(
|
||||
projection.ScopePaths[new AclScopeRef(NodeAclScopeKind.Equipment, "EQ-mixer")].ShouldHaveSingleItem().Segments);
|
||||
|
||||
var snapshot = new DataPlaneAuthorityState().Apply(
|
||||
"c1", "rev-1", projection.Keys, projection.Grants, projection.ScopePaths, projection.EquipmentScopePaths,
|
||||
projection.ScriptedAlarmOwners, projection.UnsFolderScopes);
|
||||
snapshot.TryGetUnsFolderSegments("EQ-mixer", ["UA-w", "UL-1", "EQ-mixer"], out var segments).ShouldBeTrue();
|
||||
segments.ShouldBe(["West", "L1", "Mixer"]);
|
||||
// A live folder nested differently from what the generation deploys (moved, not yet rebuilt) is not placed
|
||||
// at all — neither at the generation's path nor at its old one.
|
||||
snapshot.TryGetUnsFolderSegments("EQ-mixer", ["UA-w", "UL-2", "EQ-mixer"], out _).ShouldBeFalse();
|
||||
snapshot.TryGetUnsFolderSegments("EQ-mixer", ["EQ-mixer"], out _).ShouldBeFalse();
|
||||
snapshot.TryGetUnsFolderSegments("EQ-gone", ["UA-w", "UL-1", "EQ-gone"], out _).ShouldBeFalse();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gitea #808 — an id two UNS entity kinds share (the address space can hold only one folder for it) is dropped
|
||||
/// rather than placed by whichever kind came first; an orphaned line or a line-less equipment has no scope.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void An_ambiguous_or_orphaned_uns_folder_has_no_scope()
|
||||
{
|
||||
var projection = DeploymentArtifact.ParseDataPlaneAuthority(
|
||||
Encoding.UTF8.GetBytes("""
|
||||
{
|
||||
"UnsAreas": [{"UnsAreaId":"X-1","ClusterId":"c1","Name":"West"}],
|
||||
"UnsLines": [
|
||||
{"UnsLineId":"X-1","UnsAreaId":"X-1","Name":"Clash"},
|
||||
{"UnsLineId":"UL-orphan","UnsAreaId":"UA-missing","Name":"Orphan"},
|
||||
{"UnsLineId":"UL-ok","UnsAreaId":"X-1","Name":"L1"}
|
||||
],
|
||||
"Equipment": [{"EquipmentId":"EQ-dangling","UnsLineId":"UL-missing","Name":"E"}],
|
||||
"NodeAcls":[{"NodeAclId":"a","ClusterId":"c1","Principal":"p","ScopeKind":0,"PermissionFlags":1}]
|
||||
}
|
||||
"""),
|
||||
NodeId);
|
||||
|
||||
projection.UnsFolderScopes.Keys.ShouldBe(["UL-ok"]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user