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

fix: "SCRAM-SHA-1 requires a username" error for mongodb srv config with username #59

Merged
merged 2 commits into from
Dec 30, 2024

Conversation

kaustavb12
Copy link
Contributor

Description

Currently we are setting None to mongodb username and password parameters in FORUM_MONGODB_CLIENT_PARAMETERS.

PyMongo currently throws the following error if the credentials as added to the host parameter as a connection string.

pymongo.errors.ConfigurationError: SCRAM-SHA-1 requires a username.

This PR fixes this issue by omitting the two parameters completely if the corresponding values are not available.

Other information

Private Ref : BB-9353

@kaustavb12 kaustavb12 force-pushed the kaustav/do_not_set_null_creds branch from e17208a to fe32d63 Compare December 21, 2024 10:04
Copy link

@0x29a 0x29a left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@regisb
Copy link
Contributor

regisb commented Dec 30, 2024

I'm not sure I understand. What is the value of FORUM_MONGODB_CLIENT_PARAMETERS for you? Is the LMS container crashing?

Also, please add a changelog entry: https://docs.tutor.edly.io/tutor.html#contributing Make sure to describe why you are doing this change, and not what change you are doing. E.g: do not say "set variable to None" but "fix crashing LMS container when setting FORUM_XYZ parameter".

@kaustavb12
Copy link
Contributor Author

@regisb Changelog entry added.

Here's the value of FORUM_MONGODB_CLIENT_PARAMETERS in LMS settings without this change:

FORUM_MONGODB_CLIENT_PARAMETERS = {
    "host": "mongodb+srv://username:password@mongo.db.hostname",
    "port": 27017,
    "username": None,
    "password": None,
    "ssl": True,
}

This crashes this LMS init job (specifically, the forum_create_mongodb_indexes management command invoked in that job fails) with the exception

pymongo.errors.ConfigurationError: SCRAM-SHA-1 requires a username

With the changes from this PR, the value of FORUM_MONGODB_CLIENT_PARAMETERS becomes:

FORUM_MONGODB_CLIENT_PARAMETERS = {
    "host": "mongodb+srv://username:password@mongo.db.hostname",
    "port": 27017,
    "ssl": True,
}

This works correctly.

Copy link
Contributor

@regisb regisb left a comment

Choose a reason for hiding this comment

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

Awesome, thanks!

@regisb regisb changed the title fix: do not set None mongodb creds fix: "SCRAM-SHA-1 requires a username" error for mongodb srv config with username Dec 30, 2024
@regisb regisb merged commit 0df007f into overhangio:release Dec 30, 2024
2 checks passed
@kaustavb12 kaustavb12 deleted the kaustav/do_not_set_null_creds branch December 30, 2024 10:23
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.

3 participants