The GitLab connector is a specialized connector that you can use to connect to GitLab Server (both GitLab.com and self-hosted instances).
You can use the GitLab Connector to securely clone private repositories in CI/CD pipelines, use GitLab CLI (glab) for advanced operations, or use custom CLI tools in containerized workloads to interact with GitLab without directly handling credentials.
Additionally, you can centralize the management of GitLab access configurations across namespaces, avoiding the need to repeat the configuration of GitLab credentials in each namespace.
Notes:
This document will describe:
The GitLab server to be accessed must meet the following conditions:
It must support HTTP/HTTPS transport protocols and is only compatible with the Git "smart HTTP" protocol mode. This mode is the standard implementation for modern Git servers, supporting efficient data transfer and authentication mechanisms.
For GitLab API operations when using GitLab CLI (glab), the GitLab server must meet the version requirements of glab CLI. More details: GitLab CLI (glab) Version Requirements
Constant value gitlab.
You can add description information for the GitLab connector through the annotations field.
cpaas.io/description: Description information for the GitLab connector.For example:
spec.address specifies the access address of the GitLab server.
Important: This address is used for repository cloning, not the API address of the GitLab server. When using GitLab CLI (glab), the connector will automatically construct the API address by appending /api/v4 to this address.
Examples:
https://gitlab.comhttps://gitlab.example.comThe GitLab connector supports the following authentication types:
patAuth: Private Access Token authentication (optional), corresponding secret type: connectors.cpaas.io/gitlab-pat-authPrivate Access Token (PAT) is the recommended authentication method for GitLab. It provides fine-grained access control and can be easily revoked without changing passwords.
For example:
You need to create a Secret in the same namespace, for example:
Note: The secret type must be connectors.cpaas.io/gitlab-pat-auth.
For detailed instructions on how to create a Personal Access Token in GitLab, please refer to the official documentation: {your-gitlab-server}/help/user/profile/personal_access_tokens.md#create-a-personal-access-token
Required Token Scopes:
When creating the token, select the following scopes based on your needs:
read_repository: Required for cloning repositorieswrite_repository: Required for pushing changes if you want to push changes to the repositoryapi: Required for GitLab API operations, e.g. list projects, list branches, list merge requests, etc.Security Best Practices:
For security best practices, we recommend creating tokens with minimal required permissions. When additional privileges are needed, create separate Connectors with more privileged tokens and use namespace isolation to control which users can access each Connector.
If the GitLab server does not require authentication (for public repositories), you can omit the secretRef field:
To enable clients to access GitLab servers without directly handling credentials, the GitLab ConnectorClass provides a proxy server that automatically injects authentication information.
Clients with access to the connector can use this proxy server to access GitLab servers without needing to configure credentials on the client side.
To simplify usage, the GitLab ConnectorClass provides configuration files that can be mounted into Pods via CSI Driver. When executing Git CLI, GitLab CLI (glab), or custom CLI operations in the Pod, these configurations automatically route requests through the proxy service.
When creating a GitLab connector, the system will automatically create a Service for proxying access to the GitLab repository.
The system will record the proxy address in the status.proxy.httpAddress field.
For example:
The GitLab connector provides the following configurations:
gitconfig: Git configuration file for Git CLI operationsgitlabconfig: Configuration file for GitLab CLI (glab) operationsThe connector also inherits the system built-in configurations from connectors-csi. For more details, see: Connectors System Built-in Configurations
Git configuration file for Git CLI operations.
.gitconfig file in which the GitLab server address is rewritten to use the proxy addressExample of the .gitconfig file generated in the Pod:
How it works:
[http] section adds an Authorization header with a Kubernetes API server token (a temporary token used for requests to the GitLab connector proxy service)[url] section rewrites the GitLab server address to use the proxy serviceUsage:
To use the gitconfig configuration in your Pod:
configuration.names: "gitconfig".gitconfig file to the user's home directory (typically /root/).gitconfig file permissions to 644Example CSI volume configuration:
For complete usage examples, see: Quick Start Guide
Configuration file for GitLab CLI (glab) operations.
config.yml configuration file for GitLab CLI (glab)Example of the configuration file generated in the Pod:
How it works:
Usage:
To use the gitlabconfig configuration in your Pod:
configuration.names: "gitlabconfig"config.yml file to ~/.config/glab-cli/600 for securityExample CSI volume configuration:
For complete usage examples with glab commands, see: Using GitLab CLI (glab)
You can mount multiple configurations in the same Pod by separating them with commas in the configuration.names field:
This enables you to use both Git CLI and GitLab CLI (glab) operations in the same Pod. For practical examples, see:
When mounting the gitlab connector, the following built-in configuration files are available:
context.token: The Private Access Token for GitLab authenticationconnector.status.proxyAddress: The proxy service addressThese files are useful for custom integrations or CLI tools that need direct access to the authentication token or proxy address.
For a complete example of using built-in configurations, see: Using Reviewdog with GitLab Connector
More details about system built-in configurations, see: Connectors-CSI Built-in Configurations