Hamburger Cross Icon
GitLab Collector - Lunar Collector

GitLab Collector

↓ Collector Experimental Vcs

Collect GitLab project settings, protected-branch and approval rules, access permissions, CI/CD job token access, and merge-request metadata. Populates the same .vcs.* schema as the GitHub collector so VCS and ticket policies work on GitLab-hosted repositories.

Add gitlab to your lunar-config.yml:
uses: github://earthly/lunar-lib/collectors/gitlab@v1.0.5

What This Integration Collects

This integration includes 9 collectors that gather metadata from your systems.

Collector code

merge-request

Fetches merge-request metadata from the GitLab API for the MR being evaluated and writes it under .vcs.pr — title, description, source and target branch, author, labels, draft flag, state, URL, and number. This is the GitLab source of .vcs.pr.* that the ticket collectors (jira, linear) and change-management / change-to-ticket checks read. Runs only in merge-request context.

gitlab merge request pr vcs.pr ticket change management
Book a demo
Collector code

repository

Fetches basic project settings from the GitLab API including visibility (public/internal/private), default branch, topics, and the configured merge method (merge commit, rebase, fast-forward) plus squash options. Writes to .vcs.provider, .vcs.visibility, .vcs.default_branch, .vcs.topics, and .vcs.merge_strategies.

gitlab settings project visibility merge method
Book a demo
Collector code

branch-protection

Fetches protected-branch config, MR approval rules, external status checks, and push rules for the default branch from the GitLab API, normalizing them into the shared .vcs.branch_protection shape with a .source field of "gitlab". Collects required approvals (from approval rules), code-owner approval, reset-on-push (dismiss stale reviews), required status checks (pipeline-success and/or external status checks, with their names in required_checks), signed-commit and linear-history enforcement, allowed force push, and push/merge access levels. Licensed- only signals degrade gracefully to their safe defaults on CE/unlicensed.

protected branches approval rules code review gitlab security
Book a demo
Collector code

access-permissions

Fetches project access permissions from the GitLab API with pagination. Collects direct project members (username, access level, type) and shared groups (path, name, access level). Does not expand group memberships. Writes to .vcs.access.collaborators and .vcs.access.teams.

access control members groups audit least privilege
Book a demo
Collector code

job-token-allowlist

Reads whether the project limits which other projects' CI/CD job tokens can access it (the CI/CD job token allowlist under Settings > CI/CD > Job token permissions) and, when it does, how many projects and groups the allowlist holds. Writes .vcs.job_token_allowlist. GitLab shows the setting only to Maintainers: a 403 or 404 is recorded in .status, never as enabled or disabled. Runs on the default branch.

gitlab ci job token job token allowlist authorized groups and projects ci/cd security
Book a demo
Collector cron

repository-cron

repository on the cron_schedule instead of on push, so settings changed without a commit are picked up. Include one of the two: with both, .vcs.topics is written twice.

gitlab settings project visibility merge method cron scheduled
Book a demo
Collector cron

branch-protection-cron

branch-protection on the cron_schedule instead of on push. Include one of the two: with both, .vcs.branch_protection.required_checks is written twice.

protected branches approval rules gitlab security cron scheduled
Book a demo
Collector cron

access-permissions-cron

access-permissions on the cron_schedule instead of on push. Include one of the two: with both, every member and shared group is listed twice.

access control members groups audit cron scheduled
Book a demo
Collector cron

job-token-allowlist-cron

job-token-allowlist on the cron_schedule instead of on push, so projects with no recent commits are covered and setting changes show up without a commit. Include one of the two.

gitlab ci job token job token allowlist cron scheduled
Book a demo

How Collectors Fit into Lunar

Lunar watches your code and CI/CD systems to collect SDLC data from config files, test results, IaC, deployment configurations, security scans, and more.

Collectors are the automatic data-gathering layer. They extract structured metadata from your repositories and pipelines, feeding it into Lunar's centralized database where guardrails evaluate it to enforce your engineering standards.

