Skip to content

feat(#7499): route GitLab jobs by registered role identity - #7510

Merged
ggallen merged 4 commits into
mainfrom
agent/7499-gitlab-role-routing
Sep 21, 2026
Merged

ggallen merged 4 commits into
mainfrom
agent/7499-gitlab-role-routing

Conversation

@fullsend-ai-coder

Copy link
Copy Markdown
Contributor

Summary

Route GitLab poll, agent, and post-review operations through the registered role-credential contract so Poller, Analyst, Coder, and administrator-registered custom roles authenticate with their own CI/CD variables when the migration gate is migrating or enforced. Existing installations stay on the shared FULLSEND_FORGE_TOKEN while the gate is unset, disabled, or rollback.

Related Issue

Stage 3 of the GitLab role-identity rollout (parent #7496). Depends on the contract from #7497 and provisioning from #7498.

Changes

  • Add gitlabroles.Select / SelectAgent / Require as the dispatch-time entry points (ValidateAgent only in role-aware modes).
  • fullsend poll selects the Poller credential and fails closed on 401/403 without switching identities.
  • fullsend run --forge gitlab exports GITLAB_TOKEN from the resolved role secret and sets PUSH_TOKEN only when the registration declares write_repository.
  • fullsend post-review refuses GitLab APPROVE when the running identity lacks approve_merge_request.
  • Diagnostics publish role/secret names and source labels, never token values.
  • Docs updated to describe routing; GitLab CI templates are unchanged (all role tokens are already project-level CI/CD variables).

Testing

  • go test -race ./internal/gitlabroles/ — Select/SelectAgent mappings, custom own/reuse roles, missing-role, migration fallback, unregistered fail-closed, capability denial, auth-failed annotation, no secret leakage in diagnostics (98% package coverage; new route.go functions at 100%).
  • go test -race ./internal/cli/ -run GitLab|PollCmd|PostReview|Role — poller/agent credential application, Analyst PUSH_TOKEN clearing, Coder cannot approve, custom-role mapping, raw-token registry rejection, disabled-mode parity.
  • go vet on changed packages.
  • Direct execution of pre-commit equivalents after pre-commit run could not fetch hook repos.

Checklist

  • PR title follows Conventional Commits (correct type, ! for breaking changes)
  • Commits are signed off (DCO) — human and human-directed agent sessions only (autonomous agent commits are exempt)
  • I wrote this contribution myself and can explain all changes in it

Closes #7499

Post-script verification

  • Branch is not main/master (agent/7499-gitlab-role-routing)
  • Secret scan passed (gitleaks — b5a460eba36746483478f2c0683126d00443903b..HEAD)
  • PR body secret scan passed (gitleaks — no-git)

Wire gitlabroles.Select into fullsend poll, fullsend run, and
post-review so Poller, Analyst, Coder, and registered custom roles
authenticate with their own credentials when the migration gate is
migrating or enforced.

Disabled and rollback keep the shared FULLSEND_FORGE_TOKEN path.
Unregistered agents fail closed in role-aware modes. Analyst jobs
do not receive PUSH_TOKEN. Coder cannot approve merge requests.
Authentication failures never switch identities.

Note: pre-commit could not fetch remote hook repos (HTTP 403).
Local equivalents were run: gofmt, go vet, gitleaks, ADR lints,
lychee, and whitespace/eof checks.

Closes #7499
@fullsend-ai-coder
fullsend-ai-coder Bot requested a review from a team September 20, 2026 21:28
@fullsend-ai-coder fullsend-ai-coder Bot added the ready-for-review Triggers review agent dispatch label Sep 20, 2026
@fullsend-ai-review

fullsend-ai-review Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 9:30 PM UTC · Completed 9:55 PM UTC

Commit: d523510 · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $11.19

@github-actions

github-actions Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Site preview

Preview: https://86b2ecfb-site.fullsend-ai.workers.dev

Commit: f3a726604b77f6fc57ef081abf3f51e540aa7392

@codecov

codecov Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.12919% with 6 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/cli/gitlab_role.go 95.69% 2 Missing and 2 partials ⚠️
internal/cli/poll.go 66.66% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@fullsend-ai-review fullsend-ai-review Bot added the risk/moderate PR risk: moderate label Sep 20, 2026
@fullsend-ai-review

fullsend-ai-review Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Risk Assessment: moderate (2/5)

Details

Re-review anchoring holds: Tier 1 is unchanged (23 files/1567 lines, large blast radius, zero protected/security-sensitive paths, no CI/dependency changes, bot author, ~26% test ratio), Tier 2 shows heavy but stable churn on shared CLI/docs files typical of this busy area (fix/revert and coupling counts appear inflated by generic grep matching and monorepo-wide commits rather than targeted regression risk on the new gitlabroles routing code, which itself has no prior history), and Tier 3 remains a well-scoped, feature-flag-gated (opt-in, default-disabled) stage of the planned #7496 rollout with no risk labels and most acceptance criteria addressed, so the recomputed weighted composite confirms the prior moderate score of 2.

Previous run

Risk Assessment: moderate (2/5)

Details

Re-review anchoring holds: Tier 1 signals are unchanged in kind from the prior assessment (still 11-25-files/800-1999-lines bucket now at 23 files/1567 lines, zero protected/security-sensitive paths, no CI or dependency changes, bot author), Tier 2 shows the same hot-but-stable, multi-author, largely-non-reverted history typical of this heavily-churned docs/CLI area, and Tier 3 remains a well-scoped, migration-gated stage of the planned #7496 rollout with acceptance criteria mostly addressed and no risk-relevant labels, so the composite confirms the prior moderate score of 2.

Previous run (2)

Risk Assessment: moderate (2/5)

Details

Tier 1 signals are unchanged in kind from the prior assessment (11-25 files, 800-1999 lines, zero protected/security-sensitive paths, no CI or dependency changes, bot author) with only incremental growth (+3 files, +257 lines) from further iteration on the same feature; Tier 2 shows the same moderately hot, multi-author, very-recent, non-reverted pattern as before; Tier 3 remains a well-scoped, gated (opt-in via migration state) stage of a planned multi-PR rollout with acceptance criteria mostly addressed, so the prior moderate score of 2 is preserved.

Previous run (3)

Risk Assessment: moderate (2/5)

Details

Despite a large raw diff (20 files, 1298 lines, new gitlabroles routing module), risk is pulled down by clean qualitative signals: bot author, zero protected/security-sensitive paths by the risk script's path heuristics, no CI or dependency changes, and a reasonable test ratio; git history shows moderately hot, multi-author files but very recent, stable code with no reverts; the linked issue is well-scoped with acceptance criteria mostly addressed. Composite score is moderate (~2.0) despite the security-relevant subject matter, which the code-review findings above surface separately.

@fullsend-ai-review

fullsend-ai-review Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

Looks good to me

Previous run

Review

Findings

Medium

  • [incorrect-doc] docs/guides/user/running-agents-locally.md:336 — The updated local-run guide states: "Once the gate is migrating or enforced, the matching per-role secret ... is required instead — the shared-token fallback no longer applies." This is inaccurate for migrating mode: gitlabroles.Resolve (internal/gitlabroles/gitlabroles.go) explicitly falls back to FULLSEND_FORGE_TOKEN when a role's own secret is unconfigured and Mode.AllowsSharedFallback() is true, which holds only for ModeMigrating (confirmed against Resolve()'s migrating branch and Mode.AllowsSharedFallback()/RequiresRoleCredentials(), and TestSelectMigratingFallbackWhenRoleMissing). Only enforced mode strictly requires the per-role secret without shared-token fallback. What actually stops working in both migrating and enforced is the separate, unmanaged fallback to a directly-set GITLAB_TOKEN when FULLSEND_FORGE_TOKEN is absent (internal/cli/run.go:921-925, gated on mode.UsesSharedOnly(), which covers only disabled/rollback). The canonical table in docs/contributing/gitlab-role-credentials.md already states this correctly — only this guide's prose is now wrong for migrating mode.
    Remediation: Clarify that in migrating mode an unconfigured role still falls back to FULLSEND_FORGE_TOKEN (shared-token fallback only ceases in enforced mode), but the unmanaged fallback to a directly-set GITLAB_TOKEN (when FULLSEND_FORGE_TOKEN is missing) no longer applies in either migrating or enforced mode.

Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR
Previous run (2)

Review

Findings

Medium

  • [incorrect-doc] docs/guides/user/running-agents-locally.md:336 — The local-run guide states that while the migration gate is unset, disabled, or rollback, GitLab runs require FULLSEND_FORGE_TOKEN and that "setting GITLAB_TOKEN directly is no longer sufficient on its own." That is the opposite of the intentional fallback in internal/cli/run.go: when applyGitLabAgentCredentials fails with gitlabroles.ErrSharedUnconfigured and mode.UsesSharedOnly() is true, runAgent logs a warning and continues, leaving a directly-set GITLAB_TOKEN/PUSH_TOKEN untouched (run.go:912-925; TestRunAgent_GitLabMissingSharedFallsBackWhenDisabled). A user of this guide with only GITLAB_TOKEN set will succeed, not fail as the doc claims. This is a re-review regression: the prior review's incorrect-doc finding on this same line was addressed by editing the text, but the new text asserts the opposite of the code's own fallback behavior. The same omission (as an incompleteness rather than an affirmative false claim) also appears in docs/cli/run.md's new "GitLab role identity" section, which lists only the shared FULLSEND_FORGE_TOKEN path for unset/disabled/rollback mode without mentioning the fallback.
    Remediation: In running-agents-locally.md, state that in unset/disabled/rollback mode FULLSEND_FORGE_TOKEN is preferred and exported to GITLAB_TOKEN, but a directly-set GITLAB_TOKEN still works as a fallback when FULLSEND_FORGE_TOKEN is absent (with a warning logged). Only migrating/enforced modes strictly require the matching per-role secret. Add the same clarification to docs/cli/run.md's new GitLab role identity section.

Low

  • [incorrect-doc] docs/problems/security-threat-model.md:124 — The "No self-approval" bullet states that once the gate is migrating or enforced, "Analyst and Coder authenticate with distinct per-role credentials." This is not universally true in migrating mode: internal/gitlabroles/gitlabroles.go's Resolve() falls back to the shared FULLSEND_FORGE_TOKEN when mode.AllowsSharedFallback() (migrating) and a role's own secret is unconfigured, so Analyst and Coder could both authenticate with the same shared PAT during partial migration. This is a documentation-precision issue rather than a functional security gap: route.go's registrationForSource/Require resolve the approve_merge_request capability from the role identity (src.Role), not from which secret backs it, so Coder is still correctly denied the approve call even on the shared-token fallback.
    Remediation: Qualify the claim: distinct per-role credentials apply once role secrets are provisioned (always true in enforced mode; true in migrating mode only for roles whose secret is already configured). Note that migrating may still fall back to the shared token for an unconfigured role, and that the approve_merge_request check still correctly denies Coder in that case because it is resolved from the role identity, not the backing secret.

  • [incorrect-doc] docs/contributing/gitlab-role-credentials.md:243 — The "How a job selects its credential" section directs callers to gitlabroles.Select / gitlabroles.SelectAgent, then lists FailedSecret among the inputs those helpers populate. In internal/gitlabroles/route.go, Select and SelectAgent both build a Request{Mode, Job, Registry, Present} with FailedSecret left at its zero value — they never set it. FailedSecret is only meaningful when a caller constructs a Request and calls Resolve directly after an auth failure (the AuthFailed / poll.go wrapGitLabAuthFailure pattern); a later Select/SelectAgent call in the same process will not honor a prior failure through this field.
    Remediation: Move the FailedSecret bullet to describe Resolve/Request directly, and note that Select/SelectAgent never populate it themselves; callers must fail closed (not re-Select) after an auth failure, per AuthFailed's doc comment.


Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR
Previous run (3)

Review

Findings

Medium

  • [auth-bypass] internal/cli/gitlab_role.go:136 — checkGitLabApprovalCapability enforces approve_merge_request against identity labels (FULLSEND_GITLAB_ROLE, then STAGE), not against the credential that will actually authenticate the approve call. harnessRole is read from the same env var as agentName (never a distinct harness role: field). resolvePostReviewClient independently builds the GitLab client from --token/GITLAB_TOKEN with no comparison to the selected Selection.Source.SecretName. If the label and the authenticating token diverge, the capability check can pass for one identity while the API call authenticates as another. See also the auth-bypass finding on the env-layering path below, which is one way the label and token can diverge.
    Remediation: Resolve the running identity from the token post-review will actually use (prefer --token, else GITLAB_TOKEN); compare it against getenv(sel.Source.SecretName) after SelectAgent, and deny APPROVE unless that authenticating secret's Registration has CapApproveMergeRequest. Do not treat STAGE/FULLSEND_GITLAB_ROLE labels as sufficient on their own.

  • [privilege-escalation] internal/cli/gitlab_role.go:67 — applyGitLabRoleSelection exports GITLAB_TOKEN (and conditionally PUSH_TOKEN) for the selected role but never blanks sibling role secrets already present in the process/CI environment: FULLSEND_FORGE_TOKEN, FULLSEND_GITLAB_POLLER_TOKEN / ANALYST / CODER, and any custom FULLSEND_GITLAB_ROLE_*_TOKEN. Those names are GitLab project-level CI/CD variables injected into every protected-branch job. Host-side pre/post-scripts inherit them via childScriptEnv's os.Environ() prefix, so e.g. a Coder post-script can read FULLSEND_GITLAB_ANALYST_TOKEN directly and call the GitLab API as Analyst, bypassing checkGitLabApprovalCapability entirely (that check only runs inside fullsend post-review itself, not for arbitrary script code reading a sibling secret).
    Remediation: After a successful Select/Token in migrating or enforced mode, unset every registered role secret in sel.Present that is not sel.Source.SecretName (and unset FULLSEND_FORGE_TOKEN when mode is enforced) before spawning pre/post-scripts, keeping only the selected secret and the GITLAB_TOKEN/PUSH_TOKEN aliases the CLI itself exports.

  • [auth-bypass] internal/cli/gitlab_role.go:67 — GitLab capability enforcement is not pinned against harness-controlled env layering. applyGitLabRoleSelection writes GITLAB_TOKEN / PUSH_TOKEN / FULLSEND_GITLAB_ROLE* into the fullsend process via os.Setenv, but run.go's childScriptEnv builds pre/post-script environments as append(os.Environ(), envToList(runnerEnv)...), which is last-wins per Go's exec.Cmd.Env semantics. h.RunnerEnv (runner_env merged with env.runner) can therefore redefine FULLSEND_GITLAB_ROLE, GITLAB_TOKEN, or FULLSEND_GITLAB_ROLE_MIGRATION for a post-script's environment, and none of those keys are in the existing oidcDenyKeys expansion denylist. Exploiting this requires control over harness/env.runner configuration (operator-trusted content, not external PR injection), so this is lower severity than an externally-injectable bypass, but it removes a defense-in-depth boundary between the role-routing decision and the environment a post-script actually observes. See also the other two findings on this file for related identity/secret leakage through this code path.
    Remediation: Pin GitLab role-routing keys (FULLSEND_GITLAB_ROLE_MIGRATION, FULLSEND_GITLAB_ROLE_REGISTRY, FULLSEND_FORGE_TOKEN, FULLSEND_GITLAB_*_TOKEN, GITLAB_TOKEN, PUSH_TOKEN, FULLSEND_GITLAB_ROLE*) so harness runner_env/env.runner cannot override them in childScriptEnv, analogous to how oidcDenyKeys are stripped. In role-aware modes, fullsend post-review should resolve its own SelectAgent+Token() and use that token for the forge client rather than trusting --token/GITLAB_TOKEN independently after a label-based capability check.

  • [incorrect-doc] docs/architecture.md:275 — The GitLab/Forgejo identity open question still states the registered-role credential contract "is not yet the runtime." This PR lands job routing in fullsend poll, fullsend run, and fullsend post-review for the migrating/enforced gate states, so the statement is now incorrect. This file is not among this PR's changed files.
    Remediation: Update the open question to state that job routing (Route GitLab jobs and forge operations by registered role identity #7499) has landed for poll/run/post-review, with the shared FULLSEND_FORGE_TOKEN path remaining the default while the migration gate is unset/disabled/rollback.

  • [incorrect-doc] docs/guides/user/running-agents-locally.md:336 — This guide says "the agent reads GITLAB_TOKEN from the environment and does not require the mint service." fullsend run --forge gitlab now calls applyGitLabAgentCredentials, which in the default/disabled migration gate requires FULLSEND_FORGE_TOKEN to be set (gitlabroles.resolveShared returns ErrSharedUnconfigured otherwise) and exports GITLAB_TOKEN from that secret itself — it no longer simply reads a pre-set GITLAB_TOKEN. A user following this exact guide with only GITLAB_TOKEN set will get a hard failure. This PR's own new test, TestRunAgent_GitLabSkipsMint, had to add t.Setenv(forge.SecretForgeToken, ...) to keep passing, confirming the new requirement. This file is not among this PR's changed files.
    Remediation: Update the local GitLab run instructions to state that fullsend run --forge gitlab resolves credentials via the GitLab role-credential contract, requires FULLSEND_FORGE_TOKEN (or the matching role token once the gate is migrating/enforced) in the environment, and exports GITLAB_TOKEN itself.

  • [backward-incompatible] internal/cli/run.go:911 — Previously fullsend run --forge gitlab skipped token minting entirely as a no-op and left GITLAB_TOKEN/PUSH_TOKEN exactly as the surrounding process environment set them. This PR makes it unconditionally call applyGitLabAgentCredentials; in the default/disabled migration gate, gitlabroles.resolveShared returns ErrSharedUnconfigured when FULLSEND_FORGE_TOKEN is absent, and the run aborts immediately — even if GITLAB_TOKEN is already set directly. Production GitLab CI jobs likely already have FULLSEND_FORGE_TOKEN provisioned as a project-level CI/CD variable, so hosted runs are probably unaffected, but local/manual invocations that only set GITLAB_TOKEN (exactly the workflow documented in running-agents-locally.md) now fail where they previously succeeded. The PR title (feat(#7499): ...) does not carry the ! breaking-change suffix that AGENTS.md/COMMITS.md require for a behavior change like this.
    Remediation: Either (a) when SelectAgent fails with ErrSharedUnconfigured while the mode is disabled/rollback, fall back to the pre-PR no-op (warn, don't abort) so a directly-set GITLAB_TOKEN keeps working; or (b) if the new hard requirement on FULLSEND_FORGE_TOKEN is intentional, mark this as a breaking change (feat(#7499)!:) and update docs/guides/user/running-agents-locally.md accordingly.

Low

  • [documentation-cross-reference] docs/problems/security-threat-model.md:124 — The existing "No self-approval" bullet still frames GitLab's single-shared-PAT identity-vs-author workaround as complete. This PR adds a real per-role approve_merge_request capability check, so once the gate is migrating/enforced, Analyst and Coder use distinct credentials and Coder is structurally blocked from approving — a materially different situation than the shared-PAT-only story this bullet describes. The adjacent GitLab role-credential contract bullet was updated to reference Route GitLab jobs and forge operations by registered role identity #7499, but the self-approval bullet itself has no qualifier or backlink to the new capability check.
    Remediation: Add a short qualifier to the "No self-approval" bullet noting that the identity-vs-author skip applies while the gate is disabled/rollback, and point to the GitLab role-credential contract's approve_merge_request check (docs/contributing/gitlab-role-credentials.md) for migrating/enforced behavior.

  • [code-clarity] internal/cli/gitlab_role.go:140 — In checkGitLabApprovalCapability, harnessRole is read from the same env var (envGitLabRole, i.e. FULLSEND_GITLAB_ROLE) as agentName — the two locals hold the same value in the common case, and the name harnessRole is misleading since it is not the harness role: field passed elsewhere (e.g. into applyGitLabAgentCredentials).
    Remediation: Drop the redundant second lookup (RoleFor already resolves role names directly), or rename it and source it independently if a distinct harness-role fallback is actually intended.


Next steps:

  • /fs-fix — agent addresses review findings automatically
  • /fs-fix <your instruction> — agent fixes with your specific guidance
  • Push commits directly — review re-runs automatically on push
  • /fs-fix-stop — disable automatic fix runs for this PR

fullsend-ai-review[bot]

This comment was marked as outdated.

@fullsend-ai-coder

fullsend-ai-coder Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Finished Fix · ✅ Success · Started 9:57 PM UTC · Completed 10:22 PM UTC

Commit: d523510 · View workflow run →

Runtime: claude · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $6.16

Fixes three GitLab role-routing security gaps flagged in review, a
backward-compatibility regression, and updates stale docs:

- checkGitLabApprovalCapability now verifies the token that will
  actually authenticate the approve call matches the selected role's
  own secret value (gitlabroles.ErrIdentityMismatch), instead of
  trusting a FULLSEND_GITLAB_ROLE/STAGE label alone. Also drops the
  redundant harnessRole lookup that read the same env var as agentName.
- applyGitLabRoleSelection now blanks sibling role secrets (and the
  shared FULLSEND_FORGE_TOKEN) that aren't the selected credential, so
  a host-side pre/post-script inheriting the process environment can't
  read another role's raw token and authenticate as that identity.
- childScriptEnv now pins GITLAB_TOKEN, FULLSEND_FORGE_TOKEN, and
  FULLSEND_GITLAB_* vars to the process environment so a harness
  runner_env/env.runner entry cannot override the dispatch-selected
  GitLab identity for a pre/post script. PUSH_TOKEN is deliberately
  left unpinned since the GitHub coder-remint path (#7231) relies on
  runner_env overriding a stale process-env PUSH_TOKEN, and GitLab
  never writes PUSH_TOKEN through that path.
- fullsend run --forge gitlab falls back to its pre-PR no-op when the
  migration gate is disabled/rollback and only FULLSEND_FORGE_TOKEN is
  missing, so a directly-set GITLAB_TOKEN (the documented local-run
  workflow) keeps working instead of hard-failing.
- Updated docs/architecture.md, docs/guides/user/running-agents-locally.md,
  and docs/problems/security-threat-model.md to describe the landed
  job-routing behavior instead of the pre-PR state.

Addresses #7510
@fullsend-ai-coder

Copy link
Copy Markdown
Contributor Author

🔧 Fix agent — iteration 1 (bot-triggered)

Addressed all 8 review findings: fixed the two auth-bypass gaps (approval capability checked against an unverified label instead of the authenticating token; GitLab role-routing env vars overridable via harness runner_env) and the privilege-escalation gap (sibling role secrets left in the process environment) with targeted checks and env clearing/pinning in internal/cli/gitlab_role.go and internal/cli/run.go; restored pre-PR no-op fallback behavior for fullsend run --forge gitlab when only the shared credential is unprovisioned in disabled/rollback mode; dropped a redundant env lookup; and updated three docs files to reflect that GitLab job routing has landed. Recorded one partial disagreement: PUSH_TOKEN is intentionally left out of the new pin list to avoid breaking the existing GitHub coder-remint mechanism (#7231), since GitLab never uses that override path anyway.

Fixed (8):

  1. auth-bypass: gitlab_role.go:136 checked approve_merge_request against a label, not the token that actually authenticates the call (internal/cli/gitlab_role.go): checkGitLabApprovalCapability now takes the token post-review will actually use (the --token flag, falling back to GITLAB_TOKEN) and compares it against getenv(sel.Source.SecretName) after SelectAgent; a mismatch fails closed with the new gitlabroles.ErrIdentityMismatch sentinel before the capability check ever runs. Updated the call site in postreview.go and all affected unit tests in gitlab_role_test.go and postreview_test.go, plus added tests covering the match/mismatch/no-token cases.
  2. privilege-escalation: gitlab_role.go:67 left sibling role secrets in the process env for pre/post-scripts to read (internal/cli/gitlab_role.go): Added clearSiblingGitLabRoleSecrets, called from applyGitLabRoleSelection in migrating/enforced mode: it blanks every registered secret in sel.Present that isn't the credential this job selected, leaving only the selected secret and the GITLAB_TOKEN/PUSH_TOKEN aliases the CLI itself exports. Added TestApplyGitLabAgentCredentialsClearsSiblingSecrets to verify siblings are blanked and the selected role's own secret variable is left untouched.
  3. auth-bypass: gitlab_role.go:67 GitLab identity env vars could be overridden for scripts via harness runner_env in childScriptEnv (internal/cli/run.go): childScriptEnv now drops any runner_env entry whose key is GITLAB_TOKEN, FULLSEND_FORGE_TOKEN, or has the FULLSEND_GITLAB_ prefix, so those resolve from the process environment applyGitLabRoleSelection actually set, analogous to oidcDenyKeys stripping. Added TestChildScriptEnv_PinsGitLabRoleRoutingKeys and TestChildScriptEnv_DoesNotPinPushToken to cover both the pin and the deliberate PUSH_TOKEN exception (see disagree entry below).
  4. backward-incompatible: run.go:911 made GitLab run unconditionally require FULLSEND_FORGE_TOKEN, breaking direct GITLAB_TOKEN local runs (internal/cli/run.go): Chose remediation option (a): when applyGitLabAgentCredentials fails with gitlabroles.ErrSharedUnconfigured while the migration mode is disabled/rollback (UsesSharedOnly), runAgent now warns and falls back to the pre-PR no-op, leaving GITLAB_TOKEN/PUSH_TOKEN exactly as the environment set them. Migrating/enforced modes and any other error still fail closed. Added TestRunAgent_GitLabMissingSharedFallsBackWhenDisabled to cover the fallback and confirm a preset GITLAB_TOKEN survives.
  5. incorrect-doc: architecture.md:275 said the role-credential contract 'is not yet the runtime', now false (docs/architecture.md): Updated the open-question bullet to state job routing (Route GitLab jobs and forge operations by registered role identity #7499) has landed for poll/run/post-review, with the shared FULLSEND_FORGE_TOKEN path remaining the default while the gate is unset/disabled/rollback.
  6. incorrect-doc: running-agents-locally.md:336 said the agent just reads a pre-set GITLAB_TOKEN, now requires FULLSEND_FORGE_TOKEN (docs/guides/user/running-agents-locally.md): Updated the paragraph to describe credential resolution through the GitLab role-credential contract, the FULLSEND_FORGE_TOKEN requirement while the gate is unset/disabled/rollback, and per-role token usage once migrating/enforced.
  7. documentation-cross-reference: security-threat-model.md:124 'No self-approval' bullet omits the new approve_merge_request check for migrating/enforced (docs/problems/security-threat-model.md): Added a qualifier scoping the shared-PAT workaround to the disabled/rollback gate states, and a sentence pointing to the GitLab role-credential contract's approve_merge_request check for migrating/enforced, where Coder is structurally denied the approve call.
  8. code-clarity: gitlab_role.go:140 harnessRole read the same env var as agentName, a redundant lookup (internal/cli/gitlab_role.go): Dropped the redundant harnessRole lookup in checkGitLabApprovalCapability; SelectAgent is now called with agentName for both parameters, matching the fact the two locals always held the same value.

Disagreed (1):

  1. auth-bypass remediation asked to also pin PUSH_TOKEN against runner_env overrides in childScriptEnv: PUSH_TOKEN is shared across both forges, and the GitHub coder-remint path (syncRunnerEnvTokens, Code agent's 60-minute budget equals the GitHub App token lifetime; post-script cannot push on full-budget runs #7231, run.go ~line 5379) intentionally relies on runner_env overriding a stale process-env PUSH_TOKEN so a post-script gets the freshly reminted token; pinning PUSH_TOKEN in childScriptEnv would silently reintroduce Code agent's 60-minute budget equals the GitHub App token lifetime; post-script cannot push on full-budget runs #7231 for GitHub runs. GitLab never writes PUSH_TOKEN through that remint path (remintAgentTokenForPostScript no-ops when forgePlatform == "gitlab"), so pinning GITLAB_TOKEN plus the FULLSEND_GITLAB_*/FULLSEND_FORGE_TOKEN vars closes the GitLab-specific gap the finding describes without touching PUSH_TOKEN's cross-forge semantics. Left a comment on isPinnedGitLabRoleRoutingKey documenting this and added TestChildScriptEnv_DoesNotPinPushToken to lock in the GitHub behavior.

Tests: passed

Decision points
  • For the run.go:911 backward-incompatible finding, chose to restore the pre-PR no-op fallback (option a) rather than marking the change as breaking with a ! suffix (option b) (alternatives: Mark the PR as a breaking change (feat(Route GitLab jobs and forge operations by registered role identity #7499)!:) and update running-agents-locally.md to require FULLSEND_FORGE_TOKEN unconditionally, Restore the pre-PR no-op when the shared-only gate is active and only FULLSEND_FORGE_TOKEN is missing, preserving a directly-set GITLAB_TOKEN; rationale: The PR's own description states existing installations should stay on the shared FULLSEND_FORGE_TOKEN path unchanged; a hard failure for a workflow the docs still described as supported contradicts that stated goal, so restoring compatibility is the smaller, more conservative fix and avoids forcing a breaking-change relabel of an otherwise additive PR.)
  • Excluded PUSH_TOKEN from the childScriptEnv pin list for GitLab role-routing keys (alternatives: Pin PUSH_TOKEN unconditionally as the finding listed it, Pin PUSH_TOKEN only when forgePlatform == gitlab (requires threading forgePlatform into childScriptEnv/postScriptEnv call sites), Leave PUSH_TOKEN unpinned and document why; rationale: Threading forgePlatform through every childScriptEnv call site was a larger, riskier change than the finding's own severity (rated lower/defense-in-depth, operator-trusted content only) warranted; leaving PUSH_TOKEN unpinned preserves the well-tested Code agent's 60-minute budget equals the GitHub App token lifetime; post-script cannot push on full-budget runs #7231 GitHub remint behavior while still closing the GitLab-specific identity/credential pinning gap for every other affected key.)

Next steps:

  • /fs-review — request a re-review of the changes
  • /fs-fix <your instruction> — run another fix pass with specific guidance
  • Push commits directly — review re-runs automatically on push
    Updated by fullsend fix agent

@fullsend-ai-review

fullsend-ai-review Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 10:24 PM UTC · Completed 10:45 PM UTC

Commit: 5a928b8 · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $10.06

fullsend-ai-review[bot]

This comment was marked as outdated.

fullsend-ai-review[bot]

This comment was marked as outdated.

@fullsend-ai-coder

fullsend-ai-coder Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Finished Fix · ✅ Success · Started 10:47 PM UTC · Completed 10:55 PM UTC

Commit: 5a928b8 · View workflow run →

Runtime: claude · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $1.45

- running-agents-locally.md / cli/run.md: document that a directly-set
  GITLAB_TOKEN still works as a fallback when FULLSEND_FORGE_TOKEN is
  absent in unset/disabled/rollback mode (matches run.go's
  UsesSharedOnly + ErrSharedUnconfigured fallback); only
  migrating/enforced strictly require the per-role secret.
- security-threat-model.md: qualify the "distinct per-role credentials"
  claim -- migrating mode can still fall back to the shared token for an
  unconfigured role, though approve_merge_request denial for Coder still
  holds because it resolves from role identity, not the backing secret.
- gitlab-role-credentials.md: move the FailedSecret bullet off
  Select/SelectAgent (which never populate it) and describe it against
  Resolve/Request and the AuthFailed fail-closed pattern instead.

Addresses #7510
@fullsend-ai-coder

Copy link
Copy Markdown
Contributor Author

🔧 Fix agent — iteration 2 (bot-triggered)

Verified all three re-review findings (one medium, two low, all category incorrect-doc) against the current code in run.go, gitlabroles.go, and route.go, confirmed each was accurate, and corrected the four affected doc files with minimal, targeted wording changes. No code changes were needed or made.

Fixed (4):

  1. incorrect-doc: running-agents-locally.md:336 wrongly claims GITLAB_TOKEN alone no longer works, contradicting run.go's shared-token fallback (docs/guides/user/running-agents-locally.md): Reworded the GitLab section to state FULLSEND_FORGE_TOKEN is preferred and exported to GITLAB_TOKEN in unset/disabled/rollback mode, but a directly-set GITLAB_TOKEN still works as a fallback (with a warning logged) when FULLSEND_FORGE_TOKEN is absent; only migrating/enforced strictly require the matching per-role secret.
  2. incorrect-doc: docs/cli/run.md's GitLab role identity section omits the same GITLAB_TOKEN fallback (docs/cli/run.md): Added a sentence to the gate unset/disabled/rollback bullet noting that a directly-set GITLAB_TOKEN is still used as a fallback (with a warning logged) when FULLSEND_FORGE_TOKEN is absent.
  3. incorrect-doc: security-threat-model.md:124 overstates that Analyst/Coder always use distinct credentials once migrating/enforced (docs/problems/security-threat-model.md): Qualified the claim: distinct per-role credentials apply once role secrets are provisioned (always true in enforced; in migrating, only for roles whose secret is already configured, since an unconfigured role may still fall back to the shared token). Clarified Coder is still structurally denied the approve call during that fallback because the capability check resolves from role identity, not the backing secret.
  4. incorrect-doc: gitlab-role-credentials.md:243 wrongly lists FailedSecret as an input Select/SelectAgent populate (docs/contributing/gitlab-role-credentials.md): Removed the FailedSecret bullet from the Select/SelectAgent input list and added a paragraph explaining FailedSecret only matters for a caller-constructed Request passed directly to Resolve, describing the actual AuthFailed/wrapGitLabAuthFailure fail-closed pattern used by fullsend poll instead.

Tests: passed

Next steps:

  • /fs-review — request a re-review of the changes
  • /fs-fix <your instruction> — run another fix pass with specific guidance
  • Push commits directly — review re-runs automatically on push
    Updated by fullsend fix agent

@fullsend-ai-review

fullsend-ai-review Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

🤖 Finished Review · ✅ Success · Started 10:57 PM UTC · Completed 11:17 PM UTC

Commit: 0d2edd1 · View workflow run →

Runtime: pi · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $8.12

fullsend-ai-review[bot]

This comment was marked as outdated.

@fullsend-ai-coder

fullsend-ai-coder Bot commented Sep 20, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 Finished Fix · ✅ Success · Started 11:19 PM UTC · Completed 11:24 PM UTC

Commit: 0d2edd1 · View workflow run →

Runtime: claude · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $0.70

The GitLab section of running-agents-locally.md said the shared-token
fallback no longer applies once the gate is migrating or enforced.
That is only true for enforced mode: in migrating mode, the resolver
still falls back to FULLSEND_FORGE_TOKEN when a role's own secret is
unconfigured, per the AllowsSharedFallback mode check which covers
migrating only. Clarify that distinction, and note separately that
the unmanaged fallback to a directly-set GITLAB_TOKEN no longer
applies in either migrating or enforced mode.

Addresses #7510
@fullsend-ai-review
fullsend-ai-review Bot dismissed stale reviews from themself September 20, 2026 23:40

Superseded by updated review

@fullsend-ai-review fullsend-ai-review Bot added the ready-for-merge All reviewers approved — ready to merge label Sep 20, 2026
@ggallen
ggallen added this pull request to the merge queue Sep 21, 2026
Merged via the queue into main with commit 465f437 Sep 21, 2026
54 checks passed
@ggallen
ggallen deleted the agent/7499-gitlab-role-routing branch September 21, 2026 00:51
@fullsend-ai-retro

fullsend-ai-retro Bot commented Sep 21, 2026 •

Copy link
Copy Markdown

🤖 Finished Retro · ✅ Success · Started 12:53 AM UTC · Completed 1:01 AM UTC

Commit: f3a7266 · View workflow run →

Runtime: claude · Model: sonnet → claude-sonnet-5 · Effort: high · Cost: $1.59

@fullsend-ai-retro

Copy link
Copy Markdown

PR #7510 ("route GitLab jobs by registered role identity", stage 3 of the #7496 GitLab role-identity rollout) went through 4 review rounds over ~1h45m before human approval and merge. Round 1 (fullsend-ai/agents review agent) caught three real security gaps in the code agent's first commit — a capability check that trusted role labels instead of the actual authenticating token identity, sibling role secrets left un-blanked in the process environment after role selection (privilege-escalation risk via inherited env in pre/post-scripts), and role-routing env vars left unprotected against override by harness runner_env config — plus a backward-compatibility regression (local GITLAB_TOKEN-only runs would now hard-fail) and stale docs. The fix agent corrected all of this correctly in a single commit. Rounds 2 and 3, however, were pure documentation-precision churn: each doc fix to docs/guides/user/running-agents-locally.md, describing which auth modes (disabled/rollback vs. migrating vs. enforced) allow falling back to the shared token, introduced a new narrower inaccuracy that the review agent caught and the next commit corrected, taking three total attempts to state one conditional/mode-gated behavior correctly. The only human involvement was a content-free final approval from ggallen after the bot's own approval — consistent with genuine agreement, not a gap in review, since the bot's review substance (all findings, all remediation guidance) was thorough across all four rounds. I found no evidence the review agent missed anything a human caught. Related but non-duplicate open issues already track general doc-accuracy/fact-checking gaps in review (fullsend-ai/agents #265, #579, #895, #727; fullsend-ai/fullsend #5297, #2199) and a sibling secret-masking gap on the same PR family (#7509); none of them address the write-side technique proposed below (deriving a state/mode truth table before writing prose about conditional behavior), so I filed it as a narrower, distinct proposal. Two remaining rollout stages (#7500 rotation/recovery, #7501 verify/retire shared-token fallback) will touch the same credential-routing code, so a checklist derived from round 1's findings is proposed to help those land clean on the first review pass.

Proposals filed

fullsend-ai-coder Bot added a commit that referenced this pull request Sep 21, 2026
The checklist intro said the terminology rule (added in #7513) was
part of "the review findings from PR #7510" and could be "reintroduced"
by a routing-code change, which only makes sense for the four code
invariants. Scope "They"/"any of them" to those four and attribute the
terminology rule to #7513 separately.

Addresses #7515
guyoron1 pushed a commit to guyoron1/fullsend that referenced this pull request Sep 21, 2026
Capture the four review findings from PR fullsend-ai#7510 as a checklist in the
existing GitLab role-credential contract so remaining rollout stages
(fullsend-ai#7500 rotation, fullsend-ai#7501 shared-token retirement) hold the same
invariants: check the authenticating token not a role label, blank
sibling secrets after selection, pin routing env vars against
runner_env override, and preserve disabled/rollback GITLAB_TOKEN
fallback unless the change is marked breaking.

Place the checklist in docs/contributing/gitlab-role-credentials.md
rather than a new file, keeping this topic single-sourced. Point
AGENTS.md's topic table at the checklist so later code-agent runs
pick it up as repo-specific context.

Note: pre-commit could not fetch remote hook repos (HTTP 403).
Local equivalents were run: trailing-whitespace, eof, gitleaks,
lint-docs-links, lychee, and lint-broken-symlinks. make lint is
pre-commit run and could not complete for the same reason.

Closes fullsend-ai#7511
ggallen added a commit that referenced this pull request Sep 21, 2026
Document the shared-token and local direct-GITLAB_TOKEN fallbacks with fixed terminology, list the four related documents, and require synchronized updates across them. Scope the checklist provenance to the four PR #7510 code invariants and attribute the terminology rule to #7513.

Signed-off-by: Greg Allen <gallen@redhat.com>
ggallen added a commit that referenced this pull request Sep 21, 2026
Document the shared-token and local direct-GITLAB_TOKEN fallbacks with fixed terminology, list the four related documents, and require synchronized updates across them. Scope the checklist provenance to the four PR #7510 code invariants and attribute the terminology rule to #7513.

Signed-off-by: Greg Allen <gallen@redhat.com>
Signed-off-by: Codex <noreply@openai.com>

This branch was successfully deployed

1 active and 1 inactive deployments
site-preview — f3a72660 Deployed Sep 20, 2026 by github-actions[bot]
dev — f3a72660 Deployed Sep 20, 2026 by fullsend-ai-coder[bot] via behaviour #13366
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-merge All reviewers approved — ready to merge ready-for-review Triggers review agent dispatch risk/moderate PR risk: moderate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Route GitLab jobs and forge operations by registered role identity

1 participant