fix(secrets): review round 1 — pre-host expander reads the same store the runtime serves, raw-string Replication:Enabled parse, leftover-key warning

- SecretsRegistration: UsesCentralSharedStore predicate shared by AddScadaBridgeSecrets and the
  new AddPreHostExpander, so a Central node's Layer-A ${secret:} expander composes against the
  shared SQL store whenever Secrets:Store:Provider=SqlServer does — closing the gap where a
  central migrated off the retired Grpc topology would boot-time-resolve config from per-node
  SQLite while serving the shared store.
- Program.cs: expander block now calls AddPreHostExpander + resolves the store-agnostic
  ISecretsStoreMigrator seam; stale Grpc-hub/replication comment rewritten.
- DeployedSecretsMirror.cs: stale "gRPC-hub follower half" doc comment rewritten to state the
  now-permanent local-SQLite-only invariant.
- StartupValidator: Secrets:Replication:Enabled read as a raw string (any non-empty, non-"false"
  value rejected) instead of GetValue<bool>, which threw a raw binder crash on "yes"/"1"; added a
  CollectWarnings entry for leftover Secrets:Replication/Secrets:GrpcHub child keys once Enabled
  is false/unset.
- Tests: +15 (AddPreHostExpander/UsesCentralSharedStore wiring, Replication:Enabled edge values,
  leftover-key warnings). Full solution build and full Host.Tests green (593/593).
This commit is contained in:
Joseph Doherty
2026-09-28 20:10:17 -04:00
parent 2bac13170c
commit bc29dc412b
6 changed files with 423 additions and 30 deletions
@@ -31,7 +31,7 @@ public static class StartupValidator
// Deploy Artifacts, and a replicated site store would publish DeployedSecretsMirror's local
// deletes fleet-wide. Checked unconditionally (both roles): a Site used to be the gRPC
// hub's follower half, so the flag was never Central-only.
var secretsReplicationEnabled = configuration.GetValue<bool>("Secrets:Replication:Enabled");
var secretsReplicationEnabled = IsSecretsReplicationEnabled(configuration);
// GrpcPort: default 8083 when absent; only fails the range rule when the key is
// present AND invalid. The out-param assignment mirrors the original so the
@@ -251,6 +251,7 @@ public static class StartupValidator
var seedNodes = configuration.GetSection("ScadaBridge:Cluster:SeedNodes").Get<List<string>>();
var provider = InboundApiKeyStoreOptions.ReadProvider(configuration);
var secretsStoreProvider = configuration["Secrets:Store:Provider"];
var secretsReplicationEnabled = IsSecretsReplicationEnabled(configuration);
var isClusteredCentral = role == "Central" && seedNodes is { Count: >= 2 };
var warnings = new List<string>();
@@ -283,9 +284,46 @@ public static class StartupValidator
+ "deploy its own secret set to sites; set Secrets:Store:Provider=SqlServer");
}
// Review round 1, Minor #4: a config that still carries Secrets:Replication or
// Secrets:GrpcHub child keys — left over from before Task 11 retired the hub — is not
// itself an error (Validate already rejects Enabled=true outright), but every key under
// either section is now silently ignored. That is worth a Warning so an operator cleans
// QA/prod appsettings rather than assuming a still-present Mode/BearerToken/Endpoint value
// does anything. Excludes the bare "Enabled" key itself: "Enabled: false" alone is the
// normal, still-valid shape of every existing deployment's config and must not warn.
var hasStaleReplicationKeys = configuration.GetSection("Secrets:Replication").GetChildren()
.Any(child => !string.Equals(child.Key, "Enabled", StringComparison.OrdinalIgnoreCase));
var hasStaleGrpcHubKeys = configuration.GetSection("Secrets:GrpcHub").GetChildren().Any();
if (!secretsReplicationEnabled && (hasStaleReplicationKeys || hasStaleGrpcHubKeys))
{
warnings.Add(
"Secrets:Replication / Secrets:GrpcHub settings are ignored — the secrets hub is "
+ "retired; remove them");
}
return warnings;
}
/// <summary>
/// Whether <c>Secrets:Replication:Enabled</c> is "set" — read as a raw string rather than
/// <c>IConfiguration.GetValue&lt;bool&gt;</c> (review round 1, Minor #3), which throws a raw
/// binder <see cref="InvalidOperationException"/> on a non-boolean value like <c>"yes"</c> or
/// <c>"1"</c>, so a malformed leftover key would surface as an unrelated parse crash instead of
/// the designed retirement message in <see cref="Validate"/>. Any value other than absent,
/// empty, or (case-insensitively) <c>"false"</c> counts as "set" — deliberately stricter than
/// bool parsing, so a typo'd leftover (<c>Enabled: 1</c>, <c>Enabled: yes</c>) still gets the
/// explanatory message rather than silently passing as falsy. Shared by <see cref="Validate"/>
/// (which rejects "set" outright) and <see cref="CollectWarnings"/> (which, for the "not set"
/// case, separately warns about any OTHER leftover key under the same retired sections).
/// </summary>
private static bool IsSecretsReplicationEnabled(IConfiguration configuration)
{
var raw = configuration["Secrets:Replication:Enabled"];
return !string.IsNullOrEmpty(raw)
&& !string.Equals(raw, "false", StringComparison.OrdinalIgnoreCase);
}
/// <summary>
/// Extracts the TCP port from an Akka seed-node address of the form
/// <c>akka.tcp://system@host:port</c>. Returns <c>-1</c> when no port can be parsed.