Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/cli/repos.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ Requires a GitHub token via `GH_TOKEN`, `GITHUB_TOKEN`, or `gh auth token`. For

Tear down fullsend from the specified repos and remove them from the manifest. By default, the command tears down first (opening a PR to remove workflow files, then deleting variables and secrets via the API), then removes successfully-torn-down repos from the manifest. Partial failures leave the manifest entry intact so the user can retry.

File deletions (workflow YAML, `.fullsend/config.yaml`, and GitLab `.gitlab-ci.yml` unmerge) are delivered as a pull request unless `--direct` is set, matching `repos install`. Variable and secret deletions are API-only operations and always happen immediately. For GitLab repos, uninstall also deletes the `fullsend-poll-state-slash` and `fullsend-poll-state-events` branches (a missing branch is ignored so older installs still uninstall cleanly) while continuing to delete the retired poll-state CI/CD variables, the role-credential gate/registry/rotation-state variables, built-in and custom `FULLSEND_GITLAB_*_TOKEN` secrets, leftover `FULLSEND_FORGE_TOKEN`, and the corresponding `fullsend-bot` / `fullsend-poller` / `fullsend-analyst` / `fullsend-coder` / `fullsend-role-*` project access tokens. Token revocation is part of uninstall success: if listing or revoking those project access tokens fails, uninstall fails and the manifest entry is left in place for retry. Reinstall and converge do not revoke credentials that are already distributed.
File deletions (workflow YAML, `.fullsend/config.yaml`, and GitLab `.gitlab-ci.yml` unmerge) are delivered as a pull request unless `--direct` is set, matching `repos install`. Variable and secret deletions are API-only operations and always happen immediately. For GitLab repos, uninstall also deletes the `fullsend-poll-state-slash` and `fullsend-poll-state-events` branches (a missing branch is ignored so older installs still uninstall cleanly) while continuing to delete the retired poll-state CI/CD variables, the historical migration variable, registry/rotation-state variables, built-in and custom `FULLSEND_GITLAB_*_TOKEN` secrets, leftover `FULLSEND_FORGE_TOKEN`, and the corresponding `fullsend-bot` / `fullsend-poller` / `fullsend-analyst` / `fullsend-coder` / `fullsend-role-*` project access tokens. Token revocation is part of uninstall success: if listing or revoking those project access tokens fails, uninstall fails and the manifest entry is left in place for retry. Reinstall and converge do not revoke credentials that are already distributed.

Uninstall PR delivery intentionally reuses the same branch as `repos install`/`converge` (`fullsend/scaffold-install`), since already-deployed per-repo shims only exclude that branch name from dispatch. **Known limitation:** if an install PR is still open on that branch when uninstall runs (or an uninstall PR is open when install/converge runs), the existing PR is updated with the new commit but its title and body are left unchanged — the PR may show an install-oriented title while its diff now removes files, or vice versa. Check the PR's diff, not just its title, before merging when install and uninstall run close together against the same repo.

Expand Down
15 changes: 7 additions & 8 deletions docs/contributing/gitlab-role-credentials.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ three-role enum.
`fullsend run` select the registered role credential via
`gitlabroles.Select` / `SelectAgent` and fail closed if that secret is
missing. There is no shared-token fallback. The historical
`FULLSEND_GITLAB_ROLE_MIGRATION` variable is ignored by runtime and install;
existing installations are converged through role provisioning. Custom roles
remain optional on existing installations.
`FULLSEND_GITLAB_ROLE_MIGRATION` variable is not part of the runtime or
install contract. It is retained only as uninstall cleanup state. Custom
roles remain optional on existing installations.

## Registered roles

Expand Down Expand Up @@ -234,7 +234,7 @@ build — it stays at its zero value. `FailedSecret` only matters when a
caller constructs a `Request` directly and calls `Resolve` after an
authentication failure. `fullsend poll`'s `wrapGitLabAuthFailure` uses the
`AuthFailed` helper for this instead of re-resolving: on a 401/403, it
wraps the error with `gitlabroles.AuthFailed(role, mode, secret)` rather
wraps the error with `gitlabroles.AuthFailed(role, secret)` rather
than calling `Select`/`SelectAgent`/`Resolve` again for that job. Per
`AuthFailed`'s doc comment, callers must fail closed on an authentication
failure, not re-Select with a different job or a cleared `FailedSecret`.
Expand Down Expand Up @@ -320,7 +320,6 @@ These are different errors. Do not collapse them.
| --- | --- | --- |
| Role name is not in the registry | `ErrUnregistered` | Custom agent referenced an unknown identity |
| Role secret absent or empty | `ErrUnconfigured` | Registered, not provisioned yet |
| Shared secret absent (leftover Token() of a constructed shared Source) | `ErrSharedUnconfigured` | Legacy sentinel; Resolve never returns it |
| Runtime 401/403 (or equivalent) from a selected credential | `ErrAuthFailed` | Credential is present but unusable |
| Job kind is empty or unrecognized | `ErrUnknownJob` | No identity to select |
| Registry JSON is malformed or untrusted | `ErrInvalidRegistry` | Fail closed; do not load custom roles |
Expand All @@ -343,7 +342,7 @@ job or a cleared `FailedSecret` in order to pick a substitute.

## Status, drift, and diagnostics

`gitlabroles.Diagnose(mode, present, registry)` is the observable
`gitlabroles.Diagnose(present, registry)` is the observable
report:

- Per-role state: `configured` or `unconfigured` (presence only),
Expand Down Expand Up @@ -524,7 +523,7 @@ Leave these to the follow-up issues.
| Issue | Work |
| --- | --- |
| [#7498](https://github.com/fullsend-ai/fullsend/issues/7498) | **Implemented.** `repos install` creates/enrolls built-in and custom PATs, stores them as protected masked CI variables, writes the registry, reports partial provisioning, preserves the shared token, and handles reinstall/drift/uninstall without deleting credentials still in use |
| [#7499](https://github.com/fullsend-ai/fullsend/issues/7499) | **Implemented.** `fullsend poll`, `fullsend run`, and `fullsend post-review` select the registered role credential, enforce `ValidateAgent` / `Registration.Has` in role-aware modes, and fail closed on authentication failure without switching identities |
| [#7499](https://github.com/fullsend-ai/fullsend/issues/7499) | **Implemented.** `fullsend poll`, `fullsend run`, and `fullsend post-review` select the registered role credential, enforce `ValidateAgent` / `Registration.Has`, and fail closed on authentication failure without switching identities |
| [#7500](https://github.com/fullsend-ai/fullsend/issues/7500) | **Implemented.** Role-aware rotation, recovery, in-flight overlap, and expiry/revocation diagnostics. See [Rotation and recovery](#rotation-and-recovery) and follow the [credential-routing security checklist](#credential-routing-security-checklist) |
| [#7501](https://github.com/fullsend-ai/fullsend/issues/7501) | **Implemented.** Built-in and registered-role readiness is surfaced on `repos status`, and ready installs retire the legacy shared-token secret. Live GitLab ACL/operation probes and deployment branch-rule verification remain deployment prerequisites. |
| [#7524](https://github.com/fullsend-ai/fullsend/issues/7524) | **Implemented.** Ordinary `repos install` provisions role credentials and retires the legacy shared credential when readiness checks pass. Partial enrollment defers retirement and runtime remains fail-closed. |
Expand Down Expand Up @@ -611,7 +610,7 @@ Ordinary `repos install` still retires leftover `FULLSEND_FORGE_TOKEN`
after role checks pass.

- [ ] Runtime `Select` / `SelectAgent` / `Resolve` never return
`Source.Shared` or `FULLSEND_FORGE_TOKEN`.
`FULLSEND_FORGE_TOKEN`.
- [ ] Missing role secrets fail closed as `ErrUnconfigured`.

### Keep fallback terminology consistent across docs
Expand Down
10 changes: 8 additions & 2 deletions internal/cli/gitlab_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func applyGitLabRoleSelection(sel gitlabroles.Selection, token string, setenv fu
}

// clearSiblingGitLabRoleSecrets blanks every registered role secret (and
// the shared FULLSEND_FORGE_TOKEN) that sel.Present reports as configured
// a legacy shared token) that sel.Present reports as configured
// but that is not the credential this job selected. Without this, a
// sibling secret such as FULLSEND_GITLAB_ANALYST_TOKEN remains sitting in
// the process environment after a Coder job selects its own token; a
Expand All @@ -90,6 +90,12 @@ func applyGitLabRoleSelection(sel gitlabroles.Selection, token string, setenv fu
// entirely — that check only runs inside `fullsend post-review` itself, not
// for arbitrary script code reading a raw CI/CD variable (see PR #7510).
func clearSiblingGitLabRoleSecrets(sel gitlabroles.Selection, setenv func(string, string)) {
// The legacy shared credential is not part of PresenceFrom, but it can
// still be inherited from the caller's environment. Never expose it to
// child scripts after role selection.
if sel.Source.SecretName != forge.SecretForgeToken {
setenv(forge.SecretForgeToken, "")
}
for name, present := range sel.Present {
if !present || name == sel.Source.SecretName {
continue
Expand Down Expand Up @@ -125,7 +131,7 @@ func wrapGitLabAuthFailure(sel gitlabroles.Selection, err error) error {
if err == nil || !isGitLabAuthFailure(err) {
return err
}
return fmt.Errorf("%w: %w", gitlabroles.AuthFailed(sel.Source.Role, sel.Mode, sel.Source.SecretName), err)
return fmt.Errorf("%w: %w", gitlabroles.AuthFailed(sel.Source.Role, sel.Source.SecretName), err)
}

// checkGitLabApprovalCapability rejects GitLab APPROVE reviews when the
Expand Down
3 changes: 0 additions & 3 deletions internal/cli/gitlab_role_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func TestResolveGitLabPollerCredentialMissingRoleFailsClosed(t *testing.T) {
_, _, err := resolveGitLabPollerCredential(mapGetenv(map[string]string{forge.SecretForgeToken: "glpat-SHARED"}))
require.Error(t, err)
assert.ErrorIs(t, err, gitlabroles.ErrUnconfigured)
assert.NotErrorIs(t, err, gitlabroles.ErrSharedUnconfigured)
assert.Contains(t, err.Error(), forge.SecretGitLabPollerToken)
}

Expand Down Expand Up @@ -317,7 +316,6 @@ func TestCheckGitLabApprovalCapability(t *testing.T) {
func TestWrapGitLabAuthFailureDoesNotSwitchIdentity(t *testing.T) {
t.Parallel()
sel := gitlabroles.Selection{
Mode: gitlabroles.ModeMigrating,
Source: gitlabroles.Source{
Role: gitlabroles.RoleAnalyst,
SecretName: forge.SecretGitLabAnalystToken,
Expand Down Expand Up @@ -364,7 +362,6 @@ func TestApplyGitLabRoleSelectionNilSetenv(t *testing.T) {
t.Setenv(envGitLabRoleSource, "")
t.Setenv("PUSH_TOKEN", "leftover")
sel := gitlabroles.Selection{
Mode: gitlabroles.ModeDisabled,
Source: gitlabroles.Source{
Role: gitlabroles.RolePoller,
SecretName: forge.SecretGitLabPollerToken,
Expand Down
39 changes: 10 additions & 29 deletions internal/cli/repos.go
Original file line number Diff line number Diff line change
Expand Up @@ -362,20 +362,8 @@ func formatRef(currentRef, expectedRef string) string {
}

func showGitLabRoleStatus(s repos.RepoStatus) bool {
if len(s.GitLabRoleDiagnostics) == 0 {
return false
}
switch s.GitLabRoleMode {
case string(gitlabroles.ModeMigrating), string(gitlabroles.ModeRollback), string(gitlabroles.ModeEnforced):
return true
case "":
// appendGitLabRoleStatus leaves GitLabRoleMode empty on a
// parse/read/registry error, but still records a diagnostic.
// Surface it in the table view too, not just JSON output.
return true
default:
return s.GitLabRolesPartial
}
// Surface role-credential diagnostics and parse/read/registry errors.
return len(s.GitLabRoleDiagnostics) > 0
}

func printStatusTable(cmd *cobra.Command, result *repos.StatusResult) {
Expand Down Expand Up @@ -437,7 +425,7 @@ func printStatusTable(cmd *cobra.Command, result *repos.StatusResult) {
if !showGitLabRoleStatus(s) {
continue
}
fmt.Fprintf(out, "\n%s GitLab roles (mode=%s):\n", s.Owner+"/"+s.Repo, s.GitLabRoleMode)
fmt.Fprintf(out, "\n%s GitLab roles:\n", s.Owner+"/"+s.Repo)
for _, d := range s.GitLabRoleDiagnostics {
fmt.Fprintf(out, " %s\n", d)
}
Expand Down Expand Up @@ -988,20 +976,13 @@ func runReposInstall(ctx context.Context, opts *reposInstallConfig) error {
}
}

// GitLab post-install: set up bot token and pipeline schedules for
// repos whose convergence result says an artifact is missing. Entry into
// the loop body is gated on
// NeedsGitLabPostInstall (true when either artifact is missing), but
// the two destructive actions inside are each gated on their own
// specific flag (NeedsGitLabBotToken / NeedsGitLabPipelineSchedules)
// rather than the combined flag — a repo re-run while its
// initialization MR is still open (#7417) keeps Installed true (the
// shim workflow is still absent from the default branch) even though
// some GitLab post-install artifacts already exist from a prior run.
// Running bot-token setup when only the token exists (or schedule
// setup when only the schedules exist) would still revoke/recreate
// the live fullsend-bot PAT or delete/recreate pipeline schedules
// that didn't need it, breaking in-flight pipelines.
// GitLab post-install: set up pipeline schedules for repos whose
// convergence result says they are missing. Entry into the loop body
// is gated on NeedsGitLabPostInstall (true when schedules are missing).
// Schedule setup itself is gated on NeedsGitLabPipelineSchedules so a
// repo re-run while its initialization MR is still open (#7417) does
// not delete and recreate live schedules. Shared-token bot-PAT setup
// was removed: role credentials are the only GitLab runtime path.
// failedRepoKeys tracks owner/repo pairs that have already failed in an
// earlier stage (post-install setup, poll-state provisioning) so the
// role-provisioning pass below can skip them instead of double-counting
Expand Down
12 changes: 4 additions & 8 deletions internal/cli/repos_gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ import (

// setupGitLabBotToken and ensureGitLabSharedCredentialAllowed were
// removed: registered role credentials are now the only supported
// runtime path (#7782 PR2), so `repos install` never provisions the
// shared fullsend-bot PAT (fresh or existing install) and there is no
// migration gate left to consult.
// runtime path (#7782 PR3), so `repos install` never provisions the
// shared fullsend-bot PAT (fresh or existing install).

// provisionGitLabPollState ensures FULLSEND_DISPATCH_SECRET exists so
// poll-state HMAC signing is on by default, then creates both poll-state
Expand Down Expand Up @@ -190,7 +189,6 @@ func annotateGitLabRoleLifecycle(ctx context.Context, clients repos.ForgeClientF
if st.Forge != "" && st.Forge != repos.ForgeGitLab {
continue
}
hasRoleStatus := st.GitLabRoleMode != "" || len(st.GitLabRoleDiagnostics) > 0
toks, listErr := adapter.ListProjectAccessTokens(ctx, st.Owner, st.Repo)
if listErr != nil {
toks = nil
Expand All @@ -201,7 +199,7 @@ func annotateGitLabRoleLifecycle(ctx context.Context, clients repos.ForgeClientF
// gains a GitLab-role lifecycle drift gets double-counted.
wasDrifted := len(st.Drifts) > 0
newlyDrifted := false
if hasRoleStatus && listErr == nil {
if listErr == nil {
newlyDrifted = repos.EnrichGitLabRoleStatus(ctx, fc.Client, st.Owner, st.Repo, toks, now, st)
}
userIDs := repos.PollerPipelineUserIDs(toks)
Expand Down Expand Up @@ -465,7 +463,7 @@ func maybeRetireGitLabSharedCredential(ctx context.Context, opts *reposInstallCo
}
result, err := repos.CutoverGitLabRoleCredentials(ctx, repos.GitLabRoleCutoverConfig{
Owner: owner, Repo: repo, Client: client, TokenInventory: tokens,
DrainConfirmed: true, DryRun: opts.dryRun,
DryRun: opts.dryRun,
})
if err != nil {
if repos.IsGitLabRoleCutoverDeferred(err) {
Expand All @@ -481,7 +479,6 @@ func maybeRetireGitLabSharedCredential(ctx context.Context, opts *reposInstallCo
}

func maybeRotateGitLabRoles(ctx context.Context, opts *reposInstallConfig, client forge.Client, printer *ui.Printer, owner, repo string) error {
mode := gitlabroles.ModeEnforced
registryJSON := opts.gitlabRoleRegistryJSON
if registryJSON == "" {
live, liveExists, liveErr := client.GetRepoVariable(ctx, owner, repo, forge.VarGitLabRoleRegistry)
Expand Down Expand Up @@ -517,7 +514,6 @@ func maybeRotateGitLabRoles(ctx context.Context, opts *reposInstallConfig, clien
Client: client,
Tokens: tokens,
Registry: reg,
Mode: mode,
Roles: opts.rotateGitLabRoleFilter,
Force: opts.rotateGitLabRoles,
ProvidedTokens: opts.gitlabRoleProvided,
Expand Down
Loading
Loading