Add API key authentication for proxy endpoints.

Support multiple API keys from config, env, and CLI, enforce auth on non-public endpoints, and pass keys through remote deploy verification.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
GitHub Actions
2026-05-08 13:08:27 +08:00
parent c1a0fe2949
commit 450faefaf9
8 changed files with 229 additions and 2 deletions

View File

@@ -363,6 +363,30 @@ REMOTE_PASSWORD='your-password' \
脚本会上传 `cmd/``internal/``vendor/``go.mod``go.sum`,在服务器上准备 Docker 构建上下文,然后用多阶段 Docker build 重建运行时镜像。远端主机需要预装 `docker``tar``curl`;不需要额外安装宿主机 Go但如果相关基础镜像未缓存仍需要能拉取 Docker 基础镜像。
### API 鉴权
可以通过环境变量 `LINGMA_PROXY_API_KEYS` 或 JSON 配置里的 `api_keys` 设置一个或多个 API Key
```bash
export LINGMA_PROXY_API_KEYS="key-one,key-two"
go run ./cmd/lingma-ipc-proxy --host 127.0.0.1 --port 8095
```
```json
{
"api_keys": ["key-one", "key-two"]
}
```
部署脚本也会透传 `LINGMA_PROXY_API_KEYS`,所以可以在远端部署时一起启用同一组 key。
配置了 key 之后,除 `/``/health``/runtime/status``/v1/runtime/status` 之外的接口都会要求鉴权。客户端可以使用:
- `Authorization: Bearer <key>`
- `x-api-key: <key>`
这也兼容大多数 OpenAI 兼容客户端自带的 API Key 配置方式。
## 客户端配置
### Claude Code