Learn How Lunar Works →
1
↓ Collectors Gather Data This Integration
Triggered by code changes or CI pipelines, collectors extract metadata from config files, tool outputs, test results, and scans
2
{ } Centralized as JSON
All data merged into each component's unified metadata document
3
✓ Guardrails Enforce Standards
Real-time feedback in PRs and AI workflows

Example Collected Data

This collector writes structured metadata to the Component JSON. Here's an example of the data it produces:

{ } component.json Component JSON
{
  "vcs": {
    "provider": "gitlab",
    "default_branch": "main",
    "visibility": "private",
    "topics": ["backend", "api", "microservice"],
    "merge_strategies": {
      "allow_merge_commit": false,
      "allow_squash_merge": true,
      "allow_rebase_merge": true
    },
    "pr": {
      "number": 42,
      "title": "[ENG-123] Add rate limiting to the auth service",
      "description": "Implements a token-bucket limiter. Closes ENG-123.",
      "url": "https://gitlab.com/acme/auth-service/-/merge_requests/42",
      "source_branch": "eng-123-rate-limiting",
      "target_branch": "main",
      "author": "alice",
      "labels": ["backend", "security"],
      "draft": false,
      "state": "open"
    },
    "branch_protection": {
      "enabled": true,
      "source": "gitlab",
      "branch": "main",
      "require_pr": true,
      "required_approvals": 2,
      "require_codeowner_review": true,
      "dismiss_stale_reviews": true,
      "require_status_checks": true,
      "required_checks": ["security-gate"],
      "require_signed_commits": false,
      "require_linear_history": false,
      "allow_force_push": false,
      "allow_deletions": false,
      "restrictions": {
        "push_access_level": "maintainer",
        "merge_access_level": "developer"
      }
    },
    "access": {
      "collaborators": [
        {"username": "alice", "permission": "owner", "type": "User"},
        {"username": "deploy-bot", "permission": "developer", "type": "Bot"}
      ],
      "teams": [
        {"slug": "platform", "name": "Platform Team", "permission": "maintainer"}
      ]
    },
    "job_token_allowlist": {
      "status": "ok",
      "enabled": true,
      "projects": 2,
      "groups": 1,
      "checked_at": "2026-11-23T14:02:11Z"
    }
  }
}

Configuration

Configure this collector in your lunar-config.yml.

Inputs

Input Required Default Description
gitlab_host Optional gitlab.com GitLab host for self-managed instances (e.g. gitlab.example.com)
cron_schedule Optional 0 8 * * * When the `-cron` sub-collectors run, as a cron expression in UTC, at least 10 minutes apart

Secrets

This collector requires the following secrets to be configured in Lunar:

Secret Description
GL_TOKEN GitLab personal or project access token with `read_api` scope for API authentication. Without GL_ALLOWLIST_TOKEN, job-token-allowlist needs this token's user to be a Maintainer of each project, and a `read_api` token on a Maintainer can also read the project's CI/CD variables.
GL_ALLOWLIST_TOKEN Optional. A fine-grained personal access token (GitLab 19.2+) from a Maintainer, with only Job Token Scope Read and Job Token Scope Allowlist Read. job-token-allowlist uses it instead of GL_TOKEN. Like every collector secret, it reaches every collector's environment.

Documentation

View on GitHub

GitLab Collector

Collects GitLab project settings, protected-branch rules, access permissions, CI/CD job token access, and merge-request metadata via the GitLab API.

Overview

This collector is the GitLab equivalent of the github collector. It queries the GitLab API to gather version control system (VCS) configuration — project visibility, default branch, topics, merge method, protected-branch and approval rules, and access permissions — and, in merge-request context, the metadata of the MR being evaluated. It writes to the same .vcs.* schema as the GitHub collector so the shared vcs policy and the ticket collectors (jira, linear) work on GitLab-hosted repositories. It requires the LUNAR_SECRET_GL_TOKEN environment variable for API authentication, and takes an optional gitlab_host input (default gitlab.com) for self-managed instances.

Collected Data

This collector writes to the following Component JSON paths:

Path Type Description
.vcs.provider string VCS provider name (always "gitlab")
.vcs.default_branch string Default branch name (e.g., "main", "master")
.vcs.visibility string Project visibility (public, internal, private)
.vcs.topics array Project topics/tags
.vcs.merge_strategies object Allowed merge strategies, mapped from the GitLab merge method
.vcs.branch_protection object Protected-branch and approval rules (source: "gitlab")
.vcs.access object Project members and shared groups
.vcs.job_token_allowlist object Whether the project limits which projects' CI/CD job tokens can access it (default branch only)
.vcs.pr object Merge-request metadata (populated only in MR context)

Merge-request fields (.vcs.pr)

Path Type Description
.vcs.pr.number number Merge-request IID
.vcs.pr.title string MR title (source for ticket-ID extraction)
.vcs.pr.description string MR description
.vcs.pr.url string Web URL of the merge request
.vcs.pr.source_branch string Source branch name
.vcs.pr.target_branch string Target branch name
.vcs.pr.author string Author username
.vcs.pr.labels array MR label names
.vcs.pr.draft boolean Whether the MR is a draft
.vcs.pr.state string MR state, normalized to the shared vocabulary (open, closed, merged)

Job token allowlist fields (.vcs.job_token_allowlist)

Path Type Description
.vcs.job_token_allowlist.status string ok when GitLab answered; forbidden (HTTP 403, the token's user isn't a Maintainer) or not_found (HTTP 404) when it didn't. Every record has it, and the newest record's wins, so read it before enabled
.vcs.job_token_allowlist.enabled boolean When status is ok. true: only projects and groups on the allowlist can access this project with a CI/CD job token. false: any project's job token can. GitLab's effective inbound_enabled, so also true when an administrator enforces the allowlist instance-wide
.vcs.job_token_allowlist.projects number Other projects on the allowlist, not counting this one. Only when enabled, and left out when the list can't be read
.vcs.job_token_allowlist.groups number Groups on the allowlist; each covers every project under it. Only when enabled, and left out when the list can't be read
.vcs.job_token_allowlist.checked_at string When GitLab was asked (UTC). The setting can change without a commit

Collectors

This integration provides the following collectors (use include to select a subset):

Collector Description
merge-request Populates .vcs.pr.* with the metadata of the MR being evaluated (title, description, branches, author, labels, draft, state, URL). Runs only in merge-request context. This is the GitLab source of .vcs.pr.* that the ticket and change-management policies consume.
repository Collects basic project settings including visibility, default branch, topics, and the merge method mapped onto .vcs.merge_strategies.
branch-protection Collects protected-branch config, MR approval rules, external status checks, and push rules for the default branch, normalized into .vcs.branch_protection with source: "gitlab".
access-permissions Collects project members and shared groups (does not expand group memberships).
job-token-allowlist Reads whether the project limits which projects' CI/CD job tokens can access it, and how many projects and groups its allowlist holds. Default branch only; needs a Maintainer's token (see Job token allowlist).
repository-cron repository on a schedule instead of on push (see Scheduled collection).
branch-protection-cron branch-protection on a schedule instead of on push.
access-permissions-cron access-permissions on a schedule instead of on push.
job-token-allowlist-cron job-token-allowlist on a schedule instead of on push.

Installation

Add to your lunar-config.yml:

collectors:
  - uses: github://earthly/lunar-lib/collectors/gitlab@v1.0.0
    on: ["domain:your-domain"]  # Or use tags like [backend, kubernetes]
    include:
      - merge-request       # MR metadata
      - repository          # Project settings
      - branch-protection   # Protected branches and approval rules
      - access-permissions  # Members and shared groups
    with:
      gitlab_host: gitlab.com   # Set to your self-managed host if applicable
    secrets:
      GL_TOKEN: ${{ secrets.GL_TOKEN }}

GL_TOKEN

A GitLab personal or project access token with read_api scope. Used for all GitLab API calls (project settings, protected branches, approval rules, members, and merge-request metadata).

Scheduled collection

repository, branch-protection, access-permissions and job-token-allowlist each have a -cron variant that runs the same collection on every component the import matches, on cron_schedule (a cron expression in UTC, daily at 08:00 by default). It picks up settings changed without a commit and covers projects with no recent pushes. After a configuration change, Lunar shows no scheduled data until the next run, so a short schedule keeps that gap small. Include one variant of each, not both: Lunar concatenates arrays written by two collectors, so lists such as .vcs.access.collaborators would repeat.

collectors:
  - uses: github://earthly/lunar-lib/collectors/gitlab@v1.0.0
    on: ["domain:your-domain"]
    include: [merge-request, repository-cron, branch-protection-cron, access-permissions-cron]
    with:
      gitlab_host: gitlab.example.com
      cron_schedule: "0 */6 * * *"

Job token allowlist

job-token-allowlist makes one read per project, GET /projects/:id/job_token_scope (GitLab 16.0+), and reads the two allowlists only when it's on. It addresses the project by the gitlab cataloger's meta.project_id when there is one, so renamed projects still resolve. Import it separately, scoped to the projects you want measured:

collectors:
  - uses: github://earthly/lunar-lib/collectors/gitlab@v1.0.0
    name: gitlab-job-tokens
    on: [tier-0]
    include: [job-token-allowlist]
    with:
      gitlab_host: gitlab.example.com

GitLab shows this setting only to Maintainers, and a read_api token on a Maintainer can also read the project's CI/CD variables. On GitLab 19.2+, use a fine-grained personal access token from a Maintainer with only Job Token Scope: Read and Job Token Scope Allowlist: Read, which cover these three reads, and set it as GL_ALLOWLIST_TOKEN; this sub-collector then uses it instead of GL_TOKEN. Every collector gets every collector secret, so the token's scope is what limits it, not the separate secret.

Before rolling it out, run the same read against one project with the token the collector will use (GL_ALLOWLIST_TOKEN if set, else GL_TOKEN). HTTP 200 with inbound_enabled in the body means it will work; HTTP 403 means the token's user isn't a Maintainer there:

curl -s -w '\nHTTP %{http_code}\n' -H "PRIVATE-TOKEN: $TOKEN" \
  "https://gitlab.example.com/api/v4/projects/<project-id>/job_token_scope"

A 403 or 404 is recorded in .status. A 401, 429, 5xx, network failure or unreadable answer records nothing and fails the run, so a bad token or an outage never replaces an earlier result. On push, projects without recent commits need a one-off lunar collector run --all --collector gitlab-job-tokens.job-token-allowlist --only-code; job-token-allowlist-cron covers them on its schedule instead.

The allowlist says who may reach a project, not what the project depends on. Where it's off, it says nothing about which projects use job tokens against the project, and those are the projects turning it on would break; the project's job token authentication log (GitLab 17.6+) shows them. Job tokens can still read some resources of public or internal projects that aren't on the list, and other token types aren't affected by it.

Why .vcs.pr.* matters

The jira and linear ticket collectors extract a ticket ID from the merge/pull-request title to populate .vcs.pr.ticket.*, which the ticket and change-management (e.g. change→ticket) policies enforce. The github and gitlab collectors are the source of .vcs.pr.*: on GitLab, this collector's merge-request sub-collector supplies it; on GitHub, the github collector's pull-request sub-collector does. The ticket collectors' after-json variant (e.g. jira's ticket-from-json) then reads .vcs.pr.title from Component JSON — no SCM API call, provider-agnostic.

Self-managed instances and nested namespaces

Set the gitlab_host input to your instance host; the API base is derived from the host prefix of the component ID. GitLab projects can live under nested groups (group/subgroup/project), so the full project path is URL-encoded for the API and multi-segment namespaces are handled.

Merge-method mapping

