Skip to content

Feature request: reverse proxy login support #1693

Closed

Description

@rcludwick

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

  1. SchrodingersGat commented on Jun 20, 2021

    @SchrodingersGat
    Member

    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 :)

  2. rcludwick commented on Jun 21, 2021

    @rcludwick
    ContributorAuthor

    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/

  3. SchrodingersGat commented on Jun 21, 2021

    @SchrodingersGat
    Member

    @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!

  4. rcludwick commented on Jun 21, 2021

    @rcludwick
    ContributorAuthor

    I'll look at it in my spare time. It's mostly "configuration" thankfully.

  5. matmair commented on Aug 19, 2021

    @matmair
    Member

    @rcludwick did you find time to do this and would you be willing to share your findings for the docs?

  6. rcludwick commented on Aug 19, 2021

    @rcludwick
    ContributorAuthor
  7. matmair commented on Aug 20, 2021

    @matmair
    Member

    @rcludwick thanks for the input, I will try to implement something if I find time. Your input would be appreciated if you find time 👼.

  8. rcludwick commented on Aug 20, 2021

    @rcludwick
    ContributorAuthor
  9. matmair commented on Sep 7, 2021

    @matmair
    Member

    This is similar to #625 but more specific about how it could be implemented.

  10. added this to the 0.6.0 milestone on Sep 13, 2021
  11. matmair commented on Oct 30, 2021

    @matmair
    Member

    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?

  12. SchrodingersGat commented on Oct 30, 2021

    @SchrodingersGat
    Member

    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.

  13. matmair commented on Oct 30, 2021

    @matmair
    Member

    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.

  14. SchrodingersGat commented on Nov 2, 2021

    @SchrodingersGat
    Member

    @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:

    • It is all disabled by default
    • It is reasonably difficult to 'accidentally' turn on
    • It is documented with a very clear caveat that the admin must know exactly what they are doing.
  15. 1 remaining item

  16. modified the milestones: 0.6.0, 0.7.0 on Nov 18, 2021
  17. self-assigned this
    on Nov 18, 2021
  18. added
    security
    on Nov 18, 2021
  19. SchrodingersGat commented on Feb 28, 2022

    @SchrodingersGat
    Member

    @rcludwick are you still interested in this?

    @matmair are you still keen to implement?

  20. matmair commented on Feb 28, 2022

    @matmair
    Member

    @SchrodingersGat yes. I planned with a longer release window and wanted to do it in the Easter break

  21. modified the milestones: 0.7.0, 0.8.0 on Apr 20, 2022
  22. added
    setup
    on Apr 20, 2022
  23. added a commit that references this issue on Apr 24, 2022
    2e4aa8a
  24. matmair commented on Apr 24, 2022

    @matmair
    Member

    @rcludwick if you have time feel free to look at the PR

  25. Repository owner moved this from On Hold to Done in Pers. Overview for InvenTreeon Apr 27, 2022
  26. larchen commented on Oct 18, 2022

    @larchen

    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

    remote_login_enabled: True
    remote_login_header: X-Forwarded-User
    

    in my inventree.yml file, and the nginx config was copied from here. I've also tried the INVENTREE_REMOTE_LOGIN=true and INVENTREE_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_backends and middlewares in the configuration yaml as well, or is there another configuration setting I'm missing?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

securitysetup

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions