Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate StatusAggregator job to MSI storage authentication #10328

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from

Conversation

drewgillies
Copy link
Contributor

Addresses: https://github.com/NuGet/Engineering/issues/5447

This is 90% @advay26 (maybe more) and the rest me. :)

This change updates StatusAggregator to use MSIs for table storage access.

@drewgillies drewgillies requested a review from a team as a code owner January 24, 2025 06:47
@@ -35,7 +35,7 @@ public Task CreateIfNotExistsAsync()
public async Task<T> RetrieveAsync<T>(string rowKey)
where T : class, ITableEntity
{
return (await _table.GetEntityAsync<T>(TablePartitionKeys.Get<T>(), rowKey)) as T;
return (await _table.GetEntityAsync<T>(TablePartitionKeys.Get<T>(), rowKey))?.Value as T;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was broken since #10106

{
var blob = _container.GetBlobClient(name);
return blob.UploadAsync(contents);
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(contents)))
{
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Necessary to send content to correct method overload, otherwise an illegal character exception is thrown.

@drewgillies drewgillies changed the title Migrate StatusAggregator job to MSI authentication to storage Migrate StatusAggregator job to MSI storage authentication Jan 24, 2025
return new Uri(tempClient.Uri.GetLeftPart(UriPartial.Path));
}

public static Uri GetPrimaryBlobServiceUri(string storageConnectionString) => GetPrimaryServiceUri(storageConnectionString);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why need this function? can we cal 0GetPrimaryServiceUri directly?

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, then we don't need mostly cosmetic changes in src/NuGet.Jobs.Common/StorageAccountExtensions.cs

public static Uri GetPrimaryBlobServiceUri(string storageConnectionString) => GetPrimaryServiceUri(storageConnectionString);


public static Uri GetPrimaryTableServiceUri(string storageConnectionString)
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems unused. Do we really need it?

{
var blob = _container.GetBlobClient(name);
return blob.UploadAsync(contents);
using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(contents)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this Encoding.UTF8.GetBytes safely handle data? If by “string” you mean we’ve forced arbitrary binary data into a .NET string (which can happen in edge cases, like reading a file with non-text bytes and interpreting them as characters), you can run into trouble.

Copy link
Contributor

Choose a reason for hiding this comment

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

UTF-8 expects valid Unicode code points. If your data wasn’t actually text to begin with, we can end up with corruption or exceptions.

/// </summary>
public string StorageAccount { get; set; }
public string PrimaryStorageBlobEndpoint { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need to make corresponding changes to NuGet.Deployment to match this change?

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