Skip to content

Commit 1df257c

Browse files
authored
Migrate AccountDeleter job to MSI storage account access (#10165)
Use MSI for storage account auth in AccountDeleter
1 parent 7186abd commit 1df257c

2 files changed

Lines changed: 12 additions & 11 deletions

File tree

src/AccountDeleter/Configuration/AccountDeleteConfiguration.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Collections.Generic;
@@ -27,6 +27,7 @@ public class AccountDeleteConfiguration
2727
/// </summary>
2828
public Dictionary<string, string> TemplateReplacements { get; set; }
2929

30+
3031
/// <summary>
3132
/// Storage container connection string where gallery content can be found
3233
/// </summary>
@@ -50,4 +51,4 @@ public SourceConfiguration GetSourceConfiguration(string source)
5051
throw new UnknownSourceException();
5152
}
5253
}
53-
}
54+
}

src/AccountDeleter/Job.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -27,6 +27,7 @@
2727
using NuGetGallery.Features;
2828
using NuGetGallery.Infrastructure.Authentication;
2929
using NuGetGallery.Security;
30+
using ConfigConstants = NuGet.Services.Configuration.Constants;
3031

3132
namespace NuGetGallery.AccountDeleter
3233
{
@@ -104,6 +105,13 @@ protected override void ConfigureJobServices(IServiceCollection services, IConfi
104105
services.AddScoped<ITelemetryClient, TelemetryClientWrapper>(
105106
sp => TelemetryClientWrapper.UseTelemetryConfiguration(ApplicationInsightsConfiguration.TelemetryConfiguration));
106107

108+
services.AddScoped<ICloudBlobClient>(serviceProvider =>
109+
{
110+
var options = serviceProvider.GetRequiredService<IOptionsSnapshot<AccountDeleteConfiguration>>();
111+
return CloudBlobClientWrapper.UsingMsi(options.Value.GalleryStorageConnectionString,
112+
configurationRoot[ConfigConstants.StorageManagedIdentityClientIdPropertyName]);
113+
});
114+
107115
ConfigureGalleryServices(services);
108116
}
109117

@@ -160,14 +168,6 @@ protected void ConfigureGalleryServices(IServiceCollection services)
160168
return new SupportRequestDbContext(connection);
161169
});
162170

163-
services.AddScoped<ICloudBlobClient>(sp =>
164-
{
165-
var options = sp.GetRequiredService<IOptionsSnapshot<AccountDeleteConfiguration>>();
166-
var optionsSnapshot = options.Value;
167-
168-
return new CloudBlobClientWrapper(optionsSnapshot.GalleryStorageConnectionString, readAccessGeoRedundant: true);
169-
});
170-
171171
services.AddScoped<ITelemetryService, TelemetryService>();
172172
services.AddScoped<ISecurityPolicyService, SecurityPolicyService>();
173173
services.AddScoped<IAppConfiguration, GalleryConfiguration>();

0 commit comments

Comments
 (0)