vernemq / vernemq

A distributed MQTT message broker based on Erlang/OTP. Built for high quality & Industrial use cases. The VerneMQ mission is active & the project maintained. Thank you for your support!
https://vernemq.com
Apache License 2.0
3.24k stars 395 forks source link

Authentication with client certificates and PostgreSQL #1360

Closed rebsp closed 5 years ago

rebsp commented 5 years ago

Environment

Expected behaviour

Connect to VerneMQ using a client certificate and authorize to topics using PostgreSQL

Actual behaviour

TLS handshake is successful but receiving bad user name or password for authentication. I have tried several combinations like no password, empty password, password same as CN but none seem to be accepted:

[warning] can't authenticate client {[],<<"test">>} from 172.25.0.1:41876 due to invalid_credentials

Steps to reproduce

rebsp commented 5 years ago

Were you able to reproduce this? Otherwise I can provide a repository with my test environment.

larshesel commented 5 years ago

Sorry, we haven't had a chance to look into this yet. Can you try to do a trace vmq-admin trace client client-id=<the clientid> and then connect and check that the username/pwd are what you expect them to be.

Btw. with the above entry you'd need to pass username: test client, password: ` (empty string) and client_id:test` when connecting.

Hope this helps

rebsp commented 5 years ago

I think I've found the issue. Could it be that the option use_identity_as_username sets the CN as username but keeps the password as undefined, so that this line: https://github.com/vernemq/vernemq/blob/45ac0c6a7bb59ab507ac4dcb5f9f62fdf6d0a410/apps/vmq_diversity/priv/auth/postgres_cockroach_commons.lua#L94 evaluates to false whenever I arrive with a client certificate?

Edit: Yep, see https://github.com/vernemq/vernemq/issues/523

Thanks & best regards