Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
infra:ldap [2026/02/16 14:46] – created avinfra:ldap [2026/11/20 13:18] (current) – Rebuild LDAP reference; add ID ranges verified 2026-11-20 threepio
Line 1: Line 1:
-===== LDAP in a nutshell =====+====== LDAP ======
  
-You configure a database /?/ of users /that you add manually/ and tell other services, like peertube /or the linux login system even/, to look for the individuals in the ldap directories. This way an admin does not make an accound for 500 different users in 500 different servers. The user is made in ldap, and then some to-be-integrated server, like Mastodon for example, is told to get the users email, password, phone number etc from LDAP.+ABI's directory service. It holds user accounts, groups, SSH public keys and mail addresses; SSH logins, Git, the wiki and the ticketing system all authenticate against it.
  
-===== Why did we re-set-up our ldap. =====+**ID ranges and storage facts verified against live systems: 2026-11-20.** Install and schema details below come from the original setup notes.
  
-Because our dear sysadmin /not telling names/ set it up on quick hand, and overlooked the transport layer security /TLS/ and plus our users didnt happen to have emails and phone numbers. So in order to not doubt our ldap when integrating new things with it - we decided to set up a new normies ldap.+^ Component ^ Value ^ 
 +| Server | OpenLDAP 2.6 (''slapd'') in the ''ldap-01'' jail on bane | 
 +| Address | ''ldap-01.local.abi.am'', 172.20.42.38 | 
 +| Database | MDB (memory-mapped) | 
 +| Base DN | ''dc=abi,dc=am'' | 
 +| Encryption | LDAPS with a self-signed certificate | 
 +| Management tools | [[https://git.abi.am/varinka/ldapscript_extension|ldapscript_extension]] (fork of ldapscripts; clone at ''/root/ldapscripts_extension'') |
  
-The main points were: - ldap shall have TLS - info such as email, phone numbers, names, etc+===== Directory layout =====
  
-We also wanted to use PostgreSQL as the database but turns out that’s not how LDAP works. So we use MDB /memory mapped database/ instead.+<code> 
 +dc=abi,dc=am 
 +  cn=admin        root DN used by the management scripts 
 +  ou=Users        user accounts (posixAccount + ldapPublicKey) 
 +  ou=Groups       groups 
 +  ou=Machines     machine accounts 
 +  ou=Idmap        id mapping 
 +  ou=Services     service accounts 
 +</code>
  
-===== Components =====+A user entry carries ''uid'', ''uidNumber'', ''gidNumber'', ''cn'', ''sn'', ''mail'', ''homeDirectory'', ''loginShell'' and one or more ''sshPublicKey'' values. Locked accounts keep their entry but use ''homeDirectory: /var/locked'' and ''loginShell: /usr/sbin/nologin''.
  
-  * Server: OpenLDAP 2.6 /slapd daemon/ +===== ID ranges =====
-  * Database: MDB +
-  * Directory base: abi.am or dc=abi,dc=am +
-  * Security: LDAPS /for tls/ +
-  * Certificate: We got one <del>Self-signed tls</del>+
  
-<code sh> +Only the start values are enforced by software; the upper bounds are conventions.
-The structure / given by ldapsearch -x -b "dc=abi,dc=am" -LLL dn+
  
-  dc=abi,dc=am +^ Range ^ Used for ^ Defined by ^ 
-   |-> cn=admin +| 10000+ | Human users (''uidNumber'') | ''UIDSTART=10000'' in ''/usr/local/etc/ldapscripts/ldapscripts.conf'' | 
-   |-> ou=admins,dc=abi,dc=am +| 10000+ | Per-user groups (''gidNumber'' mirrors the uid) | ''GIDSTART=10000'', same file | 
-      |-> cn=antranigv,ou=admins,dc=abi,dc=am +| 14999 | One-off account, excluded from the next-ID calculation | [[infra:howto:manage_users|Manage Users]] procedure | 
-   |-> ou=people,dc=abi,dc=am +| 15000-15999 | Shared and project groups | Convention (e.g. 15000 ''scientist'', 15020 ''armenian_ancestry'', 15999 ''sysadmins'') | 
-</code>+| 50000+ | Bot accounts | Convention; provisioning via ''botctl'' | 
 +| 59999 | Shared group ''bots'' | ''BOTS_GID'' in ''botctl'' | 
 + 
 +  * Users and their personal groups are allocated as highest + 1 and grow upward; there is no configured maximum. 
 +  * A bot gets a personal group whose gid equals its uid, plus membership in the shared ''bots'' group (59999). Bots are provisioned with ''botctl'', not ''ldapadduser''. 
 +  * The 15000-15999 and 50000+ ranges are conventions, not enforced by any tool. Treat this page as their definition for new allocations, and update it if a range changes. 
 + 
 +===== Adding and managing users ===== 
 + 
 +The procedure lives on [[infra:howto:manage_users|Manage Users]]: creating the group and user, setting the password, adding SSH keys and mail, group membership, and creating the matching ZFS datasets on mustafar. This page documents the server itself; do not duplicate the steps here.
  
-==== Install OpenLDAP and enable on boot ====+===== Install and configure =====
  
 <code sh> <code sh>
Line 38: Line 56:
 </code> </code>
  
-==== Generate TLS certificates /the 1/3 of our todo list/ ====+=== TLS certificate ===
  
 <code sh> <code sh>
Line 44: Line 62:
 cd /usr/local/etc/openldap/tls cd /usr/local/etc/openldap/tls
  
-# generate the key  
 openssl genrsa -out ldap-server.key 2048 openssl genrsa -out ldap-server.key 2048
- 
-# generate the csr /using that key/ 
-# csr = certificate signing request 
 openssl req -new -key ldap-server.key -out ldap-server.csr \ openssl req -new -key ldap-server.key -out ldap-server.csr \
   -subj "/C=AM/ST=Yerevan/L=Yerevan/O=abi.am/CN=ldap.abi.am"   -subj "/C=AM/ST=Yerevan/L=Yerevan/O=abi.am/CN=ldap.abi.am"
- 
-# generate certificate /using that csr, and the key/ 
 openssl x509 -req -days 365 -in ldap-server.csr \ openssl x509 -req -days 365 -in ldap-server.csr \
   -signkey ldap-server.key -out ldap-server.crt   -signkey ldap-server.key -out ldap-server.crt
  
-# permissions: ldap can read-write, others can read 
 chmod 600 ldap-server.key chmod 600 ldap-server.key
 chmod 644 ldap-server.crt chmod 644 ldap-server.crt
Line 62: Line 73:
 </code> </code>
  
-==== Create the database directory ====+=== Database directory ===
  
 <code sh> <code sh>
-mkdir -p /var/db/openldap-data # this is the file that you should not delete+mkdir -p /var/db/openldap-data
 chown -R ldap:ldap /var/db/openldap-data chown -R ldap:ldap /var/db/openldap-data
 chmod 700 /var/db/openldap-data chmod 700 /var/db/openldap-data
 </code> </code>
  
-===== Configuring =====+=== Configuration files ===
  
-We have 3 main config files we work with. - slapd.conf ''%%/usr/local/etc/openldap/slapd.conf%%''  for configuring the slapd daemon /server/. This file contains database settings, TLS config, schemas, monitoring, ACLs, admin password hash generated with ''%%slappasswd%%''+^ File ^ Purpose ^ 
 +| ''/usr/local/etc/openldap/slapd.conf'' | daemon: schemas, TLS, database, indexes, ACLs, root password hash | 
 +| ''/root/base-setup.ldif'' | initial directory structure: base DN, OUs, first admin | 
 +| ''/usr/local/etc/openldap/ldap.conf'' | client defaults: server URI, base DN, TLS |
  
-  * base-setup.ldif ''%%/root/base-setup.ldif%%''  for initializing+configuring the base structure of an LDAP directory. This file contains Base DN, organizational units /people, admins, root password hash generated with ''%%slappasswd%%'' +Essential ''slapd.conf'' settings:
-  * ldap.conf ''%%/usr/local/etc/openldap/ldap.conf%%''  for client configuration /settings for client tools like ldapsearch, ldapadd, ldapmodify/. This file contains default server URI, base DN, TLS settings for clients +
- +
-to see or modify them just run +
- +
-<code sh> +
-vim /usr/local/etc/openldap/slapd.conf +
-vim /root/base-setup.ldif +
-vim /usr/local/etc/openldap/ldap.conf +
-</code>+
  
 <code> <code>
-# slapd.conf +include     /usr/local/etc/openldap/schema/core.schema 
-     +include     /usr/local/etc/openldap/schema/cosine.schema 
-    include     /usr/local/etc/openldap/schema/core.schema +include     /usr/local/etc/openldap/schema/inetorgperson.schema
-    include     /usr/local/etc/openldap/schema/cosine.schema +
-    include     /usr/local/etc/openldap/schema/inetorgperson.schema +
-     +
-    pidfile     /var/run/openldap/slapd.pid +
-    argsfile    /var/run/openldap/slapd.args +
- +
-    # Load dynamic backend modules: +
-    modulepath  /usr/local/libexec/openldap +
-    moduleload  back_mdb +
- +
-    TLSCertificateFile  /usr/local/etc/openldap/tls/ldap-server.crt +
-    TLSCertificateKeyFile   /usr/local/etc/openldap/tls/ldap-server.key +
-    TLSCACertificateFile    /usr/local/etc/openldap/tls/ldap-server.crt +
- +
-    # Database Configuration+
  
-    database    mdb +modulepath  /usr/local/libexec/openldap 
-    suffix      "dc=abi,dc=am" +moduleload  back_mdb
-    rootdn      "cn=admin,dc=abi,dc=am" +
-    rootpw      {SSHA}WyDJGCVQmRbl57aiwOj4pSgSkkdAW64s+
  
-    directory   /var/db/openldap-data+TLSCertificateFile  /usr/local/etc/openldap/tls/ldap-server.crt 
 +TLSCertificateKeyFile   /usr/local/etc/openldap/tls/ldap-server.key 
 +TLSCACertificateFile    /usr/local/etc/openldap/tls/ldap-server.crt
  
-    index   objectClass eq +database    mdb 
-    index   cn,sn,uid,mail eq,sub+suffix      "dc=abi,dc=am" 
 +rootdn      "cn=admin,dc=abi,dc=am" 
 +rootpw      {SSHA}<hash from slappasswd> 
 +directory   /var/db/openldap-data
  
-    access to attrs=userPassword +index   objectClass eq 
-        by self write +index   cn,sn,uid,mail eq,sub
-        by anonymous auth +
-        by * none+
  
-    access to * +access to attrs=userPassword 
-        by self write +    by self write 
-        by users read +    by anonymous auth 
-        by * read+    by * none
  
-    database monitor +access to * 
-    access to * +    by self write 
-        by dn.exact="cn=admin,dc=abi,dc=am" +    by users read 
-        by * read+    by * read
 </code> </code>
  
-<code> +Import the base structure, then start the daemon:
-base-setup.ldif +
-     +
-    # Domain +
- +
-    dn: dc=abi,dc=am +
-    objectClass: top +
-    objectClass: dcObject +
-    objectClass: organization +
-    o: abi.am +
-    dc: abi +
- +
- +
-    # Organizational unit ADMINS /and their interns/ +
- +
-    dn: ou=admins,dc=abi,dc=am +
-    objectClass: organizationalUnit +
-    ou: admins +
- +
- +
-    # Organizational unit PEOPLE +
- +
-    dn: ou=people,dc=abi,dc=am +
-    objectClass: organizationalUnit +
-    ou: people +
- +
- +
-    # Antranig /the real admin/ +
- +
-    dn: cn=antranigv,ou=admins,dc=abi,dc=am +
-    objectClass: inetOrgPerson +
-    cn: Antranig +
-    sn: sysadmin +
-    mail: antranigv@abi.am +
-    userPassword: {SSHA}HGlAJt+rfJCK74xz9q+r/RdQh7cWmTel +
-     +
-</code> +
- +
-<code> +
-  # import the base structure +
-  ldapadd -x -D "cn=admin,dc=abi,dc=am" -W -f /root/base-setup.ldif +
- +
-  # to test, show all directory entries +
-  ldapsearch -x -b "dc=abi,dc=am" -LLL +
-   +
-  # or entries + hashed passwords +
-  ldapsearch -x -D "cn=admin,dc=abi,dc=am" -W -b "dc=abi,dc=am" -LLL +
-   +
-  # or authenticate +
-  ldapwhoami -x -D "cn=admin,dc=abi,dc=am" -W +
-  # TLS test: same auth but with encryption /-ZZ/ +
-  ldapwhoami -x -D "cn=admin,dc=abi,dc=am" -W -ZZ +
-</code> +
- +
-And finally start the ldap server.+
  
 <code sh> <code sh>
 +ldapadd -x -D "cn=admin,dc=abi,dc=am" -W -f /root/base-setup.ldif
 service slapd start service slapd start
- +sockstat -l | grep 389
-# Check if its running +
- +
-ps aux | grep slapd +
-sockstat -l | greo 389+
 </code> </code>
  
-===== Common actions =====+===== Schema notes =====
  
-==== Adding a new user ====+  * ''sshPublicKey'' comes from a custom schema; that is what lets SSH read keys from LDAP. 
 +  * ''mail'' is part of the user object classes, so every user can carry an address. 
 +  * Group ownership (''owner'') was hard-coded into ''posixGroup'' in the NIS schema rather than using ''groupOfNames''. Remember this when editing groups by hand.
  
-make a file for the new user eg ani.ldif (preferrably in /root/ldap/users/)+===== Common operations =====
  
-Example of a user : +=== Change a user's mail ===
- +
-<code ldif> +
-dn: uid=ani,ou=Users,dc=abi,dc=am +
-objectClass: account +
-objectClass: posixAccount +
-objectClass: ldapPublicKey +
-sn: Hakobyan +
-mail: ani.hakobyan@abi.am +
-uidNumber: 10037 +
-gidNumber: 10037 +
-homeDirectory: /mnt/home/ani +
-loginShell: /bin/bash +
-gecos: ani +
-description: User account +
-sshPublicKey: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMzmm9juul7a215P+2glagSKgU82TX3K8RtpcTM941Ad ani@DESKTOP-OG1R1UQ +
-userPassword:: e1NTSEF9SjN6cERNckttZTJwSS9jQXk1UDNpOTF0bG5QSlVPa20= +
-uid: ani +
-cn: Ani +
-</code> +
- +
-and import the user like this+
  
 <code> <code>
-ldapadd -x -H ldaps://ldap.local.abi.am:636 -D "cn=admin,dc=abi,dc=am" -y /usr/local/etc/openldap/passwd -f /root/ldap-migrations/users/ani.ldif +dn: uid=USERNAME,ou=Users,dc=abi,dc=am
-</code> +
- +
-==== modify user email ==== +
- +
-make a modify-email.ldif with the following content +
- +
-<code> +
-dn: uid=ani,ou=Users,dc=abi,dc=am+
 changetype: modify changetype: modify
 replace: mail replace: mail
-mail: ani@abi.am+mail: user@abi.am
 </code> </code>
- 
-apply changes with 
  
 <code> <code>
Line 246: Line 151:
 </code> </code>
  
-then you can search for the user by email+=== Change a password ===
  
 <code> <code>
-ldapsearch -x -b "ou=Users,dc=abi,dc=am" "(mail=newmail@abi.am)" cn mail+ldappasswd -x -D "cn=admin,dc=abi,dc=am" -W -S "uid=USERNAME,ou=Users,dc=abi,dc=am"
 </code> </code>
  
-==== change password for someone, for example Antranig ====+=== Back up the database ===
  
 <code> <code>
-ldappasswd -x -D "cn=admin,dc=abi,dc=am" -W -S "uid=antranigv,ou=admins,dc=abi,dc=am"+/usr/local/sbin/slapcat > /root/ldap-backup-$(date +%Y%m%d).ldif
 </code> </code>
  
-==== backup database ====+=== Verify authentication and TLS ===
  
 <code> <code>
-/usr/local/sbin/slapcat > /root/ldap-backup-$(date +%Y%m%d).ldif +ldapwhoami -x -D "cn=admin,dc=abi,dc=am" -W 
-</code> +ldapwhoami -x -D "cn=admin,dc=abi,dc=am" -W -ZZ 
- +ldapsearch -x -b "dc=abi,dc=am" -LLL
-Add many +
- +
-<code sh> +
- +
-for file in organizational_units/*.ldif; do +
-    echo "Adding OU: $file" +
-    ldapadd -y pass \ +
-            -D "cn=admin,dc=abi,dc=am" \ +
-            -f "$file" +
-done +
- +
-for file in groups/*.ldif; do +
-    echo "Adding group: $file" +
-    ldapadd -y pass \ +
-            -D "cn=admin,dc=abi,dc=am" \ +
-            -f "$file" +
-done +
- +
-for file in users/*.ldif; do +
-    echo "Adding user: $file" +
-    ldapadd -y pass \ +
-            -D "cn=admin,dc=abi,dc=am" \ +
-            -f "$file" +
-done+
 </code> </code>
  
-===== in /root/ldap/ =====+===== See also =====
  
-we have\\ +  * [[infra:howto:manage_users|Manage Users]] -- the day-to-day procedure 
-base.ldif\\ +  * [[infra:servers|Server Inventory]] -- ''ldap-01'' jail details 
-/projects\\ +  * [[infra:overview|Infrastructure Overview]]
-the projects have members and owners.\\ +
-''%%member%%'' comes from ''%%posixGroup%%'',\\ +
-''%%ownser%%'' comes from… posixGroup again. not groupOfNames. We hardcoded “owner” into posixGroup in ''%%/usr/local/etc/openldap/schema/nis.schema%%'' /or ''%%core.schema%%'', i dont rememember/\\ +
-/users\\ +
-users have objectclass sshPublicKey which comes from a custion schema sshPublicKey. Also the field “email” has been hardcoded into some objectclass that our users use so we can have ''%%email: testuhi@testmail.xyz%%''\\ +
-/organizationalUnits\\ +
-/groups+