microsoft / microsoft/aspire

Connecting locally to an Aspire-provisioned Azure Posgres Flexible server

Open
#14,842 12 comments 0 reactions 0 assignees View on GitHub
area-integrations azure postgres
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

### Describe the bug

I am trying to run my Aspire app on my dev machine and connect to the posgres db that was provisioned via `azd provision` but I am getting an issue, probably related to Entra.

I've included my configuration and the error returned when I try to use my DbContext.

What additional configuration do I need to perform to have this work?

Is connecting my dev environment to Azure not a supported configuration? I am running a postgres container now so I can keep going.

I believe there is also the option of `WithPasswordAuthentication` but my understanding is that it stops using Entra entirely.

### Expected Behavior

I assumed everything would just work. There's nothing in the documentation for Posgres, Azure Postgres that suggests additional configuration is necessary.

### Steps To Reproduce

AppHost

```csharp
var builder = DistributedApplication.CreateBuilder(args);

var postgres = builder.AddAzurePostgresFlexibleServer("postgres")
.ConfigureInfrastructure(infra =>
{
var flexibleServer = infra.GetProvisionableResources()
.OfType()
.Single();

flexibleServer.Sku = new PostgreSqlFlexibleServerSku
{
Tier = PostgreSqlFlexibleServerSkuTier.Burstable, Name = "Standard_B1ms",
};
});

var db = postgres.AddDatabase("db");

var api = builder.AddProject("api")
.WithReference(db).WaitFor(db)
.WithHttpHealthCheck("/health")
.WithExternalHttpEndpoints();

builder.Build().Run();
```

MyApiProject/Program.cs
```csharp
ar builder = WebApplication.CreateBuilder(args);

// Add service defaults & Aspire client integrations.
builder.AddServiceDefaults();

// PostgreSQL + EF Core via Aspire integration
builder.AddAzureNpgsqlDbContext("db");

// Boilerplate omitted
```

### Exceptions (if any)

```
28000: no pg_hba.conf entry for host "{My IP}", user "{My Email}", database "db", no encryption
```

### .NET Version info

_No response_

### Anything else?

_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.