Repository navigation
Enforce exact loaded authentication family versions - #4820
paulmedynski wants to merge 19 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The capability guard remains unconditionally true, so trimming and AOT do not remove the reflective validation path as documented.
1 open finding
What changed in this PR
Adds exact runtime version enforcement across the SqlClient authentication package family.
Changes:
- Validates driver and discovered Azure informational versions during bootstrap.
- Adds mismatch fixtures, diagnostics checks, and test targets.
- Documents package-version and trimmed/AOT behavior.
| File | Description |
|---|---|
RuntimeVersionTest.csproj |
Defines mismatched driver fixture. |
RunAuthenticationTests.ps1 |
Runs replacement-DLL scenarios. |
ConfigurationTest/Program.cs |
Verifies cached failures and diagnostics. |
SqlClient/src/PackageReadme.md |
Documents version policy. |
Microsoft.Data.SqlClient.slnx |
Adds fixture project. |
RuntimeFamilyVersionTest.cs |
Tests version comparison. |
SqlAuthenticationProviderRegistry.cs |
Enforces family versions. |
Abstractions/src/PackageReadme.md |
Documents enforcement behavior. |
AuthenticationFeatureSwitches.cs |
Adds trimming/AOT guard. |
BUILDGUIDE.md |
Documents runtime-version tests. |
build.proj |
Adds the test target. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
1dd4640 to
d0ad265
Compare
d0ad265 to
2d14e2e
Compare
Move provider registration, lookup and initialization into Extensions.Abstractions while preserving the driver's public API through type forwarding. Keep configuration and initializer precedence, replacement callbacks, and diagnostic failure handling. Guard reflective configuration and optional Azure discovery for trimming and Native AOT, and cover registry behavior, bootstrap, discovery, feature switches and type forwarding. Co-authored-by: Copilot <[email protected]>
Allow explicit provider registration and lookup after recoverable bootstrap failure while preserving configuration precedence. Improve Azure contract upgrade traces and missing-provider guidance without adding a diagnostics API. Add recovery, connection-error, switch and test-isolation coverage, and document compatibility considerations in package readmes and API guidance. Co-authored-by: Copilot <[email protected]>
Preserve connection metadata and trace-only bootstrap diagnostics, cover Open and OpenAsync with simulated-server regressions, and document authentication compatibility changes in package readmes. Co-authored-by: Copilot <[email protected]>
Remove obsolete string-schema failure cases now covered by the parent's relaxed parsing tests. Retain provider-collection validation coverage. Co-authored-by: Copilot <[email protected]>
Remove obsolete failure expectations superseded by the parent's provider-schema recovery coverage. Co-authored-by: Copilot <[email protected]>
Filter optional authentication assembly binding failures through the existing nested-fatal recoverability check. Exercise production Assembly.Load resolution for recoverable and fatal FileNotFoundException, FileLoadException, and BadImageFormatException failures. Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Trace and skip recoverable initializer and provider failures while continuing later configuration entries and enabled Azure discovery. Preserve valid options and configuration precedence, and retain fatal activation errors. Correct Azure options-contract upgrade guidance to 7.0.2, document the compatibility behavior, and add unit and real-Azure discovery coverage. Co-authored-by: Copilot <[email protected]>
Forward Abstractions test reference mode and version arguments, prepare Logging in Package mode, and cover orchestration with regression tests. Clarify diagnostic timing and recovery behavior in authentication XML docs. Co-authored-by: Copilot <[email protected]>
Restore resource-backed authentication exception factories, neutral and satellite resources, resource embedding, fallback tests and driver resource cleanup as a separate stacked layer. Verify French parent-culture lookup alongside neutral messages. Co-authored-by: Copilot <[email protected]> Fix authentication localization review feedback in #4852 Restore complete ResX headers across all authentication resource cultures and explain culture selection and diagnostic fallback intent. Co-authored-by: Copilot <[email protected]> Complete authentication exception localization in #4852 Move remaining configuration and registration exception messages into neutral resources, preserve framework exception messages, and focus string tests on helper behavior rather than translation availability. Co-authored-by: Copilot <[email protected]> Cover authentication resource lookup and refine exception factories in #4852 Use French as the stable satellite for direct lookup, parent fallback, neutral fallback, and independent UI/formatting culture coverage. Return concrete exception types from authentication factories. Co-authored-by: Copilot <[email protected]>
91b46f0 to
7ab7460
Compare
There was a problem hiding this comment.
🟡 Changes recommended
Driver-version mismatches are treated as recoverable, allowing provider registration and lookup to proceed despite the required null/false failure contract.
7 open issues
Reject provider registration and lookup after driver-version mismatch · New Version validation failure is swallowed during bootstrap FeatureGuard fails to disable dynamic provider loading in trimmed/AOT builds Add public API regression test for cached driver mismatch failure Add isolated replacement-driver bootstrap regression coverage Align test project version to preserve constructor failure handling Validate the plugin's loaded driver instead of the default-context assembly
1 resolved since last review
Review effort: Balanced
Disable further automatic Azure discovery after a family-version failure. Keep explicit provider registration, lookup and configuration precedence usable. Validate loaded drivers across load contexts while retaining exact version matching. Add regression coverage and document the breaking behavior and explicit Azure workaround. Update agent guidance to preserve the discovery-only failure policy. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Runtime validation repeats costly assembly scans under a lock and can disable Azure discovery across isolated plugins, while swallowed test exceptions undermine verification of the disabled-discovery guard.
3 open issues
7 resolved since last review
Reject provider registration and lookup after driver-version mismatch Version validation failure is swallowed during bootstrap FeatureGuard fails to disable dynamic provider loading in trimmed/AOT builds Add public API regression test for cached driver mismatch failure Add isolated replacement-driver bootstrap regression coverage Align test project version to preserve constructor failure handling Validate the plugin's loaded driver instead of the default-context assembly
Review effort: Balanced
| [RequiresDynamicCode("The SqlClient assembly is loaded dynamically.")] | ||
| private static void ValidateSqlClientVersion(bool loadIfMissing) | ||
| { | ||
| if (ValidateLoadedSqlClientVersions(AppDomain.CurrentDomain.GetAssemblies()) || !loadIfMissing) |
| if (string.Equals(assembly.GetName().Name, "Microsoft.Data.SqlClient", | ||
| StringComparison.OrdinalIgnoreCase)) | ||
| { | ||
| ValidateFamilyVersion(assembly); |
| registry.EnsureBootstrapped(loadAzureAssembly: () => | ||
| throw new InvalidOperationException("Discovery must not be retried.")); | ||
| registry.LoadAzureExtension(() => | ||
| throw new InvalidOperationException("Version failure must disable later discovery.")); |
Include explicit resource-directory inputs, isolated allowlist selection, and all three behavioral tests in this layer; retain existing validation policy. Co-authored-by: Copilot <[email protected]>
Preserve the final scenario harness, publishing checks, CI wiring and orchestration tests from the original #4817 layer while dropping obsolete intermediate fixture deferrals during restacking. Co-authored-by: Copilot <[email protected]>
Relocate runtime-version fixtures and orchestration to the final PR #4820. Align configuration scenarios and framework expectations with the rebased registry. Co-authored-by: Copilot <[email protected]>
…fixture Keep the independently buildable #4817 fixture compatible with .NET Framework after rebasing the stack. Co-authored-by: Copilot <[email protected]>
Remove the inherited deferral note now that this stack layer supplies the executable scenarios. Co-authored-by: Copilot <[email protected]>
- Describe runtime validation in authentication bootstrap documentation - Decouple authentication guidance from consumer version enforcement - Defer the executable runtime-version fixture to #4817
Disable further automatic Azure discovery after a family-version failure. Keep explicit provider registration, lookup and configuration precedence usable. Validate loaded drivers across load contexts while retaining exact version matching. Add regression coverage and document the breaking behavior and explicit Azure workaround. Update agent guidance to preserve the discovery-only failure policy. Co-authored-by: Copilot <[email protected]>
Keep replacement-driver scenarios and CI integration with the runtime policy. Verify discovery-only failure and preserved explicit provider APIs, restoring driver and configuration inputs after each run. Co-authored-by: Copilot <[email protected]>



Description
Validate exact loaded authentication-family versions in untrimmed applications, and disable automatic Azure authentication discovery after a version-policy failure without disabling explicit provider registration or lookup.
Why?
Matching assembly binding versions do not guarantee compatible SqlClient family packages. Exact informational-version checking provides actionable diagnostics before automatically registering an incompatible Azure provider, while preserving the explicit-registration escape hatch.
How
+build metadata. Missing metadata is also a version-policy failure.GetProvider/SetProvidercalls to returnnull/false.Public API and behavior changes
No public types or signatures change. This is an observable breaking change for mixed-version deployments relying on automatic provider discovery.
FileNotFoundException; Abstractions-only explicit registration remains available.[family-version, next-major). Exact discovery matching remains required.Recovery and deliberate newer-Azure usage
Prefer aligning SqlClient, Abstractions, Azure, Logging, and AKV to the same exact package version, then restart to retry automatic discovery. SqlServer.Server and native SNI remain independently versioned.
Applications deliberately using newer Azure can disable
Switch.Microsoft.Data.SqlClient.EnableAzureExtensionDiscoverybefore first registry access and explicitly construct/registerActiveDirectoryAuthenticationProviderfor every method used, checking eachSetProviderresult. Configuration-owned registrations retain precedence. This bypasses discovery's version gate, not binary compatibility requirements; newer Azure may require newer Abstractions/Logging APIs. It does not suppressSQLCLIENT001or change the independent Azure Attestation loader.See the Azure package README example.
Stack order
AOT 7, the final layer: #4821 -> #4852 -> #4942 -> #4817 -> #4820. The earlier merged layers are #4816 and #4860; #4942 replaces auto-merged #4819. General configuration and publishing validation remain in #4817; this PR adds its own runtime-version-specific coverage.
The commits and PR bases follow this order in native stack #4943.
Issues
Related consumer build-time enforcement: #4815. Runtime replacement-driver coverage previously deferred to #4817 is now included here so the earlier stack can merge without this policy change.
Testing
dotnet build build.proj -t:TestAbstractions -p:ReferenceType=Project -p:Configuration=Debug -p:TestFramework=net10.0 -v:minimal- passed: 247 tests, 3 skipped.dotnet build build.proj -t:TestAuthentication -p:ReferenceType=Project -p:Configuration=Release -p:TestFramework=net10.0 -p:AuthenticationPublish=true -p:PackageVersionSqlClient=8.0.0-stack.7 -v:minimal- passed: six configuration and two runtime-version scenarios, trimmed execution, and NativeAOT execution.NUGET_PACKAGES=<isolated-cache> dotnet build build.proj -t:TestAuthentication -p:ReferenceType=Package -p:Configuration=Release -p:TestFramework=net10.0 -p:AuthenticationPublish=true -p:PackageVersionSqlClient=8.0.0-stack.7pkg -v:minimal- passed: six configuration and two runtime-version scenarios, trimmed execution, and NativeAOT execution using locally built packages.pwsh -NoProfile -NonInteractive -Command '$r = Invoke-Pester -Path ./eng/pipelines/scripts/tests/Build-Orchestration.Tests.ps1,./eng/pipelines/scripts/tests/Pipeline-Arguments.Tests.ps1 -PassThru; if ($r.FailedCount -gt 0 -or $r.PassedCount -eq 0) { exit 1 }'- passed: 124 tests.finallyblocks.dotnet build build.proj -t:BuildAuthenticationTests -p:ReferenceType=Project -p:Configuration=Debug -p:TestFramework=net462 -v:minimal- passed: configuration and replacement-driver fixture compilation; this is not Windows runtime execution.git range-diffconfirms both original runtime-validation commits replay unchanged.git diff --checkpassed.Guidelines
Please review the contribution guidelines before submitting a pull request: