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:
@@ -12,10 +12,26 @@ namespace ZB.MOM.WW.OtOpcUa.AdminUI.Clients;
|
||||
public sealed class AdminProbeService
|
||||
{
|
||||
private readonly IAdminOperationsClient _client;
|
||||
private readonly ZB.MOM.WW.Audit.IAuditWriter? _audit;
|
||||
private readonly Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider? _auth;
|
||||
private readonly Microsoft.Extensions.Logging.ILogger _logger;
|
||||
|
||||
/// <summary>Initializes a new instance of the <see cref="AdminProbeService"/>.</summary>
|
||||
/// <param name="client">The admin operations client used to dispatch probe requests.</param>
|
||||
public AdminProbeService(IAdminOperationsClient client) => _client = client;
|
||||
/// <param name="audit">Credential-use audit sink (#835 review I-1); null ⇒ the structured log line only.</param>
|
||||
/// <param name="auth">The circuit's user (for the audit record); null ⇒ "unknown".</param>
|
||||
/// <param name="logger">Logger; null ⇒ none.</param>
|
||||
public AdminProbeService(
|
||||
IAdminOperationsClient client,
|
||||
ZB.MOM.WW.Audit.IAuditWriter? audit = null,
|
||||
Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider? auth = null,
|
||||
Microsoft.Extensions.Logging.ILogger<AdminProbeService>? logger = null)
|
||||
{
|
||||
_client = client;
|
||||
_audit = audit;
|
||||
_auth = auth;
|
||||
_logger = (Microsoft.Extensions.Logging.ILogger?)logger ?? Microsoft.Extensions.Logging.Abstractions.NullLogger.Instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Dispatches a Test Connect probe for the supplied driver type and config JSON,
|
||||
@@ -42,17 +58,23 @@ public sealed class AdminProbeService
|
||||
using var outerCts = CancellationTokenSource.CreateLinkedTokenSource(ct);
|
||||
outerCts.CancelAfter(TimeSpan.FromSeconds(65));
|
||||
|
||||
TestDriverConnectResult result;
|
||||
try
|
||||
{
|
||||
return await _client.AskAsync<TestDriverConnectResult>(msg, outerCts.Token);
|
||||
result = await _client.AskAsync<TestDriverConnectResult>(msg, outerCts.Token);
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
return new TestDriverConnectResult(false, "Probe request did not return within 65s.", null, correlationId);
|
||||
result = new TestDriverConnectResult(false, "Probe request did not return within 65s.", null, correlationId);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return new TestDriverConnectResult(false, $"Probe dispatch failed: {ex.Message}", null, correlationId);
|
||||
result = new TestDriverConnectResult(false, $"Probe dispatch failed: {ex.Message}", null, correlationId);
|
||||
}
|
||||
|
||||
// #835 review I-1: who Test-Connected which endpoint with which driver's credential reference, and how it went.
|
||||
await Audit.CredentialUseAudit.RecordAsync(_audit, _auth, _logger, Audit.CredentialUseAudit.TestConnectAction,
|
||||
driverType, configJson, driverInstanceId, result.Ok, result.Message).ConfigureAwait(false);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user