Solution for FreeIPA on RHEL 9, and GitLab 15.8.1 CE/EE (2023)
The steps for setting up LDAP filters in GitLab for FreeIPA are different to the steps for setting up LDAP filters in GitLab for Active Directory.
Setup is as follows:
- FreeIPA is hosted on:
- GitLab is hosted on:
Perform the following steps:
- create user for FreeIPA accessing GitLab
- Username: "Happy Developer"
- First name: Happy
- Last name: Developer
- Create group in FreeIPA for accessing Gitlab
- Group name: ug_gitlab_mydomain_com_login_ldap
- Add user "Happy Developer" to user group "ug_gitlab_mydomain_com_login_ldap" in FreeIPA
- create user in FreeIPA for use with LDAP bind for gitlab.mydomain.com
- Username: ldap.gitlab.mydomain.com
- Firstname: ldap
- Lastname: gitlab.mydomain.com
- Password: Alphanumeric, no special symbols like $ < /
Now, Check group membership from command line:
ldapsearch -b "dc=mydomain,dc=com" -s sub "(&(objectclass=person)(memberof=cn=ug_gitlab_mydomain_com_login_ldap,cn=groups,cn=accounts,dc=mydomain,dc=com))" -D "uid=ldap.gitlab.mydomain.com,cn=users,cn=accounts,dc=mydomain,dc=com" -W
You should see one group member, "Happy Developer".
Now change the gitlab configuration:
sudo nano /etc/gitlab.gitlab.rb
Find the section containing the LDAP configuration and add the following text:
gitlab_rails['ldap_enabled'] = true
gitlab_rails['ldap_servers'] = YAML.load <<-'EOS'
main: # 'main' is the GitLab 'provider ID' of this LDAP server
label: 'My LDAP'
host: 'dc1.mydomain.com'
port: 636
uid: 'uid'
bind_dn: 'uid=ldap.myhost.mydomain.com,cn=users,cn=accounts,dc=mydomain,dc=com'
password: 'password'
encryption: 'simple_tls' # "start_tls" or "simple_tls" or "plain"
verify_certificates: false
smartcard_auth: false
active_directory: false
allow_username_or_email_login: false
lowercase_usernames: false
block_auto_created_users: false
base: 'dc=mydomain,dc=com'
user_filter: 'memberof=cn=ug_gitlab_mydomain_com_login_ldap,cn=groups,cn=accounts,dc=mydomain,dc=com'
## EE only
group_base: ''
admin_group: ''
sync_ssh_keys: false
EOS
Reconfigure and restart GitLab and check filter results:
sudo gitlab-ctl reconfigure
sudo gitlab-ctl restart
sudo gitlab-rake gitlab:ldap:check
You should be able to see list of authorized users to login
Note: An alternate user_filter is:
user_filter: '(&(objectclass=person)(memberof=cn=ug_gitlab_mydomain_com_login_ldap,cn=groups,cn=accounts,dc=mydomain,dc=com))'
Note: Make sure you perform additional steps to verify the TLS settings of the LDAP connection in the usual way for your setup.
I am not sure if this supports nested group support. But for now, this should be a good starting point for most FreeIPA users.