Skip to content

Commit ca2f194

Browse files
committed
Added ManagedIdentityClientId + ManagedIdentityResourceId
1 parent 65b293b commit ca2f194

File tree

28 files changed

+262
-133
lines changed

28 files changed

+262
-133
lines changed

src/NLog.Extensions.AzureBlobStorage/BlobStorageTarget.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,32 +35,46 @@ public sealed class BlobStorageTarget : AsyncTaskTarget
3535
/// </summary>
3636
public Layout ServiceUri { get; set; }
3737

38+
/// <summary>
39+
/// Obsolete instead use <see cref="ServiceUri"/>
40+
/// </summary>
3841
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
3942
[Obsolete("Instead use ServiceUri")]
4043
public Layout ServiceUrl { get => ServiceUri; set => ServiceUri = value; }
4144

4245
/// <summary>
43-
/// Alternative to ConnectionString, when using <see cref="ServiceUri"/>
44-
/// tenantId for <see cref="Azure.Identity.DefaultAzureCredentialOptions"/> and <see cref="Azure.Identity.ClientSecretCredential"/>. Requires <see cref="ServiceUri"/>.
46+
/// TenantId for <see cref="Azure.Identity.DefaultAzureCredentialOptions"/> and <see cref="Azure.Identity.ClientSecretCredential"/>. Requires <see cref="ServiceUri"/>.
4547
/// </summary>
4648
public Layout TenantIdentity { get; set; }
4749

50+
/// <summary>
51+
/// Obsolete instead use <see cref="ManagedIdentityResourceId"/>
52+
/// </summary>
4853
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
4954
[Obsolete("Instead use ManagedIdentityResourceId")]
5055
public Layout ResourceIdentity { get => ManagedIdentityResourceId; set => ManagedIdentityResourceId = value; }
5156

5257
/// <summary>
53-
/// resourceId for <see cref="Azure.Identity.DefaultAzureCredentialOptions.ManagedIdentityResourceId"/> on <see cref="Azure.Identity.DefaultAzureCredentialOptions"/>. Requires <see cref="ServiceUri"/> .
58+
/// ResourceId for <see cref="Azure.Identity.DefaultAzureCredentialOptions.ManagedIdentityResourceId"/> on <see cref="Azure.Identity.DefaultAzureCredentialOptions"/>. Requires <see cref="ServiceUri"/> .
5459
/// </summary>
60+
/// <remarks>
61+
/// Do not configure this value together with <see cref="ManagedIdentityClientId"/>
62+
/// </remarks>
5563
public Layout ManagedIdentityResourceId { get; set; }
5664

65+
/// <summary>
66+
/// Obsolete instead use <see cref="ManagedIdentityClientId"/>
67+
/// </summary>
5768
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
5869
[Obsolete("Instead use ManagedIdentityClientId")]
5970
public Layout ClientIdentity { get => ManagedIdentityClientId; set => ManagedIdentityClientId = value; }
6071

6172
/// <summary>
62-
/// Sets <see cref="Azure.Identity.DefaultAzureCredentialOptions.ManagedIdentityClientId"/> on <see cref="Azure.Identity.DefaultAzureCredentialOptions"/>. Requires <see cref="ServiceUri"/>.
73+
/// ManagedIdentityClientId for <see cref="Azure.Identity.DefaultAzureCredentialOptions"/>. Requires <see cref="ServiceUri"/>.
6374
/// </summary>
75+
/// <remarks>
76+
/// If this value is configured, then <see cref="ManagedIdentityResourceId"/> should not be configured.
77+
/// </remarks>
6478
public Layout ManagedIdentityClientId { get; set; }
6579

6680
/// <summary>
@@ -69,12 +83,12 @@ public sealed class BlobStorageTarget : AsyncTaskTarget
6983
public Layout SharedAccessSignature { get; set; }
7084

7185
/// <summary>
72-
/// accountName for <see cref="Azure.Storage.StorageSharedKeyCredential"/> authentication. Requires <see cref="ServiceUri"/> and <see cref="AccessKey"/>.
86+
/// AccountName for <see cref="Azure.Storage.StorageSharedKeyCredential"/> authentication. Requires <see cref="ServiceUri"/> and <see cref="AccessKey"/>.
7387
/// </summary>
7488
public Layout AccountName { get; set; }
7589

7690
/// <summary>
77-
/// accountKey for <see cref="Azure.Storage.StorageSharedKeyCredential"/> authentication. Requires <see cref="ServiceUri"/> and <see cref="AccountName"/>.
91+
/// AccountKey for <see cref="Azure.Storage.StorageSharedKeyCredential"/> authentication. Requires <see cref="ServiceUri"/> and <see cref="AccountName"/>.
7892
/// </summary>
7993
public Layout AccessKey { get; set; }
8094

