Skip to content

Feat/gitlab pr155 - #1255

Closed
mboo2005 wants to merge 13 commits into
Tencent:mainfrom
mboo2005:feat/gitlab-pr155
Closed

mboo2005 wants to merge 13 commits into
Tencent:mainfrom
mboo2005:feat/gitlab-pr155

Conversation

@mboo2005

Copy link
Copy Markdown

What changed

Describe the user problem and the resulting behavior.

Scope

  • Platform core / API / runner
  • Public adapter / deployment
  • Classic
  • Portable
  • Shared behavior contract
  • Installer / CLI
  • Documentation only

Compatibility

List affected hosts and any migration or backward-compatibility impact.

Validation

List commands that were actually run and mark anything blocked or not run.

go test -p=2 ./... -count=1 -timeout=180s
go vet ./...
python3 scripts/check-public.py
bash local/scripts/validate.sh
bash local/scripts/smoke-install.sh
bash local/scripts/e2e.sh
bash scripts/scan-secrets.sh

Safety

  • I did not include credentials, internal endpoints, production data, or organization-specific infrastructure.
  • I preserved user files and unrelated changes.
  • I updated generated Classic host bundles when applicable.
  • I documented third-party content and licensing changes when applicable.

duyang and others added 13 commits November 10, 2026 10:13
…tance)

- internal/tracker/gitlab.go: GitLab REST client (PRIVATE-TOKEN), find/create-or-reuse MR, delivery state refresh; MRs are never auto-merged.
- internal/domain/public_repository.go: gitlab:<host>/<group>/<repo> identity, host-in-ID for multi-instance; bare URLs trusted only for internal hosts (loopback/private/link-local/172.16/12), arbitrary hosts need the explicit gitlab: prefix.
- internal/httpapi/assistant_workspace_mr.go: conversation MR submission dispatches to GitLab, reusing open MRs and refreshing title/description.
- Dispatch points in merge_mr.go, mr_delivery_sync.go, service.go, catalog.go, delivery_mr.go.
- Tests: parsing, port handling, impersonation-host boundaries, internal-host classification (documentation hosts/paths only).
The GitLab adapter dispatches MR/sync work on the gitlab: prefix in the
repository id (host-in-ID). With provider=gitlab plus a bare gongfeng
path, the handler derived gongfeng-host URLs and stored a repository no
GitLab code path could serve. It also broke
TestCatalogRepositoryAgentAndAssetBranches, which pins this input to 400.

Reject the malformed combination up front with an actionable error and
cover both prefixed ids and trusted-URL normalization in the API tests.
Three P1 issues from review on 9f35211:

1. HTTPS silently downgraded to HTTP. The gitlab: id carries no scheme,
   so the parser, tracker client and workspace MR links all hard-coded
   http://. Now the scheme is preserved from the source URL (explicit
   http kept for internal instances), resolved from the repository
   record's web/clone URL via domain.GitLabInstanceScheme, and defaults
   to https everywhere.

2. PRIVATE-TOKEN forwarded across redirects. Both GitLab clients used
   the default redirect policy, leaking the token to whatever origin a
   302 pointed at. Both now refuse redirects (CheckRedirect, mirroring
   the GitHub client).

3. EnsureAndMergeBranchMR reported success without merging: the GitLab
   branch only found/created the MR and returned !N. It now calls the
   merge endpoint and requires state=merged in the response, erroring
   otherwise (aligned with githubMergeBranch).

Regression tests added for each: scheme preservation at parse/API-link
level, cross-origin redirect refusal with credential-leak assertions,
and merge verification incl. create-then-merge and unmerged-state
rejection. Also gofmt run_admission.go (pre-existing).
isTrustedGitLabHost matched the entire 172.0.0.0/8 by first octet
only, silently treating public ranges in that /8 (172.217.0.0/16
Google, 172.64.0.0/13 Cloudflare, ...) as internal instances for bare
http(s) URLs — bypassing the explicit gitlab: prefix that arbitrary
hosts are required to use.

Drop the 172 wildcard: bare URLs now trust only loopback, RFC1918
(IsPrivate, i.e. 10/8, 172.16/12, 192.168/16) and link-local
addresses, plus .internal/.local hostnames. Non-RFC1918 internal
deployments use the gitlab: prefix, which remains the admin-declared
escape hatch for any host.

Adds the requested counter-examples (172.217.0.1, 172.64.1.1 and
other public 172.x hosts rejected; bare public 172.x URL rejected;
explicit prefix still accepted).
…ink-local trust

1. [P2] Remove the unrelated claim/admission debug logging that rode
   along with this PR (internal/repo/run_admission.go): the promote
   loop ticks every 2s via StartClaimLoop, so even an idle instance
   would emit ~43k log lines/day. The whole diff is reverted to base.
2. [P2] GongfengMRURL still hard-coded http:// for gitlab: ids — the
   last leftover from the original scheme review. It now falls back to
   https://, consistent with GitLabInstanceScheme; real instances are
   covered by the web_url from API responses.
3. [non-blocking] isTrustedGitLabHost no longer trusts link-local
   addresses (169.254.0.0/16): there is no reason to point a GitLab
   instance at the cloud metadata range; http://169.254.169.254/... is
   now rejected for bare URLs.

