| 1 | = Install the OpenLDAP Server on Ubuntu 18.04 LTS with eduPerson Schema = |
| 2 | |
| 3 | It is assumed that you have already install your Ubuntu server with a public IP address and a Domain Name (//ldap.YOUR-DOMAIN//). |
| 4 | |
| 5 | {{{ |
| 6 | sudo apt-get update |
| 7 | sudo apt-get install slapd ldap-utils gnutls-bin ssl-cert vim |
| 8 | }}} |
| 9 | In order to access some additional prompts that we need, we'll reconfigure the package after installation. To do so, type: |
| 10 | {{{ |
| 11 | sudo dpkg-reconfigure slapd |
| 12 | }}} |
| 13 | Answer the prompts appropriately, using t'''***No''' (we want an initial database and configuration) |
| 14 | * DNS domain name: '''YOUR-DOMAIN''' (use the server's domain name, minus the hostname. This will be used to create the base entry for the information tree) |
| 15 | * Organization name: '''Your Institute''' (This will simply be added to the base entry as the name of your institute) |
| 16 | * Administrator password: '''whatever you'd like''' |
| 17 | * Confirm password: '''must match the above''' |
| 18 | * Database backend to use: '''HDB''' (out of the two choices, this has the most functionality) |
| 19 | * Do you want the database to be removed when slapd is purged? (your choice. Choose '''Yes''' to allow a completely clean removal, choose '''No''' to save your data even when the software is removed) |
| 20 | * Move old database? '''Yes''' |
| 21 | === Create the Certificate Templates === |
| 22 | |
| 23 | To encrypt our connections, we'll need to configure a certificate authority and use it to sign the keys for the LDAP server(s) in our infrastructure. So for our single server setup, we will need two sets of key/certificate pairs: one for the certificate authority itself and one that is associated with the LDAP service. |
| 24 | |
| 25 | To create the certificates needed to represent these entities, we'll create some template files. These will contain the information that the certtool utility needs in order to create certificates with the appropriate properties. |
| 26 | |
| 27 | Start by making a directory to store the template files: |
| 28 | |
| 29 | {{{ |
| 30 | sudo mkdir /etc/ssl/templates |
| 31 | }}} |
| 32 | |
| 33 | Create the template for the certificate authority first. We'll call the file ca_server.conf. Create and open the file in your text editor: |
| 34 | |
| 35 | {{{ |
| 36 | sudo nano /etc/ssl/templates/ca_server.conf |
| 37 | }}} |
| 38 | |
| 39 | We only need to provide a few pieces of information in order to successfully create a certificate authority. We need to specify that the certificate will be for a CA (certificate authority) by adding the ca option. We also need the cert_signing_key option to give the generated certificate the ability to sign additional certificates. We can set the cn to whatever descriptive name we'd like for our certificate authority: |
| 40 | |
| 41 | {{{ |
| 42 | cn = LDAP Server CA |
| 43 | ca |
| 44 | cert_signing_key |
| 45 | }}} |
| 46 | |
| 47 | Save and close the file. |
| 48 | |
| 49 | Next, we can create a template for our LDAP server certificate called ldap_server.conf. Create and open the file in your text editor with sudo privileges: |
| 50 | |
| 51 | ``` |
| 52 | sudo nano /etc/ssl/templates/ldap_server.conf |
| 53 | ``` |
| 54 | |
| 55 | Here, we'll provide a few different pieces of information. We'll provide the name of our organization and set the tls_www_server, encryption_key, and signing_key options so that our cert has the basic functionality it needs. |
| 56 | |
| 57 | The cn in this template must match the FQDN of the LDAP server. If this value does not match, the client will reject the server's certificate. We will also set the expiration date for the certificate. We'll create a 10 year certificate to avoid having to manage frequent renewals: `ldapserver.conf` |
| 58 | |
| 59 | {{{ |
| 60 | organization = "Name of your institution" |
| 61 | cn = idap.YOUR-DOMAIN |
| 62 | tls_www_server |
| 63 | encryption_key |
| 64 | signing_key |
| 65 | expiration_days = 3652 |
| 66 | }}} |
| 67 | Save and close the file when you're finished. |
| 68 | === Create CA Key and Certificate === |
| 69 | Now that we have our templates, we can create our two key/certificate pairs. We need to create the certificate authority's set first. |
| 70 | Use the certtool utility to generate a private key. The `/etc/ssl/private` directory is protected from non-root users and is the appropriate location to place the private keys we will be generating. We can generate a private key and write it to a file called ca_server.key within this directory by typing: |
| 71 | {{{ |
| 72 | sudo certtool -p --outfile /etc/ssl/private/ca_server.key |
| 73 | }}} |
| 74 | Now, we can use the private key that we just generated and the template file we created in the last section to create the certificate authority certificate. We will write this to a file in the `/etc/ssl/certs` directory called ca_server.pem: |
| 75 | {{{ |
| 76 | sudo certtool -s --load-privkey /etc/ssl/private/ca_server.key --template /etc/ssl/templates/ca_server.conf --outfile /etc/ssl/certs/ca_server.pem |
| 77 | }}} |
| 78 | We now have the private key and certificate pair for our certificate authority. We can use this to sign the key that will be used to actually encrypt the LDAP session. |
| 79 | === Create LDAP Service Key and Certificate === |
| 80 | Next, we need to generate a private key for our LDAP server. We will again put the generated key in the `/etc/ssl/private` directory for security purposes and will call the file ldap_server.key for clarity. |
| 81 | We can generate the appropriate key by typing: |
| 82 | {{{ |
| 83 | sudo certtool -p --sec-param high --outfile /etc/ssl/private/ldap_server.key |
| 84 | }}} |
| 85 | Once we have the private key for the LDAP server, we have everything we need to generate a certificate for the server. We will need to pull in almost all of the components we've created thus far (the CA certificate and key, the LDAP server key, and the LDAP server template). |
| 86 | We will put the certificate in the `/etc/ssl/certs` directory and name it `ldap_server.pem`. The command we need is: |
| 87 | {{{ |
| 88 | sudo certtool -c --load-privkey /etc/ssl/private/ldap_server.key --load-ca-certificate /etc/ssl/certs/ca_server.pem --load-ca-privkey /etc/ssl/private/ca_server.key --template /etc/ssl/templates/ldap_server.conf --outfile /etc/ssl/certs/ldap_server.pem |
| 89 | }}} |
| 90 | === Give OpenLDAP Access to the LDAP Server Key === |
| 91 | We now have all of the certificates and keys we need. However, currently, our OpenLDAP process will be unable to access its own key. |
| 92 | A group called ssl-cert already exists as the group-owner of the `/etc/ssl/private` directory. We can add the user our OpenLDAP process runs under (openldap) to this group: |
| 93 | {{{ |
| 94 | sudo usermod -aG ssl-cert openldap |
| 95 | }}} |
| 96 | Now, our OpenLDAP user has access to the directory. We still need to give that group ownership of the `ldap_server.key` file though so that we can allow read access. Give the ssl-cert group ownership over that file by typing: |
| 97 | {{{ |
| 98 | sudo chown :ssl-cert /etc/ssl/private/ldap_server.key |
| 99 | }}} |
| 100 | Now, give the ssl-cert group read access to the file: |
| 101 | {{{ |
| 102 | sudo chmod 640 /etc/ssl/private/ldap_server.key |
| 103 | }}} |
| 104 | Our OpenSSL process can now access the key file properly. Configure OpenLDAP to Use the Certificate and Keys |
| 105 | We have our files and have configured access to the components correctly. Now, we need to modify our OpenLDAP configuration to use the files we've made. We will do this by creating an LDIF file with our configuration changes and loading it into our LDAP instance. |
| 106 | Move to your home directory and open a file called `addcerts.ldif`. We will put our configuration changes in this file: |
| 107 | {{{ |
| 108 | cd ~ |
| 109 | vim addcerts.ldif |
| 110 | }}} |
| 111 | To make configuration changes, we need to target the cn=config entry of the configuration DIT. We need to specify that we are wanting to modify the attributes of the entry. Afterwards we need to add the `olcTLSCACertificateFile`, `olcCertificateFile`, and `olcCertificateKeyFile` attributes and set them to the correct file locations. |
| 112 | |
| 113 | The end result will look like this: |
| 114 | {{{ |
| 115 | dn:cn=config |
| 116 | changetype:modify |
| 117 | add:olcTLSCACertificateFile |
| 118 | olcTLSCACertificateFile:/etc/ssl/certs/ca_server.pem |
| 119 | - |
| 120 | add:olcTLSCertificateFile |
| 121 | olcTLSCertificateFile:/etc/ssl/certs/ldap_server.pem |
| 122 | - |
| 123 | add:olcTLSCertificateKeyFile |
| 124 | olcTLSCertificateKeyFile:/etc/ssl/private/ldap_server.key |
| 125 | }}} |
| 126 | Save and close the file when you are finished. Apply the changes to your OpenLDAP system using the ldapmodify command: |
| 127 | {{{ |
| 128 | sudo ldapmodify -H ldapi:// -Y EXTERNAL -f addcerts.ldif |
| 129 | }}} |
| 130 | We can reload OpenLDAP to apply the changes: |
| 131 | {{{ |
| 132 | sudo service slapd force-reload |
| 133 | }}} |
| 134 | |
| 135 | If you see some error while importing, |
| 136 | |
| 137 | Start your `slapd` in debug mode |
| 138 | |
| 139 | ``` |
| 140 | sudo service slapd stop |
| 141 | sudo slapd -h ldapi:/// -u openldap -g openldap -d 65 -F /etc/ldap/slapd.d/ -d 65 |
| 142 | ``` |
| 143 | Then in another console, |
| 144 | |
| 145 | ``` |
| 146 | ldapmodify -H ldapi:// -Y EXTERNAL -f addcerts.ldif |
| 147 | ``` |
| 148 | |
| 149 | then `ctrl+c` to stop the debug mode on first console and start the service. |
| 150 | |
| 151 | ``` |
| 152 | sudo service slapd start |
| 153 | ``` |
| 154 | |
| 155 | |
| 156 | Your clients can now be configured to encrypt their connections to the server over the conventional 'ldap://ldap.YOUR-DOMAIN:389' port by using STARTTLS. |
| 157 | |
| 158 | |
| 159 | == Setting up the Client Machines == |
| 160 | |
| 161 | In order to connect to the LDAP server and initiate a STARTTLS upgrade, the clients must have access to the certificate authority certificate and must request the upgrade. |
| 162 | On the OpenLDAP Server |
| 163 | |
| 164 | If you are interacting with the OpenLDAP server from the server itself, you can set up the client utilities by copying the CA certificate and adjusting the client configuration file. |
| 165 | |
| 166 | First, copy the CA certificate from the `/etc/ssl/certs` directory to a file within the `/etc/ldap` directory. We will call this file ca_certs.pem. This file can be used to store all of the CA certificates that clients on this machine may wish to access. For our purposes, this will only contain a single certificate: |
| 167 | |
| 168 | ``` |
| 169 | sudo cp /etc/ssl/certs/ca_server.pem /etc/ldap/ca_certs.pem |
| 170 | ``` |
| 171 | Now, we can adjust the system-wide configuration file for the OpenLDAP utilities. Open up the configuration file in your text editor with sudo privileges: |
| 172 | |
| 173 | ``` |
| 174 | sudo nano /etc/ldap/ldap.conf |
| 175 | ``` |
| 176 | |
| 177 | Adjust the value of the '''TLS_CACERT''' option to point to the file we just created: |
| 178 | |
| 179 | ``` |
| 180 | TLS_CACERT /etc/ldap/ca_certs.pem |
| 181 | TLS_REQCERT allow |
| 182 | ``` |
| 183 | |
| 184 | Save and close the file. |
| 185 | |
| 186 | You should now be able to upgrade your connections to use STARTTLS by passing the '''-Z''' option when using the OpenLDAP utilities. You can force STARTTLS upgrade by passing it twice. Test this by typing: |
| 187 | |
| 188 | ``` |
| 189 | ldapwhoami -H ldap:// -x -ZZ |
| 190 | ``` |
| 191 | This forces a STARTTLS upgrade. If this is successful, you should see: |
| 192 | ``` |
| 193 | STARTTLS success |
| 194 | |
| 195 | anonymous |
| 196 | ``` |
| 197 | |
| 198 | ### Load eduPerson Schema. |
| 199 | |
| 200 | Get the schema downloaded from [Eduperson.ldif](./eduperson-201602.ldif) |
| 201 | |
| 202 | Or the latest from `https://spaces.at.internet2.edu/display/macedir/LDIFs` |
| 203 | |
| 204 | Load it using: |
| 205 | |
| 206 | ```bash |
| 207 | ldapadd -Y EXTERNAL -H ldapi:/// -f eduperson-201602.ldif |
| 208 | ``` |
| 209 | |
| 210 | Also Lets load The SChema for Academia, SCHAC. |
| 211 | Get the schema downloaded from [SCHAC.ldif](./schac-20150413.ldif) |
| 212 | |
| 213 | Or the latest from `https://wiki.refeds.org/display/STAN/SCHAC+Releases` |
| 214 | |
| 215 | Load it using: |
| 216 | |
| 217 | ```bash |
| 218 | ldapadd -Y EXTERNAL -H ldapi:/// -f schac-20150413.ldif |
| 219 | ``` |
| 220 | |
| 221 | ### Create User Structure |
| 222 | |
| 223 | Depending on your Institute's Requirement, you may create grouop as follows: |
| 224 | |
| 225 | ``` |
| 226 | dn: ou=People,dc=YOUR-DOMAIN,dc=ac,dc=lk |
| 227 | objectClass: organizationalUnit |
| 228 | objectClass: top |
| 229 | ou: People |
| 230 | |
| 231 | dn: ou=Group,dc=YOUR-DOMAIN,dc=ac,dc=lk |
| 232 | objectClass: organizationalUnit |
| 233 | objectClass: top |
| 234 | ou: Group |
| 235 | description: All groups |
| 236 | |
| 237 | # System Admin Staff Group |
| 238 | dn:cn=adm,ou=Group,dc=YOUR-DOMAIN,dc=ac,dc=lk |
| 239 | cn:adm |
| 240 | description:System Admin Staff |
| 241 | gidNumber:1500 |
| 242 | objectClass:posixGroup |
| 243 | objectClass:top |
| 244 | |
| 245 | # Acadamic staff Group |
| 246 | dn:cn=acd,ou=Group,dc=YOUR-DOMAIN,dc=ac,dc=lk |
| 247 | cn:acd |
| 248 | description:Acadamic Staff |
| 249 | gidNumber:2000 |
| 250 | objectClass:posixGroup |
| 251 | objectClass:top |
| 252 | |
| 253 | # Students Group |
| 254 | dn:cn=student,ou=Group,dc=YOUR-DOMAIN,dc=ac,dc=lk |
| 255 | cn:student |
| 256 | description:Students |
| 257 | gidNumber:5000 |
| 258 | objectClass:posixGroup |
| 259 | objectClass:top |
| 260 | |
| 261 | # servers OU |
| 262 | dn:ou=servers,dc=YOUR-DOMAIN,dc=ac,dc=lk |
| 263 | description:servers |
| 264 | objectClass:top |
| 265 | objectClass:organizationalUnit |
| 266 | ou:servers |
| 267 | |
| 268 | # idp servers |
| 269 | dn:cn=idp,ou=servers,dc=YOUR-DOMAIN,dc=ac,dc=lk |
| 270 | cn:idp |
| 271 | description:Identity Server |
| 272 | ipHostNumber: 3ffe:ffff:ffff::9 |
| 273 | objectClass:top |
| 274 | objectClass:device |
| 275 | objectClass:ipHost |
| 276 | objectClass:simpleSecurityObject |
| 277 | userPassword:{crypt}idpldap |
| 278 | |
| 279 | |
| 280 | # test User |
| 281 | |
| 282 | dn:uid=testme,ou=people,dc=YOUR-DOMAIN,dc=ac,dc=lk |
| 283 | cn:Test Me |
| 284 | uid:testme |
| 285 | uidNumber:1001 |
| 286 | gidNumber:1000 |
| 287 | givenName:Test Me |
| 288 | homeDirectory:/dev/null |
| 289 | homePhone:none |
| 290 | objectClass:person |
| 291 | objectClass:organizationalPerson |
| 292 | objectClass:inetOrgPerson |
| 293 | objectClass: eduPerson |
| 294 | objectClass:posixAccount |
| 295 | objectClass:top |
| 296 | objectClass:shadowAccount |
| 297 | sn:Test |
| 298 | mobile:+94791234567 |
| 299 | userPassword:testme |
| 300 | mail: testme@YOUR_DOMAIN |
| 301 | eduPersonPrincipalName: testme@YOUR_DOMAIN |
| 302 | |
| 303 | ``` |
| 304 | |
| 305 | Save the above as a ldif file and add it to your directory as |
| 306 | |
| 307 | `ldapadd -H ldap:// -x -D "cn=admin,dc=YOUR-DOMAIN,dc=ac,dc=lk" -W -Z -f path_to_file.ldif` |