fix(secrets): SqlServer/Akka registration is order-independent; bump 0.6.6 (scadaproj#30)
AddZbSecretsSqlServerStore / AddZbSecretsSqlServerReplication (and the Akka extension, same defect class) TryAdd-ed their ISecretStore, ISecretsStoreMigrator and ISecretReplicator ahead of their internal AddZbSecrets call. An application that had already called AddZbSecrets therefore silently kept the SQLite store (shared-store mode) or NoOpSecretReplicator (hub/Akka modes). They now call AddZbSecrets first and RemoveAll + AddSingleton their own registrations; a later AddZbSecrets only TryAdds, so either order yields the same graph with exactly one ISecretStore registration. - tests: RegistrationOrderTests (SqlServer + Akka) build and resolve the real container in both orders; core-first fails without the fix - Directory.Build.props 0.6.5 -> 0.6.6 (NOT packed or published) - code-reviews: Secrets-001 Resolved; README regenerated Claude-Session: https://claude.ai/code/session_01GT67AEHd2Acv1YPwGfXEoV
This commit is contained in:
+12
-9
@@ -82,20 +82,23 @@ public static class AkkaSecretsServiceCollectionExtensions
|
||||
new DeferredSecretCacheInvalidator(sp.GetService<ISecretCacheInvalidator>),
|
||||
sp.GetRequiredService<IOptions<AkkaSecretsReplicationOptions>>().Value));
|
||||
|
||||
// MUST be registered BEFORE AddZbSecrets. That call does
|
||||
// TryAddSingleton<ISecretReplicator, NoOpSecretReplicator>(), so if it ran first it would
|
||||
// win and the TryAdd below would be silently discarded — leaving replication bound to the
|
||||
// no-op sink, publishing nothing, with no actor ever created and no error anywhere.
|
||||
// Shipped that way in 0.2.0; fixed in 0.2.1. The SqlServer package always had this order.
|
||||
services.TryAddSingleton<ISecretReplicator>(sp =>
|
||||
new AkkaSecretReplicator(sp.GetRequiredService<SecretReplicationActorProvider>().ActorRef));
|
||||
|
||||
// The local store + migrator come from AddZbSecrets (SQLite by default).
|
||||
services.AddZbSecrets(config, secretsSectionPath);
|
||||
|
||||
// REPLACED after the core call rather than TryAdd-ed before it (scadaproj#30). AddZbSecrets
|
||||
// does TryAddSingleton<ISecretReplicator, NoOpSecretReplicator>(); a TryAdd here only won when
|
||||
// this package ran first, so an application that had already called AddZbSecrets got
|
||||
// replication bound to the no-op sink — publishing nothing, no actor ever created, no error
|
||||
// (the 0.2.0 shape, and still reachable from the application's side until 0.6.6).
|
||||
services.RemoveAll<ISecretReplicator>();
|
||||
services.AddSingleton<ISecretReplicator>(sp =>
|
||||
new AkkaSecretReplicator(sp.GetRequiredService<SecretReplicationActorProvider>().ActorRef));
|
||||
|
||||
// Decorate the local store so every write publishes. Resolved from the concrete SQLite store,
|
||||
// not ISecretStore — asking the container for ISecretStore here would resolve this very
|
||||
// decorator and recurse forever.
|
||||
// decorator and recurse forever. The core's ISecretStore forward is removed first so the
|
||||
// decorator is the only registration in either call order.
|
||||
services.RemoveAll<ISecretStore>();
|
||||
services.AddSingleton<ISecretStore>(sp => new ReplicatingSecretStore(
|
||||
sp.GetRequiredService<SqliteSecretStore>(),
|
||||
sp.GetRequiredService<ISecretReplicator>(),
|
||||
|
||||
+22
-10
@@ -48,14 +48,19 @@ public static class SqlServerSecretsServiceCollectionExtensions
|
||||
{
|
||||
RegisterSqlServerCore(services, config, sqlServerSectionPath);
|
||||
|
||||
// Registered BEFORE AddZbSecrets so its TryAdd calls find these already present and leave
|
||||
// them alone — that is the whole mechanism by which the SQL-Server store displaces SQLite.
|
||||
services.TryAddSingleton<ISecretStore>(sp => sp.GetRequiredService<SqlServerSecretStore>());
|
||||
services.TryAddSingleton<ISecretsStoreMigrator>(sp =>
|
||||
sp.GetRequiredService<SqlServerSecretsStoreMigrator>());
|
||||
|
||||
services.AddZbSecrets(config, secretsSectionPath);
|
||||
|
||||
// REPLACE, not TryAdd (scadaproj#30): the application may already have called AddZbSecrets,
|
||||
// whose SQLite ISecretStore / ISecretsStoreMigrator a TryAdd here would silently leave in
|
||||
// place — each node of a "shared-store" pair would then write its own local file. Replacing
|
||||
// after the core call makes the outcome independent of call order: a later AddZbSecrets only
|
||||
// TryAdds, so it cannot displace these either.
|
||||
services.RemoveAll<ISecretStore>();
|
||||
services.AddSingleton<ISecretStore>(sp => sp.GetRequiredService<SqlServerSecretStore>());
|
||||
services.RemoveAll<ISecretsStoreMigrator>();
|
||||
services.AddSingleton<ISecretsStoreMigrator>(sp =>
|
||||
sp.GetRequiredService<SqlServerSecretsStoreMigrator>());
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
@@ -87,15 +92,22 @@ public static class SqlServerSecretsServiceCollectionExtensions
|
||||
|
||||
services.TryAddSingleton<ISecretReplicationHub>(sp => sp.GetRequiredService<SqlServerSecretStore>());
|
||||
|
||||
services.TryAddSingleton<ISecretReplicator>(sp =>
|
||||
new SqlServerSecretReplicator(sp.GetRequiredService<ISecretReplicationHub>()));
|
||||
|
||||
// The local store + its migrator come from AddZbSecrets (SQLite by default).
|
||||
services.AddZbSecrets(config, secretsSectionPath);
|
||||
|
||||
// REPLACE, not TryAdd (scadaproj#30): if the application called AddZbSecrets first, its
|
||||
// NoOpSecretReplicator is already registered and a TryAdd would silently lose to it — live
|
||||
// publish disabled, propagation left to the sweep interval, no error anywhere.
|
||||
services.RemoveAll<ISecretReplicator>();
|
||||
services.AddSingleton<ISecretReplicator>(sp =>
|
||||
new SqlServerSecretReplicator(sp.GetRequiredService<ISecretReplicationHub>()));
|
||||
|
||||
// Decorate the local store so every write publishes. Resolved from the concrete SQLite store
|
||||
// rather than ISecretStore, because ISecretStore is what we are replacing — asking the
|
||||
// container for it here would resolve this very decorator and recurse forever.
|
||||
// container for it here would resolve this very decorator and recurse forever. Any earlier
|
||||
// ISecretStore registration (the core's SQLite forward) is removed so the decorator is the
|
||||
// only one, whichever order the calls came in.
|
||||
services.RemoveAll<ISecretStore>();
|
||||
services.AddSingleton<ISecretStore>(sp => new ReplicatingSecretStore(
|
||||
sp.GetRequiredService<Secrets.Sqlite.SqliteSecretStore>(),
|
||||
sp.GetRequiredService<ISecretReplicator>(),
|
||||
|
||||
+4
-2
@@ -138,8 +138,10 @@ public static class SecretsServiceCollectionExtensions
|
||||
// Migrator: singleton, constructed from the already-registered connection factory. Needed
|
||||
// before any store operations so the schema exists. Registered BOTH concretely (for callers
|
||||
// that want the SQLite migrator specifically) and behind the ISecretsStoreMigrator seam that
|
||||
// the hosted service and CLI consume — a replication package that swaps the store registers
|
||||
// its own ISecretsStoreMigrator BEFORE calling AddZbSecrets, and TryAdd leaves it in place.
|
||||
// the hosted service and CLI consume. A package that swaps the store (SQL-Server shared-store
|
||||
// mode) REPLACES these after its own AddZbSecrets call, and the TryAdds here leave such a
|
||||
// replacement in place when the application calls AddZbSecrets again afterwards — so the
|
||||
// outcome does not depend on call order (scadaproj#30).
|
||||
services.TryAddSingleton(sp =>
|
||||
new SqliteSecretsStoreMigrator(sp.GetRequiredService<SecretsSqliteConnectionFactory>()));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user