Tests: GongfengMRURL https fallback assertion, link-local rejection
cases added to TestIsTrustedGitLabHost.
isTrustedGitLabHost used strings.Contains(host, ".internal"), so a
public attacker domain merely containing the substring — e.g.
gitlab.internal.attacker.example — passed the bare-URL trust check,
was stored as a gitlab: project, and received members' PRIVATE-TOKEN
on sync/MR calls: a token-exfiltration primitive for any project
owner via a pasted URL.

Match real suffixes only (HasSuffix .internal / .local, mirroring the
.local check). Regression test adds gitlab.internal.attacker.example
and internal.example.com to the rejected list.
Keep both imports on the conflicted line: main's slices and this branch's
strconv.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Reviewer note (Tencent#2): the PRIVATE-TOKEN comment mentioned an internal
project name; replaced with the neutral statement.
`gitlab:` 前缀只说明"这是 GitLab",不代表 host 可信:任何能写
POST /api/repositories 的项目成员都能绑定任意 host,随后 MR 同步会把
owner 的 Git 令牌当 PRIVATE-TOKEN 发到该 host(评审阻塞项)。

新增 AGENTFLOW_GITLAB_ALLOWED_HOSTS(逗号分隔 host[:port],可带
scheme)作为凭据信任边界:绑定入口与 tracker / 工作区 MR 客户端双重
校验,未声明的实例直接拒绝且不发任何认证头;公网、内网、回环地址
一视同仁——内网也能起一个服务收走令牌。未配置用户令牌时不再发送
空 PRIVATE-TOKEN 头(空头同样是一次凭证提交)。

测试:allowlist 归一化与端口匹配、catalog 绑定拦截(公网/内网/裸
URL)、tracker 拒绝未声明实例、工作区 MR 拒绝未声明实例、无凭据时
不带认证头。
main 的 Tencent#947(agent-owned Git)删掉了平台侧的对话 MR 创建
(createGitHubPR/createGongfengMR/createGitLabMR),改为 turn 结束后
检测 GitHub PR 登记交付,因此本分支在 assistant_workspace_mr.go 上与
main 冲突(main 删、我们改)。

按 main 侧解决:删除工作区 GitLab MR 创建路径及其测试(该能力对所有
provider 都已不存在)。GitLab 支持保留在仓库标识与绑定(含管理员
allowlist)、SOP integrate 的 find/merge、MR 状态同步与 MR URL 上。

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

main 的 Tencent#947 改成 agent 自己 push + 开 PR、平台在 turn 结束后检测 GitHub PR
登记交付;GitLab 没有等价检测,对话里的 GitLab 交付不会登记。

- 枚举工作区远端,按已绑定仓库记录映射到 gitlab: 项目(https/ssh/scp、
  .git 后缀、带 token 的 URL 都归一),只查询管理员声明过的实例;
- 复用 GitLab v4 API(scope=created_by_me),按 head commit 仍在工作区、
  创建时间不早于 workspace 过滤 open/merged MR;
- GitHub PR 与 GitLab MR 统一走 turnDelivery,未登记才登记;deliveredMR
  直接携带 project/iid(GitLab MR URL 不在 Gongfeng 解析规则内);
- 登记后由现有 MR 状态同步按 gitlab: 前缀刷新状态。

测试:head/时间/状态过滤、未声明实例不发请求不发凭据、无凭据不发
PRIVATE-TOKEN、远端形态归一化、直接 project/iid 登记到需求。
Brings in GitLab support (gitlab:<host>/<group>/<repo> identity, multi-instance)
on top of main's per-host HTTPS Git credentials:

- internal/tracker/gitlab.go: GitLab v4 MR adapter (find/list/merge, PRIVATE-TOKEN)
  authenticated via GitHTTPCredentialForHost instead of the obsolete u.GitToken.
- internal/domain/gitlab_allowlist.go: AGENTFLOW_GITLAB_ALLOWED_HOSTS trust boundary
  so credentials are never sent to an unlisted host.
- internal/domain/public_repository.go: gitlab: prefix + bare-URL parsing limited to
  private/internal hosts; keeps main's GitHub/工蜂 precedence.
- internal/httpapi/catalog.go: provider validation for gitlab + allowlist check.
- web/chatbot: LoopForgeGitLab parser and GitLab labels in the repo drawer/wizard.
- docs/deployment.md: HTTPS-only GitLab deployment notes (no SSH required).

Conflicts resolved in favor of main where main already implements GitLab
delivery-MR refresh and URL parsing (delivery_mr.go, assistant_workspace_mr.go,
assistant_conversation_issue.go); PR Tencent#155's superseded assistant_workspace_gitlab_mr.go
was dropped.

Co-Authored-By: Claude Code <noreply@anthropic.com>
The GitLab adapter reads AGENTFLOW_GITLAB_ALLOWED_HOSTS and the control-plane
dialer reads AGENTFLOW_GIT_EGRESS_ALLOW_CIDRS, but compose.yaml lists platform
environment variables explicitly and never forwarded either one. A container
install therefore could not enable self-hosted GitLab at all.

Co-Authored-By: Claude Code <noreply@anthropic.com>
@mboo2005 mboo2005 closed this Nov 23, 2026
@mboo2005
mboo2005 deleted the feat/gitlab-pr155 branch November 23, 2026 09:01
@mboo2005
mboo2005 restored the feat/gitlab-pr155 branch November 23, 2026 09:01
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.

1 participant