From 3acfa2aa9627dabd80ca0b655de2c29be2aafcca Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Tue, 17 Nov 2026 12:00:25 -0700 Subject: [PATCH 1/2] Set SqlClient registered application identity to DataApiBuilder Identify query, metadata, and CLI SQL connections before login. Upgrade SqlClient and aligned dependencies while preserving Azure authentication support. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/design/application-name-telemetry.md | 13 +++++++ ...soft.Data.SqlClient.SNI.7.1.2.License.txt} | 0 scripts/notice-generation.ps1 | 2 +- src/Cli/ConfigGenerator.cs | 5 ++- src/Config/Azure.DataApiBuilder.Config.csproj | 1 + .../Telemetry/ApplicationNameTelemetry.cs | 2 + src/Core/Azure.DataApiBuilder.Core.csproj | 1 + src/Core/Resolvers/MsSqlQueryExecutor.cs | 1 + .../MsSqlMetadataProvider.cs | 8 +++- .../MetadataProviders/SqlMetadataProvider.cs | 14 +++++-- src/Directory.Packages.props | 15 ++++---- .../ApplicationNameGeneralTelemetryTests.cs | 2 + .../SqlMetadataProviderHelperTests.cs | 16 ++++++++ .../UnitTests/SqlQueryExecutorUnitTests.cs | 38 +++++++++++++++++++ 14 files changed, 104 insertions(+), 14 deletions(-) rename external_licenses/{Microsoft.Data.SqlClient.SNI.6.0.2.License.txt => Microsoft.Data.SqlClient.SNI.7.1.2.License.txt} (100%) diff --git a/docs/design/application-name-telemetry.md b/docs/design/application-name-telemetry.md index 1f52cbfce0..5d115f1224 100644 --- a/docs/design/application-name-telemetry.md +++ b/docs/design/application-name-telemetry.md @@ -21,6 +21,19 @@ dab_oss_2.0.0+XXSX|L1AC0M|110000M1M000MMMMMWMM|100?111001110?+ It is opt-out (`DAB_TELEMETRY_APPNAME_OPT_OUT=1`), carries no secrets or identifiers, and is purely additive to the existing `Application Name` value. +## SqlClient registered application identity + +SQL Server and DWSQL connections also set +`SqlConnection.RegisteredApplication = RegisteredApplication.DataApiBuilder` before opening, +including metadata discovery and CLI autoentity discovery. This requires SqlClient 7.1 or later; +the Azure authentication extension remains included to preserve Entra ID authentication support. + +This fixed product identifier is independent of the application-name token and its opt-out. +It contains no configuration or customer identifiers, is not part of the connection-pool key, +and must not be used for authorization. SqlClient reports it during physical connection login; +reused pooled connections retain the original identity, and background connections created for +`Min Pool Size` report `Unknown`. + ## Motivation DAB ships as an open-source container that customers run anywhere. We have very little visibility into how it is configured or which features are exercised. The connection's `Application Name` is a standard, low-cost signal that the database side already records, so encoding a small feature fingerprint there gives us aggregate usage insight with: diff --git a/external_licenses/Microsoft.Data.SqlClient.SNI.6.0.2.License.txt b/external_licenses/Microsoft.Data.SqlClient.SNI.7.1.2.License.txt similarity index 100% rename from external_licenses/Microsoft.Data.SqlClient.SNI.6.0.2.License.txt rename to external_licenses/Microsoft.Data.SqlClient.SNI.7.1.2.License.txt diff --git a/scripts/notice-generation.ps1 b/scripts/notice-generation.ps1 index b7ec5044a2..a3a82a1b5d 100644 --- a/scripts/notice-generation.ps1 +++ b/scripts/notice-generation.ps1 @@ -15,7 +15,7 @@ Invoke-WebRequest $chiliCreamLicenseMetadataURL -UseBasicParsing | Out-File $chiliCreamLicenseSavePath # Define the path to the license file in your repository and Read the content of the license file -$sqlClientSNILicenseFilePath = "$BuildSourcesDir/external_licenses/Microsoft.Data.SqlClient.SNI.6.0.2.License.txt" +$sqlClientSNILicenseFilePath = "$BuildSourcesDir/external_licenses/Microsoft.Data.SqlClient.SNI.7.1.2.License.txt" $sqlClientSNILicense = Get-Content -Path $sqlClientSNILicenseFilePath -Raw # Replace erroneous copyright, using [System.IO.File] for better performance than Get-Content and Set-Content diff --git a/src/Cli/ConfigGenerator.cs b/src/Cli/ConfigGenerator.cs index 834b26f519..6eb931b376 100644 --- a/src/Cli/ConfigGenerator.cs +++ b/src/Cli/ConfigGenerator.cs @@ -4000,7 +4000,10 @@ public static bool TrySimulateAutoentities(AutoConfigSimulateOptions options, Fi try { - using SqlConnection connection = new(connectionString); + using SqlConnection connection = new(connectionString) + { + RegisteredApplication = RegisteredApplication.DataApiBuilder + }; connection.Open(); foreach ((string filterName, Autoentity autoentity) in runtimeConfig.Autoentities.Autoentities) diff --git a/src/Config/Azure.DataApiBuilder.Config.csproj b/src/Config/Azure.DataApiBuilder.Config.csproj index a0b378263a..892c1f791d 100644 --- a/src/Config/Azure.DataApiBuilder.Config.csproj +++ b/src/Config/Azure.DataApiBuilder.Config.csproj @@ -23,6 +23,7 @@ + diff --git a/src/Config/Telemetry/ApplicationNameTelemetry.cs b/src/Config/Telemetry/ApplicationNameTelemetry.cs index 564dea54d4..accbf75851 100644 --- a/src/Config/Telemetry/ApplicationNameTelemetry.cs +++ b/src/Config/Telemetry/ApplicationNameTelemetry.cs @@ -417,7 +417,9 @@ private static char EncodeManagedIdentity(EncodeInputs inputs) SqlAuthenticationMethod.ActiveDirectoryDefault or SqlAuthenticationMethod.ActiveDirectoryWorkloadIdentity => MISSING, SqlAuthenticationMethod.NotSpecified => sql.IntegratedSecurity || !string.IsNullOrEmpty(sql.UserID) || !string.IsNullOrEmpty(sql.Password) ? '0' : MISSING, +#pragma warning disable CS0618 // Classify legacy authentication without enabling it. SqlAuthenticationMethod.SqlPassword or SqlAuthenticationMethod.ActiveDirectoryPassword +#pragma warning restore CS0618 or SqlAuthenticationMethod.ActiveDirectoryIntegrated or SqlAuthenticationMethod.ActiveDirectoryInteractive or SqlAuthenticationMethod.ActiveDirectoryServicePrincipal or SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow => '0', _ => MISSING, diff --git a/src/Core/Azure.DataApiBuilder.Core.csproj b/src/Core/Azure.DataApiBuilder.Core.csproj index 3d16d85067..61bd812519 100644 --- a/src/Core/Azure.DataApiBuilder.Core.csproj +++ b/src/Core/Azure.DataApiBuilder.Core.csproj @@ -49,6 +49,7 @@ + diff --git a/src/Core/Resolvers/MsSqlQueryExecutor.cs b/src/Core/Resolvers/MsSqlQueryExecutor.cs index 26a4582c40..1bc2988fd0 100644 --- a/src/Core/Resolvers/MsSqlQueryExecutor.cs +++ b/src/Core/Resolvers/MsSqlQueryExecutor.cs @@ -130,6 +130,7 @@ public override SqlConnection CreateConnection(string dataSourceName) SqlConnection conn = new() { ConnectionString = connectionString, + RegisteredApplication = RegisteredApplication.DataApiBuilder, }; // Extract info message from SQLConnection diff --git a/src/Core/Services/MetadataProviders/MsSqlMetadataProvider.cs b/src/Core/Services/MetadataProviders/MsSqlMetadataProvider.cs index 2e6e5b1ae2..dd755687ce 100644 --- a/src/Core/Services/MetadataProviders/MsSqlMetadataProvider.cs +++ b/src/Core/Services/MetadataProviders/MsSqlMetadataProvider.cs @@ -53,6 +53,12 @@ public override string GetDefaultSchemaName() return "dbo"; } + /// + protected override SqlConnection CreateConnection() => new() + { + RegisteredApplication = RegisteredApplication.DataApiBuilder + }; + /// /// Takes a string version of an SQL Server data type (also applies to Azure SQL DB) /// and returns its .NET common language runtime (CLR) counterpart @@ -186,7 +192,7 @@ protected override async Task FillSchemaForStoredProcedureAsync( StoredProcedureDefinition storedProcedureDefinition, CancellationToken cancellationToken) { - using DbConnection conn = new SqlConnection(); + using DbConnection conn = CreateConnection(); conn.ConnectionString = ConnectionString; await QueryExecutor.SetManagedIdentityAccessTokenIfAnyAsync( conn, diff --git a/src/Core/Services/MetadataProviders/SqlMetadataProvider.cs b/src/Core/Services/MetadataProviders/SqlMetadataProvider.cs index 1fe5c32eb6..d323c4f049 100644 --- a/src/Core/Services/MetadataProviders/SqlMetadataProvider.cs +++ b/src/Core/Services/MetadataProviders/SqlMetadataProvider.cs @@ -493,7 +493,7 @@ protected virtual async Task FillSchemaForStoredProcedureAsync( StoredProcedureDefinition storedProcedureDefinition, CancellationToken cancellationToken) { - using ConnectionT conn = new(); + using ConnectionT conn = CreateConnection(); conn.ConnectionString = ConnectionString; DataTable procedureMetadata; string[] procedureRestrictions = new string[NUMBER_OF_RESTRICTIONS]; @@ -1876,6 +1876,12 @@ private async Task GetTableWithSchemaFromDataSetAsync( return dataTable!; } + /// + /// Creates an unopened connection for metadata discovery and connection validation. + /// + /// A new database connection. + protected virtual ConnectionT CreateConnection() => new(); + /// /// This method attempts to open a database connection using the provided connection string. /// If the connection fails to open, it catches the exception and throws a DataApiBuilderException. @@ -1885,7 +1891,7 @@ private async Task GetTableWithSchemaFromDataSetAsync( private async Task ValidateDatabaseConnection( CancellationToken cancellationToken) { - using ConnectionT conn = new(); + using ConnectionT conn = CreateConnection(); conn.ConnectionString = ConnectionString; await QueryExecutor.SetManagedIdentityAccessTokenIfAnyAsync( conn, @@ -1921,7 +1927,7 @@ private async Task FillSchemaForTableAsync( string tableName, CancellationToken cancellationToken) { - using ConnectionT conn = new(); + using ConnectionT conn = CreateConnection(); // If connection string is set to empty string // we throw here to avoid having to sort out // complicated db specific exception messages. @@ -2407,7 +2413,7 @@ protected virtual async Task GetColumnsAsync( string tableName, CancellationToken cancellationToken) { - using ConnectionT conn = new(); + using ConnectionT conn = CreateConnection(); conn.ConnectionString = ConnectionString; await QueryExecutor.SetManagedIdentityAccessTokenIfAnyAsync( conn, diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index 2abcc3517e..231ca22ff1 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -48,15 +48,16 @@ - + + - - - - - + + + + + @@ -80,7 +81,7 @@ - +