2021-01-03 14:25:43 +05:30
---
2021-01-29 00:20:46 +05:30
stage: Manage
2022-04-04 11:22:00 +05:30
group: Authentication and Authorization
2021-02-22 17:27:13 +05:30
info: "To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments"
2021-01-03 14:25:43 +05:30
---
2021-03-11 19:13:27 +05:30
# Kerberos integration **(PREMIUM SELF)**
2019-07-31 22:56:46 +05:30
2020-04-22 19:07:51 +05:30
GitLab can integrate with [Kerberos ](https://web.mit.edu/kerberos/ ) as an authentication mechanism.
2019-07-31 22:56:46 +05:30
2021-11-11 11:23:49 +05:30
WARNING:
2022-03-02 08:16:31 +05:30
GitLab CI/CD doesn't work with a Kerberos-enabled GitLab instance unless the integration is
[set to use a dedicated port ](#http-git-access-with-kerberos-token-passwordless-authentication ).
2021-11-11 11:23:49 +05:30
2019-07-31 22:56:46 +05:30
## Overview
2020-04-22 19:07:51 +05:30
[Kerberos ](https://web.mit.edu/kerberos/ ) is a secure method for authenticating a request for a service in a
2019-07-31 22:56:46 +05:30
computer network. Kerberos was developed in the Athena Project at the
2021-02-22 17:27:13 +05:30
[Massachusetts Institute of Technology (MIT) ](https://web.mit.edu/ ). The name is taken from Greek
2019-07-31 22:56:46 +05:30
mythology; Kerberos was a three-headed dog who guarded the gates of Hades.
## Use-cases
- GitLab can be configured to allow your users to sign with their Kerberos credentials.
2021-02-22 17:27:13 +05:30
- You can use Kerberos to [prevent ](https://web.mit.edu/sipb/doc/working/guide/guide/node20.html ) anyone from intercepting or eavesdropping on the transmitted password.
2019-07-31 22:56:46 +05:30
## Configuration
For GitLab to offer Kerberos token-based authentication, perform the
following prerequisites. You still need to configure your system for
2021-09-04 01:27:46 +05:30
Kerberos usage, such as specifying realms. GitLab makes use of the
2019-07-31 22:56:46 +05:30
system's Kerberos settings.
### GitLab keytab
1. Create a Kerberos Service Principal for the HTTP service on your GitLab server.
If your GitLab server is `gitlab.example.com` and your Kerberos realm
`EXAMPLE.COM` , create a Service Principal `HTTP/gitlab.example.com@EXAMPLE.COM`
in your Kerberos database.
2021-09-04 01:27:46 +05:30
1. Create a keytab on the GitLab server for the above Service Principal. For example,
2019-07-31 22:56:46 +05:30
`/etc/http.keytab` .
The keytab is a sensitive file and must be readable by the GitLab user. Set
ownership and protect the file appropriately:
2020-04-22 19:07:51 +05:30
```shell
2019-07-31 22:56:46 +05:30
sudo chown git /etc/http.keytab
sudo chmod 0600 /etc/http.keytab
```
### Configure GitLab
2021-01-29 00:20:46 +05:30
#### Installations from source
2019-07-31 22:56:46 +05:30
2021-02-22 17:27:13 +05:30
NOTE:
2019-07-31 22:56:46 +05:30
For source installations, make sure the `kerberos` gem group
[has been installed ](../install/installation.md#install-gems ).
2021-09-04 01:27:46 +05:30
1. Edit the `kerberos` section of [`gitlab.yml` ](https://gitlab.com/gitlab-org/gitlab/-/blob/master/config/gitlab.yml.example ) to enable Kerberos ticket-based
2019-07-31 22:56:46 +05:30
authentication. In most cases, you only need to enable Kerberos and specify
the location of the keytab:
2019-09-30 21:07:59 +05:30
```yaml
omniauth:
enabled: true
allow_single_sign_on: ['kerberos']
2019-07-31 22:56:46 +05:30
2019-09-30 21:07:59 +05:30
kerberos:
# Allow the HTTP Negotiate authentication method for Git clients
enabled: true
2019-07-31 22:56:46 +05:30
2019-09-30 21:07:59 +05:30
# Kerberos 5 keytab file. The keytab file must be readable by the GitLab user,
# and should be different from other keytabs in the system.
# (default: use default keytab from Krb5 config)
keytab: /etc/http.keytab
```
2019-07-31 22:56:46 +05:30
2020-04-22 19:07:51 +05:30
1. [Restart GitLab ](../administration/restart_gitlab.md#installations-from-source ) for the changes to take effect.
2019-07-31 22:56:46 +05:30
2021-01-29 00:20:46 +05:30
#### Omnibus package installations
2019-07-31 22:56:46 +05:30
1. Edit `/etc/gitlab/gitlab.rb` :
2019-09-30 21:07:59 +05:30
```ruby
gitlab_rails['omniauth_allow_single_sign_on'] = ['kerberos']
2019-07-31 22:56:46 +05:30
2019-09-30 21:07:59 +05:30
gitlab_rails['kerberos_enabled'] = true
gitlab_rails['kerberos_keytab'] = "/etc/http.keytab"
```
2019-07-31 22:56:46 +05:30
2021-11-11 11:23:49 +05:30
To avoid GitLab creating users automatically on their first sign in through Kerberos,
don't set `kerberos` for `gitlab_rails['omniauth_allow_single_sign_on']` .
2020-04-22 19:07:51 +05:30
1. [Reconfigure GitLab ](../administration/restart_gitlab.md#omnibus-gitlab-reconfigure ) for the changes to take effect.
2019-07-31 22:56:46 +05:30
2021-06-08 01:23:25 +05:30
GitLab now offers the `negotiate` authentication method for signing in and
2019-07-31 22:56:46 +05:30
HTTP Git access, enabling Git clients that support this authentication protocol
to authenticate with Kerberos tokens.
2021-01-29 00:20:46 +05:30
#### Enable single sign-on
2019-07-31 22:56:46 +05:30
2021-12-11 22:18:48 +05:30
See [Configure initial settings ](omniauth.md#configure-initial-settings )
2021-01-29 00:20:46 +05:30
for initial settings to enable single sign-on and add Kerberos servers
as an identity provider.
2019-07-31 22:56:46 +05:30
2021-01-29 00:20:46 +05:30
## Create and link Kerberos accounts
2019-07-31 22:56:46 +05:30
2021-01-29 00:20:46 +05:30
You can either link a Kerberos account to an existing GitLab account, or
set up GitLab to create a new account when a Kerberos user tries to sign in.
### Link a Kerberos account to an existing GitLab account
If you're an administrator, you can link a Kerberos account to an
existing GitLab account. To do so:
2021-11-11 11:23:49 +05:30
1. On the top bar, select **Menu > Admin** .
2021-09-04 01:27:46 +05:30
1. On the left sidebar, select **Overview > Users** .
1. Select a user, then select the **Identities** tab.
2021-03-11 19:13:27 +05:30
1. Select 'Kerberos SPNEGO' in the 'Provider' dropdown box.
2021-01-29 00:20:46 +05:30
1. Make sure the **Identifier** corresponds to the Kerberos username.
1. Select **Save changes** .
If you're not an administrator:
2021-03-11 19:13:27 +05:30
1. In the top-right corner, select your avatar.
1. Select **Edit profile** .
2021-11-11 11:23:49 +05:30
1. On the left sidebar, select **Account** .
2021-03-11 19:13:27 +05:30
1. In the **Social sign-in** section, select **Connect Kerberos SPNEGO** .
2021-01-29 00:20:46 +05:30
If you don't see a **Social sign-in** Kerberos option, follow the
requirements in [Enable single sign-on ](#enable-single-sign-on ).
In either case, you should now be able to sign in to your GitLab account
with your Kerberos credentials.
### Create accounts on first sign-in
The first time users sign in to GitLab with their Kerberos accounts,
GitLab creates a matching account.
2021-12-11 22:18:48 +05:30
Before you continue, review the [Configure initial settings ](omniauth.md#configure-initial-settings ) options in Omnibus and GitLab source. You must also include `kerberos` .
2021-01-29 00:20:46 +05:30
With that information at hand:
1. Include `'kerberos'` with the `allow_single_sign_on` setting.
1. For now, accept the default `block_auto_created_users` option, true.
1. When a user tries to sign in with Kerberos credentials, GitLab
creates a new account.
1. If `block_auto_created_users` is true, the Kerberos user may see
a message like:
```shell
Your account has been blocked. Please contact your GitLab
administrator if you think this is an error.
```
2021-09-04 01:27:46 +05:30
1. As an administrator, you can confirm the new, blocked account:
2021-11-11 11:23:49 +05:30
1. On the top bar, select **Menu > Admin** .
2021-09-04 01:27:46 +05:30
1. On the left sidebar, select **Overview > Users** and review the **Blocked** tab.
2021-01-29 00:20:46 +05:30
1. You can enable the user.
1. If `block_auto_created_users` is false, the Kerberos user is
authenticated and is signed in to GitLab.
2021-02-22 17:27:13 +05:30
WARNING:
2021-01-29 00:20:46 +05:30
We recommend that you retain the default for `block_auto_created_users` .
Kerberos users who create accounts on GitLab without administrator
knowledge can be a security risk.
## Link Kerberos and LDAP accounts together
If your users sign in with Kerberos, but you also have [LDAP integration ](../administration/auth/ldap/index.md )
2021-06-08 01:23:25 +05:30
enabled, your users are linked to their LDAP accounts on their first sign-in.
2021-01-29 00:20:46 +05:30
For this to work, some prerequisites must be met:
2019-07-31 22:56:46 +05:30
The Kerberos username must match the LDAP user's UID. You can choose which LDAP
2021-11-18 22:05:49 +05:30
attribute is used as the UID in the GitLab [LDAP configuration ](../administration/auth/ldap/index.md#configure-ldap )
2019-07-31 22:56:46 +05:30
but for Active Directory, this should be `sAMAccountName` .
The Kerberos realm must match the domain part of the LDAP user's Distinguished
Name. For instance, if the Kerberos realm is `AD.EXAMPLE.COM` , then the LDAP
user's Distinguished Name should end in `dc=ad,dc=example,dc=com` .
2021-06-08 01:23:25 +05:30
Taken together, these rules mean that linking only works if your users'
2019-07-31 22:56:46 +05:30
Kerberos usernames are of the form `foo@AD.EXAMPLE.COM` and their
LDAP Distinguished Names look like `sAMAccountName=foo,dc=ad,dc=example,dc=com` .
2021-01-03 14:25:43 +05:30
### Custom allowed realms
[Introduced ](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/9962 ) in GitLab 13.5.
2021-01-29 00:20:46 +05:30
You can configure custom allowed realms when the user's Kerberos realm doesn't
match the domain from the user's LDAP DN. The configuration value must specify
2021-06-08 01:23:25 +05:30
all domains that users may be expected to have. Any other domains are
2021-09-04 01:27:46 +05:30
ignored and an LDAP identity is not linked.
2021-01-03 14:25:43 +05:30
**For Omnibus installations**
1. Edit `/etc/gitlab/gitlab.rb` :
```ruby
gitlab_rails['kerberos_simple_ldap_linking_allowed_realms'] = ['example.com','kerberos.example.com']
```
1. Save the file and [reconfigure ](../administration/restart_gitlab.md#omnibus-gitlab-reconfigure )
GitLab for the changes to take effect.
---
**For installations from source**
1. Edit `config/gitlab.yml` :
```yaml
kerberos:
simple_ldap_linking_allowed_realms: ['example.com','kerberos.example.com']
```
1. Save the file and [restart ](../administration/restart_gitlab.md#installations-from-source )
GitLab for the changes to take effect.
2019-07-31 22:56:46 +05:30
## HTTP Git access
A linked Kerberos account enables you to `git pull` and `git push` using your
Kerberos account, as well as your standard GitLab credentials.
GitLab users with a linked Kerberos account can also `git pull` and `git push`
2021-09-04 01:27:46 +05:30
using Kerberos tokens. That is, without having to send their password with each
2019-07-31 22:56:46 +05:30
operation.
2021-02-22 17:27:13 +05:30
WARNING:
2021-01-03 14:25:43 +05:30
There is a [known issue ](https://github.com/curl/curl/issues/1261 ) with `libcurl`
2021-09-04 01:27:46 +05:30
older than version 7.64.1 wherein it doesn't reuse connections when negotiating.
2021-01-03 14:25:43 +05:30
This leads to authorization issues when push is larger than `http.postBuffer`
2021-02-22 17:27:13 +05:30
configuration. Ensure that Git is using at least `libcurl` 7.64.1 to avoid this. To
2021-01-03 14:25:43 +05:30
know the `libcurl` version installed, run `curl-config --version` .
2019-07-31 22:56:46 +05:30
### HTTP Git access with Kerberos token (passwordless authentication)
2022-03-02 08:16:31 +05:30
Because of [a bug in current Git versions ](https://lore.kernel.org/git/YKNVop80H8xSTCjz@coredump.intra.peff.net/T/#mab47fd7dcb61fee651f7cc8710b8edc6f62983d5 ),
the `git` CLI command uses only the `negotiate` authentication
2019-07-31 22:56:46 +05:30
method if the HTTP server offers it, even if this method fails (such as when
the client does not have a Kerberos token). It is thus not possible to fall back
2022-03-02 08:16:31 +05:30
to an embedded username and password (also known as `basic` ) authentication if Kerberos
2019-07-31 22:56:46 +05:30
authentication fails.
For GitLab users to be able to use either `basic` or `negotiate` authentication
2022-03-02 08:16:31 +05:30
with current Git versions, it is possible to offer Kerberos ticket-based
2021-09-04 01:27:46 +05:30
authentication on a different port (for example, `8443` ) while the standard port
offers only `basic` authentication.
2019-07-31 22:56:46 +05:30
2022-03-02 08:16:31 +05:30
NOTE:
[Git 2.4 and later ](https://github.com/git/git/blob/master/Documentation/RelNotes/2.4.0.txt#L225-L228 ) supports falling back to `basic` authentication if the
username and password is passed interactively or through a credentials manager. It fails to fall back when the username and password is passed as part of the URL instead. For example,
this can happen in GitLab CI/CD jobs that [authenticate with the CI/CD job token ](../ci/jobs/ci_job_token.md ).
2019-07-31 22:56:46 +05:30
**For source installations with HTTPS**
1. Edit the NGINX configuration file for GitLab
2021-09-04 01:27:46 +05:30
(for example, `/etc/nginx/sites-available/gitlab-ssl` ) and configure NGINX to
2019-07-31 22:56:46 +05:30
listen to port `8443` in addition to the standard HTTPS port:
2019-09-30 21:07:59 +05:30
```conf
server {
listen 0.0.0.0:443 ssl;
listen [::]:443 ipv6only=on ssl default_server;
listen 0.0.0.0:8443 ssl;
listen [::]:8443 ipv6only=on ssl;
```
2019-07-31 22:56:46 +05:30
2021-09-04 01:27:46 +05:30
1. Update the `kerberos` section of [`gitlab.yml` ](https://gitlab.com/gitlab-org/gitlab/-/blob/master/config/gitlab.yml.example ):
2019-07-31 22:56:46 +05:30
2019-09-30 21:07:59 +05:30
```yaml
kerberos:
# Dedicated port: Git before 2.4 does not fall back to Basic authentication if Negotiate fails.
# To support both Basic and Negotiate methods with older versions of Git, configure
2021-10-27 15:23:28 +05:30
# nginx to proxy GitLab on an extra port (for example: 8443) and uncomment the following lines
2019-09-30 21:07:59 +05:30
# to dedicate this port to Kerberos authentication. (default: false)
use_dedicated_port: true
port: 8443
https: true
```
2019-07-31 22:56:46 +05:30
2020-04-22 19:07:51 +05:30
1. [Restart GitLab ](../administration/restart_gitlab.md#installations-from-source ) and NGINX for the changes to take effect.
2019-07-31 22:56:46 +05:30
**For Omnibus package installations**
1. Edit `/etc/gitlab/gitlab.rb` :
2019-09-30 21:07:59 +05:30
```ruby
gitlab_rails['kerberos_use_dedicated_port'] = true
gitlab_rails['kerberos_port'] = 8443
gitlab_rails['kerberos_https'] = true
```
2019-07-31 22:56:46 +05:30
2020-04-22 19:07:51 +05:30
1. [Reconfigure GitLab ](../administration/restart_gitlab.md#omnibus-gitlab-reconfigure ) for the changes to take effect.
2019-07-31 22:56:46 +05:30
2021-06-08 01:23:25 +05:30
After this change, Git remote URLs have to be updated to
2019-07-31 22:56:46 +05:30
`https://gitlab.example.com:8443/mygroup/myproject.git` in order to use
Kerberos ticket-based authentication.
## Upgrading from password-based to ticket-based Kerberos sign-ins
2021-11-18 22:05:49 +05:30
In previous versions of GitLab users had to submit their
2022-07-16 23:28:13 +05:30
Kerberos username and password to GitLab when signing in.
We [deprecated ](../update/deprecations.md#omniauth-kerberos-gem ) password-based
Kerberos sign-ins in GitLab 14.3 and [removed ](https://gitlab.com/gitlab-org/gitlab/-/issues/2908 )
it in GitLab 15.0. You must switch to ticket-based sign in.
2019-07-31 22:56:46 +05:30
Depending on your existing GitLab configuration, the 'Sign in with:
2021-03-11 19:13:27 +05:30
Kerberos SPNEGO' button may already be visible on your GitLab sign-in
2019-07-31 22:56:46 +05:30
page. If not, then add the settings [described above ](#configuration ).
2021-03-11 19:13:27 +05:30
Once you have verified that the 'Kerberos SPNEGO' button works
2019-07-31 22:56:46 +05:30
without entering any passwords, you can proceed to disable
password-based Kerberos sign-ins. To do this you need only need to
remove the OmniAuth provider named `kerberos` from your `gitlab.yml` /
`gitlab.rb` file.
**For installations from source**
2021-09-04 01:27:46 +05:30
1. Edit [`gitlab.yml` ](https://gitlab.com/gitlab-org/gitlab/-/blob/master/config/gitlab.yml.example ) and remove the `- { name: 'kerberos' }` line under OmniAuth
2019-07-31 22:56:46 +05:30
providers:
2019-09-30 21:07:59 +05:30
```yaml
omniauth:
2021-01-03 14:25:43 +05:30
# Rest of configuration omitted
2019-09-30 21:07:59 +05:30
# ...
providers:
2021-01-03 14:25:43 +05:30
- { name: 'kerberos' } # < -- remove this line
2019-09-30 21:07:59 +05:30
```
2019-07-31 22:56:46 +05:30
2020-04-22 19:07:51 +05:30
1. [Restart GitLab ](../administration/restart_gitlab.md#installations-from-source ) for the changes to take effect.
2019-07-31 22:56:46 +05:30
**For Omnibus installations**
1. Edit `/etc/gitlab/gitlab.rb` and remove the `{ "name" => "kerberos" }` line
under `gitlab_rails['omniauth_providers']` :
2019-09-30 21:07:59 +05:30
```ruby
gitlab_rails['omniauth_providers'] = [
{ "name" => "kerberos" } # < -- remove this entry
]
```
2019-07-31 22:56:46 +05:30
2020-04-22 19:07:51 +05:30
1. [Reconfigure GitLab ](../administration/restart_gitlab.md#omnibus-gitlab-reconfigure ) for the changes to take effect.
2019-07-31 22:56:46 +05:30
2021-09-30 23:02:18 +05:30
NOTE:
Removing the `kerberos` OmniAuth provider can also resolve a rare
`Krb5Auth::Krb5::Exception (No credentials cache found)` error (`500` error in GitLab)
when trying to clone via HTTPS.
2019-07-31 22:56:46 +05:30
## Support for Active Directory Kerberos environments
When using Kerberos ticket-based authentication in an Active Directory domain,
it may be necessary to increase the maximum header size allowed by NGINX,
as extensions to the Kerberos protocol may result in HTTP authentication headers
larger than the default size of 8kB. Configure `large_client_header_buffers`
2020-04-22 19:07:51 +05:30
to a larger value in [the NGINX configuration ](http://nginx.org/en/docs/http/ngx_http_core_module.html#large_client_header_buffers ).
2019-07-31 22:56:46 +05:30
## Troubleshooting
### Unsupported GSSAPI mechanism
With Kerberos SPNEGO authentication, the browser is expected to send a list of
mechanisms it supports to GitLab. If it doesn't support any of the mechanisms
2021-06-08 01:23:25 +05:30
GitLab supports, authentication fails with a message like this in the log:
2019-07-31 22:56:46 +05:30
2020-04-22 19:07:51 +05:30
```plaintext
2019-07-31 22:56:46 +05:30
OmniauthKerberosSpnegoController: failed to process Negotiate/Kerberos authentication: gss_accept_sec_context did not return GSS_S_COMPLETE: An unsupported mechanism was requested Unknown error
```
This is usually seen when the browser is unable to contact the Kerberos server
2021-06-08 01:23:25 +05:30
directly. It falls back to an unsupported mechanism known as
2019-07-31 22:56:46 +05:30
[`IAKERB` ](https://k5wiki.kerberos.org/wiki/Projects/IAKERB ), which tries to use
the GitLab server as an intermediary to the Kerberos server.
If you're experiencing this error, ensure there is connectivity between the
client machine and the Kerberos server - this is a prerequisite! Traffic may be
blocked by a firewall, or the DNS records may be incorrect.
Another failure mode occurs when the forward and reverse DNS records for the
2021-06-08 01:23:25 +05:30
GitLab server do not match. Often, Windows clients work in this case while
Linux clients fail. They use reverse DNS while detecting the Kerberos
realm. If they get the wrong realm then ordinary Kerberos mechanisms fail,
so the client falls back to attempting to negotiate `IAKERB` , leading to the
2019-07-31 22:56:46 +05:30
above error message.
To fix this, ensure that the forward and reverse DNS for your GitLab server
2020-03-13 15:44:24 +05:30
match. So for instance, if you access GitLab as `gitlab.example.com` , resolving
2019-07-31 22:56:46 +05:30
to IP address `1.2.3.4` , then `4.3.2.1.in-addr.arpa` must be a PTR record for
`gitlab.example.com` .
Finally, it's possible that the browser or client machine lack Kerberos support
completely. Ensure that the Kerberos libraries are installed and that you can
authenticate to other Kerberos services.
### HTTP Basic: Access denied when cloning
2020-03-13 15:44:24 +05:30
```shell
2019-07-31 22:56:46 +05:30
remote: HTTP Basic: Access denied
fatal: Authentication failed for '< KRB5 path > '
```
2019-09-30 21:07:59 +05:30
If you are using Git v2.11 or newer and see the above error when cloning, you can
2019-07-31 22:56:46 +05:30
set the `http.emptyAuth` Git option to `true` to fix this:
2020-04-22 19:07:51 +05:30
```shell
2019-07-31 22:56:46 +05:30
git config --global http.emptyAuth true
```
See also: [Git v2.11 release notes ](https://github.com/git/git/blob/master/Documentation/RelNotes/2.11.0.txt#L482-L486 )
## Helpful links
- < https: // help . ubuntu . com / community / Kerberos >
- < http: // blog . manula . org / 2012 / 04 / setting-up-kerberos-server-with-debian . html >
2019-12-21 20:55:43 +05:30
- < https: // www . roguelynn . com / words / explain-like-im-5-kerberos />