Open
feat(#436): 非白名单 host 显式凭据告警 + host 支持矩阵 #88
grape_botAdd on 1 day ago
feat(#436): 非白名单 host 显式凭据告警 + host 支持矩阵 #88
Open
Merged fromfeat/issue-436intoldw
Total: 6 files changed+260-98
| @@ -51,7 +51,7 @@ tokens leaking into shell history: | |||
| 51 | 51 | ||
| 52 | - **Contract-driven commands** — OpenAPI 3.x `operationId` becomes a command tree (`tasks_current` → `grape tasks current`); the command set mirrors the connected server. | 52 | - **Contract-driven commands** — OpenAPI 3.x `operationId` becomes a command tree (`tasks_current` → `grape tasks current`); the command set mirrors the connected server. |
| 53 | - **Automatic auth injection** — Bearer token attached by default (client also supports `PRIVATE-TOKEN` / `?access_token=` channels). | 53 | - **Automatic auth injection** — Bearer token attached by default (client also supports `PRIVATE-TOKEN` / `?access_token=` channels). |
| 54 | -- **Native git passthrough** — `grape git` runs real `git`, auto-detects the repo, and injects a short-lived credential via `GIT_CONFIG` env vars — never on the command line, never on disk. | 54 | +- **Native git passthrough** — `grape git` runs real `git`, auto-detects the repo, and injects a short-lived credential via `GIT_CONFIG` env vars — never on the command line, never on disk. Only gitcode.com / github.com hosts get credentials; other hosts get an explicit warning. |
| 55 | - **Built-in `tasks wait`** — poll a task until a terminal state (`completed` / `failed` / `cancelled`). | 55 | - **Built-in `tasks wait`** — poll a task until a terminal state (`completed` / `failed` / `cancelled`). |
| 56 | - **Machine-readable output** — `--json-out` emits single-line JSON for workers and scripts. | 56 | - **Machine-readable output** — `--json-out` emits single-line JSON for workers and scripts. |
| 57 | - **Mode-aware command sets** — `GRAPE_CLI_MODE` (WORKER / USER / ALL) filters commands by token scope (dual / session-only / user-only). | 57 | - **Mode-aware command sets** — `GRAPE_CLI_MODE` (WORKER / USER / ALL) filters commands by token scope (dual / session-only / user-only). |
| @@ -181,8 +181,13 @@ The exact groups/verbs mirror the connected server's contract — run `grape com | |||
| 181 | `clone` URL argument, or from the current directory's `remote.origin.url` — exchanges | 181 | `clone` URL argument, or from the current directory's `remote.origin.url` — exchanges |
| 182 | the session token for a short-lived platform credential in-process, and injects it via | 182 | the session token for a short-lived platform credential in-process, and injects it via |
| 183 | `GIT_CONFIG` env vars: **never on the command line, never written to disk, invisible to | 183 | `GIT_CONFIG` env vars: **never on the command line, never written to disk, invisible to |
| 184 | -the agent**. gitcode.com and github.com hosts get credentials; on an exchange failure you get a | 184 | +the agent**. Host support matrix: gitcode.com / github.com (incl. `www.`) get credentials; |
| 185 | -warning and git runs natively. `grape git --help` is identical to `git --help`. | 185 | +gitee.com, gitlab.com and other self-hosted hosts get **no credentials but an explicit stderr |
| 186 | +warning** with the current host and a one-line hint to configure that host's own credentials | ||
| 187 | +(`git config --global credential.helper store`, then push once with a personal access token | ||
| 188 | +for that host, or switch the remote to SSH). On an exchange failure you get a warning and git | ||
| 189 | +runs natively; with no remote configured there is no warning. | ||
| 190 | +`grape git --help` is identical to `git --help`. | ||
| 186 | 191 | ||
| 187 | ```bash | 192 | ```bash |
| 188 | grape git status # local command (no credential needed) | 193 | grape git status # local command (no credential needed) |
| @@ -211,7 +216,8 @@ Each contract operation carries a token scope: `dual`, `session_only`, or `user_ | |||
| 211 | - No create/revoke token subcommands (prevents self-escalation); user-level API keys come from the Web UI. | 216 | - No create/revoke token subcommands (prevents self-escalation); user-level API keys come from the Web UI. |
| 212 | - Tokens never appear in output/errors; git credentials injected via `GIT_CONFIG` stay in-process and are never written to disk. | 217 | - Tokens never appear in output/errors; git credentials injected via `GIT_CONFIG` stay in-process and are never written to disk. |
| 213 | - `tk_` session tokens auto-expire with the task/session; `grape_` user keys can be revoked. | 218 | - `tk_` session tokens auto-expire with the task/session; `grape_` user keys can be revoked. |
| 214 | -- `grape git` injects credentials for gitcode.com / github.com hosts and degrades to plain native git (with a warning) if an exchange fails. | 219 | +- `grape git` injects credentials only for gitcode.com / github.com hosts (incl. `www.`) and degrades to plain native git (with a warning) if an exchange fails. |
| 220 | +- Non-allowlisted hosts (gitee.com, gitlab.com, self-hosted) never receive the platform token: `grape git` prints a stderr warning with the host plus a hint to configure that host's own credentials (PAT / SSH) instead of skipping silently. | ||
| 215 | 221 | ||
| 216 | ## Development & Testing | 222 | ## Development & Testing |
| 217 | 223 | ||
| @@ -49,7 +49,7 @@ OpenAPI 契约,自动生成 `grape <group> <verb>` 命令,并在本地以进 | |||
| 49 | 49 | ||
| 50 | - **契约驱动命令** — OpenAPI 3.x `operationId` → click 命令树(`tasks_current` → `grape tasks current`);命令集合与所连服务端契约保持一致 | 50 | - **契约驱动命令** — OpenAPI 3.x `operationId` → click 命令树(`tasks_current` → `grape tasks current`);命令集合与所连服务端契约保持一致 |
| 51 | - **自动认证注入** — 默认自动携带 Bearer token(客户端同时支持 `PRIVATE-TOKEN` / `?access_token=` 通道) | 51 | - **自动认证注入** — 默认自动携带 Bearer token(客户端同时支持 `PRIVATE-TOKEN` / `?access_token=` 通道) |
| 52 | -- **本地 git 透传** — `grape git` 运行真实 git,自动识别仓库,凭据经 `GIT_CONFIG` 注入子进程——不进命令行、不落磁盘 | 52 | +- **本地 git 透传** — `grape git` 运行真实 git,自动识别仓库,凭据经 `GIT_CONFIG` 注入子进程——不进命令行、不落磁盘。仅 gitcode.com / github.com 宿主注入凭据,其余宿主给出显式告警 |
| 53 | - **内置 `tasks wait`** — 轮询任务直至终态(`completed` / `failed` / `cancelled`) | 53 | - **内置 `tasks wait`** — 轮询任务直至终态(`completed` / `failed` / `cancelled`) |
| 54 | - **机器可读输出** — `--json-out` 输出单行 JSON,供 worker 与脚本解析 | 54 | - **机器可读输出** — `--json-out` 输出单行 JSON,供 worker 与脚本解析 |
| 55 | - **按模式过滤命令** — `GRAPE_CLI_MODE`(WORKER / USER / ALL)按 token 作用域(dual / session-only / user-only)过滤命令集合 | 55 | - **按模式过滤命令** — `GRAPE_CLI_MODE`(WORKER / USER / ALL)按 token 作用域(dual / session-only / user-only)过滤命令集合 |
| @@ -175,8 +175,11 @@ grape skills upload --file skill.zip --scope user --agent_type coding | |||
| 175 | 175 | ||
| 176 | `grape git` 是 **git 原生命令透传**。它自动识别仓库——`clone` 从 URL 参数解析,其余从 | 176 | `grape git` 是 **git 原生命令透传**。它自动识别仓库——`clone` 从 URL 参数解析,其余从 |
| 177 | 当前目录的 `remote.origin.url` 解析——再把会话 token 换券成短期平台凭据,经 `GIT_CONFIG` | 177 | 当前目录的 `remote.origin.url` 解析——再把会话 token 换券成短期平台凭据,经 `GIT_CONFIG` |
| 178 | -env 注入 git 子进程:**不进命令行、不落磁盘、agent 感知不到**。gitcode.com / github.com 宿主注入; | 178 | +env 注入 git 子进程:**不进命令行、不落磁盘、agent 感知不到**。 |
| 179 | -换券失败仅告警、git 按本机原生行为执行。`grape git --help` 与 `git --help` 一致。 | 179 | +host 支持矩阵:gitcode.com / github.com(含 `www.`)注入凭据;gitee.com、gitlab.com 及其他自建 host |
| 180 | +**不注入,但会输出一条 stderr 显式告警**(含当前 host 与一行「配置该 host 自身凭据」示例: | ||
| 181 | +`git config --global credential.helper store`,再用该 host 的 PAT 推送一次,或改用 SSH 远端)。 | ||
| 182 | +换券失败仅告警、git 按本机原生行为执行;未配置远端时不告警。`grape git --help` 与 `git --help` 一致。 | ||
| 180 | 183 | ||
| 181 | ```bash | 184 | ```bash |
| 182 | grape git status # 本地命令(无需凭据) | 185 | grape git status # 本地命令(无需凭据) |
| @@ -205,7 +208,8 @@ grape git commit -m "fix: ..." | |||
| 205 | - CLI **不提供** create/revoke token 子命令(防自举越权);用户级 API Key 由 Web UI 生成。 | 208 | - CLI **不提供** create/revoke token 子命令(防自举越权);用户级 API Key 由 Web UI 生成。 |
| 206 | - token 不出现在输出/错误信息(`GIT_CONFIG` 注入的 git 凭据同样不外泄、不落盘)。 | 209 | - token 不出现在输出/错误信息(`GIT_CONFIG` 注入的 git 凭据同样不外泄、不落盘)。 |
| 207 | - `tk_` 会话 token 随任务/会话自动失效;`grape_` 用户 key 可吊销。 | 210 | - `tk_` 会话 token 随任务/会话自动失效;`grape_` 用户 key 可吊销。 |
| 208 | -- `grape git` 对 gitcode.com / github.com 宿主注入凭据,换券失败时降级为本机原生 git(并给出告警)。 | 211 | +- `grape git` 仅对 gitcode.com / github.com(含 `www.`)宿主注入凭据,换券失败时降级为本机原生 git(并给出告警)。 |
| 212 | +- 非白名单 host(gitee.com、gitlab.com、自建)永远收不到平台 token:`grape git` 输出含 host 与「配置该 host 自身凭据(PAT / SSH)」提示的 stderr 告警,不再静默跳过。 | ||
| 209 | 213 | ||
| 210 | ## 开发与测试 | 214 | ## 开发与测试 |
| 211 | 215 | ||