Skip to content
AnchrasDocumentation
Browse documentation

Integrations / User guide

Developer tools

Available

GitLab

Connect GitLab source repositories for verified builds and deployment updates.

On this page

Connect GitLab.com or an operator-configured GitLab Self-Managed instance for source builds and deployment updates.

Availability and limits

Available for GitLab.com, verified end to end on 2026-11-07 against a private GitLab.com project with shared runners: connect, repository and branch discovery, a verified build, deployment of that image to an instance container, a webhook-triggered build that rolled the deployment forward, and disconnect cleanup. A connected account does not establish build, deployment or application health; each build and deployment reports its own state. A Self-Managed instance uses the same contract with its own origin, CA and transport settings.

Merge-request review, registry management and issue synchronization are separate capabilities and are not provided by this source integration.

Operator prerequisites

Configure a confidential GitLab OAuth application with the exact HTTPS callback URL https://YOUR-ANCHRAS-DASHBOARD/integrations/gitlab. Configure these server settings:

  • GITLAB_SOURCE_ORIGIN: GitLab HTTPS origin, default https://gitlab.com.
  • GITLAB_SOURCE_CLIENT_ID, GITLAB_SOURCE_CLIENT_SECRET, GITLAB_SOURCE_REDIRECT_URI: OAuth application credentials and that exact callback URL.
  • GITLAB_SOURCE_TRANSPORT: public_https by default, or explicit org_network for an organization-owned destination. Organization network transport requires current enrolled-device or authenticated agent address proof and a direct route from the control plane. A Tailscale address is dialled only when the control plane is a member of the organization's tailnet (CONTROL_PLANE_TAILNET). On its own it does not create an agent tunnel. When the origin is on a private address an organization cannot prove it owns, that organization can name one of its instances as the connection's reach-via instance instead (see below).
  • GITLAB_SOURCE_CA_PEM: optional trusted certificate authority for verified Self-Managed HTTPS.
  • GITLAB_SOURCE_ARTIFACT_ORIGINS: exact public HTTPS CDN origins allowed only for artifact downloads. GitLab.com defaults to https://cdn.artifacts.gitlab-static.net and https://storage.googleapis.com. API and OAuth redirects remain refused; credentials must not be forwarded to a CDN.
  • GITLAB_SOURCE_WEBHOOK_BASE_URL: optional public HTTPS origin, without a path, for project hooks when the API origin is not reachable from GitLab. It must route /webhooks/gitlab/ to the server. Empty uses the API URL.

Authorize a dedicated GitLab account restricted to the intended projects. The OAuth api scope is needed for project hooks and pipeline creation and is broader than a per-project checkout token. Do not use a broadly privileged personal account merely to connect one repository. Project permissions must permit hook and pipeline management.

Connect and select source

  1. Open Integrations → GitLab → Connect, then continue to the configured GitLab instance.

With the org_network transport, a GitLab on a private address your organization cannot prove it owns (a lab LAN or a libvirt bridge) is reached through one of your instances: choose it under Reach via instance before continuing. The authorization and every later request then travel through that instance's host agent, which only connects to an address assigned to its own host. The instance must be online; the operator's origin should be an IP address, because the control plane resolves hostnames itself. Reconnecting sets, changes or clears the route, and the change is audited. Without a route, an origin your organization has not proven it owns is refused before any request.

  1. Approve the requested access and return while signed into the same Anchras user and organization that started the request. The callback uses a one-use state and PKCE; callback code/state are removed from the page URL immediately.
  2. Confirm the account, HTTPS origin, authorization status, transport and reach-via instance. Use Refresh authorization to check a connection. If it requires reconnecting, start Connect again with the same GitLab account.
  3. Choose the private repository and branch under the saved connection. Archived repositories cannot be selected. Discovery lists at most 100 entries and reports when more exist; the CLI can bind another known repository/branch after permission validation.
  4. Enter the exact OCI artifact repository, without a tag or digest. Optionally select an existing instance deployment by its ID to receive verified images. Enable builds.

The deployment's host pulls the image itself with its container runtime (Docker or Podman). For a private GitLab registry, log that runtime in to the registry once on the host with a deploy token that has only the read_registry scope, for example docker login registry.gitlab.com --username <token username> --password-stdin. Anchras does not store registry pull credentials.

