vps_-_netbsd_with_ldap
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
vps_-_netbsd_with_ldap [2021/04/02 09:37] – [Importing data] hc9 | vps_-_netbsd_with_ldap [2021/04/02 19:27] (current) – [Graphical Client] hc9 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Installing an OpenLDAP Server on a NetBSD VPS ====== | ||
+ | **Note: This tutorial assumes you’ve already followed the [[: | ||
+ | |||
+ | An LDAP server can be used for an endless number of things. Essentially, | ||
+ | |||
+ | In this tutorial, I will be setting up the LDAP server to provide authorisation and authentication for a nix client, but the first few stages are the same for almost any application of LDAP. | ||
+ | |||
+ | The OpenLDAP server is available in the SDF VPS pkgsrc and so the software is already installed, but does require some configuration. | ||
+ | |||
+ | ===== Jargon and Tools ===== | ||
+ | |||
+ | * OpenLDAP | ||
+ | * The LDAP server that will be used | ||
+ | * Suffix | ||
+ | * The suffix appended to all LDAP objects, which normally related to a domain name | ||
+ | * Root DN | ||
+ | * The administrative user of the server, with read and write access to all data objects. The password for this user should be kept secure | ||
+ | * '' | ||
+ | * The name of the executable of the OpenLDAP server | ||
+ | * '' | ||
+ | * The name of the executable tool used for creating password hashes | ||
+ | * '' | ||
+ | * The name of the executable tool that generates the password databases | ||
+ | ===== Initial Setup ===== | ||
+ | |||
+ | To begin with, we’ll create the chroot environment. Whilst the OpenLDAP server is running, this is the only part of the file system it will be able to see. | ||
+ | |||
+ | The first step is to create the directories and copy the initial configuration that comes from pkgsrc. | ||
+ | |||
+ | # mkdir / | ||
+ | # mkdir / | ||
+ | # cp -r / | ||
+ | # cp -r / | ||
+ | |||
+ | The next step is to create the user and group that the server will run as, and allow for this information to be available in the chroot. | ||
+ | |||
+ | # groupadd -g 17 slapd | ||
+ | # useradd -u 17 -g 17 -d / | ||
+ | # grep slapd / | ||
+ | # pwd_mkdb -d / | ||
+ | # grep slapd /etc/group > / | ||
+ | |||
+ | No password needs to be set for the slapd user as no one will ever log in using its username. This disallows logins from that user. | ||
+ | |||
+ | Finally, we’ll need to set the correct permissions necessary for OpenLDAP to access its data while keeping it secure. | ||
+ | |||
+ | # chown -R slapd:slapd / | ||
+ | # chmod -R 700 / | ||
+ | |||
+ | ===== Initial Configuration ===== | ||
+ | |||
+ | The next stage involves editing some configuration files so that paths are correct within the chroot and the chroot is enabled with the correct user and group. | ||
+ | |||
+ | This step also includes setting the password for the root DN (Distinguished Name), the LDAP administrative user. | ||
+ | |||
+ | Begin by creating a hash of the password you wish to use for the root DN. This should be a secure password, as the root DN can read and write to the database, regardless of any access restrictions that we set up later on. The slappasswd tool is used to do this. | ||
+ | |||
+ | # slappasswd -s ' | ||
+ | {SSHA}1LuiLGmSO+EoPA0uk80v4TC5xwacBOWg | ||
+ | |||
+ | **Note: The '' | ||
+ | |||
+ | You should copy the whole line to your clipboard as we will need it shortly. Then open up ''/ | ||
+ | |||
+ | The first three lines that need changing are near the top of the file. They start with include, pidfile and argsfile and have a path to a file following them. These paths point to the read-only filesystem of the SDF VPS pkgsrc and not our chroot, so they should be changed like so: | ||
+ | |||
+ | include | ||
+ | [...SNIPPED...] | ||
+ | pidfile | ||
+ | argsfile | ||
+ | |||
+ | Next, we’ll need to set the suffix, the root DN, and the password for the root DN. The suffix is normally formed from your domain name. In this example, the domain name is shiftout.org, | ||
+ | |||
+ | suffix | ||
+ | rootdn | ||
+ | [...SNIPPED...] | ||
+ | rootpw | ||
+ | |||
+ | Then there is one final path to modify. This is the directory that OpenLDAP uses for storing its data. Currently, it is set to point at the read-only SDF VPS pkgsrc, so this needs to be changed. | ||
+ | |||
+ | directory | ||
+ | |||
+ | The final step before running the server for the first time is to configure the rc scripts. These allow for the server to be started on boot. | ||
+ | |||
+ | First, copy the example rc script for slapd into the ''/ | ||
+ | |||
+ | # cp / | ||
+ | |||
+ | Then edit the new file ''/ | ||
+ | |||
+ | There are two lines you need to edit here. The line defining where to find '' | ||
+ | |||
+ | The first line that needs to be edited is the location of the configuration file, which should look like this: | ||
+ | |||
+ | required_files="/ | ||
+ | |||
+ | The second line is the command line arguments that are passed to " | ||
+ | |||
+ | command_args=" | ||
+ | |||
+ | The '' | ||
+ | |||
+ | Finally, it is necessary to enable '' | ||
+ | |||
+ | # echo " | ||
+ | |||
+ | You can edit the file manually and add this line if you would like to keep your '' | ||
+ | |||
+ | ===== Testing ===== | ||
+ | |||
+ | Before starting '' | ||
+ | |||
+ | # / | ||
+ | |||
+ | If you see something similar to: | ||
+ | |||
+ | 502c06bd slapd starting | ||
+ | 502c06bd daemon: added 4r listener=0x0 | ||
+ | 502c06bd daemon: added 6r listener=0x7f7ffc427180 | ||
+ | 502c06bd daemon: added 7r listener=0x7f7ffc427240 | ||
+ | 502c06bd daemon: select: listen=6 active_threads=0 tvp=NULL | ||
+ | 502c06bd daemon: select: listen=7 active_threads=0 tvp=NULL | ||
+ | 502c06bd daemon: activity on 1 descriptor | ||
+ | 502c06bd daemon: waked | ||
+ | 502c06bd daemon: select: listen=6 active_threads=0 tvp=NULL | ||
+ | 502c06bd daemon: select: listen=7 active_threads=0 tvp=NULL | ||
+ | |||
+ | Then you have succeeded in configuring an OpenLDAP to a point where it will start successfully. Press Ctrl+C to stop the server. You can start or stop the server as a daemon using ''/ | ||
+ | |||
+ | **Note: From this point, configuration will become specific to providing authentication and authorization services for nix clients. If you’re looking to use LDAP for another application, | ||
+ | |||
+ | ===== Including extra schemata ===== | ||
+ | |||
+ | Three schemata will need to be used by '' | ||
+ | |||
+ | * '' | ||
+ | *Includes “generally useful” objects and attributes (sic) | ||
+ | * '' | ||
+ | * Includes objects and attributes for use in representing fields from BSD-style flat file authentication and authorization files | ||
+ | * '' | ||
+ | * Includes objects and attributes for representing contact information and organizational information | ||
+ | |||
+ | These files are included by adding the following three lines underneath the first include we changed earlier in the ''/ | ||
+ | |||
+ | <file config / | ||
+ | include | ||
+ | include | ||
+ | include | ||
+ | </ | ||
+ | |||
+ | At the end of this file, we’ll also add another index. Searching on non-indexed fields can result in no results being returned, so this is important. | ||
+ | |||
+ | index | ||
+ | |||
+ | ===== Configuring ACLs ===== | ||
+ | |||
+ | The sample configuration in ''/ | ||
+ | |||
+ | <file config / | ||
+ | access to dn.base="" | ||
+ | access to dn.base=" | ||
+ | access to * | ||
+ | by self write | ||
+ | by users read | ||
+ | by anonymous auth | ||
+ | </ | ||
+ | ===== A second test ===== | ||
+ | |||
+ | To ensure that no errors have been made while configuring, | ||
+ | |||
+ | # / | ||
+ | |||
+ | ===== Importing data ===== | ||
+ | |||
+ | Assuming you’ve got this far with no problems, it’s time to import some data. The data used for interactions with an OpenLDAP server is stored in a text file in LDIF (LDAP Data Interchange Format). Once we have performed this initial import, further interactions can be performed through graphical clients. | ||
+ | |||
+ | Copy the following example into a text file: | ||
+ | |||
+ | < | ||
+ | # Create top-level object in domain | ||
+ | dn: dc=shiftout, | ||
+ | objectClass: | ||
+ | objectClass: | ||
+ | objectclass: | ||
+ | o: shiftOut | ||
+ | dc: shiftOut | ||
+ | description: | ||
+ | |||
+ | dn: ou=people, | ||
+ | objectClass: | ||
+ | ou: people | ||
+ | |||
+ | dn: ou=groups, | ||
+ | objectClass: | ||
+ | ou: groups | ||
+ | |||
+ | dn: uid=irl, | ||
+ | objectClass: | ||
+ | objectClass: | ||
+ | objectClass: | ||
+ | uid: irl | ||
+ | sn: Learmonth | ||
+ | givenName: Iain | ||
+ | cn: Iain Learmonth | ||
+ | displayName: | ||
+ | uidNumber: 2000 | ||
+ | gidNumber: 2000 | ||
+ | userPassword: | ||
+ | gecos: Iain R. Learmonth | ||
+ | loginShell: /bin/bash | ||
+ | homeDirectory: | ||
+ | shadowExpire: | ||
+ | shadowFlag: 0 | ||
+ | shadowWarning: | ||
+ | shadowMin: 8 | ||
+ | shadowMax: 999999 | ||
+ | shadowLastChange: | ||
+ | mail: irl@sdf.org | ||
+ | homePhone: +1 (206) 299 2120 x1388 | ||
+ | title: System Administrator | ||
+ | initials: IRL | ||
+ | |||
+ | dn: cn=irl, | ||
+ | objectClass: | ||
+ | cn: irl | ||
+ | gidNumber: 2000 | ||
+ | </ | ||
+ | |||
+ | The following is used in this example: | ||
+ | |||
+ | * Suffix: dc=shiftout, | ||
+ | * Initial user: irl | ||
+ | * Organisation name: shiftOut | ||
+ | |||
+ | These three values will need to be changed. Hopefully you can also use common sense to identify names and contact information that will need to be changed. | ||
+ | |||
+ | Assuming you have saved your LDIF file as ''/ | ||
+ | |||
+ | ldapadd -D " | ||
+ | |||
+ | You will need to replace the bind DN here with the correct root DN and suffix you specified earlier. | ||
+ | |||
+ | **Note for experienced users: Tools such as '' | ||
+ | |||
+ | You can check the import was successful by running: | ||
+ | |||
+ | ldapwhoami -D " | ||
+ | |||
+ | Replace the uid and suffix with the ones that you have created. You should see an output similar to: | ||
+ | |||
+ | dn: | ||
+ | |||
+ | If you see this, you have correctly configured a working LDAP server, to which you can add, query, modify, and remove data representing users and groups. | ||
+ | |||
+ | ===== Graphical Client ===== | ||
+ | |||
+ | Apache Directory Studio provides a graphical browser that you can use to add, query, modify and remove data from your LDAP database. It can be downloaded from http:// | ||
+ | |||
+ | ---- | ||
+ | $Id: VPS_NetBSD_OpenLDAP.html, |