src/NLog.Extensions.AzureBlobStorage/NLog.Extensions.AzureBlobStorage.csproj

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
<RepositoryUrl>https://github.com/JDetmar/NLog.Extensions.AzureStorage.git</RepositoryUrl>
1919
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2020
<PackageReleaseNotes>
21-
- Added support for authentication with a service principal using a secret. by @ssteiner
21+
- Added support for authentication with a service principal using a secret. by @ssteiner
22+
- Introduced ManagedIdentityClientId to replace ClientIdentity-option
23+
- Introduced ManagedIdentityResourceId to replace ResourceIdentity-option
2224

23-
Docs: https://github.com/JDetmar/NLog.Extensions.AzureStorage/blob/master/src/NLog.Extensions.AzureBlobStorage/README.md
25+
Docs: https://github.com/JDetmar/NLog.Extensions.AzureStorage/blob/master/src/NLog.Extensions.AzureBlobStorage/README.md
2426
</PackageReleaseNotes>
2527
</PropertyGroup>
2628

src/NLog.Extensions.AzureBlobStorage/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ _connectionString_ - Azure storage connection string. Ex. `UseDevelopmentStorage
4141

4242
_serviceUri_ - Uri to reference the blob service (e.g. https://{account_name}.blob.core.windows.net). Input for `BlobServiceClient`. Required, when `connectionString` is not configured. Overrides `connectionString` when both are set.
4343

44-
_managedIdentityClientId_ - Sets `ManagedIdentityClientId` on `DefaultAzureCredentialOptions`. Requires `serviceUri`
44+
_managedIdentityClientId_ - Sets `ManagedIdentityClientId` on `DefaultAzureCredentialOptions`. Requires `serviceUri`.
4545

46-
_managedIdentityResourceId_ - resourceId for `ManagedIdentityResourceId` on `DefaultAzureCredentialOptions`. Requires `serviceUri`.
46+
_managedIdentityResourceId_ - resourceId for `ManagedIdentityResourceId` on `DefaultAzureCredentialOptions`, do not use together with `ManagedIdentityClientId`. Requires `serviceUri`.
4747

4848
_tenantIdentity_ - tenantId for `DefaultAzureCredentialOptions` and `ClientSecretCredential`. Requires `serviceUri`.
4949

src/NLog.Extensions.AzureDataTables/DataTablesTarget.cs

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -66,32 +66,55 @@ public override int GetHashCode()
6666
/// </remarks>
6767
public Layout ServiceUri { get; set; }
6868

69+
/// <summary>
70+
/// Obsolete instead use <see cref="ServiceUri"/>
71+
/// </summary>
6972
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
7073
[Obsolete("Instead use ServiceUri")]
7174
public Layout ServiceUrl { get => ServiceUri; set => ServiceUri = value; }
7275

7376
/// <summary>
74-
/// Alternative to ConnectionString, when using <see cref="ServiceUri"/>
77+
/// TenantId for <see cref="Azure.Identity.DefaultAzureCredentialOptions"/>. Requires <see cref="ServiceUri"/>.
7578
/// </summary>
7679
public Layout TenantIdentity { get; set; }
7780

7881
/// <summary>
79-
/// Alternative to ConnectionString, when using <see cref="ServiceUri"/>
82+
/// Obsolete instead use <see cref="ManagedIdentityResourceId"/>
83+
/// </summary>
84+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
85+
[Obsolete("Instead use ManagedIdentityResourceId")]
86+
public Layout ResourceIdentity { get => ManagedIdentityResourceId; set => ManagedIdentityResourceId = value; }
87+
88+
/// <summary>
89+
/// ResourceId for <see cref="Azure.Identity.DefaultAzureCredentialOptions.ManagedIdentityResourceId"/> on <see cref="Azure.Identity.DefaultAzureCredentialOptions"/>. Requires <see cref="ServiceUri"/> .
90+
/// </summary>
91+
/// <remarks>
92+
/// Do not configure this value together with <see cref="ManagedIdentityClientId"/>
93+
/// </remarks>
94+
public Layout ManagedIdentityResourceId { get; set; }
95+
96+
/// <summary>
97+
/// Obsolete instead use <see cref="ManagedIdentityClientId"/>
8098
/// </summary>
81-
public Layout ResourceIdentity { get; set; }
99+
[System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
100+
[Obsolete("Instead use ManagedIdentityClientId")]
101+
public Layout ClientIdentity { get => ManagedIdentityClientId; set => ManagedIdentityClientId = value; }
82102

83103
/// <summary>
84-
/// Alternative to ConnectionString, when using <see cref="ServiceUri"/> with ManagedIdentityClientId / WorkloadIdentityClientId
104+
/// ManagedIdentityClientId for <see cref="Azure.Identity.DefaultAzureCredentialOptions"/>. Requires <see cref="ServiceUri"/>.
85105
/// </summary>
86-
public Layout ClientIdentity { get; set; }
106+
/// <remarks>
107+
/// If this value is configured, then <see cref="ManagedIdentityResourceId"/> should not be configured.
108+
/// </remarks>
109+
public Layout ManagedIdentityClientId { get; set; }
87110

88111
/// <summary>
89-
/// Alternative to ConnectionString, when using <see cref="ServiceUri"/> with AzureSasCredential
112+
/// Access signature for <see cref="Azure.AzureSasCredential"/> authentication. Requires <see cref="ServiceUri"/>.
90113
/// </summary>
91114
public Layout SharedAccessSignature { get; set; }
92115

93116
/// <summary>
94-
/// Alternative to ConnectionString, when using <see cref="ServiceUri"/> with <see cref="TableSharedKeyCredential"/> storage account name.
117+
/// AccountName for <see cref="TableSharedKeyCredential"/> authentication. Requires <see cref="ServiceUri"/> and <see cref="AccessKey"/>.
95118
/// </summary>
96119
/// <remarks>
97120
/// You'll need a Storage or Cosmos DB account name, primary key, and endpoint Uri.
@@ -101,7 +124,7 @@ public override int GetHashCode()
101124
public Layout AccountName { get; set; }
102125

103126
/// <summary>
104-
/// Alternative to ConnectionString, when using <see cref="ServiceUri"/> with <see cref="TableSharedKeyCredential"/> storage account access-key.
127+
/// AccountKey for <see cref="TableSharedKeyCredential"/> authentication. Requires <see cref="ServiceUri"/> and <see cref="AccountName"/>.
105128
/// </summary>
106129
public Layout AccessKey { get; set; }
107130

@@ -147,8 +170,8 @@ protected override void InitializeTarget()
147170
string connectionString = string.Empty;
148171
string serviceUri = string.Empty;
149172
string tenantIdentity = string.Empty;
150-
string resourceIdentifier = string.Empty;
151-
string clientIdentity = string.Empty;
173+
string managedIdentityResourceId = string.Empty;
174+
string managedIdentityClientId = string.Empty;
152175
string sharedAccessSignature = string.Empty;
153176
string accountName = string.Empty;
154177
string accessKey = string.Empty;
@@ -162,14 +185,14 @@ protected override void InitializeTarget()
162185
{
163186
serviceUri = ServiceUri?.Render(defaultLogEvent);
164187
tenantIdentity = TenantIdentity?.Render(defaultLogEvent);
165-
resourceIdentifier = ResourceIdentity?.Render(defaultLogEvent);
166-
clientIdentity = ClientIdentity?.Render(defaultLogEvent);
188+
managedIdentityResourceId = ManagedIdentityResourceId?.Render(defaultLogEvent);
189+
managedIdentityClientId = ManagedIdentityClientId?.Render(defaultLogEvent);
167190
sharedAccessSignature = SharedAccessSignature?.Render(defaultLogEvent);
168191
accountName = AccountName?.Render(defaultLogEvent);
169192
accessKey = AccessKey?.Render(defaultLogEvent);
170193
}
171194

172-
_cloudTableService.Connect(connectionString, serviceUri, tenantIdentity, resourceIdentifier, clientIdentity, sharedAccessSignature, accountName, accessKey);
195+
_cloudTableService.Connect(connectionString, serviceUri, tenantIdentity, managedIdentityResourceId, managedIdentityClientId, sharedAccessSignature, accountName, accessKey);
173196
InternalLogger.Debug("AzureDataTablesTarget(Name={0}): Initialized", Name);
174197
}
175198
catch (Exception ex)
@@ -384,7 +407,7 @@ class CloudTableService : ICloudTableService
384407
private TableServiceClient _client;
385408
private TableClient _table;
386409

387-
public void Connect(string connectionString, string serviceUri, string tenantIdentity, string resourceIdentifier, string clientIdentity, string sharedAccessSignature, string storageAccountName, string storageAccountAccessKey)
410+
public void Connect(string connectionString, string serviceUri, string tenantIdentity, string managedIdentityResourceId, string managedIdentityClientId, string sharedAccessSignature, string storageAccountName, string storageAccountAccessKey)
388411
{
389412
if (string.IsNullOrWhiteSpace(serviceUri))
390413
{
@@ -400,7 +423,7 @@ public void Connect(string connectionString, string serviceUri, string tenantIde
400423
}
401424
else
402425
{
403-
var tokenCredentials = AzureCredentialHelpers.CreateTokenCredentials(clientIdentity, tenantIdentity, resourceIdentifier);
426+
var tokenCredentials = AzureCredentialHelpers.CreateTokenCredentials(managedIdentityClientId, tenantIdentity, managedIdentityResourceId);
404427
_client = new TableServiceClient(new Uri(serviceUri), tokenCredentials);
405428
}
406429
}

src/NLog.Extensions.AzureDataTables/ICloudTableService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace NLog.Extensions.AzureStorage
77
{
88
interface ICloudTableService
99
{
10-
void Connect(string connectionString, string serviceUri, string tenantIdentity, string resourceIdentifier, string clientIdentity, string sharedAccessSignature, string storageAccountName, string storageAccountAccessKey);
10+
void Connect(string connectionString, string serviceUri, string tenantIdentity, string managedIdentityResourceId, string managedIdentityClientId, string sharedAccessSignature, string storageAccountName, string storageAccountAccessKey);
1111
Task SubmitTransactionAsync(string tableName, IEnumerable<TableTransactionAction> tableTransaction, CancellationToken cancellationToken);
1212
}
1313
}

src/NLog.Extensions.AzureDataTables/NLog.Extensions.AzureDataTables.csproj

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
<RepositoryUrl>https://github.com/JDetmar/NLog.Extensions.AzureStorage.git</RepositoryUrl>
1919
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2020
<PackageReleaseNotes>
21-
- Assign WorkloadIdentityClientId from ClientIdentity
22-
- Changed Layout default-value to ${message} since LogEvent is split into columns
23-
- Added automatic truncate when column-values has string-length above 32K
24-
- Skips adding column values when empty string and configured IncludeEmptyValue = false
21+
- Introduced ManagedIdentityClientId to replace ClientIdentity-option
22+
- Introduced ManagedIdentityResourceId to replace ResourceIdentity-option
2523

2624
Docs: https://github.com/JDetmar/NLog.Extensions.AzureStorage/blob/master/src/NLog.Extensions.AzureDataTables/README.md
2725
</PackageReleaseNotes>

src/NLog.Extensions.AzureDataTables/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,17 @@ _connectionString_ - Azure storage connection string. [Layout](https://github.co
3232

3333
_serviceUri_ - Alternative to ConnectionString, where Managed Identiy is acquired from DefaultAzureCredential.
3434

35-
_clientIdentity_ - Alternative to ConnectionString. Used together with ServiceUri. Input for DefaultAzureCredential as ManagedIdentityClientId.
35+
_managedIdentityClientId_ - Sets `ManagedIdentityClientId` on `DefaultAzureCredentialOptions`. Requires `serviceUri`
3636

37-
_resourceIdentity_ - Alternative to ConnectionString. Used together with ServiceUri. Input for DefaultAzureCredential as ManagedIdentityResourceId.
37+
_managedIdentityResourceId_ - resourceId for `ManagedIdentityResourceId` on `DefaultAzureCredentialOptions`, do not use together with `ManagedIdentityClientId`. Requires `serviceUri`.
3838

39-
_tenantIdentity_ - Alternative to ConnectionString. Used together with ServiceUri. Input for DefaultAzureCredential.
39+
_tenantIdentity_ - tenantId for `DefaultAzureCredentialOptions`. Requires `serviceUri`.
4040

41-
_sharedAccessSignature_ - Alternative to ConnectionString. Used together with ServiceUri. Input for AzureSasCredential
41+
_sharedAccessSignature_ - Access signature for `AzureSasCredential` authentication. Requires `serviceUri`.
4242

43-
_accountName_ - Alternative to ConnectionString. Used together with ServiceUri. Input for TableSharedKeyCredential storage account-name.
43+
_accountName_ - accountName for `TableSharedKeyCredential` authentication. Requires `serviceUri` and `accessKey`.
4444

45-
_accessKey_ - Alternative to ConnectionString. Used together with ServiceUri. Input for TableSharedKeyCredential account-access-key.
45+
_accessKey_ - accountKey for `TableSharedKeyCredential` authentication. Requires `serviceUri` and `accountName`.
4646

4747
_tableName_ - Azure table name. [Layout](https://github.com/NLog/NLog/wiki/Layouts)
4848

0 commit comments

Comments
 (0)