Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Improving and securing docker setup (#1692)

Yannick Milhahn0b75a82f456d
diff --git a/docker/.env b/docker/.env
index 673e4e4be1b..4067170fdda 100644
--- a/docker/.env
+++ b/docker/.env
@@ -1,18 +1,18 @@
-#fill with random passwords
-OPERATOR_TOKEN=super-secret-operator-token
+# fill with random passwords
+OPERATOR_TOKEN=your-super-secret-operator-token
-JWT_SECRET=super-secret-jwt-token-with-at-least-32-characters-long
+JWT_SECRET=your-super-secret-jwt-token-with-at-least-32-characters-long
-POSTGRES_PASSWORD=postgres
+POSTGRES_PASSWORD=your-super-secret-and-long-postgres-password
-# some smtp server to send your auth-mails with
+# some SMTP server to send your auth-mails with
SMTP_HOST=mail.example.com
SMTP_PORT=
SMTP_USER=
SMTP_PASS=
-#predefined; dont change these
+# predefined; don't change these unless you know what you're doing
POSTGRES_PORT=5432
AUTH_PORT=9999
REST_PORT=3000
diff --git a/docker/README.md b/docker/README.md
index 0c747bb20d2..4b0f64e1546 100644
--- a/docker/README.md
+++ b/docker/README.md
@@ -1,19 +1,25 @@
# Supabase Docker
-You can run Supabase on your local machine using `docker-compose`:
+You can run Supabase on your local machine or a server using `docker-compose`.
+For a more secure setup to use on a server (e.g. using HTTPS), have a look at the *supabase-traefik* setup.
-- Add passwords to the .env file
+## Configuration
+
+Add your passwords to the .env file.
+For better customization and security, please make sure you read the [self-hosting guide](https://supabase.io/docs/guides/self-hosting#running-supabase).
+
+## Run via docker-compose
- Starting all services: `docker-compose up`
- Stopping all services: `docker-compose down`
-**Usage**
+## Usage
```js
import { createClient } from '@supabase/supabase-js'
const SUPABASE_URL = 'http://localhost:8000'
-const SUPABASE_KEY = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJzdXBhYmFzZSIsImlhdCI6MTYwMzk2ODgzNCwiZXhwIjoxNjIwNzQyMTM1LCJhdWQiOiIiLCJzdWIiOiIiLCJSb2xlIjoiYW5vbiIsImp0aSI6ImQ1N2ZkMjFlLTNkYjQtNDk3YS1hNGViLTI4ZDY3Yzg2NjEwMiJ9.Uc0w024BLhWjMAAdzMJfkMxaFa82N-6pBxAtEGzrXCQ'
+const SUPABASE_KEY = '<anon-apikey-from-kong.yml>'
const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
```
@@ -21,8 +27,7 @@ const supabase = createClient(SUPABASE_URL, SUPABASE_KEY)
Accessing the services directly:
- Kong: http://localhost:8000
- - GoTrue: http://localhost:8000/auth/v1/?apikey=XXX
- - PostgREST: http://localhost:8000/rest/v1/?apikey=XXX
- - Realtime: http://localhost:8000/realtime/v1/?apikey=XXX
-- Postgres: http://localhost:5432
-
+ - GoTrue: http://localhost:8000/auth/v1/?apikey=<anon-apikey-from-kong.yml>
+ - PostgREST: http://localhost:8000/rest/v1/?apikey=<anon-apikey-from-kong.yml>
+ - Realtime: http://localhost:8000/realtime/v1/?apikey=<anon-apikey-from-kong.yml>
+- Postgres: http://localhost:5432
\ No newline at end of file
diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml
index 6a5da14d817..194050ee191 100644
--- a/docker/docker-compose.yml
+++ b/docker/docker-compose.yml
@@ -50,7 +50,7 @@ services:
environment:
PGRST_DB_URI: postgres://postgres:${POSTGRES_PASSWORD}@db:${POSTGRES_PORT}/postgres
PGRST_DB_SCHEMA: public
- PGRST_DB_ANON_ROLE: postgres
+ PGRST_DB_ANON_ROLE: anon
PGRST_JWT_SECRET: ${JWT_SECRET}
realtime:
container_name: supabase-realtime
diff --git a/docker/supabase-traefik/.env b/docker/supabase-traefik/.env
index 14356159fe2..4f482cc317d 100644
--- a/docker/supabase-traefik/.env
+++ b/docker/supabase-traefik/.env
@@ -1,27 +1,27 @@
-#fill with random passwords
-OPERATOR_TOKEN=
+# fill with random passwords
+OPERATOR_TOKEN=your-super-secret-operator-token
-JWT_SECRET=
+JWT_SECRET=your-super-secret-jwt-token-with-at-least-32-characters-long
-#string length 100 didnt work as password for me; length 50 did it
-POSTGRES_PASSWORD=
-# some smtp server to send your auth-mails with
+POSTGRES_PASSWORD=your-super-secret-and-long-postgres-password
+
+# some SMTP server to send your auth-mails with
SMTP_HOST=mail.example.com
SMTP_PORT=
SMTP_USER=
SMTP_PASS=
-#traefik
+# Traefik
TRAEFIK_SECURE_ENTRYPOINT=websecure
-TRAEFIK_NETWORK=your_docker_network
+TRAEFIK_NETWORK=rp
SUPABASE_HOSTNAME=supabase.example.com
-#pgadmin
+# pgAdmin
PGADMIN_DEFAULT_PASSWORD=
PGADMIN_DEFAULT_EMAIL=
-#predefined; dont change these
+# predefined; don't change these unless you know what you're doing
POSTGRES_PORT=5432
AUTH_PORT=9999
REST_PORT=3000
diff --git a/docker/supabase-traefik/README.md b/docker/supabase-traefik/README.md
index 3dbae9ee86e..37bb549fb02 100644
--- a/docker/supabase-traefik/README.md
+++ b/docker/supabase-traefik/README.md
@@ -1,36 +1,143 @@
-# use supabase with existing traefik setup
+# Supabase Docker with Traefik
-## fill the .env file and reach the endpoints at
+This guide is covering a self-hosted Supabase setup with [Traefik](https://github.com/traefik/traefik) as a reverse proxy.
-### **pgadmin**
+Please make sure you read the [self-hosting guide](https://supabase.io/docs/guides/self-hosting#running-supabase).
+
+## Not using Traefik yet? Getting started from scratch
+
+### Goal
+
+- Super simple to install
+- Run Supabase on bare metal (maximum privacy) - dedicated/root server or VPS
+- Uses Let's Encrypt certificates
+- Uses pgAdmin to provide at least some interface to Supabase on the self-hosted Supabase instance
+
+### Requirements/Assumptions
+
+- Machine with Linux and SSH access
+- Installed git, docker and docker-compose
+- Access to a Traefik supported DNS providers API: [see this list](https://doc.traefik.io/traefik/https/acme/#providers)
+- Traefik isn't used yet
+- Ports 443 and 80 aren't used yet
+
+
+### Getting started
+
+Traefik is a proxy that gets its configuration from the docker-compose labels.
+The labels needed for Supabase are already provided in the docker-compose.yml.
+
+#### 1. Clone the Supabase repository
+
+```sh
+git clone https://github.com/supabase/supabase
```
-supabase.example.com/pgadmin/
+
+#### 2. Setup Traefik
+
+##### 2.1 Change the directory into the Traefik folder
+
+First we are setting up Traefik to act as the reverse proxy and certificate generator.
+`cd supabase/docker/supabase-traefik/traefik`
+
+##### 2.2 Add your DNS provider for automatic/easy certificate generation
+
+Edit the *docker/supabase-traefik/traefik/.env* file and add your Let's Encrypt contact email address as well as your provider. This example is using PowerDNS.
+
+```.env
+# pdns is for PowerDNS - a self-hosted DNS server
+ACME_DNS_CHALLENGE_PROVIDER=pdns
+
+# DNS provider specific config for pdns
+PDNS_API_KEY=SOME API KEY
+PDNS_API_URL=https://some.url.to.your.pdns.server
```
+[Learn more about the DNS challenge](https://doc.traefik.io/traefik/user-guides/docker-compose/acme-dns/)
+
+[Learn more about available DNS providers (there are MANY)](https://doc.traefik.io/traefik/https/acme/#providers)
-### **auth**
+##### 2.3 Add the DNS provider specific details
+Edit the *docker/supabase-traefik/traefik/docker-compose.yml* environment section to be compatible with your DNS provider. This example is using PowerDNS.
+
+PDNS_API_KEY and PDNS_API_URL are acting as variables between the .env and the docker-compose file.
+
+```.yaml
+environment:
+ - PDNS_API_KEY=${PDNS_API_KEY}
+ - PDNS_API_URL=${PDNS_API_URL}
```
-supabase.example.com/auth/
+
+##### 2.4 Start Traefik
+
+Run following command in *docker/supabase-traefik/traefik/* to start Traefik detached
+`docker-compose up -d`
+
+#### 3. Change the directory into the docker/supabase-traefik folder
+
+`cd ..` (or `cd supabase/docker/supabase-traefik` if you haven't followed Step 2.)
+
+#### 4. Edit the .env file and insert your own environment variables: passwords etc.
+
+##### 4.1. Change your hostname
+
+- Change the SUPABASE_HOSTNAME to the hostname/subdomain you want to use for Supabase
+```sh
+TRAEFIK_NETWORK=rp
+SUPABASE_HOSTNAME=supabase.example.com
+```
+
+### 5. Start the Supabase containers with docker-compose
+
+Run following command in *docker/supabase-traefik/* to start the Supabase containers detached
+`docker-compose up -d`
+
+### 6. Test the endpoints below
+
+
+## Use Supabase with an existing Traefik setup
+
+You can also use the docker-compose.yml with an existing Traefik setup.
+Just ignore the *traefik* folder and customize the *.env* file and *docker-compose.yml* as it fits your setup. Run `docker-compose up -d` and check if all endpoints below are working. Use them as described in the docker/readme.md.
+
+
+## Endpoints
+
+### **Kong**
+
+```
+supabase.example.com/
+```
+
+### **GoTrue**
+
```
-you can test auth with
+supabase.example.com/auth/v1/
+```
+you can test GoTrue with
```
-supabase.example.com/auth/settings
+supabase.example.com/auth/v1/settings
```
as the default path returns 404
-### **realtime**
+### **PostgREST**
+
```
-supabase.example.com/realtime/
+supabase.example.com/rest/v1/
```
-### **rest**
+### **Realtime**
+
```
-supabase.example.com/rest/
+supabase.example.com/realtime/v1/
```
-### **kong**
+### Postgres
+
+The Postgres database is only available internally via the *db* docker network. You can however access it through pgAdmin.
+```
+supabase.example.com/pgadmin/
```
-supabase.example.com/kong/
-```
\ No newline at end of file
diff --git a/docker/config/pgadmin/config.py b/docker/supabase-traefik/config/pgadmin/config.py
similarity index 100%
rename from docker/config/pgadmin/config.py
rename to docker/supabase-traefik/config/pgadmin/config.py
diff --git a/docker/config/pgadmin/servers.json b/docker/supabase-traefik/config/pgadmin/servers.json
similarity index 100%
rename from docker/config/pgadmin/servers.json
rename to docker/supabase-traefik/config/pgadmin/servers.json
diff --git a/docker/supabase-traefik/docker-compose.yml b/docker/supabase-traefik/docker-compose.yml
index 2bc1030bd5a..387c663a64b 100644
--- a/docker/supabase-traefik/docker-compose.yml
+++ b/docker/supabase-traefik/docker-compose.yml
@@ -13,10 +13,7 @@ services:
traefik.http.routers.supabase-kong.tls: 'true'
traefik.http.services.supabase-kong.loadbalancer.server.port: ${KONG_PORT}
traefik.docker.network: ${TRAEFIK_NETWORK}
- traefik.http.routers.supabase-kong.rule: 'Host(`${SUPABASE_HOSTNAME}`) && PathPrefix(`/kong/`)'
- traefik.http.routers.supabase-kong.middlewares: repl-supabase-kong@docker
- traefik.http.middlewares.repl-supabase-kong.replacepathregex.regex: ^/kong/(.*)
- traefik.http.middlewares.repl-supabase-kong.replacepathregex.replacement: /$$1
+ traefik.http.routers.supabase-kong.rule: 'Host(`${SUPABASE_HOSTNAME}`)'
networks:
- rp
- db
@@ -48,16 +45,6 @@ services:
GOTRUE_SMTP_PORT: ${SMTP_PORT}
GOTRUE_SMTP_USER: ${SMTP_USER}
GOTRUE_SMTP_PASS: ${SMTP_PASS}
- labels:
- traefik.enable: 'true'
- traefik.http.routers.supabase-auth.entrypoints: ${TRAEFIK_SECURE_ENTRYPOINT}
- traefik.http.services.supabase-auth.loadbalancer.server.port: ${AUTH_PORT}
- traefik.http.routers.supabase-auth.tls: 'true'
- traefik.docker.network: ${TRAEFIK_NETWORK}
- traefik.http.routers.supabase-auth.rule: 'Host(`${SUPABASE_HOSTNAME}`) && PathPrefix(`/auth/`)'
- traefik.http.routers.supabase-auth.middlewares: repl-supabase-auth@docker
- traefik.http.middlewares.repl-supabase-auth.replacepathregex.regex: ^/auth/(.*)
- traefik.http.middlewares.repl-supabase-auth.replacepathregex.replacement: /$$1
networks:
- rp
- db
@@ -70,18 +57,8 @@ services:
environment:
PGRST_DB_URI: postgres://postgres:${POSTGRES_PASSWORD}@db:${POSTGRES_PORT}/postgres
PGRST_DB_SCHEMA: public
- PGRST_DB_ANON_ROLE: postgres
+ PGRST_DB_ANON_ROLE: anon
PGRST_JWT_SECRET: ${JWT_SECRET}
- labels:
- traefik.enable: 'true'
- traefik.http.routers.supabase-rest.entrypoints: ${TRAEFIK_SECURE_ENTRYPOINT}
- traefik.http.services.supabase-rest.loadbalancer.server.port: ${REST_PORT}
- traefik.http.routers.supabase-rest.tls: 'true'
- traefik.docker.network: ${TRAEFIK_NETWORK}
- traefik.http.routers.supabase-rest.rule: 'Host(`${SUPABASE_HOSTNAME}`) && PathPrefix(`/rest/`)'
- traefik.http.routers.supabase-rest.middlewares: repl-supabase-rest@docker
- traefik.http.middlewares.repl-supabase-rest.replacepathregex.regex: ^/rest/(.*)
- traefik.http.middlewares.repl-supabase-rest.replacepathregex.replacement: /$$1
networks:
- rp
- db
@@ -102,16 +79,6 @@ services:
# Disable JWT Auth locally. The JWT_SECRET will be ignored.
SECURE_CHANNELS: 'false'
JWT_SECRET: ${JWT_SECRET}
- labels:
- traefik.enable: 'true'
- traefik.http.routers.supabase-realtime.entrypoints: ${TRAEFIK_SECURE_ENTRYPOINT}
- traefik.http.services.supabase-realtime.loadbalancer.server.port: ${REALTIME_PORT}
- traefik.http.routers.supabase-realtime.tls: 'true'
- traefik.docker.network: ${TRAEFIK_NETWORK}
- traefik.http.routers.supabase-realtime.rule: 'Host(`${SUPABASE_HOSTNAME}`) && PathPrefix(`/realtime/`)'
- traefik.http.routers.supabase-realtime.middlewares: repl-supabase-realtime@docker
- traefik.http.middlewares.repl-supabase-realtime.replacepathregex.regex: ^/realtime/(.*)
- traefik.http.middlewares.repl-supabase-realtime.replacepathregex.replacement: /$$1
networks:
- rp
- db
@@ -142,8 +109,8 @@ services:
SCRIPT_NAME: /pgadmin
PGADMIN_SERVER_JSON_FILE: /pgadmin4/servers.json
volumes:
- - ../config/pgadmin/servers.json:/pgadmin4/servers.json
- - ../config/pgadmin/config.py:/pgadmin4/config.py
+ - ./config/pgadmin/servers.json:/pgadmin4/servers.json
+ - ./config/pgadmin/config.py:/pgadmin4/config.py
networks:
- db
- rp
@@ -154,7 +121,6 @@ services:
traefik.http.routers.supabase-pgadmin.tls: 'true'
traefik.docker.network: ${TRAEFIK_NETWORK}
traefik.http.routers.supabase-pgadmin.rule: 'Host(`${SUPABASE_HOSTNAME}`) && PathPrefix(`/pgadmin`)'
-
networks:
rp:
name: ${TRAEFIK_NETWORK}
diff --git a/docker/supabase-traefik/traefik/docker-compose.yml b/docker/supabase-traefik/traefik/docker-compose.yml
new file mode 100644
index 00000000000..48f92bba76a
--- /dev/null
+++ b/docker/supabase-traefik/traefik/docker-compose.yml
@@ -0,0 +1,40 @@
+version: "3.7"
+serives:
+ traefik:
+ container_name: traefik
+ image: traefik
+ restart: always
+ ports:
+ - 80:80
+ - 443:443/udp
+ - 443:443/tcp
+ networks:
+ - rp
+ volumes:
+ - /var/run/docker.sock:/var/run/docker.sock:ro
+ - ./letsencrypt:/letsencrypt
+ - ./traefik/traefik.yml:/traefik/traefik.yaml
+ environment:
+ - PDNS_API_KEY=${PDNS_API_KEY}
+ - PDNS_API_URL=https://${PDNS_API_URL}
+ command:
+ - --providers.docker=true
+ - --providers.docker.exposedbydefault=false
+ - --entrypoints.web.address=:80
+ - --entrypoints.websecure.address=:443
+ - --certificatesresolvers.default.acme.dnschallenge=true
+ - --certificatesresolvers.default.acme.dnschallenge.provider=${ACME_DNS_CHALLENGE_PROVIDER}
+ - --certificatesresolvers.default.acme.email=${ACME_EMAIL}
+ - --certificatesresolvers.default.acme.storage=/letsencrypt/acme.json
+ - --providers.file.filename=/traefik/traefik.yaml
+ labels:
+ traefik.enable: "true"
+ # redirect to https
+ traefik.http.routers.http-catchall.rule: "hostregexp(`{host:.+}`)"
+ traefik.http.routers.http-catchall.entrypoints: "web"
+ traefik.http.routers.http-catchall.middlewares: "redirect-to-https"
+ traefik.http.middlewares.redirect-to-https.redirectscheme.scheme: "https"
+ traefik.http.middlewares.redirect-to-https.redirectscheme.permanent: "true"
+
+networks:
+ rp:
\ No newline at end of file
diff --git a/docker/supabase-traefik/traefik/traefik/traefik.yml b/docker/supabase-traefik/traefik/traefik/traefik.yml
new file mode 100644
index 00000000000..45916428e19
--- /dev/null
+++ b/docker/supabase-traefik/traefik/traefik/traefik.yml
@@ -0,0 +1,13 @@
+tls:
+ options:
+ default:
+ minVersion: VersionTLS12
+ cipherSuites:
+ - TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
+ - TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384
+ - TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256
+ stores:
+ default:
+ defaultCertificate:
+ certFile: "/letsencrypt/pem/cert.pem"
+ keyFile: "/letsencrypt/pem/key.pem"
\ No newline at end of file