Skip to content

[PUI] Add 2FA login - #7469

Merged
SchrodingersGat merged 21 commits into
inventree:masterfrom
matmair:matmair/issue6200
Jun 19, 2024
Merged

SchrodingersGat merged 21 commits into
inventree:masterfrom
matmair:matmair/issue6200

Conversation

@matmair

@matmair matmair commented Jun 18, 2024

Copy link
Copy Markdown
Member

This PR adds the option to use the CUI 2FA login method for PUI. The user is automatically send to the appropriate screen, can enter their default 2FA method (TOTP code, backup code, HOTP) and is then redirected to the PUI home screen.

Screen.Recording.2024-06-18.at.13.00.50.mov

This method respects CRSF and is stateless - which should make it pretty hard to circumvent.

Closes #6200

@matmair matmair added enhancement This is an suggested enhancement or new feature user interface security Relates to a security issue User Interface Related to the frontend / User Interface labels Jun 18, 2024
@matmair matmair added this to the 0.16.0 milestone Jun 18, 2024
@matmair matmair self-assigned this Jun 18, 2024
@matmair
matmair requested a review from SchrodingersGat as a code owner June 18, 2024 11:05
@netlify

netlify Bot commented Jun 18, 2024 •

Copy link
Copy Markdown

✅ Deploy Preview for inventree-web-pui-preview canceled.

Name Link
🔨 Latest commit c04527d
🔍 Latest deploy log https://app.netlify.com/sites/inventree-web-pui-preview/deploys/667290e1ca3a530008f55aa4

@codecov

codecov Bot commented Jun 18, 2024 •

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 72.88136% with 16 lines in your changes missing coverage. Please review.

Project coverage is 83.94%. Comparing base (432e0c6) to head (c04527d).
Report is 338 commits behind head on master.

Files with missing lines Patch % Lines
src/frontend/src/functions/auth.tsx 5.88% 16 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7469      +/-   ##
==========================================
- Coverage   83.96%   83.94%   -0.03%     
==========================================
  Files        1066     1066              
  Lines       46618    46673      +55     
  Branches     1389     1392       +3     
==========================================
+ Hits        39144    39180      +36     
- Misses       7112     7121       +9     
- Partials      362      372      +10     
Flag Coverage Δ
backend 85.23% <100.00%> (+0.04%) ⬆️
pui 65.78% <5.88%> (+0.43%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@SchrodingersGat

Copy link
Copy Markdown
Member

@matmair seems like a very good approach to work around this issue

@wolflu05

Copy link
Copy Markdown
Member

Awesome that you implemented this, this was stopping me from using 2FA on my home instance. The question is just, what are we gonna do if we deprecate CUI? Will we still keep that view for entering the TOPT code? Or is there a possibility, we can directly implement that into PUI?

@matmair

matmair commented Jun 18, 2024 •

Copy link
Copy Markdown
Member Author

@wolflu05 my plan is to leave this in when we remove CUI, it is only a very small part - you can check out what this removal would look like here: matmair#174

I do not think we should implement the different 2fa factors ourself (we support 3 rn) as that would create a lot of surfaces to make costly security issues.

EDIT:
In the long run I really want to switch to allauths new included methods - see #6293

@matmair

matmair commented Jun 19, 2024

Copy link
Copy Markdown
Member Author

This is ready for review/merge - testing the frontend is proving to be very hard because we can't add MFA methods via API (yet - that is coming with #6293)

@wolflu05

Copy link
Copy Markdown
Member

In the long run I really want to switch to allauths new included methods

But this would enable use to build our own 2FA input directly in PUI and really get rid of all CUI code. In your linked allauth roadmap they mention:

Add first-class API support. As part of the delivering the API, an OpenAPI specification and example React example application will be delivered, showcasing full SPA access to all of the django-allauth flows.

If they support 2FA via API, its not "our responsibility" with custom API code to built it secure anymore, because as I understand, they want to implement the critical backend API layer we could just use, and build our own frontend around it?

@matmair

matmair commented Jun 19, 2024

Copy link
Copy Markdown
Member Author

Yes, the switch will enable that. It will however require a complete review and possibly rewrite of our auth processes/integrations. This might take a while as it has grown over the years.

@SchrodingersGat

Copy link
Copy Markdown
Member

@matmair nice work, thanks for the fix

@SchrodingersGat
SchrodingersGat merged commit 39f3b90 into inventree:master Jun 19, 2024
@SchrodingersGat
SchrodingersGat deleted the matmair/issue6200 branch June 19, 2024 22:38
martonmiklos pushed a commit to martonmiklos/InvenTree that referenced this pull request Jun 24, 2024
* Add `2fa_urls`

* Add new fields to serializer

* Add new interface to PUI interfaces

* fix url resolving

* add frontend redirect for MFA login

* redirect login if mfa is required

* Merege upstream/master into branch

* reset default login

* remove mfa states

* fix auth args

* add handler for MFA redirect auth

* Revert "Merege upstream/master into branch"

This reverts commit 717001d.

* revert api version bump

* revert frontend error handling change

* reduce complexity

* reset schema text

* Add e2e test for MFA login url

* accept either POST or body data for login pre-check

* remove CUI test

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

Labels

enhancement This is an suggested enhancement or new feature security Relates to a security issue User Interface Related to the frontend / User Interface

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

[PUI] Enable 2FA for new interface

3 participants