agu-z / roc-pg

🐘 Use PostgreSQL databases from Roc
Universal Permissive License v1.0
41 stars 5 forks source link

Unable to connect with password #6

Closed lorentzlasson closed 9 months ago

lorentzlasson commented 9 months ago

I'm trying to run this example https://github.com/agu-z/roc-pg/blob/main/examples/query.roc, but using a password in clear text instead like so

@@ -21,7 +21,7 @@ task =
         host: "localhost",
         port: 5432,
         user: "postgres",
-        auth: None,
+        auth: Password "foo",
         database: "postgres",
     }

with this postgres setup in docker compose

services:
  db:
    image: postgres:15
    ports:
      - 5432:5432
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: foo
      POSTGRES_DB: postgres

but I get

[examples/query.roc:67] (TcpPerformErr UnsupportedAuth) Something went wrong

I can connect to it using psql postgres://postgres:foo@localhost/postgres

And if I switch the compose config to POSTGRES_HOST_AUTH_METHOD: trust I can connect from query.roc

Connected! John: 32 Julio: 23

agu-z commented 9 months ago

I ran the docker compose, and after adding some logging code, I found the server is configured to use SASL / SCRAM-SHA-256 (#10), which is the default authentication method.

Unfortunately, we only support clear-text password for now. SASL requires cryptographic functions and effects that are currently not available in the Roc ecosystem. We'll definitely add support for it and TLS in the future, but I'm currently dedicating my free time to compiler work so it'll have to wait a bit 😄

In the meantime, if you're only experimenting or not exposing your database to the public. You can set the following to switch the method to clear-text:

      POSTGRES_HOST_AUTH_METHOD: password

Thanks for providing the docker setup and checking out roc-pg!

lorentzlasson commented 9 months ago

Aha, sorry though clear text was the default :facepalm: Thanks for the help! Works as intended when configuring POSTGRES_HOST_AUTH_METHOD: password :star: