background-agents icon indicating copy to clipboard operation
background-agents copied to clipboard

GitLab integration: remaining gaps for production readiness

Open ColeMurray opened this issue 8 months ago • 2 comments

Summary

The GitLab integration backend is substantially complete, but several gaps remain before it's production-ready. The primary blocker is web authentication — there's no GitLab OAuth flow, so users can't log in to a GitLab-configured deployment.

What's Done

  • Provider abstraction — SourceControlProvider interface, factory, config resolver all support GitLab
  • GitLab provider (gitlab-provider.ts) — fully implemented with PAT auth: repos, branches, merge requests, push auth, clone URLs
  • Tests — comprehensive test coverage for all provider methods + state mapping
  • Modal data plane — clone token routing and VCS env var injection handle SCM_PROVIDER=gitlab
  • Sandbox runtime — uses generic VCS_HOST/VCS_CLONE_USERNAME/VCS_CLONE_TOKEN, works for GitLab automatically
  • Web URL utilities — getScmRepoUrl/getScmBranchUrl are provider-aware
  • Documentation — ADR, provider checklist, env var docs all in place
  • Route wiring — GITLAB_ACCESS_TOKEN and GITLAB_NAMESPACE read from env and passed to provider

Remaining Gaps

Blocking

  • [ ] No GitLab OAuth login — packages/web/src/lib/auth.ts is hardcoded to GitHubProvider from next-auth. Need to add a GitLab OAuth provider and make the login flow provider-aware.
  • [ ] "Sign in with GitHub" UI — packages/web/src/components/sidebar-layout.tsx has signIn("github") hardcoded. Login button text and provider must be dynamic based on NEXT_PUBLIC_SCM_PROVIDER.

Cosmetic / Minor

  • [ ] "View in GitHub" label — packages/web/src/components/action-bar.tsx still shows GitHub-specific text in the PR dropdown.
  • [ ] Avatar URLs — packages/control-plane/src/session/participant-service.ts getAvatarUrl() returns undefined for GitLab users (only generates GitHub avatar URLs).
  • [ ] JWT field naming — auth.ts uses githubUserId/githubLogin field names in the JWT, which is misleading for GitLab deployments.

Feature Gaps

  • [ ] Reviewer assignment — gitlab-provider.ts logs a console.warn because GitLab requires numeric reviewer_ids (username→ID resolution not implemented).
  • [ ] Self-hosted GitLab — GITLAB_API_BASE is hardcoded to https://gitlab.com/api/v4. No support for self-hosted instances.

Operational Gaps

  • [ ] Terraform variables — No GITLAB_ACCESS_TOKEN, GITLAB_NAMESPACE, or SCM_PROVIDER variables in terraform/environments/production/. Must be set manually in Modal secrets.
  • [ ] Modal still requires GitHub App secrets — packages/modal-infra/src/app.py has github_app_secrets as a required Modal secret even for GitLab-only deployments. GitLab deployments need dummy GitHub App secrets to pass validation.

Suggested Priority

  1. GitLab OAuth login + provider-aware sign-in UI (unblocks GitLab deployments)
  2. Cosmetic fixes ("View in GitHub", avatars, JWT field names)
  3. Terraform variable support
  4. Decouple Modal from GitHub App secrets requirement
  5. Self-hosted GitLab + reviewer assignment (future enhancements)

ColeMurray avatar Apr 03 '26 06:04 ColeMurray

@duboff few remaining pieces to get this operational

ColeMurray avatar Apr 08 '26 06:04 ColeMurray

Reviewed current main at 6fbb915.

Current state

GitLab support is not production-ready. The provider and low-level sandbox credential plumbing are substantial, but the production router currently rejects nearly every GitLab-dependent route with 501, including the normal repository, session creation, and MR flows. GitLab OAuth and deploy-time configuration are also still absent.

Of the issue’s 9 explicit remaining gaps:

  • Resolved/obsolete: 1 (githubUserId / githubLogin JWT naming; auth has moved to Better Auth with generic provider identities)
  • Partially improved but incomplete: 1 (sign-in UI is dynamically driven by enabled auth providers, but GitLab is not a supported auth provider)
  • Still open: 7

Completed

  • Provider abstraction, deployment resolver, and factory support gitlab.
  • PAT-backed GitLab provider implements repository lookup/access, repository and branch listing, MR creation/state mapping, nested namespaces, push credentials, and manual MR/push URLs.
  • Modal selects GITLAB_ACCESS_TOKEN for SCM_PROVIDER=gitlab and injects generic VCS_HOST / VCS_CLONE_USERNAME / VCS_CLONE_TOKEN.
  • Sandbox runtime scopes git credentials to the configured VCS host.
  • Web repository and branch URL helpers support GitLab and nested namespaces.
  • /sessions/:id/scm-credentials is explicitly enabled for GitLab.
  • Unit coverage for these low-level paths is strong.

Original gaps

  • GitLab OAuth: open/blocking. Shared auth types only permit GitHub and Google (source); Better Auth also configures only those providers (source, source).
  • Provider-aware sign-in UI: partial. The UI now discovers enabled providers rather than hardcoding signIn("github"), but GitLab cannot be returned or rendered because the shared provider union excludes it. A GitLab SCM deployment therefore still advertises GitHub/Google auth, not GitLab auth.
  • “View in GitHub”: open. The overflow action still uses the GitHub icon and label (source).
  • GitLab avatars: open. The avatar helper only handles GitHub (source). Persisting the OAuth profile avatar would be more robust than synthesizing a GitLab URL, especially for self-hosted instances.
  • JWT field naming: resolved/obsolete. Current auth uses generic Better Auth account fields (provider, provider_user_id, user_id) rather than the old GitHub-specific JWT fields (source).
  • Reviewer assignment: open. Reviewers are explicitly warned about and ignored because username-to-ID resolution is not implemented (source).
  • Self-hosted GitLab: open. API, web, clone, and runtime hosts are hardcoded to gitlab.com; this needs coordinated API/web/clone/OAuth configuration, not only GITLAB_API_BASE.
  • Terraform wiring: open/blocking. There are no Terraform occurrences of SCM_PROVIDER, GITLAB_ACCESS_TOKEN, GITLAB_NAMESPACE, NEXT_PUBLIC_SCM_PROVIDER, or GITLAB_API_BASE. The control plane, Modal runtime, and web build can therefore drift and default to GitHub.
  • Modal GitHub App dependency: open. Terraform always creates a github-app secret (source), and Modal declares all GitHub App keys as required (source).

Additional gaps found

  1. Production router gate is the largest blocker. For GitLab, only /sessions/:id/scm-credentials is treated as implemented; other non-public/non-agnostic routes return 501 (source). This blocks GET /repos, branch listing, POST /sessions, and POST /sessions/:id/pr, making much of the provider implementation unreachable through normal production requests. Existing router tests intentionally assert this behavior.
  2. OAuth alone would not complete user-authenticated GitLab sessions. Session identity/token enrichment is GitHub-only (source). GitLab needs account selection, token enrichment/refresh, participant persistence, and MR attribution paths.
  3. No GitLab pagination. Repository and branch calls request per_page=100 once and do not follow X-Next-Page/Link headers (source, source). Deployments with more than 100 projects or branches silently get incomplete data.
  4. Provider-specific leftovers remain. Non-GitHub git author fallback still uses [email protected]; some errors mention GitHub App installation; automation/webhook surfaces and the installed agent CLI remain GitHub-specific (github_event, GitHub bot, gh, with no GitLab webhook/bot or glab equivalent). These should either be generalized or documented as unsupported.
  5. Repository cache is not provider-scoped. Switching a deployment’s SCM provider can temporarily serve stale repository data from the previous provider.
  6. Documentation overstates deployability. The README says the GitLab variables are configured through Terraform, but Terraform does not define them, while the ADR implies GitLab is implemented even though the production gate rejects its main routes.

Recommended completion order

  1. Define one Terraform-backed SCM configuration and propagate it consistently to control plane, Modal, and the web build; make GitHub App secrets conditional.
  2. Implement GitLab OAuth plus canonical identity/token enrichment and refresh.
  3. Enable and integration-test the GitLab router paths end to end: repos, branches, session creation, sandbox clone/push, and MR creation.
  4. Add pagination, provider-neutral UI/errors/identity fallbacks, and GitLab avatar persistence.
  5. Add reviewer resolution and self-hosted GitLab support as explicit follow-ups if they are not required for the first production milestone.

Validation

Targeted tests on current main passed:

  • Control plane: 3 files, 88 tests
  • Web: 3 files, 22 tests
  • Modal: 34 tests

These verify the implemented low-level pieces, but no current end-to-end test proves a Terraform-deployed GitLab instance can authenticate, create a session, clone/push, and open an MR.

open-inspect avatar Aug 09 '26 06:08 open-inspect