|
| 1 | +# Setting up LDAP server on local & dev environments |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This guide describes how to test the LDAP adapter in a local or dev environment. For this we use the following Docker image: [ghcr.io/hpi-schul-cloud/sc-openldap-single:main](http://ghcr.io/hpi-schul-cloud/sc-openldap-single:main) It provides a multitude of users for testing, in a compatible format. |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Setting up the LDAP server for local development & testing purposes |
| 10 | + |
| 11 | +### Starting the LDAP Container |
| 12 | + |
| 13 | +The first step is to start a Docker container with the **sc-openldap-single** image and exposed 389 port for the ldap protocol connections. |
| 14 | + |
| 15 | +Note that there have been issues running the ldaps protocol. |
| 16 | + |
| 17 | +```bash |
| 18 | +docker run -d -p 389:389 --name openldap ghcr.io/hpi-schul-cloud/sc-openldap-single:main |
| 19 | +``` |
| 20 | + |
| 21 | +You can verify the deployment using [Apache Directory Studio™](https://directory.apache.org/studio/) or a simlar software to connect: |
| 22 | + |
| 23 | +- **Hostname:** `localhost` or `127.0.0.1` |
| 24 | +- **Port:** `389` |
| 25 | +- **Bind DN or user:** `cn=admin,dc=example,dc=org` |
| 26 | +- **Bind password:** `admin` |
| 27 | + |
| 28 | +### Connecting to the LDAP Container |
| 29 | + |
| 30 | +Since we are not using the ldaps protocoll for the local deployment, we have to configure the server to accept insecure ldap connections. Add the following to your environment variables: |
| 31 | + |
| 32 | +```bash |
| 33 | +FEATURE_ALLOW_INSECURE_LDAP_URL_ENABLED: true |
| 34 | +``` |
| 35 | + |
| 36 | +To configure a school in the Bildungscloud to use your new LDAP deployment, there are two ways: Either you add the necessary data directly in the database, or you add the system in the UI. |
| 37 | + |
| 38 | +To make the changes directly, add the following Object in the `systems` collection |
| 39 | + |
| 40 | +```json |
| 41 | +{ |
| 42 | + "type": "ldap", |
| 43 | + "alias": "testldap-schoolOne0", |
| 44 | + "ldapConfig": { |
| 45 | + "active": true, |
| 46 | + "federalState": { |
| 47 | + "$oid": "0000b186816abba584714c53" |
| 48 | + }, |
| 49 | + "url": "ldap://127.0.0.1:389", |
| 50 | + "rootPath": "o=schoolOne0,dc=de,dc=example,dc=org", |
| 51 | + "searchUser": "cn=admin,dc=example,dc=org", |
| 52 | + "searchUserPassword": "<encryt this with your Base64 Key>", |
| 53 | + "provider": "general", |
| 54 | + "providerOptions": { |
| 55 | + "schoolName": "Paul-Gerhardt-Gymnasium", |
| 56 | + "userPathAdditions": "ou=users", |
| 57 | + "classPathAdditions": "ou=groups", |
| 58 | + "roleType": "group", |
| 59 | + "userAttributeNameMapping": { |
| 60 | + "givenName": " givenName", |
| 61 | + "sn": "sn", |
| 62 | + "dn": "dn", |
| 63 | + "uuid": "uuid", |
| 64 | + "uid": "uid", |
| 65 | + "mail": "mail", |
| 66 | + "role": "memberOf" |
| 67 | + }, |
| 68 | + "roleAttributeNameMapping": { |
| 69 | + "roleStudent": "cn=ROLE_STUDENT,ou=roles,o=schoolOne0,dc=de,dc=example,dc=org", |
| 70 | + "roleTeacher": "cn=ROLE_TEACHER,ou=roles,o=schoolOne0,dc=de,dc=example,dc=org", |
| 71 | + "roleAdmin": "cn=ROLE_ADMIN,ou=roles,o=schoolOne0,dc=de,dc=example,dc=org", |
| 72 | + "roleNoSc": "cn=ROLE_NBC_EXCLUDE,ou=roles,o=schoolOne0,dc=de,dc=example,dc=org" |
| 73 | + }, |
| 74 | + "classAttributeNameMapping": { |
| 75 | + "description": "description", |
| 76 | + "dn": "dn", |
| 77 | + "uniqueMember": "member" |
| 78 | + } |
| 79 | + } |
| 80 | + }, |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +Then add the following properties to a school object of your choice. |
| 85 | + |
| 86 | +```json |
| 87 | +{ |
| 88 | + [...] |
| 89 | + "systems": [ |
| 90 | + { |
| 91 | + "$oid": "<id of the system you just created>" |
| 92 | + } |
| 93 | + ], |
| 94 | + "ldapSchoolIdentifier": "o=schoolOne0,dc=de,dc=example,dc=org" |
| 95 | +} |
| 96 | +``` |
| 97 | + |
| 98 | +Alternatively, in the UI you can login as a school admin and navigate to /administration/school-settings, and under "Authentication" click on "Add LDAP System". |
| 99 | + |
| 100 | +Refer to the example above for the values. (note that the password only has to be encrypted if you add it to the database manually) |
| 101 | + |
| 102 | +> **Note:** you can not use `localhost` as the hostname, since that will be rejected by the validator. use the ip adress `127.0.0.1` instead. |
| 103 | +
|
| 104 | +Once you have filled all the fields you can verify the config. |
| 105 | + |
| 106 | +--- |
| 107 | + |
| 108 | +## Triggering the LDAP sync |
| 109 | + |
| 110 | +Before triggering the LDAP sync ensure you have a working RabbitMQ setup, and add the following environment variables |
| 111 | + |
| 112 | +```bash |
| 113 | +FEATURE_SYNCER_CONSUMER_ENABLE: 'true' |
| 114 | +SYNC_API_KEY: 'a-key-of-your-choice' |
| 115 | +``` |
| 116 | + |
| 117 | +Then trigger the sync with the following request: |
| 118 | + |
| 119 | +```bash |
| 120 | +curl -X POST -H "X-API-Key: $SYNC_API_KEY" "$API_HOST/v1/sync?target=ldap" |
| 121 | +``` |
| 122 | + |
| 123 | +You should get a response similar to: |
| 124 | + |
| 125 | +```json |
| 126 | +[{"success":true,"errors":[],"systems":{"Paul-Gerhardt-Gymnasium":{"success":true,"errors":[],"schools":1,"users":1226,"classes":17}}}] |
| 127 | +``` |
0 commit comments