https://supertokens.com/ logo
Hi Team I am attempting to connect
t

tykindsir

05/01/2023, 11:43 PM
Hi Team, I am attempting to connect Supertokens to my PostgreSQL db running in a Heroku private space. In order to achieve this I need to pass through a client certificate, client key and CA certificate. I have all of these and have tried a multitude of ways to get the connection working through docker but was unable. I have successfully made a connection to a non-secure Postgres db in Heroku, but for production purposes, we are intending to utilise the Private Space. I initially tried to connect with 'Running SuperTokens and PostgreSQL with docker, with docker-compose' but realised that since the database is already running, it makes more sense to utilise 'Running SuperTokens with Docker and PostgreSQL without docker'. The issue I am facing now is I'm not able to pass through the certificates as an environment variable as seemingly only the following are available: POSTGRESQL_CONNECTION_URI POSTGRESQL_USER POSTGRESQL_PASSWORD POSTGRESQL_PASSWORD_FILE POSTGRESQL_CONNECTION_POOL_SIZE POSTGRESQL_HOST POSTGRESQL_PORT POSTGRESQL_DATABASE_NAME POSTGRESQL_TABLE_NAMES_PREFIX POSTGRESQL_TABLE_SCHEMA
Postgres and Supertokens in docker-compose
version: "3"

services:
    db:
        build: ./postgres
        image: "postgres:latest"
        environment:
            POSTGRES_USER: <user>
            POSTGRES_PASSWORD: <password>
            POSTGRES_DB: <db>
        ports:
            - 5432:5432
        networks:
            - app_network
        restart: unless-stopped
        healthcheck:
            test:
                ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER -d $$POSTGRES_DB"]
            interval: 5s
            timeout: 5s
            retries: 5

    supertokens:
        image: registry.supertokens.io/supertokens/supertokens-postgresql:4.6
        depends_on:
            db:
                condition: service_healthy
        ports:
            - 3567:3567
        environment:
            POSTGRESQL_CONNECTION_URI: "postgresql://<user>:<password>@<host>:5432/<db>?ssl=true&sslmode=verify-ca&sslrootcert=root.crt&sslcert=server.crt&sslkey=server.key"
        networks:
            - app_network
        restart: unless-stopped
        healthcheck:
            test: >
                bash -c 'exec 3<>/dev/tcp/127.0.0.1/3567 && echo -e "GET /hello HTTP/1.1\r\nhost: 127.0.0.1:3567\r\nConnection: close\r\n\r\n" >&3 && cat <&3 | grep "Hello"'
            interval: 10s
            timeout: 5s
            retries: 5

networks:
    app_network:
        driver: bridge
Only Supertokens
version: "3"

services:
    supertokens:
        image: registry.supertokens.io/supertokens/supertokens-postgresql:4.6
        ports:
            - 3567:3567
        environment:
            POSTGRESQL_CONNECTION_URI: "postgresql://<user>:<password>@<host>:5432/<db>?ssl=true&sslmode=verify-ca&sslrootcert=root.crt&sslcert=server.crt&sslkey=server.key"
        networks:
            - app_network
        restart: unless-stopped
        healthcheck:
            test: >
                bash -c 'exec 3<>/dev/tcp/127.0.0.1/3567 && echo -e "GET /hello HTTP/1.1\r\nhost: 127.0.0.1:3567\r\nConnection: close\r\n\r\n" >&3 && cat <&3 | grep "Hello"'
            interval: 10s
            timeout: 5s
            retries: 5

networks:
    app_network:
        driver: bridge
Both end up with 'Failed to initialize pool: FATAL: connection requires a valid client certificate'
r

rp

05/02/2023, 5:40 AM
hmm. Can you open an issue about this on our repo? Might be a bug on our end.
t

tykindsir

05/02/2023, 6:35 AM
@rp Sure, I've opened one up in the postgres docker repo https://github.com/supertokens/supertokens-docker-postgresql/issues/21
r

rp

05/02/2023, 8:14 AM
thanks