Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EFCore crash when using PostgreSQL #1643

Open
AnakovaK opened this issue Jan 22, 2025 · 0 comments
Open

EFCore crash when using PostgreSQL #1643

AnakovaK opened this issue Jan 22, 2025 · 0 comments

Comments

@AnakovaK
Copy link

AnakovaK commented Jan 22, 2025

Good day to you folks!

My team, while trying to initialize CAP, has found a severe error in usage of EntityFrameworkCore with DotNetCore.CAP.PostgreSql using methods of yours:

Image

Followed by:

Image

We’ve reproduced that issue separately in the repository for you to try it (just don’t forget to create database manually and provide correct credentials):
https://github.com/AnakovaK/CAPPostgres

(Many thanks to @CAPCHIK for help in locating and replicating the problem!)

The problem is, that you've done similar (copied) logic of retrieving connection strings for all of contexts (MySql, SqlServer, PostgreSql):

Image

But that does not work with Postgres default security options. The parameter Persist Security Info makes retrieving of Password in connection string a one-time thing: once the connection has been made there is no way of retrieving password through usual GetConnectionString() method – so it results in

Initializing the storage structure failed!
      Npgsql.NpgsqlException (0x80004005): No password has been provided but the backend requires one (in SASL/SCRAM-SHA-256)

As it reaches that point only passing through switch of trying to connect with CleartextPassword and MD5Password.

In our repository we've made two actions showcasing the problems of using two different connection strings. Where there is no Persist Security Info = true (a.k.a the default value) everything crashes: https://github.com/AnakovaK/CAPPostgres/actions/runs/12903111381/job/35977818745#step:5:1

Where Persist Security Info = true is present in connection string everything works: https://github.com/AnakovaK/CAPPostgres/actions/runs/12903111381/job/35977819035#step:5:1

That problem is a security issue, as the only way of stopping it from appearing right now is setting Persist Security Info = true, which permanently saves password for the further retrievals in any place of code.

One way to resolve it would be using DataSource, which you’ve started to use: but that will result in using the hidden EFCore methods with the warnings of the possibility of them being changed: (the “It may be changed or removed without notice in any release.” warning).

Main question is: what is the purpose of UseEntityFramework option if it uses same methods as UsePostgreSql inside? (both register PostgreSqlCapOptionsExtension() and use DotNetCore.CAP.PostgreSql library). The issue is fully fixed by using normal UsePostgreSql and giving the parameters straight-on, as opposed to how it is retrieved when using the EntityFrameworkCore and not being able to get the password (rightfully so!).

Wouldn’t it be logical to make it obsolete and/or remove it completely?
One more thing: if that method has to stay, please, update README explaining the mandatory parameter for Postgres users in EFCore: the Persist Security Info, indicating the risk of its alteration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant