Skip to content

feat(git): per-host HTTPS Git credentials for workspace agents - #1015

Merged
crispinhu27 merged 15 commits into
mainfrom
feat/git-http-credentials
Nov 18, 2026
Merged

crispinhu27 merged 15 commits into
mainfrom
feat/git-http-credentials

Conversation

@crispinhu27

@crispinhu27 crispinhu27 commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Git authentication now resolves the responsible user's credential for the exact HTTPS host throughout workspace agents, SOP checkout and branch preparation, runner execution, terminals, and GitHub delivery polling. Saving a new host credential no longer leaves the platform reading an obsolete scalar token.

  • Use the standard Git credential helper with command-lifetime relays; keep tokens out of clone URLs, Git config, agent environment variables, snapshots, and durable runner tasks. Redact issued credentials even when model output splits them across streamed deltas.
  • Accept generic HTTPS Git repository URLs without identifying the hosting product. Preserve explicitly supplied SSH transport. PR/MR creation remains the Agent node's responsibility, including discovering an unfamiliar host's official API.
  • If platform checkout fails, the initial Agent receives the frozen clone URL, directory, base and work branch plus recovery instructions. The platform validates the actual checkout, origin and branch before continuing downstream nodes.
  • Make configured credentials available to their owner's workspace and remove the exposure switch. Explain that SSH keys support clone/push while PR/MR creation needs an API token. Keep an optional HTTPS authentication username because hosting providers do not share a universal token username convention.

Deployments must manually run migrations/036_git_http_credentials.sql followed by migrations/037_retire_plain_git_token.sql. These migrate historical personal GitHub tokens, retire the old scalar value and remove the exposure column. Managed deployment OAuth remains isolated in its adapter; execution does not dual-read personal tokens.

Validation: real CodeBuddy iOA/hy4 runs against personal private GitHub and CNB repositories completed clone, frozen branch preparation, commit, push and Agent-created PRs. Native and Docker SOP delivery passed, as did an injected platform-clone failure recovered by the first Agent and verified by a downstream node. Disposable PRs and branches were cleaned up; both remote main branches remained unchanged. The SQL migration was rerun locally against Docker MySQL to check idempotence. Platform web tests passed 207/207 with 87.7% line coverage (85% gate); chatbot tests/build and focused Git helper, runner claim, streamed-redaction and cancellation regressions passed. GitHub CI is tracked on the pushed head commit.

crispinhu27 and others added 2 commits November 17, 2026 21:18
Users keep one HTTPS access token per Git host. Workspace turns fetch the
token for a host on demand through the session gateway (git credential
helper, gh/glab shims) instead of receiving it in the environment. Tokens
the agent writes into the workspace are scrubbed after each CLI turn and
redacted from replies and diagnostics. PRs and MRs opened on GitHub,
GitHub Enterprise and GitLab are registered as requirement deliveries and
polled with the registering user's credential.
The new Git access token form labelled its token field "访问令牌" and added
an English translation for it. i18n translates exact text nodes, so the
GitHub credential wizard's "访问令牌" tab became "Access token" in English
too, which broke the onboarding journey that opens that tab. Label the new
field "个人访问令牌" (matching its placeholder) and translate that instead.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@crispinhu27

Copy link
Copy Markdown
Collaborator Author

CI fix: browser / first-run (commit acd486a)

Root cause. The browser and first-run jobs failed on public/welcome.spec.mjs (mobile-English-dark) with a 60 s timeout, and the two without-github.spec.mjs cases then failed because the timed-out test never restored the shared e2e-onboarding project (defaultRepositoryId left set). main at e89cda9 passes the same suites, so this came from the PR.

The new Git access token form labelled its token field 访问令牌 and this PR added "访问令牌":"Access token" to web/i18n-en.js. Translation matches exact text nodes, so the existing GitHub credential wizard's 访问令牌 tab also became "Access token" in English, and the onboarding journey that opens that tab hung.

Fix. The new field is now labelled 个人访问令牌 (it matches its placeholder 粘贴个人访问令牌), and the translation is keyed on that label: "Personal access token". The wizard tab is unchanged from main.

Local verification (this head, MySQL 8.4.7, platform started with scripts/dev.sh):

  • migrations/036_git_http_credentials.sql applied to the local DB twice; the second run is a no-op.
  • npx playwright test --config public/playwright.config.mjs: 23 passed, 6 skipped (the skips need a real model key or a fresh install). The three failing cases now pass: welcome mobile-English-dark (2.7 s) and both without-github cases.
  • webtest: 207/207; go test ./web/: ok.
  • Chrome over CDP, English UI: the wizard tabs are still GitHub 授权 / 访问令牌 and the token tab opens the secret field. The new form shows "Personal access token". Saving gitlab.example.org:8443 returns 200, the credential API lists the host but never returns the token, and deleting the test credential returns 200.
Wizard token tab (EN) Add token form (EN) Saved list (EN) Add token form (ZH)

The four new /api/users/:id/git-http-credentials routes had no e2e
request, which dropped the browser job's route coverage to 84.7% (gate
85%). Exercise save, replace, list without the token, validation, the
missing-credential verify path, the second user's 403 and delete.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@crispinhu27

Copy link
Copy Markdown
Collaborator Author

Follow-up: browser route coverage (commit 16f051d)

After acd486a, browser passed every Playwright suite but failed the route-coverage gate at 84.7% (minimum 85%). None of the four new /api/users/:id/git-http-credentials routes had an e2e request.

I added users: per-host Git access tokens are write-only and scoped to their owner to e2e/api/50-platform.test.mjs. It saves a credential, saves it again for the same host (still one row, renamed), and checks that the token is never returned. It also covers an invalid host (400), verify on a missing credential (404), a non-numeric user id (400), the second user reading or deleting (403), and delete (200). The test cleans up after itself even when it fails. Locally against MySQL 8.4.7 it passed twice in a row, and the server log shows all four routes were hit. CI on 16f051d: all 16 checks pass.

crispinhu27 and others added 7 commits November 18, 2026 01:17
Replace scalar token reads with host-scoped Git helpers across the platform, runners and terminals. Let the first Agent recover failed repository preparation, validate the frozen checkout, preserve explicit SSH transport, and accept generic HTTPS Git URLs without a hosting adapter. Remove the workspace exposure toggle, migrate historical personal tokens with manual SQL, and redact credentials across streamed model deltas.
Refresh the GitHub credential flag when the host list changes, translate repository token guidance, and verify the generic credential dialog from repository setup on desktop and mobile.
Mount the shared selector panel in its native dialog so its options receive clicks and keyboard focus. Clarify that agents can create PRs on other hosts, and that the platform's merge reporting needs a supported hosting integration.
@Robert0622

Copy link
Copy Markdown
Collaborator

[P2] 校验检出包含已有远端工作分支的提交

本地 Git 复验中,origin/work 比 origin/main 多一个提交,而本地 work 仍指向 main。即使设置了 RequireExistingWorkBranch=true,VerifyGitPreparation 仍返回成功,后续节点会在缺失已有提交的检出上继续。请在放行前确认远端工作分支的 tip 是当前 HEAD 的祖先。

当前提交的 Git 凭据、工作区及交付 Go 回归已通过。相关代码

@Robert0622

Copy link
Copy Markdown
Collaborator

[P2] 校验兜底新建的工作分支包含冻结基线

已复验已有远端工作分支的修复。首次建工作分支时仍会放行错误的起点。用本地 Git 让 main 和 release 各前进一个提交,SOP 冻结 origin/main,从 release 创建同名 work。origin/main 不是当前 HEAD 的祖先,VerifyGitPreparation 仍返回成功,后续 SOP 会在错误的代码基线上执行。请在新建分支场景校验 HEAD 包含冻结的基线提交,保留续跑场景对远端工作分支的独立检查。相关代码

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

本地复测发现一处终端凭证归属问题,已标在代码行。

request.TerminalGitSSHKeys = nil
terminalOpen := request.Operation == domain.RunnerWorkspaceOperationTerminal && request.Terminal != nil && request.Terminal.Operation == "open"
if runnerID != "" && (request.Operation == domain.RunnerWorkspaceOperationPrepare || terminalOpen) {
invocation.GitHTTPCredentials = credentials.GitHTTPCredentials

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] 交互终端应使用打开终端的用户自己的 Git 凭证

这里把 SOP 责任人的全部 HTTPS Git 凭证放入 PreparationInvocation,Runner 随后用同一份凭证配置交互终端。项目成员打开终端时可以使用另一位用户的凭证,范围还包括当前 SOP 未绑定的 Git 主机。本地用两个测试账号和一个无仓库 SOP 复现了错误的凭证下发。请把准备阶段和终端的凭证分开,终端按 TerminalOwner 解析,与 SSH 路径一致。

Robert0622
Robert0622 previously approved these changes Nov 18, 2026

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复测通过。SOP 准备和交互终端分别选择了对应账号的 Git 凭证。用两个账号和无凭证终端验证了隔离,Runner 和实际 PTY 的专项回归也通过。

@Robert0622 Robert0622 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复审了合入 main 的这次提交。终端继续按打开终端的用户绑定 Git 凭证,SOP 准备仍按运行责任人解析。凭证隔离、实际 PTY(含 Docker)、Runner、Git 凭证中继以及 MCP 和工作区准备专项回归均通过。

@crispinhu27
crispinhu27 merged commit 0541f88 into main Nov 18, 2026
16 checks passed
@crispinhu27
crispinhu27 deleted the feat/git-http-credentials branch November 18, 2026 16:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants