Skip to content

Latest commit

 

History

History
257 lines (215 loc) · 15 KB

README.md

File metadata and controls

257 lines (215 loc) · 15 KB

SecretKit.Extensions.Configuration

Prepare complete local generations, pin them for a logical operation, and opt into ordinary-string configuration export only where required. This development preview does not provide a remote snapshot transaction or an automatic refresh worker.

Publish configuration

Integration fragment: the host supplies IEnumerable<SecretSelection> selections, IEnumerable<SecretConfigurationMapping> mappings and a cancellation token.

using Microsoft.Extensions.Configuration;
using SecretKit.Extensions.Configuration;

using var loader = new SecretSnapshotLoader(selections);
(await loader.RefreshAsync(cancellationToken)).GetValueOrThrow();
using var initial = loader.Acquire();
using var export = SecretConfigurationExport.Create(initial, mappings);
IConfigurationRoot root = new ConfigurationBuilder().Add(export).Build();
using IDisposable rootLifetime = (IDisposable)root;
(await loader.RefreshAsync(cancellationToken)).GetValueOrThrow();
using var replacement = loader.Acquire();
export.Replace(replacement);

The export contains ordinary plaintext strings. Disposing the source does not erase strings retained by configuration consumers, options, logs or downstream code.

Activate a validated client

SecretGenerationCoordinator<TClient> owns successful application-created clients implementing IAsyncDisposable. The application supplies an intended reader, required reference mapping, a candidate validator, stale policy, maximum age and clock. The validator borrows its SecretSnapshotHandle only for the call, and must construct an independent client before returning SecretOutcome<TClient>.Success(client).

Pass immutable SecretCollectionOptions as the coordinator's final collectionOptions argument to select concurrency, selection count, encoded payload size and collection timeout. The same selection validates constructor mappings and governs every Enable/Check again collection. Null selects the loader defaults: one concurrent read, 1000 selections, 16 MiB and one minute. The supported bounds are described under bounded collection.

EnableAsync collects and validates a candidate. Acquire returns a SecretGenerationLease<TClient> when the current generation is usable, or null. Run work through lease.ExecuteAsync((client, token) => ...); the callback borrows the client, and must neither retain nor dispose it. Dispose the lease asynchronously. Retiring a generation waits for existing leases and in-flight work before disposing its client. Disposing the coordinator rejects new acquisition and retires generations.

CheckAgainAsync validates without enabling a disabled integration. DisableAsync retires the active client. Choose FailClosed or explicitly bounded BoundedLastKnown policy; provider expiry still limits usability. Client activation and string export are separate operations, with no joint atomic commit.

For Infisical-first local adoption, this package is optional. Selections default to required; mark an explicitly optional selection with SecretPresencePolicy.Optional. Application key naming, tenant bindings, cache/refresh policy and Data Protection admission remain application choices. Installed-consumer qualification does not add those policies to the runtime library. The RuntimeConfiguration sample composes separate required and optional groups; capability checks and explicit client activation remain application-owned decisions.

See current support for package boundaries and observed offline evidence.

This optional package references Core and Microsoft.Extensions.Configuration. Core remains BCL-only. It installs no automatic worker or hosting lifecycle. Supplied readers and transports remain caller-owned.

Optional completed-operation diagnostics

The BCL ActivitySource and Meter are both named SecretKit.Extensions.Configuration. They are initialized lazily when completed records can be exported outside collection and client ownership. No exporter, scheduler, provider reference or Hosting dependency is installed.

The activity name is configuration.operation. The configuration.operations counter records one per completed record; configuration.duration records its duration in seconds. Both instruments and activities use only these closed tags:

Tag Values and meaning
operation Collection, Publication, Retirement
outcome The local SecretStatus
reason The local SecretFailureReason
termination Completed, CallerCanceled, DeadlineExceeded, DependencyCanceled, Faulted
state Published, Rejected, Validated, Superseded, Fresh, Stale, DeadlineElapsed, Retired, RetirementFailed

Collection measures RefreshAsync, including admission waits and candidate cleanup. Publication measures an admitted coordinator collection/validation attempt, including rejected-client cleanup; check-only validation can report Validated without activating anything. State describes the local decision at completion, not future availability. Retirement measures actual application client disposal and local retirement bookkeeping after the last pin, including disposal of a validated client that was not published. It does not measure the generation's lifetime. Material reads, acquisition and lease execution emit no use events; releasing an operation pin may cause a retirement record.

UTC start and monotonic elapsed time are captured before export. Span and histogram use the same fixed duration, with a one-TimeSpan-tick (100 ns) floor for zero or subtick intervals. Callbacks do not contribute to that interval. Export omits a record if its diagnostic clock fails; it never invents timing or bypasses owned client cleanup and completion settlement. Export occurs after completion, so these activities are not in-flight parents of reader or validator work. Only opaque W3C parent trace/span identifiers and trace flags are retained; parent objects, baggage and tracestate are not copied.

Records are deferred through enclosing Configuration operations until collection storage/admission and outer lease or coordinator disposal completions are released. Activity and metric callback failures are isolated independently, ambient Activity.Current is restored, and listener reentry does not recursively emit diagnostics. Arbitrary host listeners can still delay the returning call; there is no bounded listener completion guarantee.

Caller cancellation retains its public propagation and precedence over an actual collection deadline. Otherwise, dependency cancellation is attributed only when that reader failure wins input-order reduction. An unselected later failure cannot change the aggregate diagnostic. A selected reader cancellation still returns the existing Unavailable/TransportFailure outcome. Local diagnostics never certify opaque reader/provider side effects or downstream readiness.

SDK tags contain no consumer keys, values, content lengths, exception text, application client type names, generation identifiers or revisions. Host-added fields and instrumentation remain the host's responsibility. Offline diagnostic tests do not establish native provider or installed-package qualification.

Logical multi-key operations

Construct SecretSnapshotLoader with explicit SecretSelection entries: each consumer key names its selected ISecretReader and authority-bound SecretReference. Consumer keys use ordinal comparison. Selections are unique and fixed for that loader. RefreshAsync collects asynchronously and serializes concurrent collections. Only a complete valid candidate replaces the current generation. Absent, denied, invalid, expired or unknown-validity material cannot become a required generation. Validity deadlines are checked again at publication. Subsequent freshness and activation decisions belong to the caller. Only an optional selection's explicit Absent outcome is admitted. An absence-only generation is valid and replaces stale presence; denial, expiry and other failures still reject the entire candidate. Use separate loaders for optional capability groups when one group's failure must not block another. Successful reader observations must retain the exact requested SecretReference instance. A different object, even with the same authority and address, is rejected as Invalid before material is copied. Rejected reads are disposed and previously acquired generations and copies remain valid.

RefreshAsync returns a bounded SecretOutcome<long>; LastAttempt retains only timing, status, closed failure reason, retry timing and cancellation evidence. An unexpected reader exception becomes Unavailable without its message or inner exception. Cancellation propagates, clears candidate storage and preserves the prior generation. Cancelling a queued collection does not cancel another collection. Disposal prevents publication and future acquisition, but does not itself cancel reader I/O: the caller supplies its cancellation policy.

Acquire once with Acquire() for each logical operation, then call handle.Read(consumerKey) for every required value. Each returned SecretRead owns an independent copy and must be disposed. Generation retirement waits for all acquired handles; loader disposal cannot invalidate existing handles or copies. Handle disposal is idempotent and prevents further reads from that handle. Copies already returned survive until their own disposal. ReadOutcome(key) returns either an owned successful read or explicit Absent for a declared optional key. Read(key) throws for declared absence. Both reject unknown keys and disposed handles. Count counts present values; SelectionCount also counts absent selections.

Generation is a local publication number. Collection start/end times and each read's actual SecretObservation retain version and provider evidence; unknown versions stay unknown. Local immutability does not establish a remote transaction or simultaneous remote reads.

Bounded collection

Pass SecretCollectionOptions as the loader's options argument to adjust limits. Defaults are concurrency 1, 1000 selections, 16 MiB of candidate UTF-8 payload and a one-minute collection timeout. Admitted ranges are concurrency 1-32, selections 1-10000, payload 1 KiB-64 MiB and positive timeout up to ten minutes.

Enumeration is bounded before retaining selections. A contiguous ordinal window limits unresolved/staged work; a stalled earlier ordinal cannot grow an unbounded queue of later results. Reduction, payload accounting and failure selection follow input order, not completion order. A terminal failure stops new admission but does not cancel earlier ordinals. All started reads settle and all delivered reads are disposed, including late results rejected after cancellation or expiry.

The timeout starts after serialized admission and cancels only that collection's reads. Caller cancellation propagates and takes precedence over the deadline; deadline expiry returns Unavailable/DeadlineExceeded after started work settles. An unrelated reader cancellation becomes Unavailable/TransportFailure. A reader that ignores cancellation cannot be forcibly terminated; the collection remains in flight until it returns. Disposal prevents publication but does not kill it.

The payload limit bounds encoded candidate values, not process heap usage. UTF-16 owners, previous pinned generations, returned copies, parser buffers and concurrent reader deliveries require additional memory. Exact-reference, validity and expiry checks run again before publication. No automatic refresh or retry is installed.

One prepared owner

PreparedSecretConfiguration.PrepareAsync(selections, ...) returns an outcome containing an owner of the loader and one pinned generation. Preparation performs asynchronous reads but creates no ordinary plaintext strings. Use Read or ReadOutcome to obtain independently owned material.

Call prepared.Export(mappings) only when plaintext configuration is intended. All consumer keys and destination collisions are validated before any reveal. The returned IConfigurationRoot is borrowed; the prepared owner owns its root and export, permits one successful export and releases both before its handle and loader. Failed mapping validation can be corrected before export. Repeated disposal is harmless, borrowed readers remain host-owned and previously returned material copies remain independently usable.

Deliberate plaintext export

Call SecretConfigurationExport.Create(handle, mappings) only when ordinary managed strings are intended. Each SecretConfigurationMapping explicitly names its consumer key and destination configuration key. The complete mapping is checked for ordinal case-insensitive collisions before reading material. Add the returned source to a ConfigurationBuilder; Build and synchronous Load do no reader I/O. Declared absent selections produce explicit null entries so lower-priority configuration cannot resurrect a value. Unknown selection keys are rejected before revealing any mapped material. Each export supports exactly one successful Build, including concurrent builders. A second build throws InvalidOperationException without affecting the winning root. The slot is consumed when the source returns its provider; if a later sibling source fails, dispose the export rather than rebuilding it.

Replace(nextHandle) prepares all mapped values, atomically replaces the provider's string dictionary and signals reload. Preparation failure leaves prior strings and the reload token unchanged. Publication is committed before notification: a throwing reload callback leaves the new values committed and causes a fixed InvalidOperationException without callback text or an inner exception. There is no rollback. Callbacks run outside source/provider gates and may reenter reads, replacement or disposal. Concurrent notifications mean re-read current committed state, not delivery of every intermediate generation. The provider is read-only. Disposing either the source or configuration root clears its dictionary references and prevents replacement or rebuild; an in-flight replacement cannot resurrect a disposed provider.

Separate IConfiguration indexer reads can cross a reload and mix generations. Use an acquired handle or construct a consumer-owned immutable typed object from one handle when multi-key coherence is required. Reload does not mean consumer activation, options convergence or fleet convergence.

GetRedactedDebugView() returns only a count and excludes keys and values. Default formatting and System.Text.Json serialization of package objects exclude material, keys, references and readers. Standard IConfiguration debug views, enumeration, options binding, application serializers, logs, diagnostics and dumps can disclose exported strings or coordinates. Those surfaces are host-owned.

SDK-owned character buffers are cleared on final release, not securely erased process-wide. Exported strings, old options and consumer fields can remain alive after replacement or disposal. This package never claims export erasure or that wrapper protection survives the string boundary.