Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
feat(selfhost): add daemon server URL override (#7331)
mrlonelyc8154f9d1aea
diff --git a/.env.example b/.env.exampleindex f7cae0048b..c4bfb6cee2 100644--- a/.env.example+++ b/.env.example@@ -75,6 +75,10 @@ MULTICA_APP_URL=${FRONTEND_ORIGIN}# avoid Host / X-Forwarded-Host spoofing when a self-hosted reverse proxy# is not hardened.MULTICA_PUBLIC_URL=+# Optional API URL used only in self-host daemon setup commands. Set this+# when the daemon reaches the API through a different URL than the public+# webhook URL above. Falls back to MULTICA_PUBLIC_URL, then MULTICA_APP_URL.+MULTICA_DAEMON_SERVER_URL=# Optional delay after SIGTERM/SIGINT before the existing graceful shutdown# begins. Accepts a non-negative Go duration such as 300s or 5m. Empty or 0# preserves the default behavior and starts shutdown immediately. The platformdiff --git a/apps/docs/content/docs/environment-variables.ja.mdx b/apps/docs/content/docs/environment-variables.ja.mdxindex 1d03e636b6..b473389f90 100644--- a/apps/docs/content/docs/environment-variables.ja.mdx+++ b/apps/docs/content/docs/environment-variables.ja.mdx@@ -53,10 +53,15 @@ Kubernetes で shutdown hold を設定する場合、`terminationGracePeriodSeco| `FRONTEND_ORIGIN` | 空 | ユーザーがアクセスするフロントエンドの origin。CORS、cookie、招待リンクに使われます || `MULTICA_APP_URL` | `FRONTEND_ORIGIN` にフォールバック | ユーザーが到達できる Web アドレス。CLI ログインとアカウント連携リンクが使います || `MULTICA_PUBLIC_URL` | 空 | 公開 API アドレス。webhook URL とランタイム接続案内に使われます |+| `MULTICA_DAEMON_SERVER_URL` | `MULTICA_PUBLIC_URL`、次に `MULTICA_APP_URL` / `FRONTEND_ORIGIN` にフォールバック | API プロセスが `multica setup self-host` コマンドに埋め込むサーバー URL。デーモンから到達する API URL が公開 webhook URL と異なる場合に設定します || `CORS_ALLOWED_ORIGINS` | 空 | 追加で許可する HTTP origin。カンマ区切り || `ALLOWED_ORIGINS` | CORS / フロントエンド設定にフォールバック | WebSocket origin の許可リスト。カンマ区切り || `COOKIE_DOMAIN` | 空 | フロントエンドと API の host が異なり、ブラウザが API ドメインへ直接アクセスする場合は必須。単一ドメイン構成では空のまま |+<Callout type="warning">+`MULTICA_DAEMON_SERVER_URL` は認証なしの `/api/config` エンドポイントから返され、クライアントが読み取れます。公開設定として扱い、認証情報・トークンなどのシークレットを含めないでください。+</Callout>+フロントエンドと API が異なる host を使い、ブラウザが API ドメインへ直接アクセスする構成では、`COOKIE_DOMAIN` の設定が必須です。設定しないとブラウザが CSRF cookie を読めず、すべての書き込みリクエストが `403 CSRF validation failed` を返す一方、読み取りは正常に動きます。値には、両方の host を同時にカバーできる最も狭い親ドメインを使ってください(`.example.com` より `.agent.example.com`)。この設定はログインセッション cookie をそのドメイン配下のすべての host に広げるため、それらの host がすべて同一の信頼できる運用主体のものである場合にのみ使えます。変更後は両方の host で古い cookie を削除し、再ログインしてください。[セルフホストクイックスタート](/self-host-quickstart#3-アクセス方法を選ぶ)の同一オリジン構成(ブラウザは app ドメインのみアクセス)に従う場合は、空のままで構いません。IP アドレスは指定しないでください。ブラウザは Domain が IP の cookie を無視します。<Callout type="warning">diff --git a/apps/docs/content/docs/environment-variables.ko.mdx b/apps/docs/content/docs/environment-variables.ko.mdxindex fa2a7e4e77..b44323a49f 100644--- a/apps/docs/content/docs/environment-variables.ko.mdx+++ b/apps/docs/content/docs/environment-variables.ko.mdx@@ -53,10 +53,15 @@ Kubernetes에서 shutdown hold를 설정하면 `terminationGracePeriodSeconds`| `FRONTEND_ORIGIN` | 비어 있음 | 사용자가 접근하는 프런트엔드 origin. CORS, cookie, 초대 링크에 사용 || `MULTICA_APP_URL` | `FRONTEND_ORIGIN`으로 fallback | 사용자가 접근할 수 있는 Web 주소. CLI 로그인과 계정 연결 링크에 사용 || `MULTICA_PUBLIC_URL` | 비어 있음 | 공개 API 주소. webhook URL과 런타임 연결 안내에 사용 |+| `MULTICA_DAEMON_SERVER_URL` | `MULTICA_PUBLIC_URL`, 그다음 `MULTICA_APP_URL` / `FRONTEND_ORIGIN`으로 fallback | API 프로세스가 `multica setup self-host` 명령에 넣는 서버 URL. 데몬이 접근하는 API URL이 공개 webhook URL과 다를 때 설정 || `CORS_ALLOWED_ORIGINS` | 비어 있음 | 추가로 허용할 HTTP origin, 쉼표로 구분 || `ALLOWED_ORIGINS` | CORS 또는 프런트엔드 주소로 fallback | WebSocket origin allowlist, 쉼표로 구분 || `COOKIE_DOMAIN` | 비어 있음 | 프런트엔드와 backend의 host가 다르고 브라우저가 API 도메인에 직접 접근할 때 필수. 단일 도메인 배포에서는 비워 둠 |+<Callout type="warning">+`MULTICA_DAEMON_SERVER_URL`은 인증이 필요 없는 `/api/config` 엔드포인트에서 반환되며 클라이언트가 읽을 수 있습니다. 공개 설정으로 취급하고 자격 증명, 토큰 또는 기타 비밀을 절대 포함하지 마세요.+</Callout>+프런트엔드와 API가 서로 다른 host를 사용하고 브라우저가 API 도메인에 직접 접근한다면 `COOKIE_DOMAIN`을 설정해야 합니다. 설정하지 않으면 브라우저가 CSRF cookie를 읽지 못해 모든 쓰기 요청이 `403 CSRF validation failed`를 반환하고 읽기 요청만 정상 작동합니다. 두 host를 모두 포함하는 가장 좁은 상위 도메인을 사용하세요(`.example.com`보다 `.agent.example.com`이 더 적합). 이 설정은 로그인 세션 cookie를 해당 도메인의 모든 host로 확장하므로 모든 host를 같은 신뢰 주체가 운영할 때만 사용할 수 있습니다. 수정 후 두 host에서 이전 cookie를 삭제하고 다시 로그인해야 합니다. [자체 호스팅 빠른 시작](/self-host-quickstart#3-접근-방식-선택)의 same-origin 구성을 사용해 브라우저가 app 도메인에만 접근한다면 비워 두세요. IP 주소는 입력하지 마세요. 브라우저가 IP Domain이 포함된 cookie를 무시합니다.<Callout type="warning">diff --git a/apps/docs/content/docs/environment-variables.mdx b/apps/docs/content/docs/environment-variables.mdxindex 3d54717f18..bedc63dcd8 100644--- a/apps/docs/content/docs/environment-variables.mdx+++ b/apps/docs/content/docs/environment-variables.mdx@@ -53,10 +53,15 @@ When setting a shutdown hold on Kubernetes, `terminationGracePeriodSeconds` must| `FRONTEND_ORIGIN` | empty | Frontend origin users visit; used for CORS, cookies, and invitation links || `MULTICA_APP_URL` | falls back to `FRONTEND_ORIGIN` | User-reachable web URL; CLI sign-in and account-link URLs use it || `MULTICA_PUBLIC_URL` | empty | Public API URL; used for webhook URLs and runtime connection instructions |+| `MULTICA_DAEMON_SERVER_URL` | falls back to `MULTICA_PUBLIC_URL`, then `MULTICA_APP_URL` / `FRONTEND_ORIGIN` | Server URL the API process inserts into `multica setup self-host`; set it when daemons reach the API at a different URL than the public webhook URL || `CORS_ALLOWED_ORIGINS` | empty | Extra allowed HTTP origins, comma-separated || `ALLOWED_ORIGINS` | falls back to CORS / frontend origins | WebSocket origin allowlist, comma-separated || `COOKIE_DOMAIN` | empty | Required when the frontend and API use different hosts and the browser talks to the API domain directly; keep empty for single-domain deployments |+<Callout type="warning">+`MULTICA_DAEMON_SERVER_URL` is returned by the unauthenticated `/api/config` endpoint and is visible to clients. Treat it as public configuration; never put credentials, tokens, or other secrets in it.+</Callout>+When the frontend and API run on different hosts and the browser talks to the API domain directly, you must set `COOKIE_DOMAIN` — otherwise the browser cannot read the CSRF cookie: every write request returns `403 CSRF validation failed` while reads work fine. Use the narrowest parent domain that covers both hosts (`.agent.example.com` over `.example.com`). It spreads the sign-in session cookie to every host under that domain, which is only acceptable when all of those hosts are operated by the same trusted party. After changing it, clear the old cookies on both hosts and sign in again. If you follow the same-origin recipe in the [self-host quickstart](/self-host-quickstart#3-choose-how-to-access) (the browser only visits the app domain), keep it empty. Do not use an IP address — browsers ignore cookies whose Domain is an IP.<Callout type="warning">diff --git a/apps/docs/content/docs/environment-variables.zh.mdx b/apps/docs/content/docs/environment-variables.zh.mdxindex 7870252b8c..8fc8992f6d 100644--- a/apps/docs/content/docs/environment-variables.zh.mdx+++ b/apps/docs/content/docs/environment-variables.zh.mdx@@ -53,10 +53,15 @@ MULTICA_PUBLIC_URL=https://api.multica.example.com| `FRONTEND_ORIGIN` | 空 | 用户访问的前端 origin;用于 CORS、cookie 和邀请链接 || `MULTICA_APP_URL` | 回退到 `FRONTEND_ORIGIN` | 用户可访问的 Web 地址;CLI 登录和账号绑定链接使用它 || `MULTICA_PUBLIC_URL` | 空 | 公网 API 地址;用于 webhook URL 和运行时连接说明 |+| `MULTICA_DAEMON_SERVER_URL` | 回退到 `MULTICA_PUBLIC_URL`,再回退到 `MULTICA_APP_URL` / `FRONTEND_ORIGIN` | API 进程写入 `multica setup self-host` 命令的服务端地址;守护进程访问 API 的地址与公网 webhook 地址不同时设置 || `CORS_ALLOWED_ORIGINS` | 空 | 额外允许的 HTTP origin,逗号分隔 || `ALLOWED_ORIGINS` | 回退到 CORS / 前端地址 | WebSocket origin 白名单,逗号分隔 || `COOKIE_DOMAIN` | 空 | 前后端不同 host 且浏览器直接访问 API 域时必须设置;单域部署保持为空 |+<Callout type="warning">+`MULTICA_DAEMON_SERVER_URL` 会由无需认证的 `/api/config` 接口返回,客户端可以读取。请将它视为公开配置,切勿填入凭据、令牌或其他密钥。+</Callout>+前端和 API 使用不同 host、且浏览器直接访问 API 域时,必须设置 `COOKIE_DOMAIN`,否则浏览器读不到 CSRF cookie——所有写请求返回 `403 CSRF validation failed`,而读请求一切正常。取值用能同时覆盖两个 host 的最窄父域(`.agent.example.com` 优于 `.example.com`)。它会把登录会话 cookie 扩散到该域下的所有 host,只有这些 host 都由同一可信主体运维时才可用。修改后需要在两个 host 上清除旧 cookie 并重新登录。若采用[自托管快速上手](/self-host-quickstart#3-选择访问方式)的同源配方(浏览器只访问 app 域),保持为空即可。不要填写 IP 地址,浏览器会忽略带 IP Domain 的 cookie。<Callout type="warning">diff --git a/docker-compose.selfhost.yml b/docker-compose.selfhost.ymlindex cdb90ac848..458492b19e 100644--- a/docker-compose.selfhost.yml+++ b/docker-compose.selfhost.yml@@ -141,6 +141,10 @@ services:MULTICA_PLUGIN_SURFACE_ORIGIN: ${MULTICA_PLUGIN_SURFACE_ORIGIN:-}MULTICA_PLUGIN_API_URL: ${MULTICA_PLUGIN_API_URL:-}MULTICA_PLUGIN_DIR: ${MULTICA_PLUGIN_DIR:-}+ # Optional API URL shown in self-host daemon setup commands. Set this+ # when the daemon reaches the API through a different URL than the one+ # used for public webhook URLs; otherwise MULTICA_PUBLIC_URL is used.+ MULTICA_DAEMON_SERVER_URL: ${MULTICA_DAEMON_SERVER_URL:-}# Comma-separated CIDRs whose source IP is allowed to set# X-Forwarded-For / X-Real-IP for the webhook per-IP rate limiter.# Empty default = headers ignored, RemoteAddr used. Set e.g.diff --git a/server/internal/handler/config.go b/server/internal/handler/config.goindex 4ccb350c52..d45b84622e 100644--- a/server/internal/handler/config.go+++ b/server/internal/handler/config.go@@ -125,7 +125,10 @@ func (h *Handler) GetConfig(w http.ResponseWriter, r *http.Request) {}func daemonSetupURLsFromEnv() (string, string) {- serverURL := normalizePublicURL(os.Getenv("MULTICA_PUBLIC_URL"))+ serverURL := normalizePublicURL(os.Getenv("MULTICA_DAEMON_SERVER_URL"))+ if serverURL == "" {+ serverURL = normalizePublicURL(os.Getenv("MULTICA_PUBLIC_URL"))+ }appURL := resolveFrontendAppURL()if appURL == "" {return "", ""diff --git a/server/internal/handler/config_test.go b/server/internal/handler/config_test.goindex 2fb2ba09c5..828fc5c35d 100644--- a/server/internal/handler/config_test.go+++ b/server/internal/handler/config_test.go@@ -7,6 +7,7 @@ import ("testing""github.com/multica-ai/multica/server/internal/auth"+ "github.com/multica-ai/multica/server/internal/testutil")func TestGetConfigReportsCdnSignedMode(t *testing.T) {@@ -59,6 +60,7 @@ func TestGetConfigIncludesRuntimeAuthConfig(t *testing.T) {t.Setenv("GOOGLE_CLIENT_ID", "google-client-id")t.Setenv("POSTHOG_API_KEY", "phc_test")t.Setenv("POSTHOG_HOST", "https://eu.i.posthog.com")+ t.Setenv("MULTICA_DAEMON_SERVER_URL", "")t.Setenv("MULTICA_PUBLIC_URL", "https://api.example.com/")t.Setenv("MULTICA_APP_URL", "https://app.example.com/")@@ -104,6 +106,22 @@ func TestGetConfigIncludesRuntimeAuthConfig(t *testing.T) {}}+func TestGetConfigUsesDaemonServerURLOverride(t *testing.T) {+ t.Setenv("MULTICA_DAEMON_SERVER_URL", " https://api.internal.example/// ")+ t.Setenv("MULTICA_PUBLIC_URL", "https://hooks.example.com/")+ t.Setenv("MULTICA_APP_URL", "https://app.example.com/")++ req := httptest.NewRequest(http.MethodGet, "/api/config", nil)+ var cfg AppConfig+ testutil.Call(t, testHandler.GetConfig, req).Want(http.StatusOK).JSON(&cfg)+ if cfg.DaemonServerURL != "https://api.internal.example" {+ t.Fatalf("daemon_server_url: want override URL, got %q", cfg.DaemonServerURL)+ }+ if cfg.DaemonAppURL != "https://app.example.com" {+ t.Fatalf("daemon_app_url: want app URL, got %q", cfg.DaemonAppURL)+ }+}+func TestGetConfigHonorsVCSIntegrationSwitch(t *testing.T) {origCfg := testHandler.cfgt.Cleanup(func() { testHandler.cfg = origCfg })@@ -139,6 +157,7 @@ func TestGetConfigHonorsVCSIntegrationSwitch(t *testing.T) {}func TestGetConfigUsesAppURLForSameOriginDaemonSetup(t *testing.T) {+ t.Setenv("MULTICA_DAEMON_SERVER_URL", "")t.Setenv("MULTICA_PUBLIC_URL", "")t.Setenv("MULTICA_APP_URL", "https://multica.internal.example/")@@ -163,6 +182,7 @@ func TestGetConfigUsesAppURLForSameOriginDaemonSetup(t *testing.T) {}func TestGetConfigUsesFrontendOriginForSameOriginDaemonSetup(t *testing.T) {+ t.Setenv("MULTICA_DAEMON_SERVER_URL", "")t.Setenv("MULTICA_PUBLIC_URL", "")t.Setenv("MULTICA_APP_URL", "")t.Setenv("FRONTEND_ORIGIN", "https://multica.internal.example/")