{"id":4778,"date":"2019-11-15T23:12:53","date_gmt":"2019-11-15T20:12:53","guid":{"rendered":"https:\/\/kifarunix.com\/?p=4778"},"modified":"2024-03-12T23:15:36","modified_gmt":"2024-03-12T20:15:36","slug":"how-to-create-openldap-member-groups","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-create-openldap-member-groups\/","title":{"rendered":"How to Create OpenLDAP Member Groups"},"content":{"rendered":"\n
While assigning specific access rights or permissions to users whose access to various organization systems or resources are controlled via directory or identity management tools like OpenLDAP<\/a> or FreeIPA<\/a>, it is more feasible and less time consuming to manage this as a group. In this guide, we are going to learn how to Create OpenLDAP Member Groups to enable you to control what a specific group of members are authorized to do on a given organization system or resource.<\/p>\n\n\n\n Before you can proceed with this guide, we assume that you already have an OpenLDAP server up and running. Otherwise, you can check our OpenLDAP guides by following the links below;<\/p>\n\n\n\n Install and Setup OpenLDAP on CentOS 8<\/a><\/p>\n\n\n\n How to Configure SUDO via OpenLDAP Server<\/a><\/p>\n\n\n\n Configure SSSD for OpenLDAP Authentication on CentOS 8<\/a><\/p>\n\n\n\n Well, so how do you create member groups on OpenLDAP?<\/p>\n\n\n\n The OpenLDAP group membership is provided by the Overlays can be dynamically loaded via the overlays modules or can be compiled directly into OpenLDAP database, slapd.<\/p>\n\n\n\n To check if the As you can see in the output below, only MDB database backend module is loaded.<\/p>\n\n\n\n Find the location of the memberof overlay module and confirm if matches the already specified path above. The path below might be different in your case.<\/p>\n\n\n\n Therefore, update the slapd database with the memberof overlay module by creating an ldif file as shown below.<\/p>\n\n\n\n Load the module into slapd.<\/p>\n\n\n\n If you do not want to update the existing module, you can add another module directory information tree.<\/p>\n\n\n\n Verify again that the module is loaded.<\/p>\n\n\n\n Now that the memberof overlay modules is loaded, you then need to update it on OpenLDAP database.<\/p>\n\n\n\n The overlay should be updated on a specific database backend. To locate your database backend, you can simply run the command. In our case, we are using MDB database hence grep mdb.<\/p>\n\n\n\n Note the sequential order of your database schema.<\/p>\n\n\n\n Create an LDIF file with your memberof overlay attributes as shown below.<\/p>\n\n\n\n For more information on the overlay attributes used above, consult, Update the OpenLDAP database with memberof overlay attributes.<\/p>\n\n\n\n Another important aspect of OpenLDAP group membership is the Referential Integrity. Consider the line Referential Integrity is also managed by an overlay which has to be loaded via a module.<\/p>\n\n\n\n Since the module location is the same, you can simply load the Read more on The OpenLDAP memberof overlay is now setup. The next step is to create member groups to enable you impose specific access control authorization.<\/p>\n\n\n\n Assuming you have the following users in your OpenLDAP database, for example;<\/p>\n\n\n\n To create openldap member group with the above users as members, you can use an LDIF file as shown below;<\/p>\n\n\n\n Note that we have already created a Group OU, Check that the group is created;<\/p>\n\n\n\n The memberOf <\/strong>attribute is automatically added to user entries to indicate a group that the user belongs to. You can search the members using the memberOf attribute.<\/p>\n\n\n\n You can as well add members to specific groups using the The update the slapd database;<\/p>\n\n\n\n Well, you now have OpenLDAP groups and members added.<\/p>\n\n\n\n How do you authenticate to LDAP connected systems as a group via SSSD?<\/p>\n\n\n\n Now that you have setup your member groups, let us see how you can configure SSSD on your LDAP clients for group authentication.<\/p>\n\n\n\n Assuming you already installed SSSD on your OpenLDAP clients, edit the SSSD main configuration file, Below is our sample SSSD configuration. Note that we restrict access only to members of the admins group we created above using the You other configuration options might be different as with the above configuration, but the Once you have defined your memberOf access filter, try to authenticate as member of the admins group.<\/p>\n\n\n\n Clear SSSD cache.<\/p>\n\n\n\n Now, login as one member of the admins group.<\/p>\n\n\n\n Where:<\/p>\n\n\n\n There you go.<\/p>\n\n\n\n Try to authenticate as user who is not a member of the admins group.<\/p>\n\n\n\n You can also assign specific access controls to a group of members on OpenLDAP.<\/p>\n\n\n\n What am demoing here is not actually group access controls. But let us see how to give members of a specific group sudo rights via OpenLDAP. Learn how to configure OpenLDAP SUDO support here first<\/a>.<\/p>\n\n\n\n We already created a sudoers role on our LDAP server called, Now, modify your sudo role (if already existing) and add one of the users from the admins group.<\/p>\n\n\n\n Update the database.<\/p>\n\n\n\n Verify the sudo group membership.<\/p>\n\n\n\n Now, since only members of Well, there you. You have learn to create OpenLDAP member groups via the memberof overlay module as well as adding other users to member groups and even defining specific access controls for respective members of the group.<\/p>\n\n\n\n Extras;<\/p>\n\n\n\n You can also delete or remove users from OpenLDAP groups.<\/p>\n\n\n\n For example, to remove the user Run the command below on the terminal;<\/p>\n\n\n\n Press enter on the terminal to execute the command above<\/p>\n\n\n\n Copy the following, modify to fit your environment setup and paste and press enter to execute.<\/p>\n\n\n\n You should see the output;<\/p>\n\n\n\n Press Ctrl+c to stop the command.<\/p>\n\n\n\n Setup OpenLDAP Server with SSL\/TLS on Debian 10<\/a><\/p>\n\n\n\n Install and Configure OpenLDAP server on Fedora 29<\/a><\/p>\n\n\n\nCreating OpenLDAP Member Groups<\/h2>\n\n\n\n
Enabling OpenLDAP memberof Overlay<\/h3>\n\n\n\n
memberof<\/code> overlay. An overlay<\/a> is component of OpenLDAP that is used to perform functions similar to the functions provided by an OpenLDAP database backends.<\/p>\n\n\n\n
memberof overlay<\/code> module has already been loaded.<\/p>\n\n\n\n
ldapsearch -LLL -Y EXTERNAL -H ldapi:\/\/\/ -b cn=config -LLL | grep -i module<\/code><\/pre>\n\n\n\n
\nSASL\/EXTERNAL authentication started\nSASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\nSASL SSF: 0\n# module{0}, config\ndn: cn=module{0},cn=config\nobjectClass: olcModuleList\ncn: module{0}\nolcModulePath: \/usr\/libexec\/openldap\nolcModuleLoad: {0}back_mdb.la<\/strong>\n...\n<\/code><\/pre>\n\n\n\n
find \/ -iname memberof.la<\/code><\/pre>\n\n\n\n
\/usr\/libexec\/openldap\/memberof.la<\/code><\/pre>\n\n\n\n
vim update-module.ldif<\/code><\/pre>\n\n\n\n
dn: cn=module{0},cn=config\nchangetype: modify\nadd: olcModuleLoad\nolcModuleLoad: memberof.la<\/code><\/pre>\n\n\n\n
ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f update-module.ldif<\/code><\/pre>\n\n\n\n
vim load-memberof-module.ldif<\/code><\/pre>\n\n\n\n
dn: cn=module,cn=config\ncn: module\nobjectClass: olcModuleList\nolcModuleLoad: memberof.la\nolcModulePath: \/usr\/libexec\/openldap<\/code><\/pre>\n\n\n\n
ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f load-memberof-module.ldif<\/code><\/pre>\n\n\n\n
SASL\/EXTERNAL authentication started\nSASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\nSASL SSF: 0\nadding new entry \"cn=module,cn=config\"<\/code><\/pre>\n\n\n\n
ldapsearch -LLL -Y EXTERNAL -H ldapi:\/\/\/ -b cn=config -LLL | grep -i module<\/code><\/pre>\n\n\n\n
\nSASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\nSASL SSF: 0\ndn: cn=module{0},cn=config\nobjectClass: olcModuleList\ncn: module{0}\nolcModulePath: \/usr\/libexec\/openldap\nolcModuleLoad: {0}back_mdb.la\nolcModuleLoad: {1}memberof.la<\/strong>\n...\n<\/code><\/pre>\n\n\n\n
Add memberof Overlay to SLAPD database<\/h3>\n\n\n\n
ldapsearch -LLL -Y EXTERNAL -H ldapi:\/\/\/ -b cn=config olcDatabase | grep mdb<\/code><\/pre>\n\n\n\n
SASL\/EXTERNAL authentication started\nSASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\nSASL SSF: 0\ndn: olcDatabase={1}mdb,cn=config<\/strong>\nolcDatabase: {1}mdb<\/code><\/pre>\n\n\n\n
vim add-memberof-overlay.ldif<\/code><\/pre>\n\n\n\n
dn: olcOverlay=memberof,olcDatabase={1}mdb,cn=config\nobjectClass: olcMemberOf\nobjectClass: olcOverlayConfig\nobjectClass: olcConfig\nobjectClass: top\nolcOverlay: memberof \nolcMemberOfRefInt: TRUE\nolcMemberOfDangling: ignore\nolcMemberOfGroupOC: groupOfNames\nolcMemberOfMemberAD: member\nolcMemberOfMemberOfAD: memberOf\n<\/code><\/pre>\n\n\n\n
man slapo-memberof<\/code>.<\/p>\n\n\n\n
ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f add-memberof-overlay.ldif<\/code><\/pre>\n\n\n\n
SASL\/EXTERNAL authentication started\nSASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\nSASL SSF: 0\nadding new entry \"olcOverlay=memberof,olcDatabase={1}mdb,cn=config\"<\/code><\/pre>\n\n\n\n
olcMemberOfRefInt: TRUE<\/strong><\/code>. This line basically enables what is called referential integrity<\/a> which ensures that the integrity of the database schema is kept. For example, if any attributes of a member are adjusted, all the groups on which the member belongs are also updated.<\/p>\n\n\n\n
find \/ -iname refint.la<\/code><\/pre>\n\n\n\n
\/usr\/libexec\/openldap\/refint.la<\/code><\/pre>\n\n\n\n
refint<\/code> module as follows;<\/p>\n\n\n\n
vim add-refint.ldif<\/code><\/pre>\n\n\n\n
dn: cn=module{0},cn=config\nchangetype: modify\nadd: olcModuleLoad\nolcModuleLoad: refint.la<\/code><\/pre>\n\n\n\n
ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f add-refint.ldif<\/code><\/pre>\n\n\n\n
man slapo-refint<\/code>.<\/p>\n\n\n\n
Create OpenLDAP Member Groups<\/h3>\n\n\n\n
uid=koromicha,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\nuid=linus,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com<\/code><\/pre>\n\n\n\n
vim member-group.ldif<\/code><\/pre>\n\n\n\n
ou=groups,dc=ldapmaster,dc=kifarunix-demo,dc=com<\/code>, in our case. As such, this ldif will will simply create a group called
admins<\/strong><\/code> with the above users as members.<\/p>\n\n\n\n
\ndn: cn=admins,ou=groups,dc=ldapmaster,dc=kifarunix-demo,dc=com\nobjectClass: groupOfNames\ncn: admins\nmember: uid=koromicha,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\nmember: uid=linus,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\n<\/code><\/pre>\n\n\n\n
ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f member-group.ldif<\/code><\/pre>\n\n\n\n
ldapsearch -H ldapi:\/\/\/ -Y EXTERNAL -LLL -b \"dc=ldapmaster,dc=kifarunix-demo,dc=com\" cn=admins<\/code><\/pre>\n\n\n\n
\nSASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\nSASL SSF: 0\ndn: cn=admins,ou=groups,dc=ldapmaster,dc=kifarunix-demo,dc=com\nobjectClass: groupOfNames\ncn: admins\nmember: uid=koromicha,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\nmember: uid=linus,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\n<\/code><\/pre>\n\n\n\n
ldapsearch -H ldapi:\/\/\/ -Y EXTERNAL -LLL -b \"dc=ldapmaster,dc=kifarunix-demo,dc=com\" memberOf<\/code><\/pre>\n\n\n\n
Add OpenLDAP Users to Groups<\/a><\/h3>\n\n\n\n
memberOf<\/code> attribute. For example, to add the user,
janedoe<\/code> to the
admins<\/code> groups created above;<\/p>\n\n\n\n
vim memberof.ldif<\/code><\/pre>\n\n\n\n
dn: uid=janedoe,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\nchangetype: modify\nadd: memberOf\nmemberOf: cn=admins,ou=groups,dc=ldapmaster,dc=kifarunix-demo,dc=com<\/code><\/pre>\n\n\n\n
ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f memberof.ldif<\/code><\/pre>\n\n\n\n
ldapsearch -H ldapi:\/\/\/ -Y EXTERNAL -LLL -b \"dc=ldapmaster,dc=kifarunix-demo,dc=com\" uid=* memberOf<\/code><\/pre>\n\n\n\n
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\nSASL SSF: 0\ndn: uid=janedoe,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\nmemberOf: cn=admins,ou=groups,dc=ldapmaster,dc=kifarunix-demo,dc=com<\/strong>\n\ndn: uid=johndoe,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\n\ndn: uid=linus,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\nmemberOf: cn=admins,ou=groups,dc=ldapmaster,dc=kifarunix-demo,dc=com<\/strong>\n\ndn: uid=koromicha,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com\nmemberOf: cn=admins,ou=groups,dc=ldapmaster,dc=kifarunix-demo,dc=com<\/strong>\n<\/code><\/pre>\n\n\n\n
Setup OpenLDAP SSSD Group Authentication<\/h3>\n\n\n\n
\/etc\/sssd\/sssd.conf<\/code>.<\/p>\n\n\n\n
vim \/etc\/sssd\/sssd.conf<\/code><\/pre>\n\n\n\n
memberOf<\/code> attribute as the value of
ldap_access_filter<\/code>. Also note the access provider,
access_provider = ldap<\/code>.<\/p>\n\n\n\n
[sssd]\nservices = nss, pam, sudo\nconfig_file_version = 2\ndomains = default\n\n[sudo]\n\n[nss]\n\n[pam]\noffline_credentials_expiration = 60\n\n[domain\/default]\nldap_id_use_start_tls = True\ndebug_level = 10\ncache_credentials = True\nldap_search_base = dc=ldapmaster,dc=kifarunix-demo,dc=com\nid_provider = ldap\nauth_provider = ldap\nchpass_provider = ldap\naccess_provider = ldap\nsudo_provider = ldap\nldap_uri = ldaps:\/\/ldapmaster.kifarunix-demo.com:636\nldap_default_bind_dn = cn=readonly,ou=system,dc=ldapmaster,dc=kifarunix-demo,dc=com\nldap_default_authtok = P@ssW0rd\nldap_tls_reqcert = demand\nldap_tls_cacert = \/etc\/ssl\/certs\/cacert.crt\nldap_tls_cacertdir = \/etc\/ssl\/certs\nldap_search_timeout = 50\nldap_network_timeout = 60\nldap_sudo_search_base = ou=SUDOers,dc=ldapmaster,dc=kifarunix-demo,dc=com\nldap_access_order = filter\nldap_access_filter = memberOf=cn=admins,ou=groups,dc=ldapmaster,dc=kifarunix-demo,dc=com<\/strong>\n<\/code><\/pre>\n\n\n\n
memberOf<\/code> attribute should be there to define the group of members allowed access. Read more on man
sssd-ldap<\/code> for a more description on SSSD options.<\/p>\n\n\n\n
Test SSSD Authentication as a Group Member<\/h3>\n\n\n\n
systemctl stop sssd;rm -rf \/var\/lib\/sss\/db\/*;systemctl start sssd<\/code><\/pre>\n\n\n\n
ssh linus@192.168.56.103<\/code><\/pre>\n\n\n\n
\n
linus<\/code> is a user member of the admins group.<\/li>\n<\/ul>\n\n\n\n
The authenticity of host '192.168.56.103 (192.168.56.103)' can't be established.\nECDSA key fingerprint is SHA256:HMMbAonHoAVgZwbYi7KY4O7jXH+h9GMDDwy1kI2LyGM.\nAre you sure you want to continue connecting (yes\/no)? yes\nWarning: Permanently added '192.168.56.103' (ECDSA) to the list of known hosts.\nlinus@192.168.56.103's password: \nCreating directory '\/home\/linus'.\nWelcome to Ubuntu 18.04 LTS (GNU\/Linux 4.15.0-20-generic x86_64)\n\n * Documentation: https:\/\/help.ubuntu.com\n * Management: https:\/\/landscape.canonical.com\n * Support: https:\/\/ubuntu.com\/advantage\n\n\n * Canonical Livepatch is available for installation.\n - Reduce system reboots and improve kernel security. Activate at:\n https:\/\/ubuntu.com\/livepatch\n\nThe programs included with the Ubuntu system are free software;\nthe exact distribution terms for each program are described in the\nindividual files in \/usr\/share\/doc\/*\/copyright.\n\nUbuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by\napplicable law.\n\nLast login: Thu Dec 12 04:13:48 2019 from ::1\nlinus@ubuntu18:~$\n<\/code><\/pre>\n\n\n\n
ssh johndoe@192.168.56.103<\/code><\/pre>\n\n\n\n
johndoe@192.168.56.103's password: password here\nConnection to 192.168.56.103 closed by remote host.\nConnection to 192.168.56.103 closed.<\/code><\/pre>\n\n\n\n
Set Access Control Lists for OpenLDAP Member Group<\/h3>\n\n\n\n
sudo<\/code> with one member given sudo rights.<\/p>\n\n\n\n
ldapsearch -H ldapi:\/\/\/ -Y EXTERNAL -LLL -b \"dc=ldapmaster,dc=kifarunix-demo,dc=com\" cn=sudo<\/code><\/pre>\n\n\n\n
SASL\/EXTERNAL authentication started\nSASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth\nSASL SSF: 0\ndn: cn=sudo,ou=SUDOers,dc=ldapmaster,dc=kifarunix-demo,dc=com\nobjectClass: top\nobjectClass: sudoRole\ncn: sudo\nsudoUser: johndoe<\/strong>\nsudoHost: ALL\nsudoRunAsUser: ALL\nsudoCommand: ALL\n<\/code><\/pre>\n\n\n\n
vim addtosudo.ldif<\/code><\/pre>\n\n\n\n
dn: cn=sudo,ou=SUDOers,dc=ldapmaster,dc=kifarunix-demo,dc=com\nchangetype: modify\nadd: sudoUser\nsudoUser: linus<\/code><\/pre>\n\n\n\n
ldapadd -Y EXTERNAL -H ldapi:\/\/\/ -f addtosudo.ldif<\/code><\/pre>\n\n\n\n
ldapsearch -H ldapi:\/\/\/ -Y EXTERNAL -LLL -b \"dc=ldapmaster,dc=kifarunix-demo,dc=com\" cn=sudo<\/code><\/pre>\n\n\n\n
dn: cn=sudo,ou=SUDOers,dc=ldapmaster,dc=kifarunix-demo,dc=com\nobjectClass: top\nobjectClass: sudoRole\ncn: sudo\nsudoUser: johndoe\nsudoUser: linus<\/strong>\nsudoHost: ALL\nsudoRunAsUser: ALL\nsudoCommand: ALL\n<\/code><\/pre>\n\n\n\n
admins<\/code> group are allowed to authenticate, only user,
linus<\/code> has been given sudo rights as defined above.<\/p>\n\n\n\n
root@ubuntu18:~# sudo -U linus -ll<\/strong><\/code><\/pre>\n\n\n\n
Matching Defaults entries for linus on ubuntu18:\n !visiblepw, always_set_home, match_group_by_gid, always_query_group_plugin, env_reset, env_keep = \"COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR\n LS_COLORS\", env_keep += \"MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE\", env_keep += \"LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT\n LC_MESSAGES\", env_keep += \"LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE\", env_keep += \"LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET\n XAUTHORITY\", env_keep+=SSH_AUTH_SOCK, secure_path = \/sbin:\/bin:\/usr\/sbin:\/usr\/bin, env_reset, mail_badpass,\n secure_path=\/usr\/local\/sbin\\:\/usr\/local\/bin\\:\/usr\/sbin\\:\/usr\/bin\\:\/sbin\\:\/bin\\:\/snap\/bin\n\nUser linus may run the following commands on ubuntu18:\n\nSSSD Role: sudo\n RunAsUsers: ALL\n Commands:\n\tALL\n<\/code><\/pre>\n\n\n\n
root@ubuntu18:~# sudo -U koromicha -ll\nUser koromicha is not allowed to run sudo on ubuntu18.<\/strong><\/code><\/pre>\n\n\n\n
How to Delete Users from an OpenLDAP Group<\/h3>\n\n\n\n
uid=janedoe<\/code><\/strong> from the
admins<\/code> group;<\/p>\n\n\n\n
ldapmodify -Y EXTERNAL -H ldapi:\/\/\/ -QQQ<\/code><\/pre>\n\n\n\n
dn: cn=admins,ou=groups,dc=ldapmaster,dc=kifarunix-demo,dc=com\ndelete: member\nmember: uid=janedoe,ou=people,dc=ldapmaster,dc=kifarunix-demo,dc=com<\/code><\/pre>\n\n\n\n
modifying entry \"cn=admins,ou=groups,dc=ldapmaster,dc=kifarunix-demo,dc=com\"<\/code><\/pre>\n\n\n\n
Other tutorials<\/h3>\n\n\n\n