Fork me on GitHub
#babashka
<
2024-04-29
>
István Karaszi18:04:19

`pod.babashka.postgresql` without SSL

István Karaszi18:04:33

Is there a way to connect to a PostgreSQL host without using SSL?

borkdude18:04:13

Can you try this using normal next.jdbc on the JVM? If you can get it to work there, then I would try it again with the pod. I think it should work the same

borkdude18:04:20

If it does not, please let me know

István Karaszi18:04:21

does pod.babashka.postgresql support JDBC connection strings?

borkdude18:04:06

it's using next.jdbc under the hood so it's best to try that directly first when running into issues and only after that see if it's a pod-specific issue

István Karaszi18:04:30

Thanks, I’ll try that first

borkdude18:04:04

yeah so adding :useSSL false to your db spec might be what you need

István Karaszi18:04:34

It did not seem to work 😞

István Karaszi18:04:51

Type:     clojure.lang.ExceptionInfo
  Message:  SSL error: Remote host terminated the handshake
  Data:     {:type "class org.postgresql.util.PSQLException"}
  Location: pnn/db.clj:19:8

borkdude18:04:16

can I see the invocation that you tried? next, try next.jdbc directly.

István Karaszi18:04:48

the relevant part looks like this:

(ns pnn.db
  (:refer-clojure :exclude [get])
  (:require
   [honey.sql :as hsql]
   [pod.babashka.postgresql :as pg]))

(def db
  {:dbtype "postgresql"
   :host (or (System/getenv "DB_HOST") "localhost")
   :dbname (or (System/getenv "DB_NAME") "pnn")
   :user (or (System/getenv "DB_USER") (System/getenv "USER"))
   :password (System/getenv "DB_PASS")
   :port (parse-long (or (System/getenv "DB_PORT") "5432"))
   :useSSL (not (System/getenv "DB_NOSSL"))})

(defn get [url]
  (->> {:select [:url :info] :from [:notifications] :where [:= :url url]}
       hsql/format
       (pg/execute-one! db)))

borkdude18:04:17

can you substitute false directly to see if that helps?

borkdude18:04:29

I think you can also use a direct JDBC url instead of the map. Not sure why this wouldn't work though

István Karaszi18:04:00

I’ll try that as the next option

István Karaszi18:04:26

same error with explicit false:

----- Error --------------------------------------------------------------------
  Type:     clojure.lang.ExceptionInfo
  Message:  SSL error: Remote host terminated the handshake
  Data:     {:type "class org.postgresql.util.PSQLException"}
  Location: pnn/db.clj:19:8
  ----- Context ------------------------------------------------------------------
  15:
  16: (defn get [url]
  17:   (->> {:select [:url :info] :from [:notifications] :where [:= :url url]}
  18:        hsql/format
  19:        (pg/execute-one! db)))
             ^--- SSL error: Remote host terminated the handshake

István Karaszi18:04:18

I feel like I am trying to catch a red herring

borkdude18:04:07

Try with JVM

István Karaszi19:04:47

I’ll try to verify if the DB is configured correctly

István Karaszi19:04:03

I’ve checked the connection settings with a simple psql Docker image:

FROM postgres:16.2

CMD psql -a -c "SELECT 1;" $DATABASE_URL

István Karaszi19:04:28

&ssl=false&sslmode=disable

borkdude20:04:52

ok, perhaps :ssl false works in the db settings?

borkdude20:04:05

This might be a question #C1Q164V29, how to get next.jdbc to produce ssl=false in the query string

István Karaszi21:04:09

sslmode=disable was necessary, tomorrow, I’ll try without ssl=false

👍 1