-
Notifications
You must be signed in to change notification settings - Fork 96
ldap provider #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
ldap provider #166
Changes from 10 commits
8841350
f28ee27
3c8e496
9e53b1a
3c8ff78
55ecec7
6804d68
b322c65
67d0a82
5ec93a3
34d6769
8118ed3
2f96664
615c511
62e8f0d
aaa4ab1
11d3b5b
cb4cab4
37fc2cd
4bac818
923a0b1
98980cc
634cec8
f596585
89448e4
44f8bf3
ffecd35
54b475c
9645271
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| run: | ||
| docker compose build | ||
| docker compose up --remove-orphans |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| services: | ||
| otterwiki: | ||
| depends_on: | ||
| - ldap | ||
| image: otterwiki-test-ldap | ||
| build: | ||
| context: ../../.. | ||
| dockerfile: docker/Dockerfile.slim | ||
| ports: | ||
| - "8080:8080" | ||
| environment: | ||
| - LOG_LEVEL=DEBUG | ||
| - LDAP_URI=ldap://ldap:389 | ||
| - LDAP_USERNAME=cn=Manager,dc=ldap,dc=local | ||
| - LDAP_PASSWORD=secret | ||
| - LDAP_BASE=dc=ldap,dc=local | ||
| - LDAP_SCOPE=subtree | ||
| - LDAP_DOMAIN=ldap.org | ||
| # fixed SECRET_KEY for easier testing while keeping the session | ||
| - SECRET_KEY=aabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabbaabb | ||
| volumes: | ||
| - app-data:/app-data | ||
| command: | ||
| - sh | ||
| - -c | ||
| - | | ||
| cat <<EOF >> /tmp/provider.sql | ||
| PRAGMA foreign_keys=OFF; | ||
| BEGIN TRANSACTION; | ||
| DROP TABLE IF EXISTS user; | ||
| CREATE TABLE user ( | ||
| id INTEGER NOT NULL, | ||
| name VARCHAR(128), | ||
| email VARCHAR(128), | ||
| password_hash VARCHAR(512), | ||
| first_seen DATETIME, | ||
| last_seen DATETIME, | ||
| is_approved BOOLEAN, | ||
| is_admin BOOLEAN, | ||
| email_confirmed BOOLEAN, | ||
| allow_read BOOLEAN, | ||
| allow_write BOOLEAN, | ||
| allow_upload BOOLEAN, | ||
| provider VARCHAR(8), | ||
| PRIMARY KEY (id) | ||
| ); | ||
| INSERT INTO user VALUES(2,'John','john@ldap.org',NULL,'2024-12-01 19:28:13.273738','2024-12-01 19:28:13.273750',1,1,1,1,1,1,'ldap'); | ||
| INSERT INTO user VALUES(3,'Fulano','fulano@ldap.org',NULL,'2024-12-01 19:28:49.696271','2024-12-01 19:28:49.696281',1,0,0,1,1,0,'ldap'); | ||
| INSERT INTO user VALUES(4,'Max','max@ldap.org',NULL,'2024-12-01 19:29:11.958025','2024-12-01 19:29:11.958039',1,0,0,1,1,1,'ldap'); | ||
| COMMIT; | ||
| EOF | ||
| test -f /app-data/db.sqlite || sqlite3 -init /tmp/provider.sql /app-data/db.sqlite | ||
| /entrypoint.sh | ||
| /usr/sbin/uwsgi --ini /app/uwsgi.ini | ||
| stop_signal: SIGINT | ||
| ldap: | ||
| image: otterwiki-example-ldap | ||
| build: example-ldap | ||
| stop_signal: SIGINT | ||
|
|
||
| volumes: | ||
| app-data: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| FROM almalinux:9 | ||
|
|
||
| COPY *.ldif / | ||
|
|
||
| RUN dnf install -y epel-release procps \ | ||
| && dnf install -y openldap-clients openldap-servers \ | ||
| && slapd -u ldap -h ldapi:/// \ | ||
| && ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif \ | ||
| && ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif \ | ||
| && ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif \ | ||
| && ldapmodify -Y EXTERNAL -H ldapi:/// -f /config.ldif \ | ||
| && ldapadd -H ldapi:/// -D "cn=Manager,dc=ldap,dc=local" -w secret -f /directory.ldif \ | ||
| && pkill -INT slapd \ | ||
| && dnf clean all && rm -rf /var/cache/yum | ||
|
|
||
| EXPOSE 389/tcp | ||
|
|
||
| ENTRYPOINT /sbin/slapd -u ldap -h "ldap:/// ldapi:///" -d 256 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| dn: olcDatabase={2}mdb,cn=config | ||
| changetype: modify | ||
| replace: olcSuffix | ||
| olcSuffix: dc=ldap,dc=local | ||
|
|
||
| dn: olcDatabase={2}mdb,cn=config | ||
| changetype: modify | ||
| replace: olcRootDN | ||
| olcRootDN: cn=Manager,dc=ldap,dc=local | ||
|
|
||
| dn: olcDatabase={2}mdb,cn=config | ||
| changetype: modify | ||
| replace: olcRootPW | ||
| olcRootPW: secret |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| dn: dc=ldap,dc=local | ||
| dc: ldap | ||
| o: ldap | ||
| objectClass: dcObject | ||
| objectClass: organization | ||
| objectClass: top | ||
|
|
||
| dn: ou=Main,dc=ldap,dc=local | ||
| ou: Main | ||
| objectClass: organizationalUnit | ||
| objectClass: top | ||
|
|
||
| dn: ou=Branch,dc=ldap,dc=local | ||
| ou: Branch | ||
| objectClass: organizationalUnit | ||
| objectClass: top | ||
|
|
||
| dn: cn=John Doe,ou=Main,dc=ldap,dc=local | ||
| cn: John Doe | ||
| givenName: John | ||
| sn: Doe | ||
| objectClass: inetOrgPerson | ||
| objectClass: person | ||
| objectClass: top | ||
| userPassword: 12345678 | ||
| uid: john | ||
| mail: john@ldap.org | ||
|
|
||
| dn: cn=Fulano de Tal,ou=Main,dc=ldap,dc=local | ||
| cn: Fulano de Tal | ||
| givenName: Fulano | ||
| sn: de Tal | ||
| objectClass: inetOrgPerson | ||
| objectClass: person | ||
| objectClass: top | ||
| userPassword: password | ||
| uid: fulano | ||
| mail: fulano@ldap.org | ||
|
|
||
| dn: cn=Max Mustermann,ou=Branch,dc=ldap,dc=local | ||
| cn: Max Mustermann | ||
| givenName: Max | ||
| sn: Mustermann | ||
| objectClass: inetOrgPerson | ||
| objectClass: person | ||
| objectClass: top | ||
| userPassword: qwertyui | ||
| uid: max | ||
| mail: max@ldap.org |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -408,6 +408,7 @@ def handle_user_add(form): | |
| # update user from form | ||
| user.name = form.get("name").strip() # pyright: ignore | ||
| user.email = form.get("email").strip() # pyright: ignore | ||
| user.provider = form.get("provider").strip() # pyright: ignore | ||
|
||
|
|
||
| for value, _ in [ | ||
| ("email_confirmed", "email confirmed"), | ||
|
|
@@ -505,6 +506,9 @@ def handle_user_edit(uid, form): | |
| else: | ||
| user.password_hash = generate_password_hash(form.get("password1")) | ||
| msgs.append("Updated password") | ||
| if user.provider != form.get("provider","local"): | ||
| user.provider = form.get("provider","local").strip() # pyright: ignore | ||
| msgs.append("Updated provider") | ||
| user_was_already_approved = user.is_approved | ||
| # handle all the flags | ||
| for value, label in [ | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this try/catch block was added to allow ldap to be an optional dependency
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the log to make sure, I have all the dependencies added to the docker image.