Skip to content

Commit cfa976b

Browse files
committed
Removed obsolete and vulnerable Microsoft.Azure.Services.AppAuthentication
* Fixes vulnerablities found in #417 * Microsoft.Azure.Services.AppAuthentication is obsolete. SqlClient was updated to version 3.0.0 which has integrated AD authentication capablities which can be configured in the connection string (https://learn.microsoft.com/en-us/sql/connect/ado-net/sql/azure-active-directory-authentication?view=sql-server-ver16). * Removed sink options UseAzureManagedIdentity, AzureServiceTokenProviderResource, AzureTenantId and any related code.
1 parent 507d323 commit cfa976b

File tree

19 files changed

+23
-393
lines changed

19 files changed

+23
-393
lines changed

README.md

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,6 @@ Basic settings of the sink are configured using the properties in a `MSSqlServer
243243
* `BatchPostingLimit`
244244
* `BatchPeriod`
245245
* `EagerlyEmitFirstEvent`
246-
* `UseAzureManagedIdentity`
247-
* `AzureServiceTokenProviderResource`
248-
* `AzureTenantId`
249246

250247
### TableName
251248

@@ -283,34 +280,6 @@ This setting is not used by the audit sink as it writes each event immediately a
283280
A Flag to eagerly write a batch to the database containing the first received event regardless of `BatchPostingLimit` or `BatchPeriod`. It defaults to `true`.
284281
This setting is not used by the audit sink as it writes each event immediately and not in a batched manner.
285282

286-
### UseAzureManagedIdentity
287-
288-
A flag specifiying to use Azure Managed Identities for authenticating with an Azure SQL server. It defaults to `false`. If enabled the property `AzureServiceTokenProviderResource` must be set as well.
289-
290-
**IMPORTANT:** Azure Managed Identities is only supported for the target frameworks .NET Framework 4.7.2+ and .NET (Core) 2.2+. Setting this to `true` when targeting a different framework results in an exception.
291-
292-
See [Azure AD-managed identities for Azure resources documentation](https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/) for details on how to configure and use Azure Managed Identitites.
293-
294-
### AzureServiceTokenProviderResource
295-
296-
Specifies the token provider resource to be used for aquiring an authentication token when using Azure Managed Identities for authenticating with an Azure SQL server. This setting is only used if `UseAzureManagedIdentity` is set to `true`. For Azure SQL databases this value will always be `https://database.windows.net/`.
297-
298-
### AzureTenantId
299-
300-
Specifies the tenant ID of the the tenant the Azure SQL database exists in. This only needs to be set if the user authenticating against the database is in a different tenant to the database. This will most likely be the case when you are debugging locally and authenticating as yourself rather than the app to be deployed to.
301-
302-
```
303-
.WriteTo.MSSqlServer(
304-
Environment.GetEnvironmentVariable("LogConnection"),
305-
sinkOptions: new MSSqlServerSinkOptions()
306-
{
307-
TableName = "_Log",
308-
UseAzureManagedIdentity = true,
309-
AzureServiceTokenProviderResource = "https://database.windows.net/",
310-
AzureTenantId = Environment.GetEnvironmentVariable("AZURE_TENANT_ID")
311-
}
312-
```
313-
314283

315284
## ColumnOptions Object
316285

@@ -825,6 +794,7 @@ WHERE
825794

