Skip to main content

How to set up GitLab

Connect GitLab to Foundational: pick read-only or read and write access, create a token, add the access key, and configure webhooks for merge requests.

Setup takes about 10 minutes.

Introduction

Use the GitLab connector when you want Foundational to access source code in GitLab. The setup supports cloud deployments.


To make the connection, you need to:

  • Choose an access level and create an access token

  • Connect Foundational to GitLab

  • Configure webhooks


Prerequisites

Ensure you have:

  • Access to GitLab

  • Permissions to create webhooks: the Owner role for a group webhook, or the Maintainer role for a project webhook

  • Permissions to create access tokens: the Owner role for a group access token, or the Maintainer role for a project access token

  • Added Foundational IP addresses to the allowlist, see the article Allowing IP access to Foundational


Access permissions

Access to GitLab allows Foundational to determine data lineage and analyze open and past merge requests. Choose one of two access levels.

Read and write (recommended)

Foundational reads code, commits and merge requests. It also writes to merge requests for the features you turn on:

  • Merge request comments: Foundational comments on merge requests and adds labels

  • Pipeline checks: Foundational sets commit statuses

  • Policies: Foundational adds reviewers, and a policy with a review action approves or unapproves merge requests

Foundational never pushes code, merges, or changes project settings.

This level needs the api scope, or a fine-grained personal access token on GitLab 19.2 and later (Option 4 below).

Read-only

Foundational reads code, commits and merge requests, builds lineage and analyzes merge requests. It cannot write to GitLab. This level does not need the api scope.

With this level, keep merge request comments, pipeline checks and policy actions off. If they are on, GitLab rejects the writes and nothing appears on the merge request.


Create an access token

GitLab authentication uses an API access token. Use the role and scopes for the access level you chose:

  • Read and write: role Developer, scopes api and read_repository

  • Read-only: role Reporter, scopes read_api and read_repository

GitLab requires the Developer role to set commit statuses, add labels and reviewers, and approve merge requests. With classic scopes, api is the only scope that allows these writes. Do not add write_repository. Foundational does not push with the token.

Give the token a descriptive name (for example foundational-app). The name appears as the author of Foundational merge request comments. Set the token to expire one year from now.

Select one token type. Options 1 to 3 work for both access levels. Option 4 gives read and write access without the api scope.

Option 1: Group access token (preferred)

A group access token covers all projects in a group and its subgroups. On GitLab.com, group access tokens require GitLab Premium or Ultimate. See the GitLab article on group access tokens.

  1. To find your group, on the top bar select Search or go to and enter the name of the group.

  2. Go to Settings > Access tokens.

  3. Click Add new token.

  4. Enter the name and expiry date. Select the role and scopes for your access level.

  5. Copy and save the token. You need it to set up the connection.

Option 2: Project access token

Use this option if you cannot create a group access token. A project access token reaches only its own project, so create one token, and one Foundational access key, for each project. On GitLab.com, project access tokens require GitLab Premium or Ultimate. See the GitLab article on project access tokens.

  1. In the project, go to Settings > Access tokens.

  2. Click Add new token.

  3. Enter the name and expiry date. Select the role and scopes for your access level.

  4. Copy and save the token. You need it to set up the connection.

Option 3: Service account

Service accounts are available on all GitLab tiers, including Free. See the GitLab article on service accounts.

  1. Create a service account for your group.

  2. Add the service account as a member of the group or projects, with the role for your access level.

  3. Create a personal access token for the service account, with the scopes for your access level.

  4. Copy and save the token. You need it to set up the connection.

Option 4: Fine-grained personal access token (read and write, no api scope)

Use this option for the read and write level when your security policy does not allow the api scope. It needs GitLab 19.2 or later. A fine-grained token grants only the permissions you select. With the permissions below, every Foundational feature works.

Group and project access tokens cannot be fine-grained. Create the token for one of these accounts:

  • A dedicated GitLab user (for example foundational-app), with the Developer role in the groups you want to scan. Foundational comments appear under this user's name.

  • A service account, with the Developer role in the groups you want to scan.

Grant only these permissions. For All memberships:

  • To read: Project: Read, Branch: Read, Repository: Read, Commit: Read, Merge Request: Read, Work Item: Read, Label: Read and Code: Download

  • To comment, and to add labels and reviewers: Merge Request: Create, Merge Request: Update, Work Item: Create, Work Item: Update and Label: Create

  • To set pipeline checks: Commit Status: Create

  • To approve and unapprove from a policy: Merge Request: Approve

For User, so Foundational can list the groups and projects the token reaches:

  • User: Read, Group: Read and Project: Read

For Instance, so Foundational can match commit authors and reviewers to GitLab users:

  • User: Read

Also grant Personal Access Token: Read, so Foundational can warn you before the token expires.

Limitations:

  • It needs GitLab 19.2 or later.

  • It belongs to a user account. If that user is blocked or removed, the token stops working.

  • It cannot be narrower than this list. GitLab stores merge request comments as work item notes. So Work Item: Create, which lets Foundational comment on merge requests, also lets it create issues. Merge Request: Create, which Foundational uses for merge request discussions, also lets it open merge requests.


Configure network access

If GitLab access is restricted, add Foundational IP addresses to the allowlist, see Prerequisites.


Connect Foundational to GitLab

  1. In Foundational, open the Connectors & Integrations page.
    ​

  2. In Source Control, select the GitLab card and click Connect.
    ​

  3. Click Add Access Key.

  4. The initial setup screen opens. Click Start Setup.
    ​

  5. The Set Up New Connection screen opens.
    ​

  6. Enter the details:

    • API Access Token: The token you created earlier.

    • Webhook URL: Read-only. Click the copy button. You need it to configure the webhooks.

    • Webhook Secret Token: Auto-generated. Click the copy button. You need it to configure the webhooks.

  7. Click Next.

  8. The final setup screen opens. To complete the connection, click Save.
    ​


Configure webhooks

Webhooks notify Foundational about events such as new merge requests and new commits.

Prefer a group webhook. It covers every project in the group and its subgroups, including new projects. Group webhooks require GitLab Premium or Ultimate and the Owner role for the group.

If you use project webhooks, add one to every project, and add one to every new project. Project webhooks require the Maintainer role.

See the GitLab article on webhooks.

Webhook settings

  1. In GitLab, open the group or project, go to Settings > Webhooks and click Add new webhook.

  2. Set the webhook URL to the Webhook URL from Foundational:

    https://hooks.foundational.io/api/v1/gitlab_webhook
  3. In the Secret token field, paste the Webhook Secret Token from Foundational. Each access key has its own secret. Use the secret shown for this key. Foundational checks the secret token, so you do not need a signing token.

    ​

    ​

  4. Under Trigger, select:

    • Push events

    • Merge request events

    • Comments, only if merge request comments are on. Foundational uses them to see replies to its comments.

    Foundational does not use Pipeline events. Leave them off.

  5. Under SSL verification, ensure Enable SSL verification is selected.

  6. Click Add webhook.

That's it. Foundational is now connected to GitLab.

GitLab disables a webhook after four failed deliveries in a row. If Foundational stops seeing new merge requests, open Settings > Webhooks in GitLab and check the webhook's status.

Did this answer your question?