PostgreSQL container fails with SCRAM auth when started by Aspire if data volume exists: “password authentication failed for user '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
When starting a .NET Aspire solution that provisions a PostgreSQL container, connections to the database fail with a SCRAM authentication error if the container uses an existing persistent data volume. The error messages include:
```
DETAIL: Connection matched file "/var/lib/postgresql/data/pg_hba.conf" line 124: "host all all all scram-sha-256"
FATAL: password authentication failed for user "postgres"
DETAIL: Connection matched file "/var/lib/postgresql/data/pg_hba.conf" line 124: "host all all all scram-sha-256"
```
This typically happens when the persisted volume was initialized with MD5 password hashes but pg_hba.conf now enforces SCRAM-SHA-256
### Expected Behavior
I expect Aspire to launch the PostgreSQL container and connect to the database successfully, regardless of whether the volume is new or pre-existing, provided the configured credentials are correct. There should be no password authentication errors during development or repeated runs.
### Steps To Reproduce
1. Create a minimal Aspire solution with a PostgreSQL container resource (e.g. AddPostgres, AddDatabase).
2. Run the solution once, so the PostgreSQL volume and DB files are initialized.
3. Stop the Aspire solution.
5. Start Aspire again using the same persistent data volume.
6. Observe connection errors and SCRAM authentication failures in logs:
```
FATAL: password authentication failed for user "postgres"
DETAIL: Connection matched file "/var/lib/postgresql/data/pg_hba.conf" line 124: "host all all all scram-sha-256"
```
### Exceptions (if any)
PostgreSQL container log output:
```
DETAIL: Connection matched file "/var/lib/postgresql/data/pg_hba.conf" line 124: "host all all all scram-sha-256"
FATAL: password authentication failed for user "postgres"
```
### .NET Version info
.NET SDK:
Version: 10.0.100-preview.7.25380.108
Commit: 30000d883e
Workload version: 10.0.100-manifests.8bb6be96
MSBuild version: 17.15.0-preview-25380-108+30000d883
### Anything else?
IDE: Rider
Contributor guide
Assessment
This issue has not been assessed yet.