Skip to main content

GitLab Self-Hosted: Personal Access Token Setup

Create a personal access token on your self-hosted GitLab so Elestio can connect to your repositories.

When connecting a self-hosted GitLab instance to Elestio CI/CD, you must provide a Personal Access Token (PAT) with the api scope. This guide explains exactly how to create it and why that specific scope is required.


Step-by-step: Create a Personal Access Token​
  1. Sign in to your self-hosted GitLab instance.

  2. Click your avatar (top-right) → Preferences → Access Tokens
    (or go directly to /-/profile/personal_access_tokens)

  3. Fill in:

    • Token name — e.g. elestio-cicd
    • Expiration date — optional, depending on your team’s policy
  4. Under "Select scopes," enable only the api scope (details below).

  5. Click Create personal access token.

  6. Copy the token immediately — GitLab will not display it again.

image.png


Required scope: api (mandatory, no substitutes)​
ScopeWhy it is needed
apiMandatory. Grants full REST API read/write access. Elestio requires this for creating and deleting webhooks (to track pushes), managing deploy keys (SSH access for CI runners), creating projects from templates, listing projects and groups, reading repository content, and performing git-over-HTTPS operations (oauth2:@...) during deployments.

Why narrower scopes are not enough​

It may seem possible to combine smaller scopes, but in practice, they do not cover what CI/CD needs:

ScopeWhat it coversWhat it is missing
read_apiRead-only REST APINo write access
read_repositorygit clone over HTTPSNo API access
write_repositorygit push over HTTPSNo API access
read_userBasic user info (GET /api/v4/user)No repo/project access

Even combining all of the above still does not allow the following:

  • Creating webhooks
  • Managing deploy keys
  • Creating projects

These require REST API write permissions, which are only available via the api scope.

If you attempt to use limited scopes, deployments will fail with the following:

insufficient_scope

GitLab version note​

Elestio verifies token scopes using the following:

GET /api/v4/personal_access_tokens/self

This endpoint was introduced in GitLab 13.5 (October 2020).

  • On newer versions → scope is validated directly
  • On older versions → validation is skipped

However, the api scope is still required for CI/CD to function correctly, regardless of version.


Admin settings required for template-based project creation​

If you use “Create repo from Elestio template," GitLab must allow imports from external URLs.

Enable this setting:​
  1. Go to Admin Area
  2. Navigate to Settings → General
  3. Expand Import and export settings
  4. Enable Allow imports from external URLs
  5. Save changes

image.png

If disabled, GitLab may return the following:

  • insufficient_scope
  • 404

Even when your token is correctly configured.

👉 This is not a token issue, but a GitLab instance configuration restriction.


Troubleshooting​
SymptomLikely causeFix
AUTH_FAILED at connectionWrong token or instance URLVerify URL format (http:// or https://, no trailing slash) and re-copy token
INSUFFICIENT_SCOPES at connectionMissing api scopeEdit or recreate the token with only api
insufficient_scope during deployment (project creation)Using limited scopesRecreate the token with api
insufficient_scope during template importImport setting disabledEnable “Allow imports from external URLs."
Repositories not loadingMissing or expired tokenReconnect with a valid token
Webhook not createdNo api scoperead_api is not sufficient
Deploy fails at git cloneMissing api scopeUse api (covers HTTPS git access too)

Key takeaway​

For GitLab + Elestio CI/CD integrations:

Always use a Personal Access Token with the api scope nothing else will fully work.

Trying to minimize scopes here will break core deployment functionality.