Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-2614: randomize self-host Postgres password (#3893)
Bohan Jiang3389e887e039
diff --git a/Makefile b/Makefileindex 3186295dd1..3aab24e1c1 100644--- a/Makefile+++ b/Makefile@@ -58,12 +58,17 @@ selfhost: ## Create .env if needed, then pull and start the official self-hostedecho "==> Creating .env from .env.example..."; \cp .env.example .env; \JWT=$$(openssl rand -hex 32); \+ PGPASS=$$(openssl rand -hex 24); \if [ "$$(uname)" = "Darwin" ]; then \sed -i '' "s/^JWT_SECRET=.*/JWT_SECRET=$$JWT/" .env; \+ sed -i '' "s/^POSTGRES_PASSWORD=.*/POSTGRES_PASSWORD=$$PGPASS/" .env; \+ sed -i '' -E "s#^(DATABASE_URL=postgres://[^:]+:)[^@]*(@.*)#\1$$PGPASS\2#" .env; \else \sed -i "s/^JWT_SECRET=.*/JWT_SECRET=$$JWT/" .env; \+ sed -i "s/^POSTGRES_PASSWORD=.*/POSTGRES_PASSWORD=$$PGPASS/" .env; \+ sed -i -E "s#^(DATABASE_URL=postgres://[^:]+:)[^@]*(@.*)#\1$$PGPASS\2#" .env; \fi; \- echo "==> Generated random JWT_SECRET"; \+ echo "==> Generated random JWT_SECRET and POSTGRES_PASSWORD"; \fi@echo "==> Pulling official Multica images..."@if ! docker compose -f docker-compose.selfhost.yml pull; then \@@ -108,12 +113,17 @@ selfhost-build: ## Build backend/web from the current checkout and start the selecho "==> Creating .env from .env.example..."; \cp .env.example .env; \JWT=$$(openssl rand -hex 32); \+ PGPASS=$$(openssl rand -hex 24); \if [ "$$(uname)" = "Darwin" ]; then \sed -i '' "s/^JWT_SECRET=.*/JWT_SECRET=$$JWT/" .env; \+ sed -i '' "s/^POSTGRES_PASSWORD=.*/POSTGRES_PASSWORD=$$PGPASS/" .env; \+ sed -i '' -E "s#^(DATABASE_URL=postgres://[^:]+:)[^@]*(@.*)#\1$$PGPASS\2#" .env; \else \sed -i "s/^JWT_SECRET=.*/JWT_SECRET=$$JWT/" .env; \+ sed -i "s/^POSTGRES_PASSWORD=.*/POSTGRES_PASSWORD=$$PGPASS/" .env; \+ sed -i -E "s#^(DATABASE_URL=postgres://[^:]+:)[^@]*(@.*)#\1$$PGPASS\2#" .env; \fi; \- echo "==> Generated random JWT_SECRET"; \+ echo "==> Generated random JWT_SECRET and POSTGRES_PASSWORD"; \fi@echo "==> Building Multica from the current checkout..."docker compose -f docker-compose.selfhost.yml -f docker-compose.selfhost.build.yml up -d --builddiff --git a/apps/docs/content/docs/getting-started/self-hosting.zh.mdx b/apps/docs/content/docs/getting-started/self-hosting.zh.mdxindex 14ef967a7c..8088f629ad 100644--- a/apps/docs/content/docs/getting-started/self-hosting.zh.mdx+++ b/apps/docs/content/docs/getting-started/self-hosting.zh.mdx@@ -51,7 +51,7 @@ cd multicamake selfhost```-`make selfhost` automatically creates `.env`, generates a random `JWT_SECRET`, and starts all services via Docker Compose.+`make selfhost` automatically creates `.env`, generates a random `JWT_SECRET` and Postgres password, and starts all services via Docker Compose.By default it pulls the latest stable release images from GHCR. To build the backend/web from your current checkout instead, run `make selfhost-build`.If the selected GHCR tag has not been published yet, `make selfhost` now tells you to fall back to `make selfhost-build`.@@ -63,7 +63,7 @@ Once ready:- **Backend API:** http://localhost:8080<Callout>-If you prefer running the Docker Compose steps manually: `cp .env.example .env`, edit `JWT_SECRET`, then `docker compose -f docker-compose.selfhost.yml pull && docker compose -f docker-compose.selfhost.yml up -d`.+If you prefer running the Docker Compose steps manually: `cp .env.example .env`, edit `JWT_SECRET`, `POSTGRES_PASSWORD`, and the password segment in `DATABASE_URL`, then `docker compose -f docker-compose.selfhost.yml pull && docker compose -f docker-compose.selfhost.yml up -d`.</Callout>### Step 2 — Log In@@ -226,7 +226,8 @@ All configuration is done via environment variables. Copy `.env.example` as a st| Variable | Description | Example ||----------|-------------|---------|-| `DATABASE_URL` | PostgreSQL connection string | `postgres://multica:multica@localhost:5432/multica?sslmode=disable` |+| `DATABASE_URL` | PostgreSQL connection string. Keep the password segment in sync with `POSTGRES_PASSWORD`. | `postgres://multica:<postgres-password>@localhost:5432/multica?sslmode=disable` |+| `POSTGRES_PASSWORD` | **Must change from default.** Password used by the bundled Postgres container. Keep it in sync with `DATABASE_URL`. | `openssl rand -hex 24` || `JWT_SECRET` | **Must change from default.** Secret key for signing JWT tokens. Use a long random string. | `openssl rand -hex 32` || `FRONTEND_ORIGIN` | URL where the frontend is served (used for CORS) | `https://app.example.com` |diff --git a/apps/docs/content/docs/self-host-quickstart.ja.mdx b/apps/docs/content/docs/self-host-quickstart.ja.mdxindex 9739e529a3..fea29f9a4c 100644--- a/apps/docs/content/docs/self-host-quickstart.ja.mdx+++ b/apps/docs/content/docs/self-host-quickstart.ja.mdx@@ -30,7 +30,7 @@ make selfhost`make selfhost` は次のことを行います。-1. `.env` がなければ `.env.example` から生成し、**ランダムな JWT_SECRET** を併せて作成します+1. `.env` がなければ `.env.example` から生成し、**ランダムな JWT_SECRET と Postgres パスワード** を併せて作成します2. 公式の Docker イメージ(PostgreSQL、Multica backend、Multica frontend)を取得します3. `docker-compose.selfhost.yml` を使ってすべてのサービスを起動します4. バックエンドの `/health` エンドポイントが準備できるまで待機します@@ -49,7 +49,7 @@ make selfhost- **バックエンド**: [http://localhost:8080](http://localhost:8080)<Callout type="info">-**ポートは `127.0.0.1` でのみ待ち受けます。** `docker-compose.selfhost.yml` は公開されるすべてのポートを loopback にバインドします — `ss -tlnp` には `0.0.0.0:8080` は表示されず、設計上、他のマシンからはサービスにアクセスできません。デフォルトの `JWT_SECRET` と Postgres の認証情報は、公開インターネット上に置いては絶対にいけません。マシン間アクセスが必要な場合は、TLS を終端するリバースプロキシをスタックの前に置いてください — [ステップ5b — マシン間: リバースプロキシを前に置く](#5b-cross-machine-front-with-a-reverse-proxy)を参照してください。+**ポートは `127.0.0.1` でのみ待ち受けます。** `docker-compose.selfhost.yml` は公開されるすべてのポートを loopback にバインドします — `ss -tlnp` には `0.0.0.0:8080` は表示されず、設計上、他のマシンからはサービスにアクセスできません。サーバーのシークレットと Postgres の認証情報は、公開インターネット上に置いては絶対にいけません。マシン間アクセスが必要な場合は、TLS を終端するリバースプロキシをスタックの前に置いてください — [ステップ5b — マシン間: リバースプロキシを前に置く](#5b-cross-machine-front-with-a-reverse-proxy)を参照してください。</Callout>## 2. 重要: プロダクションの安全設定を維持する@@ -154,7 +154,7 @@ multica setup self-host### 5b. マシン間: リバースプロキシを前に置く-compose スタックは `127.0.0.1` でのみ待ち受けるため、別のマシンにあるデーモンは `http://<server-ip>:8080` に直接接続できません — そして、そうなることを望むべきでもありません。さもなければデフォルトの `JWT_SECRET` が公開インターネットから到達可能になってしまうからです。TLS を終端し、`127.0.0.1:8080`(バックエンド)と `127.0.0.1:3000`(フロントエンド)へ転送するリバースプロキシをサーバーに置き、CLI を公開 HTTPS URL に向けてください。+compose スタックは `127.0.0.1` でのみ待ち受けるため、別のマシンにあるデーモンは `http://<server-ip>:8080` に直接接続できません — そして、そうなることを望むべきでもありません。さもなければサーバーのシークレットが公開インターネットから到達可能になってしまうからです。TLS を終端し、`127.0.0.1:8080`(バックエンド)と `127.0.0.1:3000`(フロントエンド)へ転送するリバースプロキシをサーバーに置き、CLI を公開 HTTPS URL に向けてください。```bashmultica setup self-host \diff --git a/apps/docs/content/docs/self-host-quickstart.ko.mdx b/apps/docs/content/docs/self-host-quickstart.ko.mdxindex 73dfe3c524..b5c9787734 100644--- a/apps/docs/content/docs/self-host-quickstart.ko.mdx+++ b/apps/docs/content/docs/self-host-quickstart.ko.mdx@@ -30,7 +30,7 @@ make selfhost`make selfhost`는 다음을 수행합니다.-1. `.env`가 없으면 `.env.example`로부터 생성하며 **무작위 JWT_SECRET**을 함께 만듭니다+1. `.env`가 없으면 `.env.example`로부터 생성하며 **무작위 JWT_SECRET과 Postgres 비밀번호**를 함께 만듭니다2. 공식 Docker 이미지(PostgreSQL, Multica backend, Multica frontend)를 받아옵니다3. `docker-compose.selfhost.yml`을 사용해 모든 서비스를 시작합니다4. 백엔드의 `/health` 엔드포인트가 준비될 때까지 기다립니다@@ -49,7 +49,7 @@ make selfhost- **백엔드**: [http://localhost:8080](http://localhost:8080)<Callout type="info">-**포트는 `127.0.0.1`에서만 수신합니다.** `docker-compose.selfhost.yml`은 공개된 모든 포트를 loopback에 바인딩합니다 — `ss -tlnp`에서는 `0.0.0.0:8080`이 보이지 않으며, 설계상 다른 기기에서는 서비스에 접근할 수 없습니다. 기본 `JWT_SECRET`과 Postgres 자격 증명이 공개 인터넷에 노출되어서는 절대 안 됩니다. 기기 간 접근이 필요하면 TLS를 종료하는 리버스 프록시를 스택 앞에 두세요 — [5b단계 — 기기 간: 리버스 프록시를 앞에 두기](#5b-cross-machine-front-with-a-reverse-proxy)를 참고하세요.+**포트는 `127.0.0.1`에서만 수신합니다.** `docker-compose.selfhost.yml`은 공개된 모든 포트를 loopback에 바인딩합니다 — `ss -tlnp`에서는 `0.0.0.0:8080`이 보이지 않으며, 설계상 다른 기기에서는 서비스에 접근할 수 없습니다. 서버 시크릿과 Postgres 자격 증명이 공개 인터넷에 노출되어서는 절대 안 됩니다. 기기 간 접근이 필요하면 TLS를 종료하는 리버스 프록시를 스택 앞에 두세요 — [5b단계 — 기기 간: 리버스 프록시를 앞에 두기](#5b-cross-machine-front-with-a-reverse-proxy)를 참고하세요.</Callout>## 2. 중요: 프로덕션 안전 설정 유지하기@@ -154,7 +154,7 @@ multica setup self-host### 5b. 기기 간: 리버스 프록시를 앞에 두기-compose 스택은 `127.0.0.1`에서만 수신하므로, 다른 기기에 있는 데몬은 `http://<server-ip>:8080`에 직접 연결할 수 없습니다 — 그리고 그렇게 되기를 원해서도 안 됩니다. 그렇지 않으면 기본 `JWT_SECRET`이 공개 인터넷에서 접근 가능해지기 때문입니다. 서버에 TLS를 종료하고 `127.0.0.1:8080`(백엔드)과 `127.0.0.1:3000`(프런트엔드)으로 전달하는 리버스 프록시를 두고, CLI를 공개 HTTPS URL로 연결하세요.+compose 스택은 `127.0.0.1`에서만 수신하므로, 다른 기기에 있는 데몬은 `http://<server-ip>:8080`에 직접 연결할 수 없습니다 — 그리고 그렇게 되기를 원해서도 안 됩니다. 그렇지 않으면 서버 시크릿이 공개 인터넷에서 접근 가능해지기 때문입니다. 서버에 TLS를 종료하고 `127.0.0.1:8080`(백엔드)과 `127.0.0.1:3000`(프런트엔드)으로 전달하는 리버스 프록시를 두고, CLI를 공개 HTTPS URL로 연결하세요.```bashmultica setup self-host \diff --git a/apps/docs/content/docs/self-host-quickstart.mdx b/apps/docs/content/docs/self-host-quickstart.mdxindex 1877e9b20c..e756c88514 100644--- a/apps/docs/content/docs/self-host-quickstart.mdx+++ b/apps/docs/content/docs/self-host-quickstart.mdx@@ -30,7 +30,7 @@ make selfhost`make selfhost` will:-1. Generate a `.env` from `.env.example` if missing, with a **random JWT_SECRET**+1. Generate a `.env` from `.env.example` if missing, with a **random JWT_SECRET and Postgres password**2. Pull the official Docker images (PostgreSQL, Multica backend, Multica frontend)3. Bring up every service using `docker-compose.selfhost.yml`4. Wait until the backend's `/health` endpoint is ready@@ -50,7 +50,7 @@ Once it's up:- **Backend**: [http://localhost:8080](http://localhost:8080)<Callout type="info">-**Ports listen on `127.0.0.1` only.** `docker-compose.selfhost.yml` binds every published port to loopback — `ss -tlnp` will not show `0.0.0.0:8080`, and the services are unreachable from other machines by design. The default `JWT_SECRET` and Postgres credentials must never sit on the open internet. For cross-machine access, front the stack with a reverse proxy that terminates TLS — see [Step 5b — Cross-machine: front with a reverse proxy](#5b-cross-machine-front-with-a-reverse-proxy).+**Ports listen on `127.0.0.1` only.** `docker-compose.selfhost.yml` binds every published port to loopback — `ss -tlnp` will not show `0.0.0.0:8080`, and the services are unreachable from other machines by design. Secrets and Postgres credentials must never sit on the open internet. For cross-machine access, front the stack with a reverse proxy that terminates TLS — see [Step 5b — Cross-machine: front with a reverse proxy](#5b-cross-machine-front-with-a-reverse-proxy).</Callout>## 2. Important: keep production safety on@@ -155,7 +155,7 @@ That points the CLI at `http://localhost:8080` (backend) and `http://localhost:3### 5b. Cross-machine: front with a reverse proxy-Because the compose stack only listens on `127.0.0.1`, a daemon on a different machine cannot reach `http://<server-ip>:8080` directly — and you do not want it to, since the default `JWT_SECRET` would otherwise be reachable from the open internet. Put a reverse proxy on the server that terminates TLS and forwards to `127.0.0.1:8080` (backend) and `127.0.0.1:3000` (frontend), then point the CLI at the public HTTPS URL:+Because the compose stack only listens on `127.0.0.1`, a daemon on a different machine cannot reach `http://<server-ip>:8080` directly — and you do not want it to, since server secrets would otherwise be reachable from the open internet. Put a reverse proxy on the server that terminates TLS and forwards to `127.0.0.1:8080` (backend) and `127.0.0.1:3000` (frontend), then point the CLI at the public HTTPS URL:```bashmultica setup self-host \diff --git a/apps/docs/content/docs/self-host-quickstart.zh.mdx b/apps/docs/content/docs/self-host-quickstart.zh.mdxindex bb3a90e80d..d656f7e001 100644--- a/apps/docs/content/docs/self-host-quickstart.zh.mdx+++ b/apps/docs/content/docs/self-host-quickstart.zh.mdx@@ -30,7 +30,7 @@ make selfhost`make selfhost` 会:-1. 如果没有 `.env` 文件,从 `.env.example` 自动生成一份并**生成随机 JWT_SECRET**+1. 如果没有 `.env` 文件,从 `.env.example` 自动生成一份,并**生成随机 JWT_SECRET 和 Postgres 密码**2. 拉取官方 Docker 镜像(PostgreSQL、Multica backend、Multica frontend)3. 用 `docker-compose.selfhost.yml` 启动全部服务4. 等后端 `/health` 端点准备就绪@@ -49,7 +49,7 @@ make selfhost- **后端**:[http://localhost:8080](http://localhost:8080)<Callout type="info">-**所有端口只监听 `127.0.0.1`。** `docker-compose.selfhost.yml` 把每个 publish 出来的端口都绑到 loopback —— `ss -tlnp` 不会看到 `0.0.0.0:8080`,外网/其它机器默认根本连不上。这是为了避免默认 `JWT_SECRET` 和 Postgres 凭据被直接暴露到公网。要做跨机访问,请用反向代理在前面终结 TLS,详见下方 [Step 5b —— 跨机访问:用反向代理把服务挡在前面](#5b-跨机访问用反向代理把服务挡在前面)。+**所有端口只监听 `127.0.0.1`。** `docker-compose.selfhost.yml` 把每个 publish 出来的端口都绑到 loopback —— `ss -tlnp` 不会看到 `0.0.0.0:8080`,外网/其它机器默认根本连不上。这是为了避免服务密钥和 Postgres 凭据被直接暴露到公网。要做跨机访问,请用反向代理在前面终结 TLS,详见下方 [Step 5b —— 跨机访问:用反向代理把服务挡在前面](#5b-跨机访问用反向代理把服务挡在前面)。</Callout>## 2. 重要:保持生产安全配置@@ -154,7 +154,7 @@ multica setup self-host### 5b. 跨机访问:用反向代理把服务挡在前面-因为 compose 默认只监听 `127.0.0.1`,从别的机器跑的 daemon 是连不上 `http://<server-ip>:8080` 的——这也是有意为之,否则默认 `JWT_SECRET` 等于直接暴露在公网。正确做法是在 server 上跑一个反向代理(Caddy / nginx / Cloudflare Tunnel),由它终结 TLS,再反代到 `127.0.0.1:8080`(backend)和 `127.0.0.1:3000`(frontend)。然后把 CLI 指到公开的 HTTPS 域名:+因为 compose 默认只监听 `127.0.0.1`,从别的机器跑的 daemon 是连不上 `http://<server-ip>:8080` 的——这也是有意为之,否则服务密钥会直接暴露在公网。正确做法是在 server 上跑一个反向代理(Caddy / nginx / Cloudflare Tunnel),由它终结 TLS,再反代到 `127.0.0.1:8080`(backend)和 `127.0.0.1:3000`(frontend)。然后把 CLI 指到公开的 HTTPS 域名:```bashmultica setup self-host \diff --git a/scripts/install.ps1 b/scripts/install.ps1index f2aad96059..d37a6795da 100644--- a/scripts/install.ps1+++ b/scripts/install.ps1@@ -30,6 +30,19 @@ function Test-CommandExists {$null -ne (Get-Command $Name -ErrorAction SilentlyContinue)}+function New-RandomHex {+ param([int]$ByteCount)++ $bytes = New-Object byte[] $ByteCount+ $rng = [System.Security.Cryptography.RandomNumberGenerator]::Create()+ try {+ $rng.GetBytes($bytes)+ } finally {+ $rng.Dispose()+ }+ return -join ($bytes | ForEach-Object { "{0:x2}" -f $_ })+}+function Get-EnvFileValue {param([string]$Path,@@ -411,11 +424,16 @@ function Install-Server {Write-Ok "Repository ready at $InstallDir ($serverRef)"if (-not (Test-Path ".env")) {- Write-Info "Creating .env with random JWT_SECRET..."+ Write-Info "Creating .env with random secrets..."Copy-Item ".env.example" ".env"- $jwt = -join ((1..32) | ForEach-Object { "{0:x2}" -f (Get-Random -Maximum 256) })- (Get-Content ".env") -replace '^JWT_SECRET=.*', "JWT_SECRET=$jwt" | Set-Content ".env"- Write-Ok "Generated .env with random JWT_SECRET"+ $jwt = New-RandomHex 32+ $pgpass = New-RandomHex 24+ $content = Get-Content ".env"+ $content = $content -replace '^JWT_SECRET=.*', "JWT_SECRET=$jwt"+ $content = $content -replace '^POSTGRES_PASSWORD=.*', "POSTGRES_PASSWORD=$pgpass"+ $content = $content -replace '^(DATABASE_URL=postgres://[^:]+:)[^@]*(@.*)', "`${1}$pgpass`${2}"+ $content | Set-Content ".env"+ Write-Ok "Generated .env with random JWT_SECRET and POSTGRES_PASSWORD"} else {Write-Ok "Using existing .env"}diff --git a/scripts/install.sh b/scripts/install.shindex 6a6ad2dc0e..536707cfe7 100755--- a/scripts/install.sh+++ b/scripts/install.sh@@ -357,16 +357,21 @@ setup_server() {# Generate .env if neededif [ ! -f .env ]; then- info "Creating .env with random JWT_SECRET..."+ info "Creating .env with random secrets..."cp .env.example .env- local jwt+ local jwt pgpassjwt=$(openssl rand -hex 32)+ pgpass=$(openssl rand -hex 24)if [ "$(uname -s)" = "Darwin" ]; thensed -i '' "s/^JWT_SECRET=.*/JWT_SECRET=$jwt/" .env+ sed -i '' "s/^POSTGRES_PASSWORD=.*/POSTGRES_PASSWORD=$pgpass/" .env+ sed -i '' -E "s#^(DATABASE_URL=postgres://[^:]+:)[^@]*(@.*)#\1$pgpass\2#" .envelsesed -i "s/^JWT_SECRET=.*/JWT_SECRET=$jwt/" .env+ sed -i "s/^POSTGRES_PASSWORD=.*/POSTGRES_PASSWORD=$pgpass/" .env+ sed -i -E "s#^(DATABASE_URL=postgres://[^:]+:)[^@]*(@.*)#\1$pgpass\2#" .envfi- ok "Generated .env with random JWT_SECRET"+ ok "Generated .env with random JWT_SECRET and POSTGRES_PASSWORD"elseok "Using existing .env"fi