Skip to main content

Common Misconfiguration

Exposed GitLab tokens can lead to unauthorized repository access, CI/CD pipeline manipulation, and container registry breaches. 😱

Vulnerable Example

Secure Example


Detection Patterns

  • GitLab Personal Access Token: `glpat-[0-9a-zA-Z\-\_]{20}`
  • GitLab Project Access Token: `glpat-[0-9a-zA-Z\-\_]{20}`
  • GitLab Group Access Token: `glpat-[0-9a-zA-Z\-\_]{20}`
  • GitLab Deploy Token Password: `gldt-[0-9a-zA-Z\-\_]{20}`
  • GitLab Runner Registration Token: `GR1348941[0-9a-zA-Z\-\_]{20}`
  • GitLab CI/CD Job Token (format): `glc[i|j]t-[0-9a-zA-Z\-\_]{20,}` (Note: $CI_JOB_TOKEN itself is secure in context)
  • GitLab Trigger Token: `gl[p|t]t-[0-9a-zA-Z]{20,}`
  • GitLab Feed Token: `feed_token_[0-9a-zA-Z\-\_]{20,}`

Prevention Best Practices

  1. Use CI/CD Variables: Never hardcode tokens directly in your .gitlab-ci.yml or scripts. Store them in GitLab CI/CD Variables (Settings > CI/CD > Variables). ⚙️
  2. Mask & Protect Variables: For sensitive variables like API keys or deploy tokens, mark them as Masked (hides value in job logs, requires specific format) and Protected (only available on protected branches/tags). This significantly reduces exposure risk.
  3. Prefer Job Tokens ($CI_JOB_TOKEN): Use the automatically available $CI_JOB_TOKEN whenever possible. It’s short-lived (only valid for the job’s duration) and has limited permissions scoped to the project. It’s ideal for accessing the project’s own container registry or package registry.
  4. Implement Token Rotation: Regularly rotate all static tokens (Personal, Project, Group Access Tokens, Deploy Tokens). Define a schedule (e.g., every 90 days) and automate the rotation process if possible using the GitLab API.
  5. Use Project/Group Tokens over Personal: Avoid using Personal Access Tokens (PATs) for automation. PATs are tied to a user account and often have broad permissions. Use Project Access Tokens or Group Access Tokens instead, which are designed for automation and have more granular scope control.
  6. Enforce 2FA: Require Two-Factor Authentication (2FA) for all user accounts, especially those with Maintainer or Owner roles. This prevents account takeover, which could lead to token compromise.
  7. Monitor Audit Events: Regularly review GitLab’s Audit Events (Admin Area or Group/Project Settings) for suspicious activity related to token creation, usage, or CI/CD variable changes.
  8. Use Dependency Proxy: Enable GitLab’s Dependency Proxy to securely cache Docker Hub images. This reduces reliance on external registries and allows you to authenticate using the GitLab job token ($CI_DEPENDENCY_PROXY_USER, $CI_DEPENDENCY_PROXY_PASSWORD).