Repository navigation
Description
Follow up to #1611 (comment) and #1753
First of all thank you for supporting Entra auth in v4. This will save my org time as we plan to migrate a lot of different databases and do not want to deal with setting up SQL username + password auth for all of them when we have a entra setup working already.
First let me clarify that I am familiar with the different authentication types mentioned here, but I am mostly familiar with the Azure.Identity package in .NET, so some details may be different in MSAL4J.
Currently the only personal auth method is ActiveDirectoryPassword
Two issues with supporting this:
- It is deprecated due to MFA requirements https://learn.microsoft.com/en-us/sql/connect/jdbc/connecting-using-azure-active-directory-authentication?view=sql-server-ver17#connect-using-activedirectorypassword-authentication-mode
The ActiveDirectoryPassword authentication option (Microsoft Entra ID password authentication) is deprecated in the Microsoft SQL drivers. This high-risk authentication flow is incompatible with [mandatory Microsoft Entra multifactor authentication (MFA)](https://learn.microsoft.com/en-us/entra/identity/authentication/concept-mandatory-multifactor-authentication) and might not work in tenants where MFA is enforced. Plan to migrate to a different Microsoft Entra authentication method.
- If I am not mistaken you can't really get this working anymore unless you create some exceptions to conditional access (not recommended), re: https://learn.microsoft.com/en-us/entra/identity/authentication/concept-mandatory-multifactor-authentication?tabs=dotnet
For instance I just tried the ActiveDirectoryPassword auth and ended up with this:
[1/3] Running pgloader...
10:02:38.167 INFO [main] pgloader.cli - Parsing commands from file /tmp/tmp.chCNaCp5bl/migration.load
10:02:38.772 INFO [main] pgloader.core - Connected to PostgreSQL at postgresql://nis-gateway:kZ_NHmzwgVCus2tsL6TMn16BS_Dlf07X0L1vhF03ubg@127.0.0.1:5432/gateway?sslmode=disable
10:02:40.137 WARN [pool-2-thread-1] c.m.a.m.PublicClientApplication - [Correlation ID: 7f27db7b-25f8-4428-929b-743fa7f9987b] Execution of class com.microsoft.aad.msal4j.AcquireTokenByAuthorizationGrantSupplier failed: AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access xxxx-aaa-bbbb'. Trace ID: 5a2948ef-bc6d-4b8e-bbfa-be5fb76c5700 Correlation ID: 7f27db7b-25f8-4428-929b-743fa7f9987b Timestamp: 2026-07-06 08:02:38Z
Essentially what my org is used to using is Active Directory Default when connecting to a database from localhost. During local development I recommened our developers to run az login before starting their applications to connect to the Azure SQL databases. I think the same would make sense here. Currently when setting the connection string I end up with:
[1/3] Running pgloader...
10:00:12.006 INFO [main] pgloader.cli - Parsing commands from file /tmp/tmp.iPqkUaOklD/migration.load
10:00:12.619 INFO [main] pgloader.core - Connected to PostgreSQL at postgresql://nis-gateway:kZ_NHmzwgVCus2tsL6TMn16BS_Dlf07X0L1vhF03ubg@127.0.0.1:5432/gateway?sslmode=disable
Exception in thread "main" java.lang.NoClassDefFoundError: com/azure/identity/DefaultAzureCredentialBuilder
Before you created #1753 Claude did manage to generate working code for me to authenticate with Active Directory Default via Azure CLI, which shows that it should be possible. The generated code was not very clean so I don't have a PR to contribute with unfortunately.
Activity
feat(mssql): bundle azure-identity for ActiveDirectoryDefault/AzCli/W…
dimitri commentedon Jul 6, 2026
@audunsolemdal Thanks for the detailed write-up — and for linking the workaround in miljodir/DataEngineerPersona#6. That PR turned out to be exactly the right pointer: it confirmed the correct
azure-identityversion to pin (1.11.1, the same one mssql-jdbc 12.6.1 was certified against), documented the WSL2linux_xdg_open_failedfailure forActiveDirectoryInteractivethat I'd only inferred from the driver source, and gave a real-world test of theActiveDirectoryDefault+az loginconnection string. All of that fed directly into the fix.PR #1755 (now merged into
main) bundlescom.azure/azure-identity 1.11.1in the pgloader v4 uberjar, which should make the following modes work out of the box:ActiveDirectoryDefault— theaz loginfallback chain, includingAzureCliCredentialin WSL2ActiveDirectoryAzCli— explicit CLI tokenActiveDirectoryWorkloadIdentity— for Kubernetes OIDCThe connection string from your workaround should work directly against a fresh JAR build:
The dev release JAR is rebuilt automatically on every merge to
main:Would you be able to test this against your Azure SQL setup and let us know if it fully resolves the issue? In particular: does
ActiveDirectoryDefaultpick up youraz loginsession as expected, and are there any edge cases with your tenant's conditional access or Entra configuration that still cause problems?audunsolemdal commentedon Jul 6, 2026
ActiveDirectoryDefault works without issues and picks up my az login.
My only complaint here is that the output is very spammy. Essentially it seems that multiple tokens are fetched and every time this happens the ChainedTokenCredential logs appear like this:
I have not seen
authentication=ActiveDirectoryAzClibefore. And I get the error below. Perhaps this is only supported in Golang, ref. the results here: https://github.com/search?q=ActiveDirectoryAzCli&type=code&p=1fix(mssql): remove invalid auth modes; suppress azure-identity log noise
fix(mssql): remove invalid auth modes; suppress azure-identity log no…
dimitri commentedon Jul 6, 2026
Thank you — this is exactly the kind of real-world feedback that makes the difference between a feature that looks correct and one that is correct.
Two follow-up fixes landed in PR #1756:
ActiveDirectoryAzCliandActiveDirectoryWorkloadIdentityremoved from the docsThese modes don't exist in the Java
mssql-jdbcdriver — they'reMicrosoft.Data.SqlClient(.NET) andgo-mssqldb(Go) concepts only. We added them by mistake when reading azure-identity's own documentation rather than checking mssql-jdbc'sSqlAuthenticationenum directly. Verified viajavap: the valid mssql-jdbc 12.6.1 modes areActiveDirectoryDefault,ActiveDirectoryServicePrincipal,ActiveDirectoryServicePrincipalCertificate,ActiveDirectoryManagedIdentity,ActiveDirectoryIntegrated,ActiveDirectoryInteractive,ActiveDirectoryPassword.Verbose
DefaultAzureCredentialchain logging suppressedThe INFO-level messages for each unavailable credential (
EnvironmentCredential unavailable,ManagedIdentityCredential unavailable, etc.) are expected behaviour when running on a developer machine, but very noisy — and multiplied by pgloader's connection pool thread count. We've setcom.azure.identitytoWARNandcom.microsoft.aad.msal4jtoERRORinlogback.xmlso those chain traversal messages are suppressed by default while genuine errors still surface.On the lack of CI testing for this
We don't currently have end-to-end CI coverage for Azure AD authentication because it genuinely requires real Azure infrastructure — SQL Server in Docker has no Entra ID integration, so it can't be mocked. The right approach would be an Azure SQL Database serverless instance (free tier) with GitHub Actions OIDC / Workload Identity Federation so no secrets need to be stored. If you or anyone at your org would be willing to contribute that Azure setup, we'd be happy to wire it into the CI workflow — the pgloader side is straightforward once the Azure SQL instance and app registration exist.
audunsolemdal commentedon Jul 6, 2026
Works well, thanks.