GitLab exposes a single merge_method (merge, rebase_merge, ff) plus squash options rather than GitHub's three independent booleans. These are normalized onto .vcs.merge_strategies.allow_merge_commit / allow_rebase_merge / allow_squash_merge so the shared vcs policy applies unchanged.

Branch-protection field mapping

.vcs.branch_protection is normalized so the shared vcs policy checks evaluate GitLab the same as GitHub:

.vcs.branch_protection field GitLab source
required_approvals sum of approval_rules[].approvals_required for the default branch; falls back to the deprecated approvals_before_merge
require_status_checks / required_checks only_allow_merge_if_pipeline_succeeds, and configured External Status Checks (their names populate required_checks)
require_codeowner_review protected branch code_owner_approval_required
dismiss_stale_reviews MR approval setting reset_approvals_on_push
require_signed_commits push rule reject_unsigned_commits
require_linear_history merge_method == "ff" (fast-forward merges enforce linear history)

Approval rules, external status checks, and push rules are GitLab premium/Ultimate features; on CE/unlicensed instances those endpoints return 403 and the corresponding fields degrade to their safe defaults (0 / false). GitHub's require_branches_up_to_date has no GitLab equivalent and is left unset (the require-branches-up-to-date check is GitHub-specific).

Open Source

This collector is open source and available on GitHub. Contribute improvements, report issues, or fork it for your own use.

View Repository

Common Use Cases

Explore guardrails that use data from GitLab Collector.

+
Branch Protection Enabled + GitLab Collector Requires branch protection rules to be enabled on the default branch. Branch...
→
+
Require Pull Request + GitLab Collector Requires all changes to go through pull requests before merging. Prevents direct...
→
+
Minimum Approvals + GitLab Collector Enforces a minimum number of approving reviews before merge (default...
→
+
Require Codeowner Review + GitLab Collector Requires approval from designated code owners defined in CODEOWNERS...
→
+
Dismiss Stale Reviews + GitLab Collector Automatically dismisses approvals when new commits are pushed to a PR. Prevents...
→
+
Require Status Checks + GitLab Collector Requires CI status checks to pass before merging pull requests. Prevents merging...
→
+
Require Branches Up To Date + GitLab Collector Requires PR branches to be up-to-date with the base branch before...
→
+
Disallow Force Push + GitLab Collector Prohibits force pushes to protected branches to preserve commit history. Force...
→
+
Disallow Branch Deletion + GitLab Collector Prevents deletion of protected branches (typically main/master). Protects...
→
+
Require Linear History + GitLab Collector Enforces linear commit history by requiring squash or rebase merges. Makes git...
→
+
Require Signed Commits + GitLab Collector Requires all commits to be GPG or SSH signed for authenticity...
→
+
Disallow Bypass Actors + GitLab Collector Fails when anyone can bypass protection on the default branch: a ruleset bypass...
→
+
Pr Commits Signed + GitLab Collector Requires every commit in a pull request to carry a signature GitHub verified....
→
+
Release Commits Merged Via Pr + GitLab Collector Every commit since the previous release tag must have reached the default branch...
→
+
Require Private + GitLab Collector Ensures repository visibility is set to private, not public. Prevents accidental...
→
+
Require Default Branch + GitLab Collector Validates the default branch name matches the required name (default...
→
+
Allowed Merge Strategies + GitLab Collector Restricts merge strategies to an allowed list (merge, squash, rebase). Enforces...
→
+
Require Job Token Allowlist + GitLab Collector Opt-in (`require_job_token_allowlist: "true"`). GitLab only: fails when any...
→

Ready to Automate Your Standards?

See how Lunar can turn your AGENTS.md, engineering wiki, compliance docs, or postmortem action items into automated guardrails with our 300+ built-in guardrails.

Works with any process
check AI agent rules & prompt files
check Post-mortem action items
check Security & compliance policies
check Testing & quality requirements
Auto-ID My Guardrails
Paste your AGENTS.md or manual process doc and get guardrails in minutes
Book a Demo