fix(security): /raw credential banner keeps running findings when the ConfigDb scan fails (#847)
This commit is contained in:
@@ -113,9 +113,47 @@ public sealed class CredentialReferencePreflight(IDbContextFactory<OtOpcUaConfig
|
||||
.Select(kv => new CredentialReferenceFinding(
|
||||
CredentialFindingSource.Running, "", s.DriverInstanceId, s.DriverInstanceId, null,
|
||||
$"{kv.Key[LegacyCredentialReferenceTracker.DiagnosticsKeyPrefix.Length..]}: {kv.Value}")))
|
||||
// Both nodes of a redundant pair run the same driver and report the same finding; the health store
|
||||
// keeps one snapshot per (driver, node) since lmxopcua#847, so collapse the identical pair here.
|
||||
.Distinct()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// What the <c>/raw</c> credential banner renders (lmxopcua#847), composed from two INDEPENDENT sources: the
|
||||
/// ConfigDb scan (draft + deployed rows) and the live driver-health feed (running drivers' warn-only
|
||||
/// <c>credential-compat:*</c> resolutions). A failed ConfigDb scan must never hide the running findings — they
|
||||
/// come from the in-process health store and are exactly what is still true while the database is unreachable.
|
||||
/// </summary>
|
||||
/// <param name="ScanFindings">Draft / Deployed findings from the last successful scan (empty when it failed).</param>
|
||||
/// <param name="RunningFindings">Running-driver findings from the live health feed.</param>
|
||||
/// <param name="ScanError">The scan failure note, or null when the scan succeeded (or has not run).</param>
|
||||
/// <param name="ScannedAtUtc">When the scan last ran.</param>
|
||||
public sealed record CredentialReferenceBannerModel(
|
||||
IReadOnlyList<CredentialReferenceFinding> ScanFindings,
|
||||
IReadOnlyList<CredentialReferenceFinding> RunningFindings,
|
||||
string? ScanError,
|
||||
DateTime? ScannedAtUtc)
|
||||
{
|
||||
/// <summary>Whether the banner renders at all.</summary>
|
||||
public bool Visible => ScanFindings.Count > 0 || RunningFindings.Count > 0 || ScanError is not null;
|
||||
|
||||
/// <summary>Composes the banner from the last scan result and the current driver-health snapshots.</summary>
|
||||
/// <param name="scan">The last preflight result.</param>
|
||||
/// <param name="healthSnapshots">The live driver-health snapshots.</param>
|
||||
/// <returns>The banner model.</returns>
|
||||
public static CredentialReferenceBannerModel Compose(
|
||||
CredentialReferencePreflightState.Snapshot scan,
|
||||
IEnumerable<Commons.Messages.Drivers.DriverHealthChanged> healthSnapshots)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(scan);
|
||||
var running = CredentialReferencePreflight.RunningFindings(healthSnapshots ?? []);
|
||||
// Running-source rows only ever come from the health feed; a scan result never carries them.
|
||||
var scanned = scan.Findings.Where(f => f.Source != CredentialFindingSource.Running).ToList();
|
||||
return new(scanned, running, scan.Error, scan.ScannedAtUtc);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The last preflight result, shown by the AdminUI <c>/raw</c> credential banner.</summary>
|
||||
public sealed class CredentialReferencePreflightState
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user