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(login): improve auth handlers #7969

Merged
merged 19 commits into from
May 22, 2024
Merged

fix(login): improve auth handlers #7969

merged 19 commits into from
May 22, 2024

Conversation

livio-a
Copy link
Member

@livio-a livio-a commented May 16, 2024

Which Problems Are Solved

During the implementation of #7486 it was noticed, that projections in the auth database schema could be blocked.
Investigations suggested, that this is due to the use of GORM and it's inability to use an existing (sql) transaction.
With the improved / simplified handling (see below) there should also be a minimal improvement in performance, resp. reduced database update statements.

How the Problems Are Solved

The handlers in auth are exchanged to proper (sql) statements and gorm usage is removed for any writing part.
To further improve / simplify the handling of the users, a new auth.users3 table is created, where only attributes are handled, which are not yet available from the projections.users, projections.login_name and projections.user_auth_methods do not provide. This reduces the events handled in that specific handler by a lot.

Additional Changes

None

Additional Context

relates to #7486

Copy link

vercel bot commented May 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 22, 2024 3:09pm

Copy link

github-actions bot commented May 16, 2024

Thanks for your contribution! 🎉

Please make sure you tick the following checkboxes before marking this Pull Request (PR) as ready for review:

  • I am happy with the code
  • Documentations and examples are up-to-date
  • Logical behavior changes are tested automatically
  • No debug or dead code
  • My code has no repetitions
  • The PR title adheres to the conventional commit format
  • The example texts in the PR description are replaced.
  • If there are any open TODOs or follow-ups, they are described in issues and link to this PR
  • If there are deviations from a user stories acceptance criteria or design, they are agreed upon with the PO and documented.

Copy link

codecov bot commented May 17, 2024

Codecov Report

Attention: Patch coverage is 32.99832% with 400 lines in your changes are missing coverage. Please review.

Project coverage is 62.45%. Comparing base (cca3421) to head (bd961a0).

Files Patch % Lines
...h/repository/eventsourcing/handler/user_session.go 20.32% 145 Missing ⚠️
...nal/auth/repository/eventsourcing/handler/token.go 37.25% 92 Missing and 4 partials ⚠️
.../repository/eventsourcing/handler/refresh_token.go 19.44% 58 Missing ⚠️
...rnal/auth/repository/eventsourcing/handler/user.go 59.00% 39 Missing and 2 partials ⚠️
internal/user/repository/view/user_view.go 0.00% 14 Missing ⚠️
internal/user/repository/view/model/token.go 0.00% 13 Missing ⚠️
...nternal/user/repository/view/model/user_session.go 70.00% 11 Missing and 1 partial ⚠️
internal/user/repository/view/user_session_view.go 0.00% 8 Missing ⚠️
cmd/setup/26.go 0.00% 5 Missing ⚠️
internal/eventstore/handler/v2/statement.go 0.00% 3 Missing ⚠️
... and 3 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7969      +/-   ##
==========================================
- Coverage   62.75%   62.45%   -0.30%     
==========================================
  Files        1341     1342       +1     
  Lines      111029   110812     -217     
==========================================
- Hits        69672    69213     -459     
- Misses      37431    37721     +290     
+ Partials     3926     3878      -48     
Flag Coverage Δ
core-integration-tests-postgres 62.45% <32.99%> (-0.30%) ⬇️

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.

@livio-a livio-a requested a review from adlerhurst May 17, 2024 07:24
@livio-a livio-a changed the title perf(login): improve auth handlers fix(login): improve auth handlers May 17, 2024
@livio-a livio-a marked this pull request as ready for review May 17, 2024 07:35
adlerhurst
adlerhurst previously approved these changes May 22, 2024
@livio-a livio-a enabled auto-merge (squash) May 22, 2024 15:01
@livio-a livio-a merged commit fb162a7 into main May 22, 2024
25 of 27 checks passed
@livio-a livio-a deleted the auth-handlers branch May 22, 2024 15:26
livio-a added a commit that referenced this pull request May 28, 2024
# Which Problems Are Solved

As already mentioned and (partially) fixed in #7992 we discovered,
issues with v2 tokens that where obtained through an IDP, with
passwordless authentication or with password authentication (wihtout any
2FA set up) using the v1 login for zitadel API calls
- (Previous) authentication through an IdP is now correctly treated as
auth method in case of a reauth even when the user is not redirected to
the IdP
- There were some cases where passwordless authentication was
successfully checked but not correctly set as auth method, which denied
access to ZITADEL API
- Users with password and passwordless, but no 2FA set up which
authenticate just wich password can access the ZITADEL API again

Additionally while testing we found out that because of #7969 the login
UI could completely break / block with the following error:
`sql: Scan error on column index 3, name "state": converting NULL to
int32 is unsupported (Internal)`
# How the Problems Are Solved

- IdP checks are treated the same way as other factors and it's ensured
that a succeeded check within the configured timeframe will always
provide the idp auth method
- `MFATypesAllowed` checks for possible passwordless authentication
- As with the v1 login, the token check now only requires MFA if the
policy is set or the user has 2FA set up
- UserAuthMethodsRequirements now always uses the correctly policy to
check for MFA enforcement
- `State` column is handled as nullable and additional events set the
state to active (as before #7969)

# Additional Changes

- Console now also checks for 403 (mfa required) errors (e.g. after
setting up the first 2FA in console) and redirects the user to the login
UI (with the current id_token as id_token_hint)
- Possible duplicates in auth methods / AMRs are removed now as well.

# Additional Context

- Bugs were introduced in #7822 and # and 7969 and only part of a
pre-release.
- partially already fixed with #7992
- Reported internally.
Copy link

🎉 This PR is included in version 2.53.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

livio-a added a commit that referenced this pull request May 29, 2024
# Which Problems Are Solved

A customer noted that after upgrade to 2.53.0, users were no longer able
to reset their passwords through the login UI.
This was due to a accidental change in
#7969

# How the Problems Are Solved

The `preferred_login_name` is now correctly read from the database.

# Additional Changes

None.

# Additional Context

relates to #7969
livio-a added a commit that referenced this pull request May 29, 2024
# Which Problems Are Solved

A customer noted that after upgrade to 2.53.0, users were no longer able
to reset their passwords through the login UI.
This was due to a accidental change in
#7969

# How the Problems Are Solved

The `preferred_login_name` is now correctly read from the database.

# Additional Changes

None.

# Additional Context

relates to #7969

(cherry picked from commit eca8ffd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

None yet

2 participants