dotnet / aspire

An opinionated, cloud ready stack for building observable, production ready, distributed applications in .NET
https://learn.microsoft.com/dotnet/aspire
MIT License
3.79k stars 440 forks source link

[WebToolsE2E][Aspire] After submitted attachment, click the http link in the 'Console logs' shows 'AuthorizationFailure', and cannot find the file in the storage. #2640

Closed v-cazhang closed 5 months ago

v-cazhang commented 7 months ago

REGRESSION INFO: Also repro on Aspire 8.0.0-preview.3.24105.21

INSTALL STEPS

  1. Clean machine: Win11 x64 23h2 ENU
  2. Install 17.10.0 Preview 2.0 [34701.141.d17.10] (Includes Aspire 8.0.0-preview.4.24129.7)
  3. Apply NuGet Feeds
  4. Install Docker Desktop

REPRO STEPS

  1. New Project > Blazor Web App > name it 'AspireStorage'> 8.0 > None> Per page/component > check 'Enlist in .NET Aspire orchestration'
  2. Right-click the AspireStorage project > Add > .NET Aspire Component > Aspire.Azure.Storage.Blobs > installed with matched version
  3. In the Program.cs file of the AspireStorage project, add following codes:
    
    using
    Azure.Storage.Blobs;

builder.AddAzureBlobService("BlobConnection");

4. Open Program.cs of AspireStorage project, add following codes behind the HTTP request confirguration line:

else { var blobService = app.Services.GetRequiredService(); var docsContainer = blobService.GetBlobContainerClient("fileuploads");

await

docsContainer.CreateIfNotExistsAsync(); }

5. Open Components/Pages/Home.razor, update the codes with following codes:

@page "/"

@using System.ComponentModel.DataAnnotations @using Azure.Storage.Blobs

@inject BlobServiceClient BlobClient

Home

Request Support

<EditForm Model="@Ticket" FormName="Tickets" method="post" OnValidSubmit="@HandleValidSubmit" enctype="multipart/form-data">

<ValidationSummary />

<div class="mb-4">
    <label>Issue Title</label>
    <InputText class="form-control" @bind-Value="@Ticket.Title" />
    <ValidationMessage For="() => Ticket.Title" />
</div>
<div class="mb-4">
    <label>Issue Description</label>
    <InputText class="form-control" @bind-Value="@Ticket.Description" />
    <ValidationMessage For="() => Ticket.Description" />
</div>
<div class="mb-4">
    <label>Attachment</label>
    <InputFile class="form-control" name="Ticket.Document" />
    <ValidationMessage For="() => Ticket.Document" />
</div>
<button class="btn btn-primary" type="submit">Submit</button>
<button class="btn btn-danger mx-2" type="reset" @onclick=@ClearForm>Clear</button>

@code { [SupplyParameterFromForm(FormName = "Tickets")] private SupportTicket Ticket { get; set; } = new();

private async Task HandleValidSubmit()
{
    var docsContainer = BlobClient.GetBlobContainerClient("fileuploads");

    // Upload file to blob storage
    await docsContainer.UploadBlobAsync(
        Ticket.Document.FileName,
        Ticket.Document.OpenReadStream());
}

private void ClearForm() => Ticket = new();

private class SupportTicket()
{
    [Required] public string Title { get; set; } = default!;
    [Required] public string Description { get; set; } = default!;
    [Required] public IFormFile Document { get; set; } = default!;
}

}

6. Right-click AspireStorage.AppHost project > Add > .NET Aspire Component > Aspire.Hosting.Azure
7. Open Program.cs of AspireStorage.AppHost project, add following codes:

var storage = builder.AddAzureStorage("[StorageName]"); if (builder.Environment.IsDevelopment()) { storage.UseEmulator(); } var blobs = storage.AddBlobs("BlobConnection"); builder.AddProject("aspirestorage") .WithReference(blobs);


8. Build and F5
9. Open the endpoint url of AspireStorage, fill the content and submit an attachment
10. Open console logs on the dashboard and select aspirestorage, click the http://xxx/devstoreaccount1/fileuploads/1.txt

**Notes**:
1. It will also met [Bug 1985774](https://devdiv.visualstudio.com/DefaultCollection/DevDiv/_workitems/edit/1985774) and [Bug 1987396](https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1987396).

**ACTUAL**
Open the http link shows 'AuthorizationFailure'
![image](https://github.com/dotnet/aspire/assets/82028229/45b528e1-3024-4309-bff9-543f9949c555)
![image](https://github.com/dotnet/aspire/assets/82028229/0ab26bfa-abd9-4fba-94cc-68b1ee8ea38e)

Also cannot find the file in the storage on the Azure portal.
![image](https://github.com/dotnet/aspire/assets/82028229/4142d13c-888b-41c6-be1d-26387fde8d83)
![image](https://github.com/dotnet/aspire/assets/82028229/684ba050-5ceb-44b6-89d8-42d64aa6bdbe)

**EXPECTED**
Should show the uploaded file.
eerhardt commented 6 months ago

It looks like you don't have authorization to the storage account you configured. Can you ensure you have configured the storage account correctly?

dotnet-policy-service[bot] commented 5 months ago

This submission has been automatically marked as stale because it has been marked as requiring author action but has not had any activity for 14 days. It will be closed if no further activity occurs within 7 days of this comment.