FerretDB / FerretDB

A truly Open Source MongoDB alternative

Home Page:https://www.ferretdb.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

C# MongoDB driver: "no PostgreSQL user name specified in startup packet"

Evengard opened this issue · comments

FerretDB version

1.19.0

Backend

PostgreSQL 15.2

Environment

  • OS: Debian 11.8
  • Deployment: k8s deployment
  • Deployment details: Both FerretDB and PostgreSQL are deployed in an k8s instance

What did you do?

I either can't authenticate at all (if not using StableAPI), or can't Insert documents (if using the StableAPI).

Consider this sample which will fail no matter if I set StableAPI or not:

using MongoDB.Driver;

var mongoClientSettings = MongoClientSettings.FromConnectionString("mongodb://username:password@myferretdb:25017/?authMechanism=PLAIN");
mongoClientSettings.ServerApi = new ServerApi(ServerApiVersion.V1);
var mongoClient = new MongoClient(mongoClientSettings);
var mongoDb = mongoClient.GetDatabase("dm3dev");
var collection = mongoDb.GetCollection<Test>("test");
collection.InsertOne(new Test("World"));

public record Test(string Hello);

If I run it as it is, I get 'Command insert failed: insert: unknown field "apiVersion".', which seems to be related to #3121

If I run it without the line mongoClientSettings.ServerApi = new ServerApi(ServerApiVersion.V1); which sets the StableAPI, I then get:

'Command insert failed: [msg_insert.go:169 handler.(*Handler).MsgInsert] [collection.go:123 postgresql.(*collection).InsertAll] [registry.go:479 metadata.(*Registry).CollectionCreate] [registry.go:132 metadata.(*Registry).getPool] [pool.go:128 pool.(*Pool).Get] [opendb.go:95 pool.openDB] [opendb.go:110 pool.checkConnection] failed to connect tohost=postgres-db-rw.postgres.svc.cluster.local user= database=dm3_ferret_dev: server error (FATAL: no PostgreSQL user name specified in startup packet (SQLSTATE 28000)).'

Which looks like the username from the client isn't passed down to the Postgres server.

What did you expect to see?

I expect it to work at least with some settings...

Please note that I'm using this postgresql setting:

- name: FERRETDB_POSTGRESQL_URL
  value: "postgres://postgres-db-rw.postgres.svc.cluster.local:5432/dm3_ferret_dev"

I explicitely did not provide a username and password here, as I need to restrict anonymous logins completely.

What is your driver version?

@AlekSi I suspect 2.15 or older see this comment.

As I said in the PR, it is 2.23.1

First of all, we should be able to reproduce that issue with dance. That's on @b1ron (FerretDB/dance#769)