I built this in-house web app (built on Flask and served with Gunicorn) and for ages it's never stored any sort of user data or session data and it worked fine. Now I added an authentication page, using my organization's LDAP - user inputs username and password (same they use to log in on their machines), app verifies the credentials on the LDAP server and lets the user through if everything matches.
When I serve the app with only one process (gunicorn -w 1
) it works fine. But when I serve the app with multiple processes I get erratic behavior! Sometimes authentication fails even though username and password are correct. Sometimes if one user authenticates then others are treated as authenticated. And sometimes the user authenticates and gets to use the app for a while but then clicks something and gets redirected to the login page (all functions are decorated to check that the user is authenticated).
My guess is that I'm failing to properly isolate the users - user X enters correct username and password but when clicks "submit" the app thinks that's user Y, who hasn't authenticated, and therefore denies access (here's the logic of the authentication: I check if flask.session
has the key user
; if it does, the user gets through; if not, user is redirected to the login page and if authentication is successful I store the username in flask.session["user"]
).
How can I debug this? If my guess is correct then how can I make sure that users' credentials don't get mixed up?