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:
Joseph Doherty
2026-11-11 04:12:40 -05:00
parent 87416a230f
commit 271b96a644
18 changed files with 753 additions and 25 deletions
@@ -24,10 +24,20 @@ public static class OpcUaUserCertificatePaths
/// <summary>The directory in force (configured, else <see cref="DefaultDirectory"/>).</summary>
public static string CurrentDirectory => _configured ?? DefaultDirectory;
/// <summary>Sets the process-wide directory (blank ⇒ the default). Called by the host at startup.</summary>
/// <summary>
/// Sets the process-wide directory (blank ⇒ the default). Called by the host at startup. A RELATIVE value is
/// resolved against the application's install directory (<see cref="AppContext.BaseDirectory"/>), never the
/// working directory — a Windows service starts in <c>System32</c> (review L-4).
/// </summary>
/// <param name="directory">The configured directory.</param>
public static void Configure(string? directory) =>
_configured = string.IsNullOrWhiteSpace(directory) ? null : Path.GetFullPath(directory);
public static void Configure(string? directory) => _configured = Normalize(directory, AppContext.BaseDirectory);
/// <summary>The directory a configured value means: blank ⇒ null; relative ⇒ under <paramref name="baseDirectory"/>.</summary>
/// <param name="directory">The configured value.</param>
/// <param name="baseDirectory">The base a relative value is resolved against.</param>
/// <returns>The absolute directory, or null.</returns>
public static string? Normalize(string? directory, string baseDirectory) =>
string.IsNullOrWhiteSpace(directory) ? null : Path.GetFullPath(directory.Trim(), baseDirectory);
/// <summary>
/// Resolves an authored <c>UserCertificatePath</c> to the file to load, fail-closed