Ability to set CORS policy for the Blob Storage emulator
- Dominant language
- C#
- Stars
- 6.3k
- Forks
- 991
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 196
Description
### Is there an existing issue for this?
- [x] I have searched the existing issues
### Is your feature request related to a problem? Please describe the problem.
Description
When using Azure Storage within an Aspire application, specifically leveraging the storage account emulator, the CORS (Cross-Origin Resource Sharing) policies for the blob container are not automatically configured.
Our application relies on generating a SAS (Shared Access Signature) token on the backend and then allowing a frontend application to directly upload binaries to the blob container. This requires specific CORS rules to be set on the blob service to allow the cross-origin requests from the frontend.
Currently, every time the Aspire application runs and the storage emulator spins up, we must manually configure the required CORS policies in the storage emulator tools (like Azure Storage Explorer or Azurite command line/tool), which is a significant developer friction point.
### Describe the solution you'd like
We request the ability to configure the CORS policies directly on the Aspire Azure Storage resource within the AppHost project. This configuration should be applied automatically to the storage emulator's blob service when the application starts up.
This could potentially be implemented via a new extension method or configuration property on the storage resource builder.
This may not be a perfect match but it covers the load and clarifies the request:
```csharp
builder.AddAzureStorage("storage")
.RunAsEmulator(options =>
{
options.ConfigureBlobService(blob =>
{
// Configure CORS rules specific to the blob service
blob.SetCorsPolicies(new CorsRule[]
{
new CorsRule
{
AllowedOrigins = new[] { "http://localhost:5173", "https://*.myapp.com" },
AllowedMethods = new[] { "PUT", "GET", "POST" },
AllowedHeaders = new[] { "*" },
ExposedHeaders = new[] { "*" },
MaxAgeInSeconds = 3600
}
});
});
});
```
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.