Existing issue
- I have searched the existing issues and found no duplicate.
Related but not duplicates: #75 (first-class GitLab, which mentions self-hosted instances), #1871 (GitLab.com connections, which left self-managed instances out of scope), #624 (persist the clone URL).
Problem or use case
Since 1.0.2 a workspace can connect GitLab.com, but not a self-managed GitLab instance. docs/git-providers.md says so explicitly ("Self-managed GitLab origins are outside this adapter"), and the API origin is fixed in packages/platform/src/engine/modules/gitlab/client.ts:
const url = new URL("https://gitlab.com/api/v4/" + path);People who self-host OpenShip often self-host their Git server too. Today their only options are to mirror every repository to GitHub or GitLab.com, or to deploy by folder upload and lose push-to-deploy. TODO.md already notes that self-managed is "the harder half and the one operators actually ask for".
Proposed solution
Let a GitLab connection carry its own instance URL, and use it everywhere the adapter currently assumes gitlab.com. Scope for a first PR: access-token connections only (personal, group or project token), with browsing, stack detection, private clone and signed push deployments. Same product surface as GitLab.com, no new provider.
Connection (Settings → Git → GitLab, and the New Project picker)
- Add an optional GitLab URL field to the GitLab connection form, using the existing credential
selector(the mechanismdocker-registryalready uses for "Registry host"). Empty means GitLab.com, so existing connections are unchanged and need no migration. - The saved connection row shows the host next to the account, as registry connections do.
- "Create token on GitLab" opens the token page of the host that was typed.
- The field is schema-driven, so it renders in the shared
CredentialFormin both places. New strings go in all ten locales.
Adapter
gitlabRequesttakes the connection's origin instead of the constant.verifyGitLabToken,gitlabCredentials,projectConnection, the repository reader and the webhook registration thread it through.- A token is only ever sent to the host it was saved for. Today every GitLab token of the workspace is tried against one host; with several hosts, credentials are selected by origin first.
cloneUrland the clone-origin guard ingit/providers/gitlab.tscompare against the connection's origin instead of the default one.git-clone.tsalready pins the credential helper to the URL's host; it only needs theoauth2username for GitLab origins other thangitlab.com.
Which host a project belongs to
A project stores gitProvider, gitOwner, gitRepo and gitUrl, with no host. I would make project.gitUrl the source of truth for the origin of GitLab projects (in line with #624) and stop re-deriving it from webBaseUrl. That avoids a schema change. If you would rather have an explicit column or bind the project to the credential id, tell me and I will do that instead.
Webhooks
- Registration is unchanged apart from the host: a project hook with
signing_token, delivered to the same/api/webhooks/gitlabendpoint. - Matching currently uses
(provider, namespace, name)fromproject.path_with_namespace. The same path can exist on two instances, so the lookup and the hook key scope should also include the origin, taken from the project binding and checked againstproject.web_urlin the payload. The per-project signing key still authenticates the delivery. signing_tokenexists from GitLab 19.0 (behind a flag, generally available in 19.1). For older instances I would not fall back to the plainX-Gitlab-Tokenheader: verification readsGET /version, and Auto Deploy reports that it needs GitLab 19.1 or newer while browsing, cloning and manual deploys keep working.
Outbound requests
A user-supplied host is an SSRF surface, so requests to a custom origin would go through the existing safeFetch with the same policy the registry verifier uses (allowHttp and allowPrivate only when not in Cloud mode), no redirects, and the current response-size cap. URL normalisation follows normalizeGitHubBaseUrl: https origin, no credentials, query or fragment.
Out of scope for this PR
- Browser (OAuth) authorization and the
glabCLI link for self-managed hosts. - Instances served under a path (
https://example.com/gitlab), custom CA bundles, SSH clones. - Merge-request previews (still tracked in #75).
Tests
apps/api/test/modules/git/gitlab.test.ts: verification, browsing and clone-origin guard against a custom origin; a token saved for one host is never sent to another; a signed push forgroup/appon host A does not deploy the projectgroup/appbound to host B.apps/api/test/modules/credentials/verify-ssrf.test.ts: a private address is refused in Cloud mode and allowed on a self-hosted controller.packages/adapters/src/runtime/git-clone.test.ts: clone credentials for a self-managed origin.- Dashboard: the form sends the selector, and an existing GitLab.com connection renders as before.
Alternatives considered
- Mirroring to GitHub or GitLab.com. Works today, but it adds a second copy of private code on a third party, which is what self-hosting the Git server is meant to avoid.
- A
git_source-style table, as for GitHub Enterprise. That model exists because a GitHub App has its own identity and keys. A token connection only needs a host, which the credentialselectoralready stores, indexes and passes to the verifier. - An instance-wide environment variable for the GitLab host. Simpler, but one host per controller, and it cannot coexist with GitLab.com connections.
Additional context
I run a self-hosted controller next to a recent self-managed GitLab and can test the whole flow against it (private clone, hook registration, signed push). I am happy to open the PR once the scope and the project-binding choice above are agreed.
Carrying the host on the connection and the origin on the project is also what a Gitea/Forgejo adapter would need. I will open that as a separate issue rather than widen this one.
Need that