e11en
e11en

Reputation: 115

Possible to use Azure Managed Identity to access Cosmos DB with Entity Framework?

I'm trying to figure out if it is possible to use EF with a Cosmos DB and authenticate with Azure Managed Identity. I know you can add an interceptor for SQL databases to authenticate but I can't get it to work with Cosmos DB nor can I find any documentation on this.

Does that mean it's not possible?

Upvotes: 1

Views: 1787

Answers (2)

XWIKO
XWIKO

Reputation: 343

If you want to get it to work with managed identity you can do a quick tweak (if you dont want to wait for EF 7 in november). You can have a look at my gist what you need to do to create a custom extension and to get it to work.

https://gist.github.com/wkoeter/4ed90c7c8f61e3b3a52d2667d5a7c856

...
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddCosmosCustom<CosmosContext>(
    endpoint: "https://westus22.documents.azure.com:443/",
    databaseName: "MyDb",
    managedIdentityClientId: "90df9398-990d-459f-8833-bfa4d762a4d7");

...

The github issue here https://github.com/dotnet/efcore/issues/26491

Upvotes: 0

Alex
Alex

Reputation: 18526

Support is planned for EF Core 7.0 and tracked here: Cosmos: Support AAD RBAC via the ClientSecretCredential

this is currently planned for the next release; that is EF Core 7.0, which will be released next November.

Upvotes: 2

Related Questions