826795
Feature | Notes
827796
:--- | :---
797+
`UseAzureManagedIdentity` | Since the update of Microsoft.Data.SqlClient in sink release 5.8.0 Active Directory auth capabilities of SqlClient can be used. You can specify one of the supported AD authentication methods, which include Azure Managed Identites, directly in the connection string. Refer to the [SqlClient documentation](https://learn.microsoft.com/en-us/sql/connect/ado-net/sql/azure-active-directory-authentication?view=sql-server-ver16) for details.
828798
`AdditionalDataColumns` | Use the `AdditionalColumns` collection instead. Configuring the sink no longer relies upon .NET `DataColumn` objects or .NET `System` types.
829799
`Id.BigInt` | Use `Id.DataType = SqlDb.BigInt` instead. (The `BigInt` property was only available in dev packages).
830800
`Binary` and `VarBinary` | Due to the way Serilog represents property data internally, it isn't possible for the sink to access property data as a byte array, so the sink can't write to these column types.

sample/WorkerServiceDemo/appsettings.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
"connectionString": "Server=localhost;Database=LogTest;Integrated Security=SSPI;",
1717
"sinkOptionsSection": {
1818
"tableName": "LogEvents",
19-
"autoCreateSqlTable": true,
20-
"useAzureManagedIdentity": false,
21-
"azureServiceTokenProviderResource": "https://database.windpws.net/"
19+
"autoCreateSqlTable": true
2220
},
2321
"restrictedToMinimumLevel": "Information",
2422
"columnOptionsSection": {
@@ -49,9 +47,7 @@
4947
"logEventFormatter": "WorkerServiceDemo.CustomLogEventFormatter::Formatter, WorkerServiceDemo",
5048
"sinkOptionsSection": {
5149
"tableName": "LogEventsAudit",
52-
"autoCreateSqlTable": true,
53-
"useAzureManagedIdentity": false,
54-
"azureServiceTokenProviderResource": "https://database.windpws.net/"
50+
"autoCreateSqlTable": true
5551
},
5652
"columnOptionsSection": {
5753
"addStandardColumns": [ "LogEvent" ],

src/Serilog.Sinks.MSSqlServer/Configuration/Implementations/Microsoft.Extensions.Configuration/MicrosoftExtensionsSinkOptionsProvider.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ public MSSqlServerSinkOptions ConfigureSinkOptions(MSSqlServerSinkOptions sinkOp
1515

1616
ReadTableOptions(config, sinkOptions);
1717
ReadBatchSettings(config, sinkOptions);
18-
ReadAzureManagedIdentitiesOptions(config, sinkOptions);
1918

2019
return sinkOptions;
2120
}
@@ -34,12 +33,5 @@ private static void ReadBatchSettings(IConfigurationSection config, MSSqlServerS
3433
SetProperty.IfNotNull<string>(config["batchPeriod"], val => sinkOptions.BatchPeriod = TimeSpan.Parse(val, CultureInfo.InvariantCulture));
3534
SetProperty.IfNotNull<bool>(config["eagerlyEmitFirstEvent"], val => sinkOptions.EagerlyEmitFirstEvent = val);
3635
}
37-
38-
private static void ReadAzureManagedIdentitiesOptions(IConfigurationSection config, MSSqlServerSinkOptions sinkOptions)
39-
{
40-
SetProperty.IfNotNull<bool>(config["useAzureManagedIdentity"], val => sinkOptions.UseAzureManagedIdentity = val);
41-
SetProperty.IfNotNull<string>(config["azureServiceTokenProviderResource"], val => sinkOptions.AzureServiceTokenProviderResource = val);
42-
SetProperty.IfNotNull<string>(config["azureTenantId"], val => sinkOptions.AzureTenantId = val);
43-
}
4436
}
4537
}

src/Serilog.Sinks.MSSqlServer/Configuration/Implementations/System.Configuration/MSSqlServerConfigurationSection.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -185,25 +185,6 @@ internal set
185185
base[nameof(PrimaryKeyColumnName)] = value;
186186
}
187187
}
188-
189-
[ConfigurationProperty(nameof(UseAzureManagedIdentity))]
190-
public ValueConfigElement UseAzureManagedIdentity
191-
{
192-
get => (ValueConfigElement)base[nameof(UseAzureManagedIdentity)];
193-
}
194-
195-
[ConfigurationProperty(nameof(AzureServiceTokenProviderResource))]
196-
public ValueConfigElement AzureServiceTokenProviderResource
197-
{
198-
get => (ValueConfigElement)base[nameof(AzureServiceTokenProviderResource)];
199-
}
200-
201-
202-
[ConfigurationProperty(nameof(AzureTenantId))]
203-
public ValueConfigElement AzureTenantId
204-
{
205-
get => (ValueConfigElement)base[nameof(AzureTenantId)];
206-
}
207188
}
208189
}
209190

src/Serilog.Sinks.MSSqlServer/Configuration/Implementations/System.Configuration/SystemConfigurationSinkOptionsProvider.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public MSSqlServerSinkOptions ConfigureSinkOptions(MSSqlServerConfigurationSecti
1010
{
1111
ReadTableOptions(config, sinkOptions);
1212
ReadBatchSettings(config, sinkOptions);
13-
ReadAzureManagedIdentitiesOptions(config, sinkOptions);
1413

1514
return sinkOptions;
1615
}
@@ -32,13 +31,5 @@ private static void ReadBatchSettings(MSSqlServerConfigurationSection config, MS
3231
SetProperty.IfProvided<bool>(config.EagerlyEmitFirstEvent, nameof(config.EagerlyEmitFirstEvent.Value),
3332
value => sinkOptions.EagerlyEmitFirstEvent = value);
3433
}
35-
36-
private static void ReadAzureManagedIdentitiesOptions(MSSqlServerConfigurationSection config, MSSqlServerSinkOptions sinkOptions)
37-
{
38-
SetProperty.IfProvided<bool>(config.UseAzureManagedIdentity, nameof(config.UseAzureManagedIdentity.Value),
39-
value => sinkOptions.UseAzureManagedIdentity = value);
40-
SetProperty.IfProvided<string>(config.AzureServiceTokenProviderResource, nameof(config.AzureServiceTokenProviderResource.Value),
41-
value => sinkOptions.AzureServiceTokenProviderResource = value);
42-
}
4334
}
4435
}