The backend checks the branch tip before creating the initial build. Subsequent verified push events on the bound branch enqueue updates. A moved branch, missing permissions or invalid build result must appear as a failure rather than a deployment success.

Prepare the GitLab pipeline

The project must have a runner and a .gitlab-ci.yml pipeline that builds and publishes the selected commit. Anchras supplies ANCHRAS_RUN_ID, ANCHRAS_COMMIT_SHA and ANCHRAS_ARTIFACT_REPOSITORY as pipeline variables. Keep registry push credentials in GitLab's protected CI variables; they are not source-connection fields.

Restrict the Anchras pipeline to API-triggered runs (CI_PIPELINE_SOURCE == "api") and fail before building unless CI_COMMIT_SHA exactly equals ANCHRAS_COMMIT_SHA. Never replace the supplied commit with the current branch tip.

The successful pipeline needs one successful job named anchras-result that uploads a file named anchras-result.json:

json
{"image_digest_ref":"registry.example/group/image@sha256:<64-lowercase-hex>"}

Use the actual digest returned by the registry after publication. Its repository must exactly equal the saved binding. Tags, mismatched repositories, ambiguous result jobs and malformed artifacts are rejected. Anchras verifies the exact pipeline, commit, branch, operation variables and result job; a webhook cannot supply the deployable artifact identity.

Use Build history to inspect status and errors. A successful build records an immutable artifact; deployment reconciliation and application verification remain separate steps.

CLI and API

sh
anchras source connections connect --provider gitlab
anchras source connections list
anchras source repositories discover --connection CONNECTION_ID
anchras source repositories branches --connection CONNECTION_ID --repository group/project
anchras source repositories bind --connection CONNECTION_ID --repository group/project --branch main --artifact-repository registry.example/group/image
anchras source builds list
anchras source connections refresh --connection CONNECTION_ID
anchras source connections disconnect --connection CONNECTION_ID

The authenticated SourceService provides these same operations. The dashboard normally consumes the OAuth return. For an uncaptured callback, source connections complete --provider gitlab --callback-file PATH reads a private file containing the callback URL; do not paste authorization codes into shell arguments. Delete that temporary file after completion. Expired or consumed callbacks require a new authorization attempt.

Disconnect

Disconnect stops new Anchras builds, removes its project hooks, revokes the saved OAuth grant and removes the Anchras connection/build ledger. Existing GitLab pipelines, artifacts and projects are retained. If hook cleanup or revocation fails, the connection stays disconnecting with its credentials retained for retry. A GitLab-side revoked grant may require reconnecting before hook cleanup can finish.

Troubleshooting

If setup is unavailable, check OAuth configuration and the exact callback URL. If a private destination is denied, check current organization ownership and routing; do not enable a global private-address exception. Missing repositories usually indicate project membership, account scope or the discovery limit. Pipeline failures require checking the runner, registry credentials, branch and result artifact. Verify a disposable project's initial build/deploy, subsequent webhook update and disconnect cleanup before relying on this preview.

Verify the integration

The targeted browser journey source.gitlab-authorization uses a preconnected disposable fixture in the authenticated test organization. Set E2E_SOURCE_GITLAB_CONNECTION_ID, E2E_SOURCE_GITLAB_REPOSITORY and E2E_SOURCE_GITLAB_BRANCH to run it. It checks authorization refresh and API-backed repository/branch selection; refresh may rotate the fixture OAuth token. It creates no pipeline or deployment and does not satisfy the live runner release gate. Reconnecting the same GitLab account preserves its Anchras connection ID and bindings. A connection already awaiting disconnect remains in cleanup mode after reconnect so Disconnect can be retried safely.

CLI commands

Install and authenticate using the CLI guide. The table describes command families; required arguments are shown in their usage output.

CommandPurpose
source connections listShow provider, account, origin, authorization status, transport and reach-via instance.
source repositories discover --connection IDDiscover accessible repositories, including nested GitLab namespaces.
source builds list / source builds get RUN_IDInspect build state, errors and immutable artifact identity.