debian-mirror-gitlab/doc/administration/auth/ldap.md

556 lines
17 KiB
Markdown
Raw Normal View History

2019-09-30 21:07:59 +05:30
---
type: reference
---
<!-- If the change is EE-specific, put it in `ldap-ee.md`, NOT here. -->
2018-11-08 19:23:39 +05:30
2016-06-02 11:05:42 +05:30
# LDAP
GitLab integrates with LDAP to support user authentication.
2019-10-12 21:52:04 +05:30
This integration works with most LDAP-compliant directory servers, including:
- Microsoft Active Directory
- Apple Open Directory
- Open LDAP
- 389 Server.
GitLab Enterprise Editions (EE) include enhanced integration,
2018-11-08 19:23:39 +05:30
including group membership syncing as well as multiple LDAP servers support.
2019-10-12 21:52:04 +05:30
For more details about EE-specific LDAP features, see the
[LDAP Enterprise Edition documentation](ldap-ee.md).
2018-11-08 19:23:39 +05:30
2019-10-12 21:52:04 +05:30
NOTE: **Note:**
The information on this page is relevant for both GitLab CE and EE.
## Overview
[LDAP](https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol)
stands for **Lightweight Directory Access Protocol**, which is a standard
application protocol for accessing and maintaining distributed directory
information services over an Internet Protocol (IP) network.
2016-06-02 11:05:42 +05:30
## Security
2019-10-12 21:52:04 +05:30
GitLab assumes that LDAP users:
- Are not able to change their LDAP `mail`, `email`, or `userPrincipalName` attribute.
An LDAP user who is allowed to change their email on the LDAP server can potentially
[take over any account](#enabling-ldap-sign-in-for-existing-gitlab-users)
on your GitLab server.
- Have unique email addresses, otherwise it is possible for LDAP users with the same
email address to share the same GitLab account.
2016-06-02 11:05:42 +05:30
We recommend against using LDAP integration if your LDAP users are
2019-10-12 21:52:04 +05:30
allowed to change their 'mail', 'email' or 'userPrincipalName' attribute on
the LDAP server or share email addresses.
2016-06-02 11:05:42 +05:30
### User deletion
2019-07-31 22:56:46 +05:30
If a user is deleted from the LDAP server, they will be blocked in GitLab as
2016-06-02 11:05:42 +05:30
well. Users will be immediately blocked from logging in. However, there is an
2019-07-31 22:56:46 +05:30
LDAP check cache time of one hour (see note) which means users that
2016-06-02 11:05:42 +05:30
are already logged in or are using Git over SSH will still be able to access
2020-03-13 15:44:24 +05:30
GitLab for up to one hour. Manually block the user in the GitLab Admin Area to
2016-06-02 11:05:42 +05:30
immediately block all access.
2018-11-08 19:23:39 +05:30
NOTE: **Note**:
GitLab Enterprise Edition Starter supports a
2019-07-31 22:56:46 +05:30
[configurable sync time](ldap-ee.md#adjusting-ldap-user-sync-schedule),
2018-11-08 19:23:39 +05:30
with a default of one hour.
2016-06-02 11:05:42 +05:30
2018-03-17 18:26:18 +05:30
## Git password authentication
LDAP-enabled users can always authenticate with Git using their GitLab username
or email and LDAP password, even if password authentication for Git is disabled
in the application settings.
2019-09-30 21:07:59 +05:30
## Google Secure LDAP **(CORE ONLY)**
2019-07-07 11:18:12 +05:30
> Introduced in GitLab 11.9.
[Google Cloud Identity](https://cloud.google.com/identity/) provides a Secure
LDAP service that can be configured with GitLab for authentication and group sync.
See [Google Secure LDAP](google_secure_ldap.md) for detailed configuration instructions.
2016-06-02 11:05:42 +05:30
## Configuration
2018-11-08 19:23:39 +05:30
NOTE: **Note**:
In GitLab Enterprise Edition Starter, you can configure multiple LDAP servers
to connect to one GitLab server.
2019-10-12 21:52:04 +05:30
For a complete guide on configuring LDAP with:
- GitLab Community Edition, see
[How to configure LDAP with GitLab CE](how_to_configure_ldap_gitlab_ce/index.md).
- Enterprise Editions, see
[How to configure LDAP with GitLab EE](how_to_configure_ldap_gitlab_ee/index.md). **(STARTER ONLY)**
2018-03-17 18:26:18 +05:30
2016-06-02 11:05:42 +05:30
To enable LDAP integration you need to add your LDAP server settings in
2018-11-08 19:23:39 +05:30
`/etc/gitlab/gitlab.rb` or `/home/git/gitlab/config/gitlab.yml` for Omnibus
GitLab and installations from source respectively.
2016-06-02 11:05:42 +05:30
2017-08-17 22:00:37 +05:30
There is a Rake task to check LDAP configuration. After configuring LDAP
using the documentation below, see [LDAP check Rake task](../raketasks/check.md#ldap-check)
for information on the LDAP check Rake task.
2016-06-02 11:05:42 +05:30
Prior to version 7.4, GitLab used a different syntax for configuring
LDAP integration. The old LDAP integration syntax still works but may be
removed in a future version. If your `gitlab.rb` or `gitlab.yml` file contains
LDAP settings in both the old syntax and the new syntax, only the __old__
syntax will be used by GitLab.
The configuration inside `gitlab_rails['ldap_servers']` below is sensitive to
incorrect indentation. Be sure to retain the indentation given in the example.
Copy/paste can sometimes cause problems.
2018-11-08 19:23:39 +05:30
NOTE: **Note:**
The `encryption` value `ssl` corresponds to 'Simple TLS' in the LDAP
library. `tls` corresponds to StartTLS, not to be confused with regular TLS.
Normally, if you specify `ssl` it will be on port 636, while `tls` (StartTLS)
would be on port 389. `plain` also operates on port 389.
2019-07-07 11:18:12 +05:30
NOTE: **Note:**
LDAP users must have an email address set, regardless of whether it is used to log in.
2016-06-02 11:05:42 +05:30
**Omnibus configuration**
```ruby
gitlab_rails['ldap_enabled'] = true
2019-12-26 22:10:19 +05:30
gitlab_rails['prevent_ldap_sign_in'] = false
2016-06-02 11:05:42 +05:30
gitlab_rails['ldap_servers'] = YAML.load <<-EOS # remember to close this block with 'EOS' below
2018-11-08 19:23:39 +05:30
##
## 'main' is the GitLab 'provider ID' of this LDAP server
##
main:
##
## A human-friendly name for your LDAP server. It is OK to change the label later,
## for instance if you find out it is too large to fit on the web page.
##
## Example: 'Paris' or 'Acme, Ltd.'
##
2016-06-02 11:05:42 +05:30
label: 'LDAP'
2018-11-08 19:23:39 +05:30
##
## Example: 'ldap.mydomain.com'
##
2016-06-02 11:05:42 +05:30
host: '_your_ldap_server'
2018-11-08 19:23:39 +05:30
##
## This port is an example, it is sometimes different but it is always an
## integer and not a string.
##
2017-09-10 17:25:29 +05:30
port: 389 # usually 636 for SSL
2017-08-17 22:00:37 +05:30
uid: 'sAMAccountName' # This should be the attribute, not the value that maps to uid.
2018-11-08 19:23:39 +05:30
##
2018-12-05 23:21:45 +05:30
## Examples: 'america\momo' or 'CN=Gitlab Git,CN=Users,DC=mydomain,DC=com'
2018-11-08 19:23:39 +05:30
##
2016-06-02 11:05:42 +05:30
bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
password: '_the_password_of_the_bind_user'
2018-11-08 19:23:39 +05:30
##
## Encryption method. The "method" key is deprecated in favor of
## "encryption".
##
## Examples: "start_tls" or "simple_tls" or "plain"
##
## Deprecated values: "tls" was replaced with "start_tls" and "ssl" was
## replaced with "simple_tls".
##
##
2017-09-10 17:25:29 +05:30
encryption: 'plain'
2018-11-08 19:23:39 +05:30
##
## Enables SSL certificate verification if encryption method is
## "start_tls" or "simple_tls". Defaults to true since GitLab 10.0 for
## security. This may break installations upon upgrade to 10.0, that did
2018-12-05 23:21:45 +05:30
## not know their LDAP SSL certificates were not set up properly.
2018-11-08 19:23:39 +05:30
##
2018-03-17 18:26:18 +05:30
verify_certificates: true
2017-09-10 17:25:29 +05:30
2019-07-07 11:18:12 +05:30
# OpenSSL::SSL::SSLContext options.
tls_options:
# Specifies the path to a file containing a PEM-format CA certificate,
# e.g. if you need to use an internal CA.
#
# Example: '/etc/ca.pem'
#
ca_file: ''
# Specifies the SSL version for OpenSSL to use, if the OpenSSL default
# is not appropriate.
#
# Example: 'TLSv1_1'
#
ssl_version: ''
# Specific SSL ciphers to use in communication with LDAP servers.
#
# Example: 'ALL:!EXPORT:!LOW:!aNULL:!eNULL:!SSLv2'
ciphers: ''
# Client certificate
#
# Example:
# cert: |
# -----BEGIN CERTIFICATE-----
# MIIDbDCCAlSgAwIBAgIGAWkJxLmKMA0GCSqGSIb3DQEBCwUAMHcxFDASBgNVBAoTC0dvb2dsZSBJ
# bmMuMRYwFAYDVQQHEw1Nb3VudGFpbiBWaWV3MRQwEgYDVQQDEwtMREFQIENsaWVudDEPMA0GA1UE
# CxMGR1N1aXRlMQswCQYDVQQGEwJVUzETMBEGA1UECBMKQ2FsaWZvcm5pYTAeFw0xOTAyMjAwNzE4
# rntnF4d+0dd7zP3jrWkbdtoqjLDT/5D7NYRmVCD5vizV98FJ5//PIHbD1gL3a9b2MPAc6k7NV8tl
# ...
# 4SbuJPAiJxC1LQ0t39dR6oMCAMab3hXQqhL56LrR6cRBp6Mtlphv7alu9xb/x51y2x+g2zWtsf80
# Jrv/vKMsIh/sAyuogb7hqMtp55ecnKxceg==
# -----END CERTIFICATE -----
cert: ''
# Client private key
# key: |
# -----BEGIN PRIVATE KEY-----
# MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQC3DmJtLRmJGY4xU1QtI3yjvxO6
# bNuyE4z1NF6Xn7VSbcAaQtavWQ6GZi5uukMo+W5DHVtEkgDwh92ySZMuJdJogFbNvJvHAayheCdN
# 7mCQ2UUT9jGXIbmksUn9QMeJVXTZjgJWJzPXToeUdinx9G7+lpVa62UATEd1gaI3oyL72WmpDy/C
# rntnF4d+0dd7zP3jrWkbdtoqjLDT/5D7NYRmVCD5vizV98FJ5//PIHbD1gL3a9b2MPAc6k7NV8tl
# ...
# +9IhSYX+XIg7BZOVDeYqlPfxRvQh8vy3qjt/KUihmEPioAjLaGiihs1Fk5ctLk9A2hIUyP+sEQv9
# l6RG+a/mW+0rCWn8JAd464Ps9hE=
# -----END PRIVATE KEY-----
key: ''
2017-09-10 17:25:29 +05:30
2018-11-08 19:23:39 +05:30
##
## 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.
##
2016-06-02 11:05:42 +05:30
timeout: 10
2018-11-08 19:23:39 +05:30
##
## 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.
##
2016-06-02 11:05:42 +05:30
active_directory: true
2018-11-08 19:23:39 +05:30
##
## If allow_username_or_email_login is enabled, GitLab will ignore everything
## after the first '@' in the LDAP username submitted by the user on login.
##
## Example:
## - the user enters 'jane.doe@example.com' and 'p@ssw0rd' as LDAP credentials;
## - GitLab queries the LDAP server with 'jane.doe' and 'p@ssw0rd'.
##
## If you are using "uid: 'userPrincipalName'" on ActiveDirectory you need to
## disable this setting, because the userPrincipalName contains an '@'.
##
2016-06-02 11:05:42 +05:30
allow_username_or_email_login: false
2018-11-08 19:23:39 +05:30
##
## To maintain tight control over the number of active users on your GitLab installation,
## enable this setting to keep new users blocked until they have been cleared by the admin
## (default: false).
##
2016-06-02 11:05:42 +05:30
block_auto_created_users: false
2018-11-08 19:23:39 +05:30
##
## Base where we can search for users
##
## Ex. 'ou=People,dc=gitlab,dc=example' or 'DC=mydomain,DC=com'
##
##
2016-06-02 11:05:42 +05:30
base: ''
2018-11-08 19:23:39 +05:30
##
## Filter LDAP users
##
## Format: RFC 4515 https://tools.ietf.org/search/rfc4515
## Ex. (employeeType=developer)
##
## Note: GitLab does not support omniauth-ldap's custom filter syntax.
##
## Example for getting only specific users:
## '(&(objectclass=user)(|(samaccountname=momo)(samaccountname=toto)))'
##
2016-06-02 11:05:42 +05:30
user_filter: ''
2018-11-08 19:23:39 +05:30
##
## LDAP attributes that GitLab will use to create an account for the LDAP user.
## The specified attribute can either be the attribute name as a string (e.g. 'mail'),
## or an array of attribute names to try in order (e.g. ['mail', 'email']).
## Note that the user's LDAP login will always be the attribute specified as `uid` above.
##
2016-06-02 11:05:42 +05:30
attributes:
2018-11-08 19:23:39 +05:30
##
## The username will be used in paths for the user's own projects
## (like `gitlab.example.com/username/project`) and when mentioning
## them in issues, merge request and comments (like `@username`).
## If the attribute specified for `username` contains an email address,
## the GitLab username will be the part of the email address before the '@'.
##
2016-06-02 11:05:42 +05:30
username: ['uid', 'userid', 'sAMAccountName']
email: ['mail', 'email', 'userPrincipalName']
2018-11-08 19:23:39 +05:30
##
## If no full name could be found at the attribute specified for `name`,
## the full name is determined using the attributes specified for
## `first_name` and `last_name`.
##
2016-06-02 11:05:42 +05:30
name: 'cn'
first_name: 'givenName'
last_name: 'sn'
2018-11-08 19:23:39 +05:30
##
## If lowercase_usernames is enabled, GitLab will lower case the username.
##
2018-03-17 18:26:18 +05:30
lowercase_usernames: false
2018-11-08 19:23:39 +05:30
##
2016-08-24 12:49:21 +05:30
## EE only
2018-11-08 19:23:39 +05:30
##
2016-08-24 12:49:21 +05:30
2018-11-08 19:23:39 +05:30
## Base where we can search for groups
##
## Ex. ou=groups,dc=gitlab,dc=example
##
2016-08-24 12:49:21 +05:30
group_base: ''
2018-11-08 19:23:39 +05:30
## The CN of a group containing GitLab administrators
##
## Ex. administrators
##
## Note: Not `cn=administrators` or the full DN
##
2016-08-24 12:49:21 +05:30
admin_group: ''
2018-11-08 19:23:39 +05:30
## An array of CNs of groups containing users that should be considered external
##
## Ex. ['interns', 'contractors']
##
## Note: Not `cn=interns` or the full DN
##
external_groups: []
##
## The LDAP attribute containing a user's public SSH key
##
## Example: sshPublicKey
##
2016-08-24 12:49:21 +05:30
sync_ssh_keys: false
2016-06-02 11:05:42 +05:30
2018-11-08 19:23:39 +05:30
## GitLab EE only: add more LDAP servers
## Choose an ID made of a-z and 0-9 . This ID will be stored in the database
## so that GitLab can remember which LDAP server a user belongs to.
#uswest2:
# label:
# host:
# ....
2016-06-02 11:05:42 +05:30
EOS
```
**Source configuration**
Use the same format as `gitlab_rails['ldap_servers']` for the contents under
`servers:` in the example below:
2018-11-08 19:23:39 +05:30
```yaml
2016-06-02 11:05:42 +05:30
production:
# snip...
ldap:
enabled: false
2019-12-26 22:10:19 +05:30
prevent_ldap_sign_in: false
2016-06-02 11:05:42 +05:30
servers:
2018-11-08 19:23:39 +05:30
##
## 'main' is the GitLab 'provider ID' of this LDAP server
##
main:
##
## A human-friendly name for your LDAP server. It is OK to change the label later,
## for instance if you find out it is too large to fit on the web page.
##
## Example: 'Paris' or 'Acme, Ltd.'
2016-06-02 11:05:42 +05:30
label: 'LDAP'
2018-11-08 19:23:39 +05:30
## snip...
2016-06-02 11:05:42 +05:30
```
## Using an LDAP filter to limit access to your GitLab server
If you want to limit all GitLab access to a subset of the LDAP users on your
LDAP server, the first step should be to narrow the configured `base`. However,
it is sometimes necessary to filter users further. In this case, you can set up
an LDAP user filter. The filter must comply with
[RFC 4515](https://tools.ietf.org/search/rfc4515).
**Omnibus configuration**
```ruby
gitlab_rails['ldap_servers'] = YAML.load <<-EOS
main:
# snip...
user_filter: '(employeeType=developer)'
EOS
```
**Source configuration**
```yaml
production:
ldap:
servers:
main:
# snip...
user_filter: '(employeeType=developer)'
```
Tip: If you want to limit access to the nested members of an Active Directory
2018-03-17 18:26:18 +05:30
group, you can use the following syntax:
2016-06-02 11:05:42 +05:30
2020-04-08 14:13:33 +05:30
```plaintext
2017-09-10 17:25:29 +05:30
(memberOf:1.2.840.113556.1.4.1941:=CN=My Group,DC=Example,DC=com)
2016-06-02 11:05:42 +05:30
```
2017-09-10 17:25:29 +05:30
Find more information about this "LDAP_MATCHING_RULE_IN_CHAIN" filter at
2019-12-21 20:55:43 +05:30
<https://docs.microsoft.com/en-us/windows/win32/adsi/search-filter-syntax>. Support for
2017-09-10 17:25:29 +05:30
nested members in the user filter should not be confused with
2019-09-30 21:07:59 +05:30
[group sync nested groups support](ldap-ee.md#supported-ldap-group-typesattributes). **(STARTER ONLY)**
2017-09-10 17:25:29 +05:30
2016-06-02 11:05:42 +05:30
Please note that GitLab does not support the custom filter syntax used by
2019-12-21 20:55:43 +05:30
OmniAuth LDAP.
2016-06-02 11:05:42 +05:30
2018-11-08 19:23:39 +05:30
### Escaping special characters
2019-09-30 21:07:59 +05:30
The `user_filter` DN can contain special characters. For example:
2018-11-08 19:23:39 +05:30
2019-09-30 21:07:59 +05:30
- A comma:
2018-11-08 19:23:39 +05:30
2020-04-08 14:13:33 +05:30
```plaintext
2019-09-30 21:07:59 +05:30
OU=GitLab, Inc,DC=gitlab,DC=com
```
2018-11-08 19:23:39 +05:30
2019-09-30 21:07:59 +05:30
- Open and close brackets:
2018-11-08 19:23:39 +05:30
2020-04-08 14:13:33 +05:30
```plaintext
2019-09-30 21:07:59 +05:30
OU=Gitlab (Inc),DC=gitlab,DC=com
```
These characters must be escaped as documented in
[RFC 4515](https://tools.ietf.org/search/rfc4515).
- Escape commas with `\2C`. For example:
2020-04-08 14:13:33 +05:30
```plaintext
2019-09-30 21:07:59 +05:30
OU=GitLab\2C Inc,DC=gitlab,DC=com
```
- Escape open and close brackets with `\28` and `\29`, respectively. For example:
2020-04-08 14:13:33 +05:30
```plaintext
2019-09-30 21:07:59 +05:30
OU=Gitlab \28Inc\29,DC=gitlab,DC=com
```
2018-11-08 19:23:39 +05:30
2016-06-02 11:05:42 +05:30
## Enabling LDAP sign-in for existing GitLab users
When a user signs in to GitLab with LDAP for the first time, and their LDAP
email address is the primary email address of an existing GitLab user, then
the LDAP DN will be associated with the existing user. If the LDAP email
attribute is not found in GitLab's database, a new user is created.
In other words, if an existing GitLab user wants to enable LDAP sign-in for
themselves, they should check that their GitLab email address matches their
LDAP email address, and then sign into GitLab via their LDAP credentials.
2018-03-17 18:26:18 +05:30
## Enabling LDAP username lowercase
2020-04-08 14:13:33 +05:30
Some LDAP servers, depending on their configurations, can return uppercase usernames.
This can lead to several confusing issues such as creating links or namespaces with uppercase names.
2018-03-17 18:26:18 +05:30
GitLab can automatically lowercase usernames provided by the LDAP server by enabling
the configuration option `lowercase_usernames`. By default, this configuration option is `false`.
**Omnibus configuration**
1. Edit `/etc/gitlab/gitlab.rb`:
2019-09-30 21:07:59 +05:30
```ruby
gitlab_rails['ldap_servers'] = YAML.load <<-EOS
main:
# snip...
lowercase_usernames: true
EOS
```
2018-03-17 18:26:18 +05:30
2018-11-20 20:47:30 +05:30
1. [Reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure) for the changes to take effect.
2018-03-17 18:26:18 +05:30
**Source configuration**
1. Edit `config/gitlab.yaml`:
2019-09-30 21:07:59 +05:30
```yaml
production:
ldap:
servers:
main:
# snip...
lowercase_usernames: true
```
2018-11-20 20:47:30 +05:30
1. [Restart GitLab](../restart_gitlab.md#installations-from-source) for the changes to take effect.
2018-03-17 18:26:18 +05:30
2019-12-26 22:10:19 +05:30
## Disable LDAP web sign in
2020-04-22 19:07:51 +05:30
It can be useful to prevent using LDAP credentials through the web UI when
2019-12-26 22:10:19 +05:30
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 will not see a **LDAP** tab on the sign in page.
This does not disable [using LDAP credentials for Git access](#git-password-authentication).
**Omnibus configuration**
1. Edit `/etc/gitlab/gitlab.rb`:
```ruby
gitlab_rails['prevent_ldap_sign_in'] = true
```
1. [Reconfigure GitLab](../restart_gitlab.md#omnibus-gitlab-reconfigure) for the changes to take effect.
**Source configuration**
1. Edit `config/gitlab.yaml`:
```yaml
production:
ldap:
prevent_ldap_sign_in: true
```
1. [Restart GitLab](../restart_gitlab.md#installations-from-source) for the changes to take effect.
2017-09-10 17:25:29 +05:30
## Encryption
### TLS Server Authentication
There are two encryption methods, `simple_tls` and `start_tls`.
2018-03-17 18:26:18 +05:30
For either encryption method, if setting `verify_certificates: false`, TLS
2017-09-10 17:25:29 +05:30
encryption is established with the LDAP server before any LDAP-protocol data is
exchanged but no validation of the LDAP server's SSL certificate is performed.
2018-03-17 18:26:18 +05:30
>**Note**: Before GitLab 9.5, `verify_certificates: false` is the default if
2017-09-10 17:25:29 +05:30
unspecified.
2016-06-02 11:05:42 +05:30
## Limitations
### TLS Client Authentication
Not implemented by `Net::LDAP`.
You should disable anonymous LDAP authentication and enable simple or SASL
authentication. The TLS client authentication setting in your LDAP server cannot
be mandatory and clients cannot be authenticated with the TLS protocol.
## Troubleshooting
2020-04-22 19:07:51 +05:30
Please see our [administrator guide to troubleshooting LDAP](ldap-troubleshooting.md).