Skip to content

Enforce exact loaded authentication family versions - #4820

Draft
paulmedynski wants to merge 19 commits into
dev/paul/aot/phase-1.6from
dev/paul/aot/phase-1.4
Draft

paulmedynski wants to merge 19 commits into
dev/paul/aot/phase-1.6from
dev/paul/aot/phase-1.4

Conversation

@paulmedynski

@paulmedynski paulmedynski commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

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

  • Compare loaded driver and discovered Azure extension informational versions with Abstractions exactly, including prerelease labels but excluding + build metadata. Missing metadata is also a version-policy failure.
  • Inspect loaded driver assemblies across load contexts, including drivers loaded after successful bootstrap. A matching default-context driver cannot hide a mismatched plugin.
  • Check the driver independently of the configuration and discovery switches while the runtime-validation capability is enabled and no prior family-version failure has disabled discovery.
  • Trace a family-version failure once and stop future automatic Azure discovery/registration. Do not poison bootstrap, remove providers, or force subsequent GetProvider/SetProvider calls to return null/false.
  • Preserve ordinary validation, callbacks, and configuration precedence.
  • Guard reflective runtime validation for removal from trimmed and NativeAOT images.
  • Include controlled-version unit regressions and the durable replacement-driver fixture/scenarios and CI integration moved from Add dedicated trimming and AOT tests #4817.
  • Document breaking behavior, recovery, and explicit newer-Azure registration in package READMEs and agent instructions.

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.

Scenario Consumer-visible behavior
Loaded driver or discovered Azure version differs, or metadata is missing Trace once and disable future automatic Azure discovery/registration. Existing and explicitly registered providers remain usable under normal validation and configuration precedence.
Driver appears in another load context or after bootstrap Later registry access checks loaded drivers while discovery remains enabled; a matching default-context driver cannot hide the mismatch.
Configuration or discovery switch is disabled The driver check remains independent of those switches, subject to its capability guard and discovery-disabled state after a failure. Explicit provider access remains available.
Driver assembly is absent Trace and skip the initial name-load check on FileNotFoundException; Abstractions-only explicit registration remains available.
No authentication provider is registered No Azure defaults are installed after the failure; Entra ID connections can fail without a suitable provider or application-supplied access-token callback.
Newer Azure patch/minor version Do not automatically accept [family-version, next-major). Exact discovery matching remains required.
Trimmed/NativeAOT publish Remove the guarded reflective path. Consumers must resolve compatible package versions before publishing; runtime checks do not replace package-graph validation.
Validation scope Check the loaded driver and discovered Azure extension, not Logging or AKV directly. Consumer build-time checks remain separate in #4815.

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.EnableAzureExtensionDiscovery before first registry access and explicitly construct/register ActiveDirectoryAuthenticationProvider for every method used, checking each SetProvider result. 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 suppress SQLCLIENT001 or 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.
  • Replacement-driver scenarios retain the real binding version but report informational version 7.0.1. With switches enabled or disabled, they verify one diagnostic, suppressed future discovery, and successful explicit registration/lookup; original DLL/configuration are restored in finally blocks.
  • Trim/AOT publishes treat compiler/linker warnings as errors, execute the produced applications, and verify Azure runtime assets are absent.
  • 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-diff confirms both original runtime-validation commits replay unchanged. git diff --check passed.
  • Windows/.NET Framework runtime execution was not run on this Linux host; CI covers that matrix.

Guidelines

Please review the contribution guidelines before submitting a pull request:

Copilot AI balanced review requested due to automatic review settings October 9, 2026 18:24
@paulmedynski
paulmedynski added this pull request to stack #4822 October 9, 2026 18:25

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@paulmedynski paulmedynski added the Area\Azure Connectivity Use this to tag issues that are related to Azure connectivity. label Oct 13, 2026
@paulmedynski paulmedynski added this to the 8.0.0-preview1 milestone Oct 13, 2026
@paulmedynski paulmedynski changed the title Enforce exact loaded authentication family versions AOT 4: Enforce exact loaded authentication family versions Oct 13, 2026
Copilot AI balanced review requested due to automatic review settings October 13, 2026 17:41
@paulmedynski
paulmedynski removed this pull request from stack #4822 October 13, 2026 17:44
@paulmedynski
paulmedynski added this pull request to stack #4839 October 13, 2026 17:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The new capability guard always returns true, so trimmed and NativeAOT images do not remove reflective runtime validation as claimed.

1 open finding

🧠 Review effort: Balanced

@paulmedynski paulmedynski changed the title AOT 4: Enforce exact loaded authentication family versions AOT 5: Enforce exact loaded authentication family versions Oct 13, 2026
Copilot AI balanced review requested due to automatic review settings October 14, 2026 10:49
@paulmedynski
paulmedynski force-pushed the dev/paul/aot/phase-1.4 branch from 1dd4640 to d0ad265 Compare October 14, 2026 10:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The constant capability guard retains reflective validation in trimmed and NativeAOT outputs.

1 open finding

🧠 Review effort: Balanced

Copilot AI balanced review requested due to automatic review settings October 14, 2026 11:36
@paulmedynski
paulmedynski force-pushed the dev/paul/aot/phase-1.4 branch from d0ad265 to 2d14e2e Compare October 14, 2026 11:36
@paulmedynski
paulmedynski removed this pull request from stack #4839 October 14, 2026 11:39
@paulmedynski paulmedynski changed the title AOT 5: Enforce exact loaded authentication family versions AOT 3: Enforce exact loaded authentication family versions Oct 14, 2026
@paulmedynski
paulmedynski added this pull request to stack #4841 October 14, 2026 11:40
paulmedynski and others added 11 commits October 27, 2026 15:52
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]>
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]>
@paulmedynski
paulmedynski force-pushed the dev/paul/aot/phase-1.4 branch from 91b46f0 to 7ab7460 Compare October 29, 2026 10:58
Copilot AI balanced review requested due to automatic review settings October 29, 2026 10:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

paulmedynski added a commit that referenced this pull request Oct 29, 2026
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]>
Copilot AI balanced review requested due to automatic review settings October 29, 2026 12:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[RequiresDynamicCode("The SqlClient assembly is loaded dynamically.")]
private static void ValidateSqlClientVersion(bool loadIfMissing)
{
if (ValidateLoadedSqlClientVersions(AppDomain.CurrentDomain.GetAssemblies()) || !loadIfMissing)
Comment on lines +695 to +698
if (string.Equals(assembly.GetName().Name, "Microsoft.Data.SqlClient",
StringComparison.OrdinalIgnoreCase))
{
ValidateFamilyVersion(assembly);
Comment on lines +104 to +107
registry.EnsureBootstrapped(loadAzureAssembly: () =>
throw new InvalidOperationException("Discovery must not be retried."));
registry.LoadAzureExtension(() =>
throw new InvalidOperationException("Version failure must disable later discovery."));
paulmedynski and others added 8 commits October 29, 2026 10:25
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]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area\Azure Connectivity Use this to tag issues that are related to Azure connectivity. Breaking Change 🔨 Issues/PRs that are related with breaking API changes in the driver.

Projects

Status: In progress

Development

Successfully merging this pull request may close these issues.

4 participants