src/Serilog.Sinks.MSSqlServer/Serilog.Sinks.MSSqlServer.csproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,12 @@
4545
<Compile Remove="Configuration\Extensions\System.Configuration\**\*.*" />
4646
<Compile Remove="Configuration\Implementations\Microsoft.Extensions.Configuration\**\*.*" />
4747
<Compile Remove="Configuration\Implementations\System.Configuration\**\*.*" />
48-
<Compile Remove="Sinks\MSSqlServer\Platform\AzureManagedServiceAuthenticator.cs" />
49-
<Compile Remove="Sinks\MSSqlServer\Platform\AzureManagedServiceAuthenticatorStub.cs" />
5048
<!-- Show in VStudio, but MSBuild ignores these (indicates files are not code, non-published-content, etc.) -->
5149
<None Include="Configuration\Extensions\Hybrid\**\*.*" />
5250
<None Include="Configuration\Extensions\Microsoft.Extensions.Configuration\**\*.*" />
5351
<None Include="Configuration\Extensions\System.Configuration\**\*.*" />
5452
<None Include="Configuration\Implementations\Microsoft.Extensions.Configuration\**\*.*" />
5553
<None Include="Configuration\Implementations\System.Configuration\**\*.*" />
56-
<None Include="Sinks\MSSqlServer\Platform\AzureManagedServiceAuthenticator.cs" />
57-
<None Include="Sinks\MSSqlServer\Platform\AzureManagedServiceAuthenticatorStub.cs" />
5854
<!-- ItemGroups below with TFM conditions will re-include the compile targets -->
5955
</ItemGroup>
6056

@@ -64,7 +60,6 @@
6460
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.4" />
6561
<Compile Include="Configuration\Extensions\Microsoft.Extensions.Configuration\**\*.cs" />
6662
<Compile Include="Configuration\Implementations\Microsoft.Extensions.Configuration\**\*.cs" />
67-
<Compile Include="Sinks\MSSqlServer\Platform\AzureManagedServiceAuthenticatorStub.cs" />
6863
</ItemGroup>
6964

7065
<ItemGroup Condition=" '$(TargetFramework)' == 'net462' ">
@@ -75,19 +70,16 @@
7570
<Compile Include="Configuration\Extensions\Hybrid\**\*.cs" />
7671
<Compile Include="Configuration\Implementations\Microsoft.Extensions.Configuration\**\*.cs" />
7772
<Compile Include="Configuration\Implementations\System.Configuration\**\*.cs" />
78-
<Compile Include="Sinks\MSSqlServer\Platform\AzureManagedServiceAuthenticatorStub.cs" />
7973
</ItemGroup>
8074

8175
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp3.1' Or '$(TargetFramework)' == 'net472' ">
8276
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
8377
<PackageReference Include="Microsoft.Data.SqlClient" Version="3.0.0" />
84-
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.4.0" />
8578
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.1.4" />
8679
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="3.1.4" />
8780
<Compile Include="Configuration\Extensions\Hybrid\**\*.cs" />
8881
<Compile Include="Configuration\Implementations\Microsoft.Extensions.Configuration\**\*.cs" />
8982
<Compile Include="Configuration\Implementations\System.Configuration\**\*.cs" />
90-
<Compile Include="Sinks\MSSqlServer\Platform\AzureManagedServiceAuthenticator.cs" />
9183
</ItemGroup>
9284

9385
<ItemGroup>

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/Dependencies/SinkDependenciesFactory.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@ internal static SinkDependencies Create(
2121
var sqlConnectionFactory =
2222
new SqlConnectionFactory(connectionString,
2323
sinkOptions?.EnlistInTransaction ?? default,
24-
sinkOptions?.UseAzureManagedIdentity ?? default,
25-
new SqlConnectionStringBuilderWrapper(),
26-
new AzureManagedServiceAuthenticator(
27-
sinkOptions?.UseAzureManagedIdentity ?? default,
28-
sinkOptions.AzureServiceTokenProviderResource,
29-
sinkOptions.AzureTenantId));
24+
new SqlConnectionStringBuilderWrapper());
3025
var logEventDataGenerator =
3126
new LogEventDataGenerator(columnOptions,
3227
new StandardColumnDataGenerator(columnOptions, formatProvider,

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/MSSqlServerSinkOptions.cs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,20 +66,5 @@ internal MSSqlServerSinkOptions(
6666
/// Flag to eagerly emit a batch containing the first received event (default: true)
6767
/// </summary>
6868
public bool EagerlyEmitFirstEvent { get; set; }
69-
70-
/// <summary>
71-
/// Flag to enable SQL authentication using Azure Managed Identities (default: false)
72-
/// </summary>
73-
public bool UseAzureManagedIdentity { get; set; }
74-
75-
/// <summary>
76-
/// Azure service token provider to be used for Azure Managed Identities
77-
/// </summary>
78-
public string AzureServiceTokenProviderResource { get; set; }
79-
80-
/// <summary>
81-
/// ID of the tenant where the Azure resource exists
82-
/// </summary>
83-
public string AzureTenantId { get; set; }
8469
}
8570
}

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/Platform/AzureManagedServiceAuthenticator.cs

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/Serilog.Sinks.MSSqlServer/Sinks/MSSqlServer/Platform/AzureManagedServiceAuthenticatorStub.cs

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)