fix(security): #835/#836 review — unsaved endpoints never borrow the owner's secrets; audit credential use; path rule follows AuthType
I-1: Test Connect / browse configs may carry unsaved edits (the device modal merges the stored DriverConfig with the typed device config). The server (DriverInstanceIdentities.EffectiveOwnerAsync, used by AdminOperationsActor and BrowserSessionService) honours the named owner only when every endpoint value (new DriverCredentialRules.EndpointFields: Galaxy Endpoint, OpcUaClient EndpointUrl/EndpointUrls/DiscoveryUrl, Heidenhain Host/Port) is one that driver stores; otherwise the owner is null and its instance-named secrets are refused. Every Test Connect / browse whose config carries an in-scope secret:/env: reference is recorded (CredentialUseAudit: IAuditWriter event category CredentialUse + a structured Information line: user, driver, endpoint hosts, outcome). L-1: the UserCertificatePath rule is skipped only in an object that explicitly sets AuthType to non-Certificate (string or ordinal); the deploy gate also checks the runtime-merged driver+device config so the switch cannot be split from the path; the form no longer persists the hidden field. L-2: a ConfigDb fault in the browse check is a refusal; RawBrowseModal catches open failures into its error message. L-4: a relative UserCertificateDirectory resolves against AppContext.BaseDirectory. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -8,7 +8,38 @@ namespace ZB.MOM.WW.OtOpcUa.Core.Abstractions;
|
||||
/// </summary>
|
||||
/// <param name="Name">The JSON property name (matched case-insensitively, as the driver binds it).</param>
|
||||
/// <param name="DirectoryDescription">How the operator configures the directory (for messages).</param>
|
||||
public sealed record CredentialPathField(string Name, string DirectoryDescription);
|
||||
/// <param name="ActiveWhenKey">
|
||||
/// Optional sibling key that switches the field on (OpcUaClient <c>AuthType</c>): the field is checked UNLESS the same
|
||||
/// JSON object sets this key to something other than <paramref name="ActiveWhenValue"/> /
|
||||
/// <paramref name="ActiveWhenOrdinal"/>. An absent key keeps the field checked (conservative — the driver's merge may
|
||||
/// supply the switch from another config), so only an EXPLICITLY inactive object is exempt.
|
||||
/// </param>
|
||||
/// <param name="ActiveWhenValue">The string value of <paramref name="ActiveWhenKey"/> that activates the field.</param>
|
||||
/// <param name="ActiveWhenOrdinal">The numeric (enum ordinal) value that activates the field.</param>
|
||||
public sealed record CredentialPathField(
|
||||
string Name, string DirectoryDescription, string? ActiveWhenKey = null, string? ActiveWhenValue = null, int? ActiveWhenOrdinal = null)
|
||||
{
|
||||
/// <summary>Whether the field is in force in <paramref name="owner"/> (the JSON object holding it).</summary>
|
||||
/// <param name="owner">The object.</param>
|
||||
/// <returns>False only when the object explicitly switches the field off.</returns>
|
||||
public bool IsActiveIn(System.Text.Json.JsonElement owner)
|
||||
{
|
||||
if (ActiveWhenKey is null || owner.ValueKind != System.Text.Json.JsonValueKind.Object) return true;
|
||||
foreach (var p in owner.EnumerateObject())
|
||||
{
|
||||
if (!string.Equals(p.Name, ActiveWhenKey, StringComparison.OrdinalIgnoreCase)) continue;
|
||||
return p.Value.ValueKind switch
|
||||
{
|
||||
System.Text.Json.JsonValueKind.Null => true,
|
||||
System.Text.Json.JsonValueKind.String => string.Equals(p.Value.GetString(), ActiveWhenValue, StringComparison.OrdinalIgnoreCase),
|
||||
System.Text.Json.JsonValueKind.Number => !p.Value.TryGetInt32(out var n) || n == ActiveWhenOrdinal,
|
||||
_ => true,
|
||||
};
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The one rule for <see cref="CredentialPathField"/> values (lmxopcua#836): authored as a RELATIVE path inside a
|
||||
|
||||
Reference in New Issue
Block a user