Skip to content

Support assigning UserAssigned Managed Identities to compute resources #8441

@eerhardt

Description

@eerhardt

Update (05/09/2025): Remaining work here is to support assigning UMIs to compute resources.

Today when using targeted role assignments (#6161), each container app gets its own managed identity.

Sometimes this can pose problems, like in #8389, where a "data migration" app is used to create a database, but then an "API" app wants to CRUD against it. It is simpler to assign both apps the same managed identity, thus only needing a single database user, which both apps use.

To support custom scenarios like this, we should add the ability for the user to manually create a managed identity, and then assign container apps (projects and containers) to a managed identity manually. Doing this would cause the automatic managed identity to no longer be generated for that container app.

Example code:

var builder = DistributedApplication.CreateBuilder(args);
builder.AddAzureContainerAppEnvironment("env");

var dbServer = builder.AddAzureSqlServer("sqlserver");
var todosDb = dbServer.AddDatabase("todosdb");

// The ApiDbService project is responsible for managing the database schema and seeding data.
var apiDbService = builder.AddProject<Projects.AspireStarterDb_ApiDbService>("apidbservice")
    .WithReference(todosDb);

// The ApiService project provides backend HTTP APIs for the web frontend.
var apiService = builder.AddProject<Projects.AspireStarterDb_ApiService>("apiservice")
    .WithReference(todosDb);

// NEW
var dbuser = builder.AddAzureUserAssignedIdentity("dbuser");
apiDbService.WithAppIdentity(dbuser);
apiService.WithAppIdentity(dbuser);

When paired with the WithRoleAssignments API, any role assignments for apiDbService and apiService would be generated for the dbuser managed identity.

Open Questions

  1. In RunMode, how should AddAzureUserAssignedIdentity work? We probably don't want to provision these Azure resources at dotnet run time, since nothing will use them. So we would add the resource in memory, but not add it to the model.

cc @davidfowl @tg-msft @mitchdenny

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-integrationsIssues pertaining to Aspire Integrations packagesazureIssues associated specifically with scenarios tied to using Azuresecurity 🔐

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions