Skip to content

FEAT: Entra id authentication support for AQE - #870

Open
Subrata (subrata-ms) wants to merge 3 commits into
mainfrom
subrata-ms/AQEEntraIdAuth
Open

Subrata (subrata-ms) wants to merge 3 commits into
mainfrom
subrata-ms/AQEEntraIdAuth

Conversation

@subrata-ms

@subrata-ms Subrata (subrata-ms) commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Work Item / Issue Reference

AB#49671

GitHub Issue: #<ISSUE_NUMBER>


Summary

This pull request introduces Entra (Azure Active Directory) authentication support for asynchronous connections in the mssql_python package. It adds a new authentication helper, updates the async connection logic to handle various Entra authentication modes and token providers, and improves validation and error handling for authentication options. The tests have also been updated to reflect the new authentication flow.

Entra Authentication Support and Async Connection Updates:

  • Added a new module mssql_python/async_query/_auth.py that provides Entra authentication helpers, credential caching, and async token acquisition for async connections. It supports built-in Azure Identity credentials and custom token providers, with careful handling of multi-user scenarios.
  • Updated mssql_python/async_query/async_connection.py to:
    • Accept a new token_provider parameter for supplying a custom token provider.
    • Use the new prepare_async_authentication function to handle authentication and token acquisition before establishing a connection.
    • Expanded the connect method's docstring to explain Entra authentication modes, token provider usage, and limitations. [1] [2] [3] [4]

Authentication Validation Improvements:

  • Improved validation in mssql_python/async_query/_connection_context.py to accept supported Entra authentication modes and provide clearer error messages for unsupported modes. [1] [2]

Testing Updates:

  • Updated the test in tests/AsyncTest/test_002_async_connection.py to check that Entra authentication modes are accepted in the connection context without immediately acquiring a token, reflecting the new authentication flow.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings October 28, 2026 07:41
@github-actions github-actions Bot added the pr-size: large Substantial code update label Oct 28, 2026
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

PR Performance Report

✅ No regression detected

No consistent slowdowns detected across all 2 environments.

0 IMPROVEMENTS 0 SLOWDOWNS 2/2 ENVIRONMENTS

Coverage: 2 of 2 environments completed. Advisory result; does not block merging.

Performance diagnostics

Phase times are inclusive diagnostics and must not be added together. They identify where measured time changed, not why it changed.

No affected phases or call-count changes were recorded.

All database tasks and timings

Unix / SQL Server 2022

Database task Before After Paired change Result
Connection opening 10.829 ms 10.852 ms -0.9% no signal
SELECT queries 1.242 ms 1.119 ms -12.1% no signal
Row insertion 35.696 ms 35.429 ms -0.8% no signal
Executemany inserts 160.136 ms 161.536 ms +2.6% no signal
Fetch-all queries 122.531 ms 124.181 ms +1.3% no signal
Row-by-row fetching 14.652 ms 14.739 ms +0.4% no signal
Batched row fetching 120.138 ms 120.799 ms +0.6% no signal
Transaction commit and rollback 117.629 ms 116.843 ms -0.3% no signal
Arrow row fetching 95.010 ms 95.962 ms +1.2% no signal
100,000-row insertion 468.030 ms 462.889 ms -1.0% no signal
Row fetching in batches of 100 122.438 ms 121.787 ms -0.7% no signal
Row fetching in batches of 10,000 134.942 ms 138.594 ms +2.7% no signal
Repeated positional queries 34.023 ms 34.250 ms +0.9% no signal
Repeated named-parameter queries 37.082 ms 37.201 ms +0.5% no signal
Legacy 100,000-row insertion 369.689 ms 374.645 ms +2.2% no signal
Insertion with explicit input sizes 515.174 ms 518.118 ms +0.6% no signal
Joined aggregation queries 175.733 ms 174.894 ms -0.3% no signal
Large joined-result fetching 196.850 ms 193.077 ms -2.7% no signal
1.2-million-row fetching 3484.325 ms 3461.566 ms +0.3% no signal
Common table expression queries 5.729 ms 5.590 ms -3.0% no signal
256 KiB VARCHAR(MAX) / fetchall() 1.299 ms 1.307 ms +1.6% no signal
10,000 scalar values / fetchval() (debug disabled) 107.042 ms 109.012 ms +1.7% no signal

Unix / SQL Server 2025

Database task Before After Paired change Result
Connection opening 98.265 ms 97.447 ms -0.7% no signal
SELECT queries 1.127 ms 1.077 ms -5.9% no signal
Row insertion 34.206 ms 34.145 ms -1.3% no signal
Executemany inserts 151.371 ms 151.865 ms +0.1% no signal
Fetch-all queries 119.811 ms 120.473 ms +0.5% no signal
Row-by-row fetching 14.274 ms 14.449 ms +1.3% no signal
Batched row fetching 116.877 ms 118.462 ms +0.7% no signal
Transaction commit and rollback 115.327 ms 114.720 ms -0.5% no signal
Arrow row fetching 92.551 ms 92.550 ms -0.0% no signal
100,000-row insertion 434.341 ms 424.780 ms -2.1% no signal
Row fetching in batches of 100 121.078 ms 122.080 ms -0.2% no signal
Row fetching in batches of 10,000 129.563 ms 125.995 ms -1.1% no signal
Repeated positional queries 33.944 ms 33.946 ms -0.7% no signal
Repeated named-parameter queries 36.200 ms 36.000 ms -0.8% no signal
Legacy 100,000-row insertion 340.168 ms 345.527 ms +0.9% no signal
Insertion with explicit input sizes 478.256 ms 484.028 ms +1.0% no signal
Joined aggregation queries 159.037 ms 157.867 ms -0.5% no signal
Large joined-result fetching 184.668 ms 180.891 ms -1.9% no signal
1.2-million-row fetching 3439.355 ms 3440.923 ms -0.7% no signal
Common table expression queries 5.145 ms 5.135 ms -0.9% no signal
256 KiB VARCHAR(MAX) / fetchall() 1.505 ms 1.504 ms -0.3% no signal
10,000 scalar values / fetchval() (debug disabled) 106.753 ms 106.833 ms +0.3% no signal
Build and measurement details

