Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.it.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Opzioni da riga di comando:
| `-config` | `config.json` | Percorso del file di configurazione. |
| `-listen` | Non impostato | Sostituisce l'indirizzo di ascolto API. |
| `-web-listen` | Non impostato | Sostituisce l'indirizzo di ascolto WebUI. |
| `-trust-cloudflare-client-ip` | `false` | I limiti di login/Playground della WebUI usano `CF-Connecting-IP`, solo se il peer diretto è loopback (`cloudflared` locale). |

La directory di configurazione deve essere scrivibile per migrare la password, salvare la configurazione e memorizzare le cache dei modelli.

Expand Down Expand Up @@ -277,7 +278,7 @@ I nomi derivano dal percorso di configurazione effettivo. Il monitoraggio soprav

`GET /healthz` non chiama l'upstream e non richiede chiavi. Rilevamento in attesa/vuoto, WARP indisponibile o assenza di proxy sani necessari producono 503. Un catalogo obsoleto ma utilizzabile può restituire 200 e `status: "degraded"`; la soglia è due volte l'intervallo di aggiornamento, almeno 60 secondi. La disponibilità non certifica chiavi, quota o inferenza. La risposta pubblica include conteggi/stato, senza segreti o indirizzi proxy.

Per uso locale limita API e gestione a loopback. Per accesso in rete usa HTTPS e limita l'ingresso amministrativo. Un reverse proxy fidato deve impostare correttamente `X-Forwarded-Proto`; i limiti usano il peer diretto, quindi i client dietro un proxy li condividono. L'eseguibile serve HTTP.
Per uso locale limita API e gestione a loopback. Per accesso in rete usa HTTPS e limita l'ingresso amministrativo. Un reverse proxy fidato deve impostare correttamente `X-Forwarded-Proto`; i limiti usano il peer diretto, quindi i client dietro un proxy li condividono. Dietro un tunnel `cloudflared` sullo stesso host, avvia con `-trust-cloudflare-client-ip` per dare a ogni visitatore il proprio limite: `CF-Connecting-IP` è usato solo per peer loopback (Cloudflare sovrascrive l'header) e i client IPv6 condividono un limite per /64. Non attivarlo per altri reverse proxy. L'eseguibile serve HTTP.

Configurazione e backup contengono chiavi upstream, password proxy e token OAuth; l'hash della password non li cifra. Limita i permessi dei file, con ACL su Windows, ed escludi i file di runtime dalla condivisione del codice. `logging.dump_request_bodies` è disabilitato e richiede livello debug; i corpi possono rivelare conversazioni anche dopo riduzione e mascheramento. Playground e test attivi consumano potenzialmente quota o credits reali.

Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Command-line options:
| `-config` | `config.json` | Configuration file path. |
| `-listen` | Unset | Override the API listen address. |
| `-web-listen` | Unset | Override the WebUI listen address. |
| `-trust-cloudflare-client-ip` | `false` | WebUI login/Playground limits use `CF-Connecting-IP`, only when the direct peer is loopback (a local `cloudflared`). |

The configuration directory must be writable for password migration, configuration saves, and model caches.

Expand Down Expand Up @@ -279,7 +280,7 @@ Names use the actual configuration path. Monitoring survives hot reloads but is

`GET /healthz` makes no upstream request and requires no key. Pending/empty discovery, unavailable WARP, or missing required healthy proxies return 503. A usable stale catalog can return 200 with `status: "degraded"`; stale means older than twice the refresh interval, at least 60 seconds. Readiness is not proof of a valid key, remaining allowance, or successful inference. The public response contains counts/status, not secret values or proxy addresses.

Keep API and management listeners on loopback for local use. For network access, use HTTPS and restrict access to management. A trusted reverse proxy must set `X-Forwarded-Proto` consistently; rate limiting uses the direct peer, so clients behind one proxy share its limits. The executable itself serves HTTP.
Keep API and management listeners on loopback for local use. For network access, use HTTPS and restrict access to management. A trusted reverse proxy must set `X-Forwarded-Proto` consistently; rate limiting uses the direct peer, so clients behind one proxy share its limits. Behind a `cloudflared` tunnel on the same host, start with `-trust-cloudflare-client-ip` so each visitor gets its own limit: `CF-Connecting-IP` is then used only for loopback peers (Cloudflare overwrites that header), and IPv6 clients share one limit per /64. Do not enable it for other reverse proxies. The executable itself serves HTTP.

Configuration files and backups hold upstream keys, proxy passwords, and OAuth tokens; password hashing does not encrypt them. Restrict filesystem permissions (Windows ACLs when applicable) and exclude runtime files from source sharing. `logging.dump_request_bodies` is off by default and requires debug logging; even redacted, capped body dumps can reveal conversation content. Playground and availability probes send real upstream requests and can consume quota or credits.

Expand Down
3 changes: 2 additions & 1 deletion README.vi.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Tuỳ chọn dòng lệnh:
| `-config` | `config.json` | Đường dẫn file cấu hình. |
| `-listen` | Không đặt | Ghi đè địa chỉ lắng nghe của API. |
| `-web-listen` | Không đặt | Ghi đè địa chỉ lắng nghe của WebUI. |
| `-trust-cloudflare-client-ip` | `false` | Giới hạn đăng nhập/Playground của WebUI dùng `CF-Connecting-IP`, chỉ khi peer trực tiếp là loopback (`cloudflared` cục bộ). |

Thư mục cấu hình phải ghi được để thực hiện việc chuyển mật khẩu, lưu cấu hình và cache mô hình.

Expand Down Expand Up @@ -277,7 +278,7 @@ Tên tệp theo đường dẫn cấu hình thực tế. Theo dõi giữ qua n

`GET /healthz` không gọi upstream, không cần key. Khám phá chưa xong/trống, WARP không dùng được hoặc thiếu proxy khỏe bắt buộc trả 503. Danh mục cũ nhưng dùng được có thể trả 200 với `status: "degraded"`; ngưỡng cũ là hai lần chu kỳ, ít nhất 60 giây. Sẵn sàng không chứng minh key hợp lệ, đủ hạn mức hay suy luận thành công. Phản hồi công khai chỉ có số lượng/trạng thái, không có bí mật hay địa chỉ proxy.

Dùng loopback cho API và quản trị cục bộ. Khi truy cập qua mạng, dùng HTTPS và giới hạn lối vào quản trị. Reverse proxy tin cậy phải đặt `X-Forwarded-Proto` đúng; giới hạn dùng địa chỉ peer trực tiếp, nên client cùng proxy chia sẻ giới hạn. Tệp thực thi phục vụ HTTP.
Dùng loopback cho API và quản trị cục bộ. Khi truy cập qua mạng, dùng HTTPS và giới hạn lối vào quản trị. Reverse proxy tin cậy phải đặt `X-Forwarded-Proto` đúng; giới hạn dùng địa chỉ peer trực tiếp, nên client cùng proxy chia sẻ giới hạn. Khi dùng đường hầm `cloudflared` trên cùng máy, thêm `-trust-cloudflare-client-ip` để mỗi khách có giới hạn riêng: `CF-Connecting-IP` chỉ được dùng cho peer loopback (Cloudflare ghi đè header này), IPv6 gộp theo /64. Không bật cho reverse proxy khác. Tệp thực thi phục vụ HTTP.

Cấu hình/bản sao lưu chứa key upstream, mật khẩu proxy, token OAuth; hash mật khẩu không mã hóa chúng. Hạn chế quyền tệp, dùng ACL trên Windows, và loại tệp runtime khi chia sẻ mã. `logging.dump_request_bodies` mặc định tắt và cần mức debug; nội dung đã cắt/che vẫn có thể lộ hội thoại. Playground và thử chủ động có thể tiêu hao hạn mức hoặc credits thật.

Expand Down
3 changes: 2 additions & 1 deletion README.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Windows 下使用 `Copy-Item config.example.json config.json` 复制配置,执
| `-config` | `config.json` | 配置文件路径。 |
| `-listen` | 未设置 | 覆盖 API 监听地址。 |
| `-web-listen` | 未设置 | 覆盖 WebUI 监听地址。 |
| `-trust-cloudflare-client-ip` | `false` | WebUI 登录/Playground 限流改用 `CF-Connecting-IP`,仅当直连对端为 loopback(本机 `cloudflared`)时生效。 |

配置所在目录需要可写,以便迁移密码、保存配置和写入模型缓存。

Expand Down Expand Up @@ -279,7 +280,7 @@ API Key 页面支持创建、命名、启用、停用、删除。自动 Key 使

`GET /healthz` 不发送上游请求、无需 Key。目录未就绪/为空、WARP 不可用或必要代理全部不健康时返回 503。可用但过期目录可返回 200 及 `status: "degraded"`;过期阈值为两倍刷新间隔,最低 60 秒。就绪不保证 Key 有效、额度充足或推理成功;公开响应只含计数与状态,不含凭证或代理地址。

本地使用将 API 与管理监听在 loopback。网络访问须使用 HTTPS 并限制管理入口;可信反向代理应正确设置 `X-Forwarded-Proto`。限流使用直连对端地址,同一反向代理后的客户端共享限制。可执行文件本身提供 HTTP。
本地使用将 API 与管理监听在 loopback。网络访问须使用 HTTPS 并限制管理入口;可信反向代理应正确设置 `X-Forwarded-Proto`。限流使用直连对端地址,同一反向代理后的客户端共享限制。若通过本机 `cloudflared` 隧道访问,可加 `-trust-cloudflare-client-ip` 让每个访客独立限流:仅对 loopback 对端采用 `CF-Connecting-IP`(Cloudflare 会覆盖该头),IPv6 按 /64 合并。其他反向代理不要开启。可执行文件本身提供 HTTP。

配置和备份包含上游 Key、代理密码、OAuth Token,密码哈希不加密这些内容。限制文件权限,Windows 使用 ACL,分享源码时排除运行文件。`logging.dump_request_bodies` 默认关闭且需 debug 才输出,即使截断与脱敏仍可能暴露对话内容。Playground 和主动可用性探测会发送真实上游请求,可能消耗额度或 credits。

Expand Down
5 changes: 5 additions & 0 deletions cmd/opencode2api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func main() {
configPath := flag.String("config", "config.json", "path to config.json")
listen := flag.String("listen", "", "override the configured API listen address")
webListen := flag.String("web-listen", "", "override the configured WebUI listen address")
trustCloudflareIP := flag.Bool("trust-cloudflare-client-ip", false, "WebUI: take the client IP for login limits from CF-Connecting-IP, only for loopback peers (local cloudflared)")
flag.Parse()

cfg, err := config.Load(*configPath)
Expand Down Expand Up @@ -68,6 +69,10 @@ func main() {

if cfg.WebUI.Enabled {
admin := adminui.New(manager, monitor, hub, logger)
if *trustCloudflareIP {
admin.TrustCloudflareClientIP()
logger.Info("webui trusts CF-Connecting-IP from loopback peers", "component", "webui", "event", "cloudflare_client_ip_trusted")
}
webServer := &http.Server{
Addr: cfg.WebUI.Listen, Handler: admin.Handler(), ReadHeaderTimeout: 15 * time.Second, IdleTimeout: 120 * time.Second,
}
Expand Down
2 changes: 1 addition & 1 deletion docs/management.it.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ L'interfaccia supporta cinese semplificato, inglese, vietnamita e italiano; ling

L'amministratore accede con nome utente e password e riceve un cookie di sessione `HttpOnly`, `SameSite=Strict`. Tutte le API di gestione tranne il login richiedono una sessione valida; le scritture richiedono anche `X-CSRF-Token`. Se presente, `Origin` deve corrispondere all'origine del servizio. Le risposte di login/sessione forniscono `csrf_token`. Le chiavi locali `server_keys` non sostituiscono il login amministrativo.

La sessione dura 720 minuti per impostazione predefinita, con intervallo consentito di 5–10.080 minuti. Modificare le credenziali amministrative o riavviare il processo invalida le sessioni esistenti; l'endpoint di modifica dell'account richiede nuovamente la password corrente. Il login ha un limite di frequenza; il Playground consente al massimo 12 richieste al minuto per client connesso direttamente. Il servizio non considera attendibile `X-Forwarded-For`, quindi i client dietro un reverse proxy condividono il limite del peer. Un reverse proxy HTTPS deve impostare correttamente `X-Forwarded-Proto`, usato per il flag Secure del cookie e per il controllo dell'origine.
La sessione dura 720 minuti per impostazione predefinita, con intervallo consentito di 5–10.080 minuti. Modificare le credenziali amministrative o riavviare il processo invalida le sessioni esistenti; l'endpoint di modifica dell'account richiede nuovamente la password corrente. Il login ha un limite di frequenza; il Playground consente al massimo 12 richieste al minuto per client connesso direttamente. Il servizio non considera attendibile `X-Forwarded-For`, quindi i client dietro un reverse proxy condividono il limite del peer; con `-trust-cloudflare-client-ip`, i peer loopback (`cloudflared` locale) sono limitati per `CF-Connecting-IP`, IPv6 per /64. Un reverse proxy HTTPS deve impostare correttamente `X-Forwarded-Proto`, usato per il flag Secure del cookie e per il controllo dell'origine.

## Salvataggio e ricarica della configurazione

Expand Down
2 changes: 1 addition & 1 deletion docs/management.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ The UI supports Simplified Chinese, English, Vietnamese, and Italian. Language a

Administrators log in with a username and password and receive an `HttpOnly`, `SameSite=Strict` session cookie. Every management API except login requires a valid session. Writes also require `X-CSRF-Token`; when an `Origin` header is present, it must match the service's origin. Login and session responses provide `csrf_token`. Local `server_keys` do not grant management access.

Sessions default to 720 minutes, with a range of 5–10,080 minutes. Changing administrator credentials or restarting the process invalidates existing sessions; the account update endpoint requires the current password again. Login is throttled. Playground allows at most 12 requests per direct client per minute. The service does not trust `X-Forwarded-For`, so clients behind a reverse proxy share its limits. An HTTPS reverse proxy must set `X-Forwarded-Proto` correctly because it affects the cookie's Secure flag and origin checks.
Sessions default to 720 minutes, with a range of 5–10,080 minutes. Changing administrator credentials or restarting the process invalidates existing sessions; the account update endpoint requires the current password again. Login is throttled. Playground allows at most 12 requests per direct client per minute. The service does not trust `X-Forwarded-For`, so clients behind a reverse proxy share its limits; with `-trust-cloudflare-client-ip`, loopback peers (a local `cloudflared`) are limited by `CF-Connecting-IP` instead, IPv6 per /64. An HTTPS reverse proxy must set `X-Forwarded-Proto` correctly because it affects the cookie's Secure flag and origin checks.

## Saving and reloading configuration

Expand Down
2 changes: 1 addition & 1 deletion docs/management.vi.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Giao diện hỗ trợ tiếng Trung giản thể, Anh, Việt và Ý; ngôn ng

Quản trị viên đăng nhập bằng tên và mật khẩu để nhận cookie phiên có `HttpOnly` và `SameSite=Strict`. Mọi API quản trị, trừ đăng nhập, đều cần phiên hợp lệ; thao tác ghi còn cần `X-CSRF-Token`. Nếu có header `Origin`, giá trị phải trùng với nguồn của dịch vụ. Phản hồi đăng nhập/phiên cung cấp `csrf_token`. `server_keys` cục bộ không thay thế được đăng nhập quản trị.

Phiên mặc định kéo dài 720 phút, cho phép cấu hình từ 5 đến 10.080 phút. Đổi thông tin xác thực quản trị hoặc khởi động lại tiến trình làm các phiên hiện có mất hiệu lực; API đổi tài khoản yêu cầu xác minh lại mật khẩu hiện tại. Đăng nhập có giới hạn tần suất; Playground cho phép tối đa 12 lần mỗi phút trên mỗi client kết nối trực tiếp. Dịch vụ không tin cậy `X-Forwarded-For`, nên các client sau reverse proxy dùng chung giới hạn của đầu kết nối. Reverse proxy HTTPS phải đặt đúng `X-Forwarded-Proto` vì header này tham gia xác định cờ Secure của cookie và kiểm tra nguồn.
Phiên mặc định kéo dài 720 phút, cho phép cấu hình từ 5 đến 10.080 phút. Đổi thông tin xác thực quản trị hoặc khởi động lại tiến trình làm các phiên hiện có mất hiệu lực; API đổi tài khoản yêu cầu xác minh lại mật khẩu hiện tại. Đăng nhập có giới hạn tần suất; Playground cho phép tối đa 12 lần mỗi phút trên mỗi client kết nối trực tiếp. Dịch vụ không tin cậy `X-Forwarded-For`, nên các client sau reverse proxy dùng chung giới hạn của đầu kết nối; với `-trust-cloudflare-client-ip`, peer loopback (`cloudflared` cục bộ) được giới hạn theo `CF-Connecting-IP`, IPv6 theo /64. Reverse proxy HTTPS phải đặt đúng `X-Forwarded-Proto` vì header này tham gia xác định cờ Secure của cookie và kiểm tra nguồn.

## Lưu và nạp lại cấu hình

Expand Down
2 changes: 1 addition & 1 deletion docs/management.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Windows 原生方式为 `go build -trimpath -o opencode2api.exe ./cmd/opencode2a

管理员通过用户名/密码登录,获得 `HttpOnly`、`SameSite=Strict` Session Cookie。所有管理 API 除登录均需有效 Session;写操作另需 `X-CSRF-Token`,带 `Origin` 时须与服务来源一致。登录/Session 响应提供 `csrf_token`。本地 `server_keys` 不能代替管理登录。

Session 默认 720 分钟,范围 5–10,080 分钟。修改管理员凭证或重启进程会使现有 Session 失效;改账号接口要求再次验证当前密码。登录有限流;Playground 每直连客户端每分钟最多 12 次。服务不信任 `X-Forwarded-For`,反向代理后的客户端会共享对端限制。HTTPS 反向代理须正确设置 `X-Forwarded-Proto`,它参与 Cookie Secure 标记与来源校验。
Session 默认 720 分钟,范围 5–10,080 分钟。修改管理员凭证或重启进程会使现有 Session 失效;改账号接口要求再次验证当前密码。登录有限流;Playground 每直连客户端每分钟最多 12 次。服务不信任 `X-Forwarded-For`,反向代理后的客户端会共享对端限制;启用 `-trust-cloudflare-client-ip` 时,loopback 对端(本机 `cloudflared`)改按 `CF-Connecting-IP` 限流,IPv6 按 /64。HTTPS 反向代理须正确设置 `X-Forwarded-Proto`,它参与 Cookie Secure 标记与来源校验。

## 配置保存与重载

Expand Down
Loading