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

IBX-8323: Reworked RepositoryAuthenticationProvider and moved its logic to a dedicated subscriber #396

Merged
merged 3 commits into from
Jul 9, 2024

Conversation

konradoboza
Copy link
Contributor

@konradoboza konradoboza commented Jun 28, 2024

🎫 Issue IBX-8323

Description:

RememberMeRepositoryAuthenticationProvider is another part of our codebase relying on deprecated security layer. It basically covers some additional checks performed on repository users like "forgot password redirect" being the subject of the underlying bug.

In order to replace the deprecated approach I did the following:

  • removed mentioned provider alongside its unit test counterpart,
  • I removed registering it in SecurityPass as the original class being replaced will be removed in Symfony 6 anyway,
  • I moved ibexa.security.authentication.constant_auth_time setting from mentioned compiler pass and provided the same default value,
  • I registered RepositoryUserAuthenticationSubscriber that will take over checks performed in the provider,
  • I provided adjusted test coverage taken from the original provider's test counterpart.

The choice of CheckPassportEvent is intentional - I wanted to have possibility to stop and resume the authenticator process and according to my research this was the only suitable event for such purpose. Excerpt from Symfony doc:

CheckPassportEvent
Dispatched after the authenticator created the security passport. Listeners of this event do the actual authentication checks (like checking the passport, validating the CSRF token, etc.)

Note

Getting rid of injecting user into our PermissionResolver is intentional - the entire system got it covered within recently introduced https://github.com/ibexa/core/blob/main/src/lib/MVC/Symfony/Security/Authentication/EventSubscriber/OnAuthenticationTokenCreatedRepositoryUserSubscriber.php#L30.

The main part I am concerned about and have little knowledge of is:

// $currentUser can either be an instance of UserInterface or just the username (e.g. during form login).
        /** @var \Ibexa\Core\MVC\Symfony\Security\UserInterface|string $currentUser */
        $currentUser = $token->getUser();
        if ($currentUser instanceof UserInterface) {
            if ($currentUser->getAPIUser()->passwordHash !== $apiUser->passwordHash) {
                throw new BadCredentialsException('The credentials were changed in another session.');
            }

            $apiUser = $currentUser->getAPIUser();
        } else {
            $credentialsValid = $this->userService->checkUserCredentials($apiUser, $token->getCredentials());

            if (!$credentialsValid) {
                throw new BadCredentialsException('Invalid credentials', 0);
            }
        }

I don't think we have any documented use-cases for that part but still believe it should be approached differently if needed. Will discuss that internally but also summon @adamwojs to check if he remembers what it was all about.

Update:
We believe this is already covered by Symfony and was needed long time ago to make sure that user password change performed in another browser tab is effectively caught. Most likely we are fine due to usage of Symfony\Component\Security\Core\User\EquatableInterface which tends to be used to test if two objects are equal in security and re-authentication context.

For QA:

Documentation:

Dropping RememberMeRepositoryAuthenticationProvider should be mentioned.

@konradoboza konradoboza force-pushed the ibx-8323-unsupported-password-type branch from 0c1a674 to 80e3526 Compare June 28, 2024 17:18
@konradoboza konradoboza reopened this Jun 28, 2024
@konradoboza konradoboza force-pushed the ibx-8323-unsupported-password-type branch 5 times, most recently from af2f5fe to bfdf393 Compare July 2, 2024 10:16
@konradoboza konradoboza added Bug Something isn't working Feature New feature request Ready for review labels Jul 2, 2024
@konradoboza konradoboza marked this pull request as ready for review July 2, 2024 13:20
@konradoboza konradoboza requested review from a team and adamwojs July 2, 2024 13:21
@konradoboza konradoboza added the Doc needed The changes require some documentation label Jul 3, 2024
@alongosz alongosz requested a review from a team July 4, 2024 11:53
@konradoboza konradoboza requested review from a team and Steveb-p July 5, 2024 07:55
@konradoboza konradoboza force-pushed the ibx-8323-unsupported-password-type branch from bfdf393 to 85806bd Compare July 5, 2024 11:32
@konradoboza konradoboza force-pushed the ibx-8323-unsupported-password-type branch from bcaac47 to bf62516 Compare July 5, 2024 13:17
Copy link

sonarqubecloud bot commented Jul 5, 2024

@konradoboza konradoboza requested a review from Steveb-p July 5, 2024 13:18
@konradoboza
Copy link
Contributor Author

I also dropped lib/MVC/Symfony/Security/Authentication/RememberMeRepositoryAuthenticationProvider since it wasn't loaded in SecurityPass anyway.

@alongosz alongosz merged commit fe4c34a into main Jul 9, 2024
13 checks passed
@alongosz alongosz deleted the ibx-8323-unsupported-password-type branch July 9, 2024 09:37
barw4 pushed a commit that referenced this pull request Oct 17, 2024
…ic to a dedicated subscriber (#396)

For more details see https://issues.ibexa.co/browse/IBX-8323 and #396

Key changes:

* Reworked RepositoryAuthenticationProvider and moved its logic to a dedicated subscriber
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working Doc needed The changes require some documentation Feature New feature request QA approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants