Set up GitLab service credential
A GitLab service credential lets a Glean agent work with repositories, issues, merge requests, and pipelines under a shared service-account identity. You create a GitLab service account, grant it access to the required top-level group, generate a personal access token, and store the connection details in Glean.
Glean stores the token encrypted and adds it to outbound GitLab API requests. The agent never sees the raw token.
- Authentication: GitLab service account personal access token (Bearer)
- Scope: One GitLab host and top-level group, limited by the service account's memberships, role, and token scopes
- Access: Read and write access determined by the GitLab role and token scopes; write requests require approval in Glean
Prerequisites
- For GitLab.com, the Owner role in the top-level group.
- For GitLab Self-Managed or GitLab Dedicated, administrator access or the Owner role in a group that can create service accounts.
- Permission to add the service account to the required group or projects and assign its role.
- A Glean administrator who can create service credentials.
- The GitLab service credential template enabled for your deployment. If you don't see it in the list of templates, contact your Glean representative.
Step 1: Identify the GitLab host and group path
Copy these values from the URL of the top-level group the agent will use. For example, for https://gitlab.example.com/my-organization:
- The GitLab host is
gitlab.example.com - The top-level group path is
my-organization
Use the group URL path, which can differ from the group's display name. The host must be a hostname without https://, a port, or a path.
Step 2: Create and scope a GitLab service account
-
In GitLab, go to the top-level group.
-
Go to Settings → Service accounts.
-
Select Add service account.
-
Enter a name that identifies the agent integration, then select Create service account.
-
Add the service account to the top-level group or the specific projects it needs.
-
Assign the lowest role that supports the agent's work:
Role Use when the agent needs to Reporter Read repository content and work with issues without pushing code Developer Create branches, push to non-protected branches, and create merge requests
GitLab service accounts are external users. Grant the account explicit access to each private group or project the agent needs.
Step 3: Create a service account access token
-
On the Service accounts page, find the account you created.
-
Open the vertical ellipsis menu and select Manage access tokens.
-
Select Add new token.
-
Enter a descriptive token name and an expiration date that follows your organization's rotation policy.
-
Choose the least-privileged scopes for the agent:
Access Token scopes Read GitLab API data and repository files read_apiandread_repositoryCreate or update issues, merge requests, comments, branches, and repository files api -
Select Create personal access token.
-
Copy the token and store it in your secret manager. GitLab doesn't display the value again.
The api scope grants complete API access within the service account's effective GitLab permissions. Keep the service account's role and project memberships as narrow as possible.
Step 4: Create the service credential in Glean
- In Glean, go to Admin console → Platform → Tools → Service credentials.
- Select Add, then select GitLab.
- Fill in these fields:
- Credential name: A name that identifies the credential.
- Description: The GitLab host, top-level group, and intended use. Include enough detail for an agent builder to select the correct credential.
- GitLab Host: The hostname from Step 1, such as
gitlab.comorgitlab.example.com. - Top-level Group Path: The path from the top-level group's URL, such as
my-organization. - Service Account Access Token: The personal access token you created in Step 3.
- Audience: The people or groups who can attach this credential to agents.
- Select Save. Glean stores the token encrypted and doesn't display it again.
Step 5: Attach the credential to an agent
- Go to Agents in Glean and select the agent.
- Open the Tools tab.
- Under Service credentials, select the GitLab credential you created.
Verify it works
Ask the agent to read from a project in the configured top-level group, such as, "List the open merge requests in my-organization/example-project." If it returns the expected results, the credential is working.
If the credential includes write access, create or update an issue in a test project. Confirm that Glean asks for approval and that GitLab attributes the change to the service account.
What the agent can do
Depending on the service account's role and token scopes, the agent can:
- Read repositories, files, branches, issues, merge requests, comments, and pipelines
- Create or update issues, merge requests, comments, branches, files, and labels
- Work with projects under the configured top-level group on GitLab.com or a custom GitLab host
Glean instructs the agent to stay within the configured top-level group. It also instructs the agent not to merge a merge request, delete a project or branch, force-push, change permissions or settings, or write directly to a default or protected branch unless the user explicitly requests that action.
Security and operational notes
- Dedicated service account: use a service account created for this integration so GitLab attributes agent activity separately from human activity.
- Least privilege: restrict the account's group and project memberships, choose the lowest GitLab role that supports the task, and grant only the required token scopes.
- Group boundary: enter the intended top-level group path in Glean and don't grant the service account access outside that group unless another approved workflow requires it.
- Injected server-side: Glean adds the token only to requests for the configured GitLab host. The agent runtime never receives the raw token.
- Write approval: Glean requires approval before the agent sends requests that create or update GitLab data.
- Rotation: create or rotate the token in GitLab, update Service Account Access Token in Glean, test the credential, and then revoke the old token.
- Revocation: revoke the token in GitLab or remove the GitLab service credential in Glean to cut off access.