Published on: February 25, 2025
10 min read
Learn all the steps in the end-to-end process of identifying, managing, and securing tokens for improved security across the software development lifecycle.
Imagine this: You are an engineer at a growing tech company, and it’s 2 a.m. when you get an urgent call. A critical deployment pipeline has failed, and your team is scrambling to figure out why. After hours of digging, you realize someone revoked a personal access token belonging to an engineer who left the company a week ago. This token was tied to several key automation processes, and now your entire system is in chaos. How do you make sure it does not happen again?
Follow this guide, which takes GitLab customers through the end-to-end process of identifying, managing, and securing their tokens. It is meant to be a handy supplement to the extensive token overview documentation for GitLab administrators, developers, and security teams who need to ensure proper token management within their projects.
Here's what is covered in this guide:
Choosing the right token ensures optimal security and functionality based on your use case. Tokens can be used for authenticating API requests, automating CI/CD pipelines, integrating third-party tools, managing deployments and repositories, and more.
For the sake of simplicity, the chart illustrates a straightforward use case tied to single user ownership. For more information, check out our documentation of user roles and permissions at each namespace (user/group) in your instance or top-level group. Example use cases could be as follows:
Below is a list of GitLab tokens with their default prefixes and use cases. For more information, please visit the GitLab Token overview page.
Tokens | Prefix | Description |
---|---|---|
Personal access token | glpat | Access user-specific data |
OAuth 2.0 token | gloas | Integrate with third-party applications using OAuth2.0 authentication protocol |
Impersonation token | glpat | Act on behalf of another user for administrative purposes |
Project access token | glpat | Access data from a specific project |
Group access token | glpat | Access data from a specific group |
Deploy token | gldt | Clone, push, and pull container registry images of a project without a user and a password |
Deploy keys | N/A | Allow read-only or read-write access to your repositories |
Runner authentication token | glrt | Authenticate GitLab Runners |
CI/CD job token | glcbt | Automate CI/CD processes |
Trigger token | glptt | Trigger pipelines manually or programmatically |
Feed token | glft | Authenticate access to package/RSS feeds |
Incoming mail token | glimt | Process incoming emails |
GitLab agent for Kubernetes token | glagent | Manage Kubernetes clusters via the GitLab agent |
SCIM tokens | glsoat | Enable SCIM integrations for user provisioning |
Feature flags client token | glffct | Enable feature flags programmatically |
Webhook token | N/A | User set secret token to secure webhook payloads and ensure that the requests are from GitLab |
On GitLab Ultimate, administrators (GitLab Self-Managed) and top-level group owners of an enterprise organization (GitLab.com as of Version 17.5) can monitor the credentials in their namespace.
This inventory tracks token details such as:
A well-maintained credentials inventory helps identify over-permissioned tokens, and gives insight into credentials that may need to be rotated, ensuring a secure and efficient workflow.
As a complement to the UI, there is ongoing development to release a credentials inventory API through the new /group/:id/manage endpoint. The credentials accessible under this endpoint are limited to enterprise users, and can be accessed by the top-level group owner of an enterprise organization. An example of the future API call would be:
curl --header "PRIVATE-TOKEN: <pat>" "https://verified_domain.com/api/v4/groups/<group_id>/manage/personal_access_tokens"
The GitLab API allows you to programmatically list and manage tokens within your organization. Key authentication-related endpoints support various token types), including personal, group, CI/CD tokens, and more. An example of using a personal access token to list all visible projects across GitLab for the authenticated user is:
curl --header "PRIVATE-TOKEN: <your_access_token>" \
"https://gitlab.example.com/api/v4/projects"
Watch this video to learn how to make API calls to the GitLab API.
Customers can find where tokens are used in different ways:
Information on token usage is updated every 10 minutes for last_used and every minute for last_used_ip.
The ability to view IP addresses was introduced in GitLab 17.9, and is controlled by the :pat_ip feature flag. Follow these steps to view the last time a token was used, along with its last five distinct IP addresses.
The following table includes videos detailing a few token creations in the UI and demonstrates their usage via the API.
Tokens | GitLab UI | GitLab API |
---|---|---|
Personal access token | Documentation and video | Documentation and video |
Group access token | Documentation and video | Documentation and video |
Project access token | Documentation and video | Documentation and video |
Implementing token rotation and strict expiration policies reduces the risk of compromise and ensures compliance with security standards. Regular rotation and enforced expirations prevent stale credentials from becoming security vulnerabilities.
Previously, expired group and project access tokens were automatically deleted upon expiration, which made auditing and security reviews more challenging due to the lack of a record of inactive tokens. To address this, a recent feature introduced the retention of inactive group and project access token records in the UI for 30 days after they became inactive. This enhancement aims to allow teams to track token usage, expiration, and revocation for better compliance and monitoring.
To be more proactive in your token rotation and expiration management, do the following:
Until GitLab 17.7, customers had to programmatically rotate access tokens with the API. Its counterpart is now available on the UI. Check out the video in the table below or follow the documentation for guidance.
The following table includes videos detailing the rotation of GitLab tokens.
Tokens | Prerequisites | GitLab UI | GitLab API |
---|---|---|---|
Personal access token | Scope: api | Documentation and video | Documentation and video |
Group access token | Scope: api and Role(s): owner | Documentation and video | Documentation and video |
Project access token | Scope: api and Role(s): owner, maintainer | Documentation and video | Documentation and video |
Mitigate risk by restricting assigned permissions to tokens required for their respective tasks. This allows you to proactively predict and troubleshoot points of failure in your systems. You can do this by:
Service accounts ensure tokens are tied to non-human entities, separating them from individual user accounts and reducing dependency on specific users. Instead of using personal accounts to generate tokens for automation, create service accounts with limited scopes. Benefits include:
GitLab plans to release a new Service Accounts UI as a counterpart to its API-based creation, designed to simplify the management of service accounts and their associated tokens. Check out the demo below on the programmatic usage of service accounts.
Leverage GitLab’s built-in security tools to identify and mitigate vulnerabilities associated with token usage. For maximum coverage, it is recommended to use them all in tandem.
Maintain token health by regularly reviewing audit logs and token usage, instance- and/or group-wide.
With GitLab’s large token catalog, there are ongoing plans for consolidation with a focus on the lifetime, fine-grained scopes, consistent management, and usage. Our current prioritized token-related features include a complete UI for service accounts, additional credential types in the credentials inventory, and improved auditing for tokens and service accounts.
Sign up for a free 60-day trial of GitLab Ultimate to start using token management.