Changes between Initial Version and Version 1 of ldapiam2018


Ignore:
Timestamp:
Sep 4, 2018, 6:13:48 AM (6 years ago)
Author:
admin
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ldapiam2018

    v1 v1  
     1= Install the OpenLDAP Server on Ubuntu 18.04 LTS with eduPerson Schema =
     2
     3It is assumed that you have already install your Ubuntu server with a public IP address and a Domain Name (//ldap.YOUR-DOMAIN//).
     4
     5{{{
     6sudo apt-get update
     7sudo apt-get install slapd ldap-utils gnutls-bin ssl-cert vim
     8}}}
     9In order to access some additional prompts that we need, we'll reconfigure the package after installation. To do so, type:
     10{{{
     11sudo dpkg-reconfigure slapd
     12}}}
     13Answer 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
     23To 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
     25To 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
     27Start by making a directory to store the template files:
     28
     29{{{
     30sudo mkdir /etc/ssl/templates
     31}}}
     32
     33Create 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{{{
     36sudo nano /etc/ssl/templates/ca_server.conf
     37}}}
     38
     39We 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{{{
     42cn = LDAP Server CA
     43ca
     44cert_signing_key
     45}}}
     46
     47Save and close the file.
     48
     49Next, 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```
     52sudo nano /etc/ssl/templates/ldap_server.conf
     53```
     54
     55Here, 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
     57The 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{{{
     60organization = "Name of your institution"
     61cn = idap.YOUR-DOMAIN
     62tls_www_server
     63encryption_key
     64signing_key
     65expiration_days = 3652
     66}}}
     67Save and close the file when you're finished.
     68=== Create CA Key and Certificate ===
     69Now that we have our templates, we can create our two key/certificate pairs. We need to create the certificate authority's set first.
     70Use 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{{{
     72sudo certtool -p --outfile /etc/ssl/private/ca_server.key
     73}}}
     74Now, 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{{{
     76sudo 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}}}
     78We 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 ===
     80Next, 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.
     81We can generate the appropriate key by typing:
     82{{{
     83sudo certtool -p --sec-param high --outfile /etc/ssl/private/ldap_server.key
     84}}}
     85Once 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).
     86We will put the certificate in the `/etc/ssl/certs` directory and name it `ldap_server.pem`. The command we need is:
     87{{{
     88sudo 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 ===
     91We now have all of the certificates and keys we need. However, currently, our OpenLDAP process will be unable to access its own key.
     92A 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{{{
     94sudo usermod -aG ssl-cert openldap
     95}}}
     96Now, 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{{{
     98sudo chown :ssl-cert /etc/ssl/private/ldap_server.key
     99}}}
     100Now, give the ssl-cert group read access to the file:
     101{{{
     102sudo chmod 640 /etc/ssl/private/ldap_server.key
     103}}}
     104Our OpenSSL process can now access the key file properly. Configure OpenLDAP to Use the Certificate and Keys
     105We 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.
     106Move to your home directory and open a file called `addcerts.ldif`. We will put our configuration changes in this file:
     107{{{
     108cd ~
     109vim addcerts.ldif
     110}}}
     111To 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
     113The end result will look like this:
     114{{{
     115dn:cn=config
     116changetype:modify
     117add:olcTLSCACertificateFile
     118olcTLSCACertificateFile:/etc/ssl/certs/ca_server.pem
     119-
     120add:olcTLSCertificateFile
     121olcTLSCertificateFile:/etc/ssl/certs/ldap_server.pem
     122-
     123add:olcTLSCertificateKeyFile
     124olcTLSCertificateKeyFile:/etc/ssl/private/ldap_server.key
     125}}}
     126Save and close the file when you are finished. Apply the changes to your OpenLDAP system using the ldapmodify command:
     127{{{
     128sudo ldapmodify -H ldapi:// -Y EXTERNAL -f addcerts.ldif
     129}}}
     130We can reload OpenLDAP to apply the changes:
     131{{{
     132sudo service slapd force-reload
     133}}}
     134
     135If you see some error while importing,
     136
     137Start your `slapd` in debug mode
     138
     139```
     140sudo service slapd stop
     141sudo slapd -h ldapi:/// -u openldap -g openldap -d 65 -F /etc/ldap/slapd.d/ -d 65
     142```
     143Then in another console,
     144
     145```
     146ldapmodify -H ldapi:// -Y EXTERNAL -f addcerts.ldif
     147```
     148
     149then `ctrl+c` to stop the debug mode on first console and start the service.
     150
     151```
     152sudo service slapd start
     153```
     154
     155
     156Your 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
     161In 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.
     162On the OpenLDAP Server
     163
     164If 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
     166First, 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```
     169sudo cp /etc/ssl/certs/ca_server.pem /etc/ldap/ca_certs.pem
     170```
     171Now, 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```
     174sudo nano /etc/ldap/ldap.conf
     175```
     176
     177Adjust the value of the '''TLS_CACERT''' option to point to the file we just created:
     178
     179```
     180TLS_CACERT /etc/ldap/ca_certs.pem
     181TLS_REQCERT allow
     182```
     183
     184Save and close the file.
     185
     186You 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```
     189ldapwhoami -H ldap:// -x -ZZ
     190```
     191This forces a STARTTLS upgrade. If this is successful, you should see:
     192```
     193STARTTLS success
     194
     195anonymous
     196```
     197
     198### Load eduPerson Schema.
     199
     200Get the schema downloaded from [Eduperson.ldif](./eduperson-201602.ldif)
     201
     202Or the latest from `https://spaces.at.internet2.edu/display/macedir/LDIFs`
     203
     204Load it using:
     205
     206```bash
     207ldapadd -Y EXTERNAL -H ldapi:/// -f eduperson-201602.ldif
     208```
     209
     210Also Lets load The SChema for Academia, SCHAC.
     211Get the schema downloaded from [SCHAC.ldif](./schac-20150413.ldif)
     212
     213Or the latest from `https://wiki.refeds.org/display/STAN/SCHAC+Releases`
     214
     215Load it using:
     216
     217```bash
     218ldapadd -Y EXTERNAL -H ldapi:/// -f schac-20150413.ldif
     219```
     220
     221### Create User Structure
     222
     223Depending on your Institute's Requirement, you may create grouop as follows:
     224
     225```
     226dn: ou=People,dc=YOUR-DOMAIN,dc=ac,dc=lk
     227objectClass: organizationalUnit
     228objectClass: top
     229ou: People
     230 
     231dn: ou=Group,dc=YOUR-DOMAIN,dc=ac,dc=lk
     232objectClass: organizationalUnit
     233objectClass: top
     234ou: Group
     235description: All groups
     236
     237# System Admin Staff Group
     238dn:cn=adm,ou=Group,dc=YOUR-DOMAIN,dc=ac,dc=lk
     239cn:adm
     240description:System Admin Staff
     241gidNumber:1500
     242objectClass:posixGroup
     243objectClass:top
     244
     245# Acadamic staff Group
     246dn:cn=acd,ou=Group,dc=YOUR-DOMAIN,dc=ac,dc=lk
     247cn:acd
     248description:Acadamic Staff
     249gidNumber:2000
     250objectClass:posixGroup
     251objectClass:top
     252
     253# Students Group
     254dn:cn=student,ou=Group,dc=YOUR-DOMAIN,dc=ac,dc=lk
     255cn:student
     256description:Students
     257gidNumber:5000
     258objectClass:posixGroup
     259objectClass:top
     260
     261# servers OU
     262dn:ou=servers,dc=YOUR-DOMAIN,dc=ac,dc=lk
     263description:servers
     264objectClass:top
     265objectClass:organizationalUnit
     266ou:servers
     267
     268# idp servers
     269dn:cn=idp,ou=servers,dc=YOUR-DOMAIN,dc=ac,dc=lk
     270cn:idp
     271description:Identity Server
     272ipHostNumber: 3ffe:ffff:ffff::9
     273objectClass:top
     274objectClass:device
     275objectClass:ipHost
     276objectClass:simpleSecurityObject
     277userPassword:{crypt}idpldap
     278
     279
     280# test User
     281
     282dn:uid=testme,ou=people,dc=YOUR-DOMAIN,dc=ac,dc=lk
     283cn:Test Me
     284uid:testme
     285uidNumber:1001
     286gidNumber:1000
     287givenName:Test Me
     288homeDirectory:/dev/null
     289homePhone:none
     290objectClass:person
     291objectClass:organizationalPerson
     292objectClass:inetOrgPerson
     293objectClass: eduPerson
     294objectClass:posixAccount
     295objectClass:top
     296objectClass:shadowAccount
     297sn:Test
     298mobile:+94791234567
     299userPassword:testme
     300mail: testme@YOUR_DOMAIN
     301eduPersonPrincipalName: testme@YOUR_DOMAIN
     302
     303```
     304
     305Save 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`