I want to set up Gitlab with our company's LDAP as a demo. But unfortunately I have to put in an admin password in gitlab.yml to make gitlab access the LDAP service. The problem actually is the administration, as they don't want to setup another account just for Gitlab. Is there any way to circumvent this without filling in my own password? Is there a way to make Gitlab establish the LDAP connection with only the provided user credentials?
Any ideas beside logging in as anonymous?
Already posted here.
GitLab uses omniauth to manage multiple login sources (including LDAP).
So if you can somehow extend
omniauth
in order to manage the LDAP connection differently, you could fetch the password from a different source.That would allow you to avoid keeping said password in the ldap section of the
gitlab.yml
config file.I haven't tried it yet, but from the things I've build so far authenticating against LDAP and the informations from the config-file this user-account seems only to be needed when your LDAP does not support anonymous binding and searching.
So I would leave the two entries
bind_dn
andpassword
commented out and try whether it works or not.UPDATE
I've implemented LDAP-Autehntication in Gitlab and it's fairly easy.
In the
gitlab.yml
-file there is a section calledldap
.There you have to provide the informations to connect to your LDAP. It seems that all fields have to be given, there seems to be no fallback default! If you want to use anonymous binding for retrieval of the users DN supply an empty string for
bind_dn
andpassword
. Commenting them out seems not to work! At least I got a 501 Error message.More information can be found at https://github.com/patthoyts/gitlabhq/wiki/Setting-up-ldap-auth and (more outdated but still helpful) https://github.com/intridea/omniauth-ldap
I have patched gitlab to work this way and documented the process in http://foivos.zakkak.net/tutorials/gitlab_ldap_auth_without_querying_account.html
I shamelessly copy the instructions here for self-completeness.
Note: This tutorial was last tested with gitlab 8.2 installed from source.
This tutorial aims to describe how to modify a Gitlab installation to use the users credentials to authenticate with the LDAP server. By default Gitlab relies on anonymous binding or a special querying user to ask the LDAP server about the existence of a user before authenticating her with her own credentials. For security reasons, however, many administrators disable anonymous binding and forbid the creation of special querying LDAP users.
In this tutorial we assume that we have a gitlab setup at gitlab.example.com and an LDAP server running on ldap.example.com, and users have a DN of the following form:
CN=username,OU=Users,OU=division,OU=department,DC=example,DC=com
.Patching
To make Gitlab work in such cases we need to partly modify its authentication mechanism regarding LDAP.
First, we replace the omniauth-ldap module with this derivation. To achieve this we apply the following patch to
gitlab/Gemfile
:Now, we need to perform the following actions:
sudo -u git -H bundle install --without development test mysql --path vendor/bundle --no-deployment
sudo -u git -H bundle install --deployment --without development test mysql aws
These commands will fetch the modified omniauth-ldap module in
gitlab/vendor/bundle/ruby/2.x.x/bundler/gems
. Now that the module is fetched, we need to modify it to use the DN our LDAP server expects. We achieve this by patchinglib/omniauth/strategies/ldap.rb
ingitlab/vendor/bundle/ruby/2.x.x/bundler/gems/omniauth-ldap
with:With this module, gitlab uses the user's credentials to bind to the LDAP server and query it, as well as, to authenticate the user herself.
This however will only work as long as the users do not use ssh-keys to authenticate with Gitlab. When authenticating through an ssh-key, by default Gitlab queries the LDAP server to find out whether the corresponding user is (still) a valid user or not. At this point, we cannot use the user credentials to query the LDAP server, since the user did not provide them to us. As a result we disable this mechanism, essentially allowing users with registered ssh-keys but removed from the LDAP server to still use our Gitlab setup. To prevent such users from being able to still use your Gitlab setup, you will have to manually delete their ssh-keys from any accounts in your setup.
To disable this mechanism we patch
gitlab/lib/gitlab/ldap/access.rb
with:Configuration
In
gitlab.yml
use something like the following (modify to your needs):