Repository navigation
Description
I have traefik running as a reverse proxy in front of inventree. The reverse proxy handles the AUTHENTICATION (and maybe AUTHORIZATION) before handing it off to any server running behind it.
In this case I have https://inventree.{mydomain}.com pointing to the reverse proxy. The reverse proxy authenticates with google, and then sets a cookie for auth. The proxy then checks the presence of a valid auth cookie before handing the traffic off to inventree running in a docker container. (This is all done with traefik, btw)
In this scenario I have two login pages. First for the google login page, and then the second for the inventree login page.
So the reverse proxy will add a header to the request, in my case "X-Forwarded-User: [email protected]".
It would be nice to have something along the lines in the config:
INVENTREE_REVERSE_PROXY_LOGIN=True
INVENTREE_REVERSE_PROXY_HEADER="X-Forwarded-User"
This would allow easier login for people/corporations that already have a reverse proxy system setup using LDAP/SSO/etc. And Inventree wouldn't have to deal with complex auth mechanisms directly at all.
Lastly Inventree would need something like this:
INVENTREE_REVERSE_PROXY_AUTO_CREATE_USER=True/False
If True, an unknown user would be granted access (because both AUTHENTICATION of the user and AUTHORIZATION of the user accessing Inventree have been handled elsewhere) and Inventree should just add the new user into the User's table.
If False, AUTHENTICATION is handled by the reverse proxy, but AUTHORIZATION of the user accessing Inventree is controlled by the Django User table. If a user exists in table and is_active=True then the user is granted access. Otherwise the user gets a 403 Forbidden Page.
This way you can do fine grained control of user AUTHORIZATION in Inventree, yet still rely upon external AUTHENTICATION to validate who the person is.
Activity
SchrodingersGat commentedon Jun 20, 2021
sure, this seems reasonable and has been requested before:
I'm not sure how to implement this - have you any experience on configuring django in such a fashion?
We'd also need to clearly document this :)
rcludwick commentedon Jun 21, 2021
Yes. (Sadly)
So yeah... in 2021 it's fugly. It should be simple, but it's not. There are companies making billions of dollars on this.
So what I'm suggesting is probably the simplest case possible for inventree.
Authentication is either handled by django's login page, or via the X-Forwarded-User header. Then if you want something more complex than the simple login page, it's up to user to implement it and make sure the logged in user is put into the X-Forwarded-User header (or whatever header is configured above).
Fortunately Django has support for this built in though the RemoteUserMiddleware and RemoteUserBackend classes. YAY!
This is worth a careful read through.
https://docs.djangoproject.com/en/3.2/howto/auth-remote-user/
SchrodingersGat commentedon Jun 21, 2021
@rcludwick is this feature something you'd be willing to spend some time on? I'm happy to support it but this is really not my area of expertise!
rcludwick commentedon Jun 21, 2021
I'll look at it in my spare time. It's mostly "configuration" thankfully.
matmair commentedon Aug 19, 2021
@rcludwick did you find time to do this and would you be willing to share your findings for the docs?
rcludwick commentedon Aug 19, 2021
matmair commentedon Aug 20, 2021
@rcludwick thanks for the input, I will try to implement something if I find time. Your input would be appreciated if you find time 👼.
rcludwick commentedon Aug 20, 2021
matmair commentedon Sep 7, 2021
This is similar to #625 but more specific about how it could be implemented.
matmair commentedon Oct 30, 2021
I played around with this because a client needed it. It is very easy to do with the authentication backend and middleware settings in the config.yaml. It was ~40 LoC but really depenendet on how the infra is built out. Could be very dangerous if the admin setting it up does not know their stuff.
@SchrodingersGat should we still implement a solution for this? Maybe a configurable header that is used as a user reference?
SchrodingersGat commentedon Oct 30, 2021
I'm happy to provide a reference example but not implement it by default. A clear warning should be added to the documentation that "all care should be taken" but the implementing admin.
matmair commentedon Oct 30, 2021
So what should I sketch out? A simple proxy set auth-header, LDAP or something else? Google etc. are already implemented in the SSO package.
SchrodingersGat commentedon Nov 2, 2021
@matmair I'm happy for you to make a suggestion based on what you think is sensible. This is straying very far from my area of knowledge.
My key requirements would be:
1 remaining item
SchrodingersGat commentedon Feb 28, 2022
@rcludwick are you still interested in this?
@matmair are you still keen to implement?
matmair commentedon Feb 28, 2022
@SchrodingersGat yes. I planned with a longer release window and wanted to do it in the Easter break
Feature request: reverse proxy login support
matmair commentedon Apr 24, 2022
@rcludwick if you have time feel free to look at the PR
larchen commentedon Oct 18, 2022
I'm having some trouble getting the proxy auth working and I was wondering if I'm missing a setting somewhere. I'm using traefik + traefik-forward-auth for SSO, which passes the X-Forwarded-User header to an nginx container (for serving static files) running in front of inventree.
I have
in my
inventree.ymlfile, and the nginx config was copied from here. I've also tried theINVENTREE_REMOTE_LOGIN=trueandINVENTREE_REMOTE_LOGIN_HEADER=X-Forwarded-User, but in both cases I keep getting redirected to the login screen.Do I need to add to the
authentication_backendsandmiddlewaresin the configuration yaml as well, or is there another configuration setting I'm missing?