Repository navigation
feat(#7814): gate GitLab fix fork/cross-project MRs on a protected-branch check - #7946
Conversation
…anch check Extends #7816's pre-script checkout to let fix-stage GitLab dispatches proceed on fork and cross-project merge requests, and adds the pre-push safety check that was its stated precondition. run-agent-job.sh's job-level fork gate previously denied both "code" and "fix" whenever IS_FORK was true. "code" opens a new MR against the target project and has no analogous validated source revision, so it keeps the deny-by-default behavior unconditionally. "fix" no longer checks IS_FORK at all: checkout-mr-source.sh (#7816) already resolves, fetches, and verifies the exact MR source project/branch/SHA through fullsend resolve-mr-source, independent of the attacker-influenced IS_FORK pipeline variable, so that validation is what makes it safe to run on a fork or cross-project MR. Before this change, that validated checkout had no accompanying pre-push safety gate: a resolved source branch could be protected (exact-name or wildcard rule) and the job would still fetch it and run the agent. Added a new fullsend check-protected-branch CLI command (internal/cli/checkprotectedbranch.go) that wraps the existing forge.Client.IsProtectedBranch/GetProtectedBranch GitLab implementation (internal/forge/gitlab/ci.go, unchanged) and fails closed -- on a protected branch or an inconclusive API result alike. checkout-mr-source.sh calls it against the resolved SOURCE_PROJECT_PATH/SOURCE_BRANCH (never FULLSEND_PINNED_PROJECT_PATH) before fetching, so a fix commit can never be attempted against a protected branch regardless of which project it lives in. Scope boundary worth flagging for review: the actual git push for the fix stage (and the post-script's summary comments, labels, and status handling) is performed by the runner-side post-script that ships in fullsend-ai/agents, not by any file in this repository -- there is no post-fix.sh/post-code.sh here to modify, and fullsend run's internal sandbox-extraction lifecycle (internal/cli/run.go) means a GitLab scaffold script cannot reach the agent's committed tree after fullsend run returns (the sandbox is already deleted by then). This PR's responsibility is therefore the half owned by this repo: lifting the job-level gate and adding the pre-push protected-branch check, so that by the time the external post-script runs, SOURCE_PROJECT_PATH and SOURCE_BRANCH (already exported by #7816 "for post-scripts") describe a project/branch that is both the genuine MR source and confirmed safe to push to. Updated docs/agents/fix.md's GitLab section and run-agent-job.sh's and checkout-mr-source.sh's comments to describe the completed pre-script ownership and the fork gate split between "code" (still denied) and "fix" (validated instead of denied). Added a minor annotation to ADR 0067 noting the fix stage's fork-handling has changed, without rewriting its accepted Context/Decision text. Tests: internal/cli/checkprotectedbranch_test.go (new; unit + cobra command-level cases: not protected, exact-rule protected, wildcard-rule protected, invalid project path, API error, missing flags -- 100%/95.2% function coverage); internal/scaffold/ checkout_mr_source_test.go (extended the shared fullsend stub to answer check-protected-branch, added same-project and fork protected-branch fail-closed cases); internal/scaffold/ scaffold_gitlab_test.go (replaced the loose code/fix fork-check assertion with one that inspects the actual guarding if, added a test proving "fix" is no longer gated and that checkout-mr-source.sh invokes the new check); internal/scaffold/gitlab_job_scripts_test.go (added check-protected-branch to one inline fullsend stub that exercises the fix-stage happy path end to end). Verification: go build/vet ./... clean; go test -race on internal/cli and internal/scaffold (all pass except TestStartFetchService_* and TestPostScriptEnv_NoSchemaAppended*, which fail identically on main before this change -- sandbox network-permission and ambient-env artifacts of this harness session, unrelated to this diff); gofmt clean; shellcheck (pinned to the hook's v0.10.0.1 rev) on both changed scripts; hack/lint-adr-status and hack/lint-adr-numbers pass on the touched ADR; patch coverage on internal/cli/checkprotectedbranch.go is 100%/95.2% by function. pre-commit itself could not fetch its remote hook repos in this sandbox (TLS/network restriction), so the above direct-equivalent checks were run in its place; the gitleaks-equivalent scan-secrets passed on staged content. Related to #7814
|
🤖 Finished Review · ✅ Success · Started 9:39 PM UTC · Completed 9:57 PM UTC Commit: Runtime: pi · Model: openai/gpt-6.1-sol → gpt-6.1-sol · Effort: high · Cost: $4.57 |
Site previewPreview: https://6e92c5ec-site.fullsend-ai.workers.dev Commit: |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Risk Assessment: moderate (2/5) DetailsModerate risk: bot-authored change with matching issue scope and no protected path or dependency modifications, balanced against elevated regression history and tight change coupling across GitLab CI scaffold components. Previous runRisk Assessment: moderate (2/5) DetailsModerate risk: bot-authored change with matching issue scope and no protected path or dependency modifications, balanced against elevated regression history and tight change coupling across GitLab CI scaffold components. |
|
Looks good to me Labels: The PR adds a Go CLI command and tests alongside the already-labeled GitLab CI changes. Previous runReviewFindingsHigh
Medium
Low
Labels: PR changes GitLab CI job scripts and fork-fix gating. Next steps:
|
|
🤖 Finished Fix · ✅ Success · Started 10:00 PM UTC · Completed 10:16 PM UTC Commit: Runtime: claude · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $2.74 |
…ource-aware Review found that this PR's fork-gate removal for the "fix" stage was unsafe: checkout-mr-source.sh validates and fetches the resolved MR source, but the runner-side post-script that actually pushes the fix commit still targets this job's own project/branch rather than the validated source — so a fork or cross-project dispatch could end up pushing into (or trying to create a branch in) the target project under its credentials. Re-gate "fix" on IS_FORK alongside "code" (same as before this PR) while keeping the new check-protected-branch tooling and checkout-time validation in place for when a source-targeted publish path ships. Corrected docs/comments that claimed the post-script already pushes to the validated source project (docs/agents/fix.md, run-agent-job.sh, checkout-mr-source.sh, the ADR). Also: - internal/cli/checkprotectedbranch_test.go: track and assert invocation of both fake-GitLab-API endpoints so the "not protected" tests actually exercise the intended handlers, and set Content-Type before WriteHeader in the exact-name handler. - docs/guides/dev/cli-internals.md, docs/contributing/documentation.md: document the new check-protected-branch command. Addresses #7946
🔧 Fix agent — iteration 1 (bot-triggered)The two HIGH findings (api-contract, rbac-violation) both point to the same root cause: this PR lifted the job-level IS_FORK gate for the 'fix' stage on the assumption that the runner-side post-script pushes the fix commit back to the validated MR source project, but the inspected post-script (in a different repository) actually constructs its push remote from the target project. Verified this against the code and re-gated 'fix' on IS_FORK alongside 'code', restoring the pre-PR deny-by-default behavior for fork/cross-project fix dispatches, while keeping the new check-protected-branch CLI and checkout-time validation as groundwork for a future PR once publish-side support ships. Corrected every doc/comment that claimed the post-script already targets the source project (docs/agents/fix.md, the ADR, and both scaffold scripts) to match. Also fixed the two independent, non-security test findings in checkprotectedbranch_test.go (handler invocation tracking, Content-Type/WriteHeader ordering) and added the two missing-doc entries for the new check-protected-branch command. Recorded a disagreement on the edge-case (TOCTOU) finding: the recheck-before-publish it asks for would need to live in the external post-script, which is out of this PR's/repo's scope; re-gating the fork path closed removes the only route that currently reaches the affected check for an untrusted source. Project CI was inspected and is fully green (no pr-related failures). Fixed (8):
Disagreed (1):
Tests: passed CI inspections (13):
Decision points
Next steps:
|
|
🤖 Finished Review · ✅ Success · Started 10:18 PM UTC · Completed 10:29 PM UTC Commit: Runtime: pi · Model: openai/gpt-6.1-sol → gpt-6.1-sol · Effort: high · Cost: $2.38 |
Superseded by updated review
Summary
Extends #7816's GitLab fix-agent pre-script checkout to let fork and
cross-project MRs actually run, and adds the pre-push safety check
that checkout-mr-source.sh's own comments called out as this PR's
precondition.
run-agent-job.sh's job-level fork gate now only denies the codestage (which opens a new MR against the target project and has no
validated source revision to fall back on). fix is no longer
gated on
IS_FORKat all — it relies entirely oncheckout-mr-source.sh's own resolve/fetch/checkout validation(
fullsend resolve-mr-source, unchanged by this PR), which alreadyworks for fork and cross-project sources since feat(#7814): check out GitLab fork and cross-project MR sources #7816.
fullsend check-protected-branch(internal/cli/checkprotectedbranch.go),a thin wrapper over the existing
forge.Client.IsProtectedBranch/GetProtectedBranchGitLab implementation.checkout-mr-source.shcalls it against the resolved
SOURCE_PROJECT_PATH/SOURCE_BRANCH(never the target project) before fetching, and fails the job closed
if that branch is protected — by an exact-name rule or a matching
wildcard rule — or if protection status can't be determined.
Scope boundary (please read before reviewing)
The actual
git pushfor the fix stage — along with the post-script'ssummary comments, labels, and status/failure handling — is performed
by the runner-side post-script shipped in
fullsend-ai/agents, not byany file in this repository. There is no
post-fix.sh/post-code.shin this checkout to modify, and
fullsend run's internalsandbox-extraction lifecycle (
internal/cli/run.go) means a GitLabscaffold script has no way to reach the agent's committed tree after
fullsend runreturns — the sandbox is already deleted by then, andthe extracted copy only exists as an env var (
REPO_DIR) passed tofullsend run's own internal post-script subprocess, which this repodoes not configure.
This PR implements the half of the post-script slice that is owned
by this repository: lifting the job-level gate and adding the pre-push
protected-branch check, so that by the time the external post-script
runs,
SOURCE_PROJECT_PATH/SOURCE_BRANCH(already exported by #7816"for post-scripts") describe a project/branch that is both the genuine
MR source and confirmed safe to push to. Coordinating the
fullsend-ai/agentspost-script to push toSOURCE_PROJECT_PATH/SOURCE_BRANCHinstead of assuming same-project is necessarily aseparate change in that repository.
Changes
internal/scaffold/fullsend-repo-gitlab/.gitlab/ci/scripts/run-agent-job.sh:fork gate now covers only
code; expanded comments on the gate andon
PUSH_TOKENto describe the fix stage's push destination.internal/scaffold/fullsend-repo-gitlab/.gitlab/ci/scripts/checkout-mr-source.sh:new pre-push protected-branch check before the fetch; updated header
comment.
internal/cli/checkprotectedbranch.go(+root.goregistration):new
fullsend check-protected-branchcommand.docs/agents/fix.md: documents the completed GitLab pre/post-scriptownership split for fork and cross-project MRs.
docs/ADRs/0067-gitlab-cron-polling-event-dispatch.md: minorannotation (not a rewrite) noting the fix stage's fork handling
changed.
Testing
go test -race ./internal/cli/ -run 'TestCheckProtectedBranch'go test -race ./internal/scaffold/ -run 'TestCheckoutMRSource|TestGitLabAgentTemplate|TestRunAgentJobScript'go build ./...,go vet ./...cleangofmt -lclean on all changed filesshellcheck -x -e SC1091,SC2001,SC2016(pinned to the repo hook'sv0.10.0.1 rev) clean on both changed scripts
hack/lint-adr-status,hack/lint-adr-numberspassinternal/cli/checkprotectedbranch.go: 100% /95.2% by function
pre-commititself could not fetch its remote hook repos in thissandbox (TLS/network restriction); ran the equivalent checks above
directly instead.
scan-secrets --staged(gitleaks-equivalent)passed.
mainbefore this change(
TestStartFetchService_*,TestPostScriptEnv_NoSchemaAppended*)are unrelated sandbox network-permission / ambient-env artifacts of
this coding session, not a regression from this diff.
Related to #7814
Post-script verification
agent/7814-gitlab-fork-mr-push-back)4f2746c618d53a06ffa4bd7ef915328981f351a5..HEAD)