Skip to content

Use DAB's client ID for SqlClient Entra ID authentication - #3927

Draft
Cheena Malhotra (cheenamalhotra) wants to merge 1 commit into
mainfrom
dev/cheena/entra-client-identity
Draft

Cheena Malhotra (cheenamalhotra) wants to merge 1 commit into
mainfrom
dev/cheena/entra-client-identity

Conversation

@cheenamalhotra

Copy link
Copy Markdown
Member

Why make this change?

  • DAB doesn't register its own application client ID with Microsoft.Data.SqlClient. With Authentication=Active Directory ... connection strings, SqlClient falls back to its built-in application (ActiveDirectoryAuthentication.AdoClientId).
  • Apps that use SqlClient should supply their own client ID instead of relying on SqlClient's application. That application is owned by the SqlClient team, and its reply URLs, redirect URIs or allowed auth schemes can change at any time. When they change, sign-in prompts, consent and token acquisition can break for DAB's users, outside DAB's control.

What is this change?

  • Adds SqlClientAuthentication.RegisterProviders() in src/Core/AuthenticationHelpers/SqlClientAuthentication.cs.
    • When DAB_OBO_CLIENT_ID is set, DAB creates one ActiveDirectoryAuthenticationProvider(clientId). It registers that provider via SqlAuthenticationProvider.SetProvider for every SqlAuthenticationMethod the provider supports.
    • When DAB_OBO_CLIENT_ID is not set or is blank, nothing changes and SqlClient's existing providers are kept.
    • If SetProvider is rejected because app config already set a provider that can't be overridden, startup fails with a clear error. This avoids silently using SqlClient's application.
  • Registration is called from:
    • the MsSqlQueryExecutor constructor (runtime);
    • the CLI autoentities simulation in ConfigGenerator, before it opens a SqlConnection.
  • Updates the DAB_OBO_CLIENT_ID_ENV_VAR doc in DataSource.cs.
  • Scope of the client ID, based on SqlClient 6.1.5's ActiveDirectoryAuthenticationProvider:
    • The configured client ID is used for the public-client modes: Integrated, Password, Interactive and DeviceCodeFlow. For these modes, the app registration must have Allow public client flows enabled.
    • Default, ManagedIdentity/MSI, ServicePrincipal and WorkloadIdentity still use the connection string's User Id as their identity, so they are unaffected. DAB's DefaultAzureCredential access-token path is also unaffected.

How was this tested?

  • Integration Tests
  • Unit Tests
    • New src/Cli.Tests/SqlClientAuthenticationTests.cs (runs on its own and restores global state afterwards). It checks that:
      • every supported mode is registered with one provider that carries the configured client ID;
      • unsupported modes are untouched;
      • an unset or blank client ID leaves the existing providers unchanged.
    • dotnet test src\Cli.Tests\Cli.Tests.csproj --filter "FullyQualifiedName~SqlClientAuthenticationTests|FullyQualifiedName~UserDelegatedAuthRuntimeParsingTests": passed (6/6)
    • Service.Tests filter SqlQueryExecutorUnitTests.TestHandleManagedIdentityAccess|OboCredentialFactoryTests: passed (56/56)
    • dotnet format whitespace --verify-no-changes on the changed files: clean

Sample Request(s)

  • Set DAB_OBO_CLIENT_ID=<your-app-registration-client-id> and use an Entra ID connection string, for example Server=...;Database=...;Authentication=Active Directory Interactive;. SqlClient then signs in with DAB's configured application instead of SqlClient's built-in application.

Use DAB_OBO_CLIENT_ID for SqlClient's ActiveDirectoryAuthenticationProvider across all supported authentication modes instead of SqlClient's default application.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

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.

🟢 Approval recommended

The review identifies no active issues requiring changes.

No open issues 🎉

What changed in this PR

This PR configures DAB’s SQL Server authentication to use DAB_OBO_CLIENT_ID for SqlClient public-client flows when set, rather than relying on SqlClient’s built-in application identity.

Changes:

  • Adds shared authentication-provider registration, preserving existing providers when the client ID is unset or blank.
  • Registers providers during runtime executor initialization and CLI autoentities simulation.
  • Documents the client ID’s scope and adds tests for registration and unchanged-provider behavior.
File Description
src/​Core/​Resolvers/​MsSqlQueryExecutor.cs Registers SqlClient authentication providers during executor initialization.
src/​Core/​AuthenticationHelpers/​SqlClientAuthentication.cs Adds shared provider registration using the configured client ID.
src/​Config/​ObjectModel/​DataSource.cs Documents SqlClient usage and authentication scope of the environment variable.
src/​Cli/​ConfigGenerator.cs Registers providers before CLI autoentities simulation opens a connection.
src/​Cli.Tests/​SqlClientAuthenticationTests.cs Tests provider registration and preservation when no client ID is configured.

Review effort: Balanced

internal static void RegisterProviders()
{
string? clientId = Environment.GetEnvironmentVariable(UserDelegatedAuthOptions.DAB_OBO_CLIENT_ID_ENV_VAR);
if (string.IsNullOrWhiteSpace(clientId))

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

this is an important fallback, if OBO is not enabled/setup, this clientId will be null. Just want to make sure, in that situation, the existing default app client id will still be valid for EntraAuth modes, right?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

when SqlClient drops support for non-WAM broker enabled workflows by removing localhost reply URLs, would this fallback scenario continue to work when OBO is not enabled?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Looks good with respect to the isolated change for OBO flow. Left few questions for clarification.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants