Skip to content
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

ldap provider #166

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft

ldap provider #166

wants to merge 18 commits into from

Conversation

metallkopf
Copy link

Add ldap as an external authentication provider.

pending work in no specific order:

  • update documentation
  • include tests
  • database migration
  • whatever i forgot

@redimp
Copy link
Owner

redimp commented Nov 26, 2024

Hey @metallkopf thank you for this PR! I will take a look at it, set up a test environment and check whether everything works as intended. Unfortunately I'm currently swamped at work, will take care of this on the weekend.

@metallkopf
Copy link
Author

This is what am using:

  • to build: podman build -t ldap .
  • to run: podman run --rm -it -p 3890:389 ldap
  • settings.cfg:
    • LDAP_URI = 'ldap://localhost:3890'
    • LDAP_USERNAME = 'cn=Manager,dc=ldap,dc=local'
    • LDAP_PASSWORD = 'secret'
    • LDAP_BASE = 'dc=ldap,dc=local'
    • LDAP_SCOPE = 'subtree'
    • LDAP_DOMAIN = 'ldap.org'
  • user / password:

container.zip

@redimp
Copy link
Owner

redimp commented Dec 1, 2024

This looks promising! Unfortunately I did not get my example working ... can you check (and maybe fix) the example in docs/auth_examples/ldap-auth?

Things I want to check when we got this working:

  • Add an option to auto-create users existing in ldap
  • Consider to move LdapAuth in a seperate class (like ProxyHeaderAuth)

import ldap
has_ldap = True
except ImportError as e:
app.logger.debug(f"Unable to import ldap: {e}")
Copy link
Author

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

Copy link
Owner

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.

@metallkopf
Copy link
Author

i couldnt get those docker services to work, so i integrated them into one.

the problem: not all variables were defined in server.py, so they couldnt be read from the environment.

Add an option to auto-create users existing in ldap

you mean auto-register on login?, sure the common name can be recovered after binding

Consider to move LdapAuth in a seperate class (like ProxyHeaderAuth)

i was considering ldap as a secundary login, allowing both type of users. but we can work something out

ps: do you any preference on how to implement database migrations?

@redimp
Copy link
Owner

redimp commented Dec 2, 2024

i couldnt get those docker services to work, so i integrated them into one.

Looks good to me. Have not tested this yet.

you mean auto-register on login?

Yes, this should be an option.

do you any preference on how to implement database migrations?

I'm open for suggestions. I've used flask-migrate before.

@redimp
Copy link
Owner

redimp commented Dec 5, 2024

Got the example working! Have to think about the best way to integrate this.

But even with a seperate LdapAuth some work has to be done, like fetching information from ldap about the users, e.g. the Name. Or for future features groups ... ?

@@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this addition was producing an error on my end

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Juste tested this on the resent commit 615c511 adding a User works as expected. Can ypu please try to reproduce the error?

@metallkopf
Copy link
Author

...Have to think about the best way to integrate this.

you luck with that

...like fetching information from ldap about the users, e.g. the Name.

i've already added retrieving the -common- name of an user when he self-registers

...Or for future features groups ... ?

can you elaborate a bit more

@redimp
Copy link
Owner

redimp commented Dec 8, 2024

...Or for future features groups ... ?

can you elaborate a bit more

The request for more fine grained permissions exists for a long time. I think, that for a useful implementation a concept groups is necessary (For some more details, please see #54 (comment)).

But I think that this can be implemented easily on top of your ldap auth and is no case a blocker.

@redimp
Copy link
Owner

redimp commented Dec 8, 2024

Sorry, my time is very limited at the moment 😞 Please don't let this discourage you.

The example works as expected, wonderful!

Will be on vacation in a week, will spent time on this then.

skillpoint and others added 4 commits January 12, 2025 23:34
As requested in redimp#176 code blocks can be configured to display
line numbers by adding a = to the specified language. e.g.

```python=
print("Hello Line Numbers!")
```
Bumps [jinja2](https://github.com/pallets/jinja) from 3.1.4 to 3.1.5.
- [Release notes](https://github.com/pallets/jinja/releases)
- [Changelog](https://github.com/pallets/jinja/blob/main/CHANGES.rst)
- [Commits](pallets/jinja@3.1.4...3.1.5)

---
updated-dependencies:
- dependency-name: jinja2
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <[email protected]>
@redimp
Copy link
Owner

redimp commented Jan 12, 2025

I chose to implement the database migrations myself. This works for sqlite, mariadb and postgres.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants