Skip to main content
Rotate the personal access tokens of a GitLab group service account on a schedule. Infisical keeps two tokens active. On each rotation, it rotates the older one in GitLab, which revokes it and issues a replacement, and stores the new token in a secret. The service account doesn’t need a token beforehand: Infisical creates the first one when you create the rotation.
Rotation Type: Dual-PhaseThis rotation maintains two active credential sets with overlapping validity, ensuring zero-downtime during rotation cycles.
This rotation needs a GitLab app connection. This guide walks you through creating a project-scoped app connection.

Prerequisites

Don’t rotate the generated tokens outside Infisical. GitLab lets a token with the api or self_rotate scope rotate itself, which revokes it and issues a replacement that Infisical doesn’t know about. The next time Infisical rotates that token, GitLab sees it was already rotated and revokes the replacement too. Until then, or if you delete the rotation first, the replacement stays active.

Step 1: Create a personal access token for Infisical

Infisical needs a GitLab connection whose user has the Owner role on the group that owns the service account, so that Infisical can create and revoke the service account’s tokens.
1
Create a personal access token with the api scope for a user that has the Owner role on the group. This token is for the connection, not for the service account you rotate.
To keep the connection independent of a person, give a second service account the Owner role on the group and create a token for it to use for the connection. It must be a different service account from the one you rotate: Infisical refuses to create tokens for the user the connection authenticates as.
2
When you create the GitLab connection in Step 2, use this token with Personal Access Token as the access token type.
GitLab doesn’t let group or project access tokens create other tokens, so the rotation fails with a connection that uses one. A connection that uses OAuth works if its user has the Owner role on the group.

Step 2: Set up the rotation in Infisical

To create the rotation using the API, use the GitLab service account token Create endpoint.
1
In your Secrets Management project, open the dashboard, select Add New, then select Add Secret Rotation.Add Secret RotationThen, select the GitLab Service Account Token option.
2
Under Configuration, choose the app connection and when the rotation runs:
  • Environment: The project environment the rotated secrets are stored in
  • GitLab Connection: The app connection the rotation uses
  • Rotation Interval (In Days): The number of days between rotations, up to 180
  • Rotate At (Local Time): The time of day the rotation runs
  • Auto-Rotation Enabled: When enabled, the token rotates on the schedule; turn it off to rotate manually only
Under GitLab Connection, select Create GitLab Connection in the dropdown, then fill in:
  • Name: A name for the connection
  • Description (optional): What the connection is for
  • Self-hosted URL (optional): The URL of your GitLab Self-Managed or GitLab Dedicated instance; leave empty for GitLab.com
  • Method: Access Token
  • Access Token Type: Personal Access Token
  • Access Token: The token from Step 1
Select Connect to GitLab. Infisical returns you to the rotation form with the new connection selected.
This creates a connection scoped to the current project. To share the connection across other projects, create it at the organization level first, then select it here.
Then select Continue.
3
Under Parameters, choose the service account and the token Infisical creates for it:
  • Group: The group that owns the service account; the list shows groups where the connection’s user has the Owner role (you can’t change it after you create the rotation)
  • Service Account: The service account whose tokens Infisical rotates (you can’t change it after you create the rotation); the list leaves out the account the connection authenticates as
  • Token Name: The name of each generated token; Infisical appends a timestamp so each rotated token has a distinct name
  • Token Description (optional): A description shown on each generated token in GitLab
  • Scopes: The scopes granted to each generated token
Then select Continue.
4
Under Mappings, choose the names of the Infisical secrets that hold the rotated values:
  • Token ID: The name of the secret that holds the ID of the token in GitLab
  • Token: The name of the secret that holds the token
Then select Continue.
5
Give the rotation a Name and an optional Description. The name must be slug-friendly.Then select Continue.
6
Under Alerts, choose who Infisical notifies if a scheduled rotation fails. Rotation failure alerts are on by default.Then select Continue.
7
Review your GitLab Service Account Token Rotation configuration, then select Create secret rotation.
The token is now available through the mapped secrets. If auto-rotation is enabled, the token rotates on your configured schedule.

Frequently asked questions

Each token expires two rotation intervals plus three days after Infisical creates it, so the token is still valid when the next rotation revokes it. GitLab limits token lifetimes to 365 days by default, so the rotation interval can be at most 180 days.A token’s expiry is fixed when Infisical creates it. When you change the rotation interval, Infisical rotates the token right away so the new token’s expiry matches the new interval, and later rotations follow the new schedule.If an administrator set a shorter maximum token lifetime on your instance, choose a rotation interval where twice the interval plus three days fits within that limit. Otherwise GitLab rejects the new token and the rotation fails with GitLab’s error.
No. Infisical only revokes the tokens it created for the rotation, so it never revokes the connection’s own token. A rotation can’t target the service account the connection authenticates as, because the generated token would carry the connection’s own access.If the service account already had tokens you created by hand, revoke them after your applications read the token from Infisical, so only the rotated tokens stay active.
The token has the scopes you select, limited by the service account’s own role in each group or project. To change what the token can reach, change the service account’s role, or edit the rotation’s scopes; from the next rotation, Infisical replaces each token with a new one that has the new scopes.

Next steps

GitLab

Set up the GitLab connection that Infisical uses to manage service account tokens.

Overview

Learn how dual-phase and single-phase rotations work.