doc/administration/auth/ldap/_index.md
{{< details >}}
{{< /details >}}
GitLab integrates with LDAP - Lightweight Directory Access Protocol to support user authentication.
This integration works with most LDAP-compliant directory servers, including:
[!note] GitLab does not support Microsoft Active Directory Trusts.
Users added through LDAP:
The LDAP distinguished name (DN) is associated with existing GitLab users when:
If an existing GitLab user wants to enable LDAP sign-in for themselves, they should:
[!note] After a user links an LDAP identity to their GitLab account, they can no longer use the standard username and password authentication flow. Instead, users must authenticate with their LDAP credentials. Attempts to sign in with their username and password authentication, return an invalid login or password error.
GitLab verifies if a user is still active in LDAP.
Users are considered inactive in LDAP when they:
base DN or user_filter search.userAccountControl:1.2.840.113556.1.4.803 has bit 2 set.To check if a user is active or inactive in LDAP, use the following PowerShell command and the Active Directory Module to check the Active Directory:
Get-ADUser -Identity <username> -Properties userAccountControl | Select-Object Name, userAccountControl
GitLab checks LDAP users' status:
If the user is no longer active in LDAP, they are:
ldap_blocked status.You should only use LDAP integration if your LDAP users cannot:
mail, email or userPrincipalName attributes on the LDAP server. These
users can potentially take over any account on your GitLab server.Prerequisites:
To configure LDAP, you edit the settings in a configuration file:
labelhostportuidbaseencryptionThe file you edit differs depending on your GitLab setup:
{{< tabs >}}
{{< tab title="Linux package (Omnibus)" >}}
Edit /etc/gitlab/gitlab.rb:
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = {
'main' => {
'label' => 'LDAP',
'host' => 'ldap.mydomain.com',
'port' => 636,
'uid' => 'sAMAccountName',
'bind_dn' => 'CN=Gitlab,OU=Users,DC=domain,DC=com',
'password' => '<bind_user_password>',
'encryption' => 'simple_tls',
'verify_certificates' => true,
'timeout' => 10,
'active_directory' => false,
'user_filter' => '(employeeType=developer)',
'base' => 'dc=example,dc=com',
'lowercase_usernames' => 'false',
'retry_empty_result_with_codes' => [80],
'allow_username_or_email_login' => false,
'block_auto_created_users' => false
}
}
Save the file and reconfigure GitLab:
sudo gitlab-ctl reconfigure
{{< /tab >}}
{{< tab title="Helm chart (Kubernetes)" >}}
Export the Helm values:
helm get values gitlab > gitlab_values.yaml
Edit gitlab_values.yaml:
global:
appConfig:
ldap:
servers:
main:
label: 'LDAP'
host: 'ldap.mydomain.com'
port: 636
uid: 'sAMAccountName'
bind_dn: 'CN=Gitlab,OU=Users,DC=domain,DC=com'
password: '<bind_user_password>'
encryption: 'simple_tls'
verify_certificates: true
timeout: 10
active_directory: false
user_filter: '(employeeType=developer)'
base: 'dc=example,dc=com'
lowercase_usernames: false
retry_empty_result_with_codes: [80]
allow_username_or_email_login: false
block_auto_created_users: false
Save the file and apply the new values:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
For more information, see how to configure LDAP for a GitLab instance that was installed by using the Helm chart.
{{< /tab >}}
{{< tab title="Docker" >}}
Edit docker-compose.yml:
version: "3.6"
services:
gitlab:
image: 'gitlab/gitlab-ee:latest'
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = {
'main' => {
'label' => 'LDAP',
'host' => 'ldap.mydomain.com',
'port' => 636,
'uid' => 'sAMAccountName',
'bind_dn' => 'CN=Gitlab,OU=Users,DC=domain,DC=com',
'password' => '<bind_user_password>',
'encryption' => 'simple_tls',
'verify_certificates' => true,
'timeout' => 10,
'active_directory' => false,
'user_filter' => '(employeeType=developer)',
'base' => 'dc=example,dc=com',
'lowercase_usernames' => 'false',
'retry_empty_result_with_codes' => [80],
'allow_username_or_email_login' => false,
'block_auto_created_users' => false
}
}
Save the file and restart GitLab:
docker compose up -d
{{< /tab >}}
{{< tab title="Self-compiled (source)" >}}
Edit /home/git/gitlab/config/gitlab.yml:
production: &base
ldap:
enabled: true
servers:
main:
label: 'LDAP'
host: 'ldap.mydomain.com'
port: 636
uid: 'sAMAccountName'
bind_dn: 'CN=Gitlab,OU=Users,DC=domain,DC=com'
password: '<bind_user_password>'
encryption: 'simple_tls'
verify_certificates: true
timeout: 10
active_directory: false
user_filter: '(employeeType=developer)'
base: 'dc=example,dc=com'
lowercase_usernames: false
retry_empty_result_with_codes: [80]
allow_username_or_email_login: false
block_auto_created_users: false
Save the file and restart GitLab:
# For systems running systemd
sudo systemctl restart gitlab.target
# For systems running SysV init
sudo service gitlab restart
For more information about the various LDAP options, see the ldap setting in
gitlab.yml.example.
{{< /tab >}}
{{< /tabs >}}
After configuring LDAP, to test the configuration, use the LDAP check Rake task.
The following basic settings are available:
| Setting | Required | Type | Description |
|---|---|---|---|
label | {{< icon name="check-circle" >}} Yes | String | A human-friendly name for your LDAP server. It is displayed on your sign-in page. Example: 'Paris' or 'Acme, Ltd.' |
host | {{< icon name="check-circle" >}} Yes | String | IP address or domain name of your LDAP server. Ignored when hosts is defined. Example: 'ldap.mydomain.com' |
port | {{< icon name="check-circle" >}} Yes | Integer | The port to connect with on your LDAP server. Ignored when hosts is defined. Example: 389 or 636 (for SSL) |
uid | {{< icon name="check-circle" >}} Yes | String | The LDAP attribute that maps to the username that users use to sign in. Should be the attribute, not the value that maps to the uid. Does not affect the GitLab username (see attributes section). Example: 'sAMAccountName' or 'uid' or 'userPrincipalName' |
base | {{< icon name="check-circle" >}} Yes | String | Base where we can search for users. Example: 'ou=people,dc=gitlab,dc=example' or 'DC=mydomain,DC=com' |
encryption | {{< icon name="check-circle" >}} Yes | String | Encryption method (the method key is deprecated in favor of encryption). It can have one of three values: 'start_tls', 'simple_tls', or 'plain'. simple_tls corresponds to 'Simple TLS' in the LDAP library. start_tls corresponds to StartTLS, not to be confused with regular TLS. If you specify simple_tls, usually it's on port 636, while start_tls (StartTLS) would be on port 389. plain also operates on port 389. |
hosts | {{< icon name="dotted-circle" >}} No | Array of strings and integers | An array of host and port pairs to open connections. Each configured server should have an identical data set. This is not meant to configure multiple distinct LDAP servers, but to configure failover. Hosts are tried in the order they are configured. Example: [['ldap1.mydomain.com', 636], ['ldap2.mydomain.com', 636]] |
bind_dn | {{< icon name="dotted-circle" >}} No | String | The full DN of the user you bind with. Example: 'america\momo' or 'CN=Gitlab,OU=Users,DC=domain,DC=com' |
password | {{< icon name="dotted-circle" >}} No | String | The password of the bind user. |
verify_certificates | {{< icon name="dotted-circle" >}} No | Boolean | Defaults to true. Enables SSL certificate verification if encryption method is start_tls or simple_tls. If set to false, no validation of the LDAP server's SSL certificate is performed. |
timeout | {{< icon name="dotted-circle" >}} No | Integer | Defaults to 10. Set a timeout, in seconds, for LDAP queries. This helps avoid blocking a request if the LDAP server becomes unresponsive. A value of 0 means there is no timeout. |
active_directory | {{< icon name="dotted-circle" >}} No | Boolean | This setting specifies if LDAP server is Active Directory LDAP server. For non-AD servers it skips the AD specific queries. If your LDAP server is not AD, set this to false. |
allow_username_or_email_login | {{< icon name="dotted-circle" >}} No | Boolean | Defaults to false. If enabled, GitLab ignores everything after the first @ in the LDAP username submitted by the user on sign-in. If you are using uid: 'userPrincipalName' on ActiveDirectory you must disable this setting, because the userPrincipalName contains an @. |
block_auto_created_users | {{< icon name="dotted-circle" >}} No | Boolean | Defaults to false. To maintain tight control over the number of billable users on your GitLab installation, enable this setting to keep new users blocked until they have been cleared by an administrator . |
user_filter | {{< icon name="dotted-circle" >}} No | String | Filter LDAP users. Follows the format of RFC 4515. GitLab does not support omniauth-ldap's custom filter syntax. Examples of the user_filter field syntax: |
'(employeeType=developer)''(&(objectclass=user)(\|(samaccountname=momo)(samaccountname=toto)))' |
| lowercase_usernames | {{< icon name="dotted-circle" >}} No | Boolean | If enabled, GitLab converts the name to lowercase. |
| retry_empty_result_with_codes | {{< icon name="dotted-circle" >}} No | Array | An array of LDAP query response code that attempt to retry the operation if the result/content is empty. For Google Secure LDAP, set this value to [80]. |[!note] GitLab is unaffected by the stricter binding requirements for Microsoft Active Directory Services introduced with Microsoft advisory ADV190023. For more information, see issue 201894.
You can configure SSL configuration settings under tls_options name/value
pairs. The following settings are all optional:
| Setting | Description | Examples |
|---|---|---|
ca_file | Specifies the path to a file containing a PEM-format CA certificate, for example, if you need an internal CA. | '/etc/ca.pem' |
ssl_version | Specifies the SSL version for OpenSSL to use, if the OpenSSL default is not appropriate. | 'TLSv1_1' |
ciphers | Specific SSL ciphers to use in communication with LDAP servers. | 'ALL:!EXPORT:!LOW:!aNULL:!eNULL:!SSLv2' |
cert | Client certificate. | '-----BEGIN CERTIFICATE----- <REDACTED> -----END CERTIFICATE -----' |
key | Client private key. | '-----BEGIN PRIVATE KEY----- <REDACTED> -----END PRIVATE KEY -----' |
The examples below illustrate how to set ca_file and ssl_version in tls_options:
{{< tabs >}}
{{< tab title="Linux package (Omnibus)" >}}
Edit /etc/gitlab/gitlab.rb:
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = {
'main' => {
'label' => 'LDAP',
'host' => 'ldap.mydomain.com',
'port' => 636,
'uid' => 'sAMAccountName',
'encryption' => 'simple_tls',
'base' => 'dc=example,dc=com',
'tls_options' => {
'ca_file' => '/path/to/ca_file.pem',
'ssl_version' => 'TLSv1_2'
}
}
}
Save the file and reconfigure GitLab:
sudo gitlab-ctl reconfigure
{{< /tab >}}
{{< tab title="Helm chart (Kubernetes)" >}}
Export the Helm values:
helm get values gitlab > gitlab_values.yaml
Edit gitlab_values.yaml:
global:
appConfig:
ldap:
servers:
main:
label: 'LDAP'
host: 'ldap.mydomain.com'
port: 636
uid: 'sAMAccountName'
base: 'dc=example,dc=com'
encryption: 'simple_tls'
tls_options:
ca_file: '/path/to/ca_file.pem'
ssl_version: 'TLSv1_2'
Save the file and apply the new values:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
For more information, see how to configure LDAP for a GitLab instance that was installed by using the Helm chart.
{{< /tab >}}
{{< tab title="Docker" >}}
Edit docker-compose.yml:
version: "3.6"
services:
gitlab:
image: 'gitlab/gitlab-ee:latest'
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = {
'main' => {
'label' => 'LDAP',
'host' => 'ldap.mydomain.com',
'port' => 636,
'uid' => 'sAMAccountName',
'encryption' => 'simple_tls',
'base' => 'dc=example,dc=com',
'tls_options' => {
'ca_file' => '/path/to/ca_file.pem',
'ssl_version' => 'TLSv1_2'
}
}
}
Save the file and restart GitLab:
docker compose up -d
{{< /tab >}}
{{< tab title="Self-compiled (source)" >}}
Edit /home/git/gitlab/config/gitlab.yml:
production: &base
ldap:
enabled: true
servers:
main:
label: 'LDAP'
host: 'ldap.mydomain.com'
port: 636
uid: 'sAMAccountName'
encryption: 'simple_tls'
base: 'dc=example,dc=com'
tls_options:
ca_file: '/path/to/ca_file.pem'
ssl_version: 'TLSv1_2'
Save the file and restart GitLab:
# For systems running systemd
sudo systemctl restart gitlab.target
# For systems running SysV init
sudo service gitlab restart
{{< /tab >}}
{{< /tabs >}}
GitLab uses these LDAP attributes to create an account for the LDAP user. The specified attribute can be either:
'mail'.['mail', 'email'].The user's LDAP sign in is the LDAP attribute specified as uid.
All of the following LDAP attributes are optional. If you define these attributes,
All of the following LDAP attributes are optional. You only need to specify attributes
that differ from the default. If you specify one, for example username, you do not
need to specify the others, defaults will apply.
If you define any of them, you must do so in an attributes hash.
| Setting | Description | Default values |
|---|---|---|
username | The @username that the GitLab account will be provisioned with. If the value contains an email address, the GitLab username is the part of the email address before the @. | Defaults to the LDAP attribute specified as uid (['uid', 'userid', 'sAMAccountName']). |
email | LDAP attribute for user email. | ['mail', 'email', 'userPrincipalName'] |
name | LDAP attribute for user display name. If name is blank, the full name is taken from the first_name and last_name. Attributes 'cn', or 'displayName' commonly carry full names. Alternatively, you can force the use of first_name and last_name by specifying an absent attribute such as 'somethingNonExistent'. | 'cn' |
first_name | LDAP attribute for user first name. Used when the attribute configured for name does not exist. | 'givenName' |
last_name | LDAP attribute for user last name. Used when the attribute configured for name does not exist. | 'sn' |
Example configuration that uses displayName for the user's name and an array of attributes for email:
{{< tabs >}}
{{< tab title="Linux package (Omnibus)" >}}
Edit /etc/gitlab/gitlab.rb:
gitlab_rails['ldap_servers'] = {
'main' => {
# Other configuration settings ...
'attributes' => {
'username' => 'uid',
'email' => ['mail', 'email', 'userPrincipalName'],
'name' => 'displayName',
'first_name' => 'givenName',
'last_name' => 'sn'
}
}
}
Save the file and reconfigure GitLab:
sudo gitlab-ctl reconfigure
{{< /tab >}}
{{< tab title="Helm chart (Kubernetes)" >}}
Export the Helm values:
helm get values gitlab > gitlab_values.yaml
Edit gitlab_values.yaml:
global:
appConfig:
ldap:
servers:
main:
# Other configuration settings ...
attributes:
username: 'uid'
email:
- 'mail'
- 'email'
- 'userPrincipalName'
name: 'displayName'
first_name: 'givenName'
last_name: 'sn'
Save the file and apply the new values:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
{{< /tab >}}
{{< tab title="Docker" >}}
Edit docker-compose.yml:
version: "3.6"
services:
gitlab:
image: 'gitlab/gitlab-ee:latest'
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
gitlab_rails['ldap_servers'] = {
'main' => {
# Other configuration settings ...
'attributes' => {
'username' => 'uid',
'email' => ['mail', 'email', 'userPrincipalName'],
'name' => 'displayName',
'first_name' => 'givenName',
'last_name' => 'sn'
}
}
}
Save the file and restart GitLab:
docker compose up -d
{{< /tab >}}
{{< tab title="Self-compiled (source)" >}}
Edit /home/git/gitlab/config/gitlab.yml:
production: &base
ldap:
servers:
main:
# Other configuration settings ...
attributes:
username: 'uid'
email:
- 'mail'
- 'email'
- 'userPrincipalName'
name: 'displayName'
first_name: 'givenName'
last_name: 'sn'
Save the file and restart GitLab:
# For systems running systemd
sudo systemctl restart gitlab.target
# For systems running SysV init
sudo service gitlab restart
{{< /tab >}}
{{< /tabs >}}
{{< details >}}
{{< /details >}}
These LDAP sync configuration settings are optional, excluding group_base which
required when external_groups is configured:
| Setting | Description | Examples |
|---|---|---|
group_base | Base used to search for groups. All valid groups have this base as part of their DN. | 'ou=groups,dc=gitlab,dc=example' |
admin_group | The CN of a group containing GitLab administrators. Not cn=administrators or the full DN. | 'administrators' |
external_groups | An array of CNs of groups containing users that should be considered external. Not cn=interns or the full DN. | ['interns', 'contractors'] |
sync_ssh_keys | The LDAP attribute containing a user's public SSH key. | 'sshPublicKey' or false if not set |
[!note] If Sidekiq is configured on a different server to the Rails server, you must add the LDAP configuration to every Sidekiq server as well for LDAP synchronisation to work.
{{< details >}}
{{< /details >}}
If you have users on multiple LDAP servers, you can configure GitLab to use them. To add additional LDAP servers:
main LDAP configuration.main, secondary, or tertiary. Use lowercase
alphanumeric characters. GitLab uses the provider ID to associate each user with a specific LDAP server.label value. These values are used for the tab names on the sign-in page.The following example shows how to configure three LDAP servers with minimal configuration:
{{< tabs >}}
{{< tab title="Linux package (Omnibus)" >}}
Edit /etc/gitlab/gitlab.rb:
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = {
'main' => {
'label' => 'GitLab AD',
'host' => 'ad.mydomain.com',
'port' => 636,
'uid' => 'sAMAccountName',
'encryption' => 'simple_tls',
'base' => 'dc=example,dc=com',
},
'secondary' => {
'label' => 'GitLab Secondary AD',
'host' => 'ad-secondary.mydomain.com',
'port' => 636,
'uid' => 'sAMAccountName',
'encryption' => 'simple_tls',
'base' => 'dc=example,dc=com',
},
'tertiary' => {
'label' => 'GitLab Tertiary AD',
'host' => 'ad-tertiary.mydomain.com',
'port' => 636,
'uid' => 'sAMAccountName',
'encryption' => 'simple_tls',
'base' => 'dc=example,dc=com',
}
}
Save the file and reconfigure GitLab:
sudo gitlab-ctl reconfigure
{{< /tab >}}
{{< tab title="Helm chart (Kubernetes)" >}}
Export the Helm values:
helm get values gitlab > gitlab_values.yaml
Edit gitlab_values.yaml:
global:
appConfig:
ldap:
servers:
main:
label: 'GitLab AD'
host: 'ad.mydomain.com'
port: 636
uid: 'sAMAccountName'
base: 'dc=example,dc=com'
encryption: 'simple_tls'
secondary:
label: 'GitLab Secondary AD'
host: 'ad-secondary.mydomain.com'
port: 636
uid: 'sAMAccountName'
base: 'dc=example,dc=com'
encryption: 'simple_tls'
tertiary:
label: 'GitLab Tertiary AD'
host: 'ad-tertiary.mydomain.com'
port: 636
uid: 'sAMAccountName'
base: 'dc=example,dc=com'
encryption: 'simple_tls'
Save the file and apply the new values:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
{{< /tab >}}
{{< tab title="Docker" >}}
Edit docker-compose.yml:
version: "3.6"
services:
gitlab:
image: 'gitlab/gitlab-ee:latest'
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = {
'main' => {
'label' => 'GitLab AD',
'host' => 'ad.mydomain.com',
'port' => 636,
'uid' => 'sAMAccountName',
'encryption' => 'simple_tls',
'base' => 'dc=example,dc=com',
},
'secondary' => {
'label' => 'GitLab Secondary AD',
'host' => 'ad-secondary.mydomain.com',
'port' => 636,
'uid' => 'sAMAccountName',
'encryption' => 'simple_tls',
'base' => 'dc=example,dc=com',
},
'tertiary' => {
'label' => 'GitLab Tertiary AD',
'host' => 'ad-tertiary.mydomain.com',
'port' => 636,
'uid' => 'sAMAccountName',
'encryption' => 'simple_tls',
'base' => 'dc=example,dc=com',
}
}
Save the file and restart GitLab:
docker compose up -d
{{< /tab >}}
{{< tab title="Self-compiled (source)" >}}
Edit /home/git/gitlab/config/gitlab.yml:
production: &base
ldap:
enabled: true
servers:
main:
label: 'GitLab AD'
host: 'ad.mydomain.com'
port: 636
uid: 'sAMAccountName'
base: 'dc=example,dc=com'
encryption: 'simple_tls'
secondary:
label: 'GitLab Secondary AD'
host: 'ad-secondary.mydomain.com'
port: 636
uid: 'sAMAccountName'
base: 'dc=example,dc=com'
encryption: 'simple_tls'
tertiary:
label: 'GitLab Tertiary AD'
host: 'ad-tertiary.mydomain.com'
port: 636
uid: 'sAMAccountName'
base: 'dc=example,dc=com'
encryption: 'simple_tls'
Save the file and restart GitLab:
# For systems running systemd
sudo systemctl restart gitlab.target
# For systems running SysV init
sudo service gitlab restart
For more information about the various LDAP options, see the ldap setting in
gitlab.yml.example.
{{< /tab >}}
{{< /tabs >}}
This example results in a sign-in page with the following tabs:
To limit all GitLab access to a subset of the LDAP users on your LDAP server, first narrow the
configured base. However, to further filter users if
necessary, you can set up an LDAP user filter. The filter must comply with RFC 4515.
{{< tabs >}}
{{< tab title="Linux package (Omnibus)" >}}
Edit /etc/gitlab/gitlab.rb:
gitlab_rails['ldap_servers'] = {
'main' => {
'user_filter' => '(employeeType=developer)'
}
}
Save the file and reconfigure GitLab:
sudo gitlab-ctl reconfigure
{{< /tab >}}
{{< tab title="Helm chart (Kubernetes)" >}}
Export the Helm values:
helm get values gitlab > gitlab_values.yaml
Edit gitlab_values.yaml:
global:
appConfig:
ldap:
servers:
main:
user_filter: '(employeeType=developer)'
Save the file and apply the new values:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
{{< /tab >}}
{{< tab title="Docker" >}}
Edit docker-compose.yml:
version: "3.6"
services:
gitlab:
image: 'gitlab/gitlab-ee:latest'
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
gitlab_rails['ldap_servers'] = {
'main' => {
'user_filter' => '(employeeType=developer)'
}
}
Save the file and restart GitLab:
docker compose up -d
{{< /tab >}}
{{< tab title="Self-compiled (source)" >}}
Edit /home/git/gitlab/config/gitlab.yml:
production: &base
ldap:
servers:
main:
user_filter: '(employeeType=developer)'
Save the file and restart GitLab:
# For systems running systemd
sudo systemctl restart gitlab.target
# For systems running SysV init
sudo service gitlab restart
{{< /tab >}}
{{< /tabs >}}
To limit access to the nested members of an Active Directory group, use the following syntax:
(memberOf:1.2.840.113556.1.4.1941:=CN=My Group,DC=Example,DC=com)
For more information about LDAP_MATCHING_RULE_IN_CHAIN filters, see
Search Filter Syntax.
Support for nested members in the user filter shouldn't be confused with group sync nested groups support.
GitLab does not support the custom filter syntax used by OmniAuth LDAP.
user_filterThe user_filter DN can contain special characters. For example:
A comma:
OU=GitLab, Inc,DC=gitlab,DC=com
Open and close brackets:
OU=GitLab (Inc),DC=gitlab,DC=com
These characters must be escaped as documented in RFC 4515.
Escape commas with \2C. For example:
OU=GitLab\2C Inc,DC=gitlab,DC=com
Escape open brackets with \28 and close brackets with \29. For example:
OU=GitLab \28Inc\29,DC=gitlab,DC=com
Some LDAP servers, depending on their configuration, can return uppercase usernames. This can lead to several confusing issues such as creating links or namespaces with uppercase names.
GitLab can automatically lowercase usernames provided by the LDAP server by enabling
the configuration option lowercase_usernames. By default, this configuration option is false.
{{< tabs >}}
{{< tab title="Linux package (Omnibus)" >}}
Edit /etc/gitlab/gitlab.rb:
gitlab_rails['ldap_servers'] = {
'main' => {
'lowercase_usernames' => true
}
}
Save the file and reconfigure GitLab:
sudo gitlab-ctl reconfigure
{{< /tab >}}
{{< tab title="Helm chart (Kubernetes)" >}}
Export the Helm values:
helm get values gitlab > gitlab_values.yaml
Edit gitlab_values.yaml:
global:
appConfig:
ldap:
servers:
main:
lowercase_usernames: true
Save the file and apply the new values:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
{{< /tab >}}
{{< tab title="Docker" >}}
Edit docker-compose.yml:
version: "3.6"
services:
gitlab:
image: 'gitlab/gitlab-ee:latest'
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
gitlab_rails['ldap_servers'] = {
'main' => {
'lowercase_usernames' => true
}
}
Save the file and restart GitLab:
docker compose up -d
{{< /tab >}}
{{< tab title="Self-compiled (source)" >}}
Edit config/gitlab.yaml:
production:
ldap:
servers:
main:
lowercase_usernames: true
Save the file and restart GitLab:
# For systems running systemd
sudo systemctl restart gitlab.target
# For systems running SysV init
sudo service gitlab restart
{{< /tab >}}
{{< /tabs >}}
It can be useful to prevent using LDAP credentials through the web UI when an alternative such as SAML is preferred. This allows LDAP to be used for group sync, while also allowing your SAML identity provider to handle additional checks like custom 2FA.
When LDAP web sign in is disabled, users don't see an LDAP tab on the sign-in page. This does not disable using LDAP credentials for Git access.
{{< tabs >}}
{{< tab title="Linux package (Omnibus)" >}}
Edit /etc/gitlab/gitlab.rb:
gitlab_rails['prevent_ldap_sign_in'] = true
Save the file and reconfigure GitLab:
sudo gitlab-ctl reconfigure
{{< /tab >}}
{{< tab title="Helm chart (Kubernetes)" >}}
Export the Helm values:
helm get values gitlab > gitlab_values.yaml
Edit gitlab_values.yaml:
global:
appConfig:
ldap:
preventSignin: true
Save the file and apply the new values:
helm upgrade -f gitlab_values.yaml gitlab gitlab/gitlab
{{< /tab >}}
{{< tab title="Docker" >}}
Edit docker-compose.yml:
version: "3.6"
services:
gitlab:
image: 'gitlab/gitlab-ee:latest'
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
gitlab_rails['prevent_ldap_sign_in'] = true
Save the file and restart GitLab:
docker compose up -d
{{< /tab >}}
{{< tab title="Self-compiled (source)" >}}
Edit config/gitlab.yaml:
production:
ldap:
prevent_ldap_sign_in: true
Save the file and restart GitLab:
# For systems running systemd
sudo systemctl restart gitlab.target
# For systems running SysV init
sudo service gitlab restart
{{< /tab >}}
{{< /tabs >}}
For more information on using smart cards with LDAP servers and GitLab, see Smart card authentication.
Instead of having the LDAP integration credentials stored in plaintext in the configuration files, you can optionally use an encrypted file for the LDAP credentials.
Prerequisites:
The encrypted configuration for LDAP exists in an encrypted YAML file. The
unencrypted contents of the file should be a subset of the secret settings from
your servers block in the LDAP configuration.
The supported configuration items for the encrypted file are:
bind_dnpassword{{< tabs >}}
{{< tab title="Linux package (Omnibus)" >}}
If initially your LDAP configuration in /etc/gitlab/gitlab.rb looked like:
gitlab_rails['ldap_servers'] = {
'main' => {
'bind_dn' => 'admin',
'password' => '123'
}
}
Edit the encrypted secret:
sudo gitlab-rake gitlab:ldap:secret:edit EDITOR=vim
Enter the unencrypted contents of the LDAP secret:
main:
bind_dn: admin
password: '123'
Edit /etc/gitlab/gitlab.rb and remove the settings for bind_dn and password.
Save the file and reconfigure GitLab:
sudo gitlab-ctl reconfigure
{{< /tab >}}
{{< tab title="Helm chart (Kubernetes)" >}}
Use a Kubernetes secret to store the LDAP password. For more information, read about Helm LDAP secrets.
{{< /tab >}}
{{< tab title="Docker" >}}
If initially your LDAP configuration in docker-compose.yml looked like:
version: "3.6"
services:
gitlab:
image: 'gitlab/gitlab-ee:latest'
restart: always
hostname: 'gitlab.example.com'
environment:
GITLAB_OMNIBUS_CONFIG: |
gitlab_rails['ldap_servers'] = {
'main' => {
'bind_dn' => 'admin',
'password' => '123'
}
}
Get inside the container, and edit the encrypted secret:
sudo docker exec -t <container_name> bash
gitlab-rake gitlab:ldap:secret:edit EDITOR=vim
Enter the unencrypted contents of the LDAP secret:
main:
bind_dn: admin
password: '123'
Edit docker-compose.yml and remove the settings for bind_dn and password.
Save the file and restart GitLab:
docker compose up -d
{{< /tab >}}
{{< tab title="Self-compiled (source)" >}}
If initially your LDAP configuration in /home/git/gitlab/config/gitlab.yml looked like:
production:
ldap:
servers:
main:
bind_dn: admin
password: '123'
Edit the encrypted secret:
bundle exec rake gitlab:ldap:secret:edit EDITOR=vim RAILS_ENVIRONMENT=production
Enter the unencrypted contents of the LDAP secret:
main:
bind_dn: admin
password: '123'
Edit /home/git/gitlab/config/gitlab.yml and remove the settings for bind_dn and password.
Save the file and restart GitLab:
# For systems running systemd
sudo systemctl restart gitlab.target
# For systems running SysV init
sudo service gitlab restart
{{< /tab >}}
{{< /tabs >}}
When an LDAP server creates a user in GitLab, the user's LDAP DN is linked to their GitLab account as an identifier.
When a user tries to sign in with LDAP, GitLab tries to find the user using the DN saved on that user's account.
GitLab doesn't support TLS client authentication. Complete these steps on your LDAP server.
The TLS client authentication setting in your LDAP server cannot be mandatory and clients cannot be authenticated with the TLS protocol.
Users deleted from the LDAP server:
However, these users can continue to use Git with SSH until the next time the LDAP check cache runs.
To delete the account immediately, you can manually block the user.
Email addresses on the LDAP server are considered the source of truth for users when LDAP is used to sign in.
Updating user email addresses must be done on the LDAP server that manages the user. The email address for GitLab is updated either:
The updated user's previous email address becomes the secondary email address to preserve that user's commit history.
You can find more details on the expected behavior of user updates in our LDAP troubleshooting section.
Google Cloud Identity provides a Secure LDAP service that can be configured with GitLab for authentication and group sync. See Google Secure LDAP for detailed configuration instructions.
For more information on synchronizing users and groups between LDAP and GitLab, see LDAP synchronization.
Optional. Disable the LDAP auth from the sign-in page.
Optional. To fix issues with linking users, you can first remove those users' LDAP identities.
Confirm that users are able to sign in to their accounts. If a user cannot sign in, check if that user's LDAP is still there and remove it if necessary. If this issue persists, check the logs to identify the problem.
In the configuration file, change:
omniauth_auto_link_user to saml only.omniauth_auto_link_ldap_user to false.ldap_enabled to false.
You can also comment out the LDAP provider settings.