Skip to content

app/: self-managed GitLab instances, their sign-in, webhooks and sync (sc-8900, forge) - #96

Draft
ndbroadbent wants to merge 5 commits into
laravel-linkfrom
laravel-gitlab
Draft

ndbroadbent wants to merge 5 commits into
laravel-linkfrom
laravel-gitlab

Conversation

@ndbroadbent

@ndbroadbent ndbroadbent commented Dec 2, 2026 •

Copy link
Copy Markdown
Member

Ports self-managed GitLab to app/: an organization's own instance.

  • Instances: admins add and remove them with POST/DELETE /api/ui/orgs/{org}/gitlab-instances[/{id}]. The OAuth application's secret is AES-256-GCM encrypted with VISUALCI_SECRETS_KEY; a server without that key refuses to store it. normalise_base refuses gitlab.com, paths, IP addresses, and http outside development. forge::instances::json_for gives the organization page its list.
  • Sign-in: /auth/gitlab-<instance id> runs the OAuth code flow with PKCE itself, because social login fixes its providers at boot. The state is tied to the instance in the session. An instance's identity names its site, so its email addresses never match an existing account.
  • Outbound requests (forge::outbound): every request to an instance reaches public addresses only (checked at DNS resolution), follows no redirects, and has time and 8 MB limits. VISUALCI_FORGE_PRIVATE_ADDRESSES=1 lifts the address check for development.
  • Webhooks: POST /webhooks/gitlab/{project} checks that project's own secret and linked repository, then dispatches PullRequestMerged, BranchClosed or BranchReopened for that project only. VisualCI adds the hook when it may: on linking, from POST /api/ui/orgs/{org}/projects/{project}/gitlab-webhook, and in the hourly sync.
  • Linking: a project on an instance links with an access token (api scope, Developer or higher), stored encrypted.
  • Hourly sync: GitLab memberships come from each linked project's members, per site; a project that can't be read holds back only the memberships of the organizations linking it. GitLab open-source status (only gitlab.com projects count). The heartbeat fails when the bot's token expires within 30 days or a GitLab can't be read.
  • Tests: gitlab_instances.rs (8), gitlab_hooks.rs (4), gitlab_sync.rs (4), plus unit tests.

Stacked on #95.

Review fixes

  • Instances: gitlab.com and its subdomains are refused, and so are IP literals (unless VISUALCI_FORGE_PRIVATE_ADDRESSES=1). GET /api/ui/orgs/{org}/gitlab-instances lists them.
  • Outbound: no proxy (a proxy would resolve names past the address check), IPv4-compatible and 6to4 addresses checked, one 30-second deadline for the whole exchange, a 16 MB cap across list pages.
  • Sync: one unreadable project holds back only its organizations' memberships (test one_unreadable_project_doesnt_stop_everyone_elses_sync); Synced.failed names the repositories.
  • forge_token_enc is never serialised. Admins see the project's webhook URL and secret (GET …/projects/{project}/gitlab-webhook).

…::encrypt/decrypt (AES-256-GCM keyed by VISUALCI_SECRETS_KEY; nothing stored in the clear without it) and secrets::webhook_secret; a gitlab_instances table; forge::instances (normalise_base refuses gitlab.com, paths, IP addresses and http outside development; for_site, for_organization, by_pid, json_for, upsert, enabled) and admins' POST/DELETE /api/ui/orgs/{org}/gitlab-instances, answering with the organization's instances, their sign-in and callback URLs
…ge, ported): /auth/gitlab-<instance id> runs the OAuth code flow with PKCE itself (social login's providers are fixed at boot), the state bound to the instance in the session; forge::outbound guards every request to an instance (public addresses only, checked at DNS resolution; no redirects; time and 8 MB limits; VISUALCI_FORGE_PRIVATE_ADDRESSES=1 for development), and gitlab.rs's API reads go through it; an instance's identity names its site, so its addresses never match an existing account; the configured GitLab's URL is recognised at boot
…900, forge, ported): POST /webhooks/gitlab/{project} checks the project's own secret and linked repository and dispatches PullRequestMerged, BranchClosed or BranchReopened for that project alone; forge::gitlab_hooks adds each project's hook (merge request and push events) when the bot or token is a Maintainer, on linking, from POST /api/ui/orgs/{org}/projects/{project}/gitlab-webhook and in the hourly sync; link_repository links a project on one of the organization's instances with an access token (api scope, Developer or more), stored encrypted, after checking the person is a maintainer there
…gitlab_sync rechecks everyone's GitLab memberships from each linked project's members, per site (gitlab.com through the bot, an organization's instance through each project's token), changing nobody at a site where some project can't be read; GitLab projects' open source status (only gitlab.com's count); the heartbeat fails when the bot's token expires within 30 days or is revoked, or a GitLab can't be read; webhooks still missing are added each run
…erals refused as instances, proxies off and one 30-second deadline for an organization's server, a 16 MB cap across list pages, one unreadable project holds back only its organizations' memberships, forge tokens never serialised, the webhook's URL and secret shown to admins, instances listed

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant