microsoft / microsoft/aspire

Support Managed Identity in AzureStorageResource emulator

Open
#7,047 11 comments 2 reactions 0 assignees View on GitHub
area-integrations azure azure-storage
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.

I am trying to use Aspire to start up my AspNetCore project and emulate all my Azure dependencies for local development.
My goal is to not mix any Aspire dependencies into my production code.
The AppHost project's sole responsibility should be to start all the emulators, replace environment variables for the AspNetCore API so that it will use the emulators and finally start the API.

One issue I'm facing off the bat is that Aspire exposes Azurite endpoints without TLS, making `Azure.Identity` throw exceptions about using plain HTTP.

Azurite should support HTTPS according to the docs.
`azurite --oauth basic --cert path/server.pem --key path/key.pem`

My current workaround is to grab the connectionstring and set it as an environment variables from Aspire and then check if it's present in my production code to decide which TableClient constructor I should use.

Example:

## Aspire AppHost
```
var storage = builder
.AddAzureStorage("storage")
.RunAsEmulator(azurite =>
{
azurite.WithLifetime(ContainerLifetime.Persistent);
azurite.WithDataVolume("datavol");
});

var tables = storage.AddTables("tables");

builder.AddProject("api")
.WithReference(tables)
.WaitFor(storage)
.WithEnvironment("TableOptions__ConnectionString", tables);
```

## Api Project

```
public class TableOptions
{
public Uri TableEndpoint { get; set; }
public string TableName { get; set; }
public string ConnectionString { get; set; }
}
```

```
public static TableClient Create(
IServiceProvider serviceProvider,
TableOptions options)
=> string.IsNullOrEmpty(options.ConnectionString)
? new TableClient(
options.TableEndpoint,
options.TableName,
new DefaultAzureCredential())
: new TableClient(
options.ConnectionString,
options.TableName);
```

Ideally I should use the same constructor and my production code should not support access keys.

### Describe the solution you'd like

Add a method that reflects the Azurite parameter like
```
var storage = builder
.AddAzureStorage("storage")
.RunAsEmulator(azurite =>
{
azurite.WithOauth();
});
```
or perhaps if it's possible, and you think it's better, to make it work with the existing `.WithHttpsEndpoint(...)` extension method.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.