ADO build 186696

PR head: e54575bcd4de5a918314986fc59191c2a41db1fa
Base: 2c6a268c28ace89b84dd535f14dfae5ed17d51fc
Measured merge: de9840c74c30814f8113cde1f0e6348b10d39ec1

  • Unix / SQL Server 2022: Python 3.12.3, x86_64, SQL 16.0.4305.5; 5 paired comparisons and 1 warmup.
  • Unix / SQL Server 2025: Python 3.12.3, x86_64, SQL 17.0.5035.5; 5 paired comparisons and 1 warmup.

A consistent change requires more than 20% median paired movement, at least 1 ms between the median runtimes, and at least 80% of pairs exceeding the relative threshold in the same direction. A slowdown without enough pair agreement is reported as inconsistent.

The displayed change is the median of paired before-and-after ratios. It is not recalculated from the two displayed median runtimes.

Both revisions use profiling-enabled builds on the same agent and database, with alternating order and discarded warmups. Results are diagnostic and do not represent production-wheel latency.

Raw samples and logs are attached to the ADO run as profiler-* artifacts.

Comment thread tests/AsyncTest/test_008_async_entraid_auth.py Dismissed
Comment thread tests/AsyncTest/test_008_async_entraid_auth.py Dismissed
Comment thread tests/AsyncTest/test_008_async_entraid_auth.py Dismissed
Comment thread tests/AsyncTest/test_008_async_entraid_auth.py Dismissed
Comment thread tests/AsyncTest/test_008_async_entraid_auth.py Dismissed
Comment thread tests/AsyncTest/test_008_async_entraid_auth.py Dismissed
Comment thread tests/AsyncTest/test_008_async_entraid_auth.py Dismissed
Comment thread tests/AsyncTest/test_008_async_entraid_auth.py Dismissed
Comment thread tests/AsyncTest/test_008_async_entraid_auth.py Dismissed
Comment thread tests/AsyncTest/test_008_async_entraid_auth.py Dismissed

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

Entra authentication depends on native Rust handshake and callback behavior that could not be runtime-validated with the pinned extension and a live Entra-enabled SQL endpoint.

No open issues 🎉

What changed in this PR

Adds Microsoft Entra ID authentication to the Rust-backed async connection layer, supporting built-in Azure Identity credentials and custom synchronous token providers.

Changes:

  • Adds credential caching, off-loop token acquisition, and service-principal callback setup.
  • Extends async connection options and validation, documenting authentication modes and limitations.
  • Adds tests for authentication flows, error handling, cancellation, credential reuse, and native integration.
File Description
tests/​AsyncTest/​test_008_async_entraid_auth.py Adds async Entra authentication and integration coverage.
tests/​AsyncTest/​test_002_async_connection.py Updates context validation expectations to accept Entra authentication.
mssql_python/​async_query/​async_connection.py Adds token_provider and prepares authentication before native login.
mssql_python/​async_query/​_connection_context.py Allows supported Entra modes through connection validation.
mssql_python/​async_query/​_auth.py Implements credential caching, token acquisition, and service-principal setup.

Review effort: Balanced

@subrata-ms Subrata (subrata-ms) changed the title FEAT: support for Entra id authentication FEAT: AQE support for Entra id authentication Oct 28, 2026
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

📊 Code Coverage Report

🔥 Diff Coverage

100%


🎯 Overall Coverage

85%


📈 Total Lines Covered: 9575 out of 11231
📁 Project: mssql-python


Diff Coverage

Diff: main...HEAD, staged and unstaged changes

  • mssql_python/async_query/_auth.py (100%)
  • mssql_python/async_query/_connection_context.py (100%)
  • mssql_python/async_query/async_connection.py (100%)

Summary

  • Total: 65 lines
  • Missing: 0 lines
  • Coverage: 100%

📋 Files Needing Attention

📉 Files with overall lowest coverage (click to expand)
mssql_python.pybind.performance_counter.hpp: 0.7%
mssql_python.pybind.logger_bridge.cpp: 57.9%
mssql_python.pybind.ddbc_bindings.h: 62.6%
mssql_python.pybind.logger_bridge.hpp: 70.8%
mssql_python.pybind.connection.connection_pool.cpp: 81.3%
mssql_python.pybind.connection.connection.cpp: 84.1%
mssql_python.logging.py: 86.2%
mssql_python.pooling.py: 90.1%
mssql_python.pybind.fetch_temporal.hpp: 92.1%
mssql_python.cursor.py: 92.5%

🔗 Quick Links

⚙️ Build Summary 📋 Coverage Details

View Azure DevOps Build

Browse Full Coverage Report

@subrata-ms Subrata (subrata-ms) changed the title FEAT: AQE support for Entra id authentication FEAT: Entra id authentication support for AQE Oct 28, 2026
Copilot AI balanced review requested due to automatic review settings October 28, 2026 09:35

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 native authentication implementation is unavailable, and existing mocks cannot establish Entra SQL handshake success, callback threading, or cancellation behavior without live validation.

No open issues 🎉

Review effort: Balanced

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

Labels

pr-size: large Substantial code update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants