1

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?

e11en
  • 107
  • 1
  • 2
  • 17
  • we can use `system-assigned managed identities` to access Azure Cosmos DB data , Please refer this [MS DOC](https://learn.microsoft.com/en-us/azure/cosmos-db/managed-identity-based-authentication) Let us know if its helps. – AjayKumarGhose Jan 14 '22 at 08:50
  • How do see this being used with Entity Framework? Where you connect your context with `optionsBuilder.UseCosmos(connectionString)` and that's it. – e11en Jan 14 '22 at 10:52

2 Answers2

2

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.

Alex AIT
  • 17,361
  • 3
  • 36
  • 73
0

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

XWIKO
  • 308
  • 4
  • 13