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 Improvements and E2E testing #2199

Merged
merged 6 commits into from
Mar 12, 2023

Conversation

cmintey
Copy link
Contributor

@cmintey cmintey commented Feb 27, 2023

What type of PR is this?

  • documentation
  • bug/feature

What this PR does / why we need it:

  • Introduces a new optional environment variable to enable STARTTLS with LDAP.
  • Introduces support for anonymous bind by setting LDAP_QUERY_BIND and LDAP_QUERY_PASSWORD env variables to None
  • Make id_attribute and mail_attribute be implied in LDAP_USER_FILTER. This now makes LDAP_USER_FILTER optional. This change maintains compatibility with previous changes.

Which issue(s) this PR fixes:

Fixes #2185
Fixes #2218
Fixes #2228

Special notes for your reviewer:

This PR also introduces end-to-end tests for LDAP as discussed here. Instead of GLAuth, I found this awesome docker image that comes pre-baked with users as well as support for STARTTLS (which GLAuth did not support).

Testing

  • Ensure existing tests still pass.
  • Created E2E tests for ldap with a openldap docker image. These tests will only be run in GitHub Actions.

Release Notes

support for STARTTLS and anonymous bind with LDAP authentication

@cmintey cmintey force-pushed the fix/ldap-starttls branch from 8da400d to 9773f06 Compare March 8, 2023 21:37
@cmintey cmintey changed the title Fix: support for STARTTLS with ldap Fix: support for STARTTLS and anonymous bind with ldap Mar 8, 2023
@cmintey cmintey force-pushed the fix/ldap-starttls branch from 9773f06 to 6b5815b Compare March 8, 2023 22:28
@hay-kot hay-kot self-assigned this Mar 9, 2023
@cmintey cmintey changed the title Fix: support for STARTTLS and anonymous bind with ldap LDAP Improvements and E2E testing Mar 9, 2023
Copy link

@swails swails left a comment

Choose a reason for hiding this comment

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

Very cool!

@@ -82,5 +88,17 @@ jobs:
env:
DB_ENGINE: ${{ matrix.Database }}
POSTGRES_SERVER: localhost
LDAP_AUTH_ENABLED: True
LDAP_SERVER_URL: ldap://localhost:10389
Copy link

Choose a reason for hiding this comment

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

Suggested change
LDAP_SERVER_URL: ldap://localhost:10389
LDAP_SERVER_URL: ldap://ldap-service:10389

I think you can set it to the name of the service.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason I used localhost instead of the service name is mainly to keep it consistent with how the Postgres service is being used above

@@ -27,6 +27,12 @@ jobs:
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
ports:
- 5432:5432
ldap:
Copy link

Choose a reason for hiding this comment

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

Suggested change
ldap:
ldap-service:

Just suggesting that the name match my suggestion on line 92.

Comment on lines +32 to +34
ports:
- 10389:10389
- 10636:10636
Copy link

Choose a reason for hiding this comment

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

Suggested change
ports:
- 10389:10389
- 10636:10636

You shouldn't have to expose any ports if you use the service name (similar to how you can do in docker-compose).

@@ -57,3 +58,192 @@ def test_user_lockout_after_bad_attemps(api_client: TestClient, unique_user: Tes
user_service = UserService(database)
user = database.users.get_one(unique_user.user_id)
user_service.unlock_user(user)


@pytest.mark.skipif(not os.environ.get("GITHUB_ACTIONS", False), reason="requires ldap service in github actions")
Copy link

Choose a reason for hiding this comment

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

This makes it impossible to test locally. Is there a reason you can't set it to skip unless LDAP_SERVER_URL is set in the environment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The reason it's like that and not just checking for the LDAP url variable is because the tests rely on the specific docker image that is spun up during the tests. So just setting your LDAP url, the tests would likely fail since it wouldn't be the correct LDAP url and wouldn't have the correct users the tests expect.

You can still test it locally by setting GITHUB_ACTIONS=true in your environment. Then you'd need to spin up the docker image and point your LDAP environment variables to that docker image. Same process as in the GitHub workflow.

@hay-kot
Copy link
Collaborator

hay-kot commented Mar 12, 2023

This PR also introduces end-to-end tests for LDAP as discussed #2107 (comment). Instead of GLAuth, I found this awesome docker image that comes pre-baked with users as well as support for STARTTLS (which GLAuth did not support).

Amazing. I really really really really appreciate all the work you've been putting into the LDAP integration lately. It's super impressive!

@hay-kot hay-kot merged commit 7d9be67 into mealie-recipes:mealie-next Mar 12, 2023
@cmintey cmintey deleted the fix/ldap-starttls branch March 24, 2023 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants