Alexander Kleinhans
Alexander Kleinhans

Reputation: 6258

Hasura use SSL certificates for Postgres connection

I can run Hashura from the Docker image.

docker run -d -p 8080:8080 \
  -e HASURA_GRAPHQL_DATABASE_URL=postgres://username:password@hostname:port/dbname \
  -e HASURA_GRAPHQL_ENABLE_CONSOLE=true \
  hasura/graphql-engine:latest

But I also have a Postgres instance that can only be accessed with three certificates:

psql "sslmode=verify-ca sslrootcert=server-ca.pem \
      sslcert=client-cert.pem sslkey=client-key.pem \
      hostaddr=$DB_HOST \
      port=$DB_PORT\
      user=$DB_USER dbname=$DB_NAME"

I don't see a configuration for Hasura that allows me to connect to a Postgres instance in such a way.

Is this something I'm suppose to pass into the database connection URL?

How should I do this?

Upvotes: 0

Views: 2521

Answers (1)

Vamshi Surabhi
Vamshi Surabhi

Reputation: 537

You'll need to mount your certificates into the docker container and then configure libpq (which is what hasura uses underneath) to use the required certificates with these environment variables. It'll be something like this (I haven't tested this):

docker run -d -p 8080:8080 \
  -v /absolute-path-of-certs-folder:/certs
  -e HASURA_GRAPHQL_DATABASE_URL=postgres://hostname:port/dbname \
  -e HASURA_GRAPHQL_ENABLE_CONSOLE=true \
  -e PGSSLMODE=verify-ca \
  -e PGSSLCERT=/certs/client-cert.pem \
  -e PGSSLKEY=/certs/client-key.pem \
  -e PGSSLROOTCERT=/certs/server-ca.pem \
  hasura/graphql-engine:latest

Upvotes: 3

Related Questions