-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Security] add support for opportunistic password migrations #31843
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
Conversation
d79e915
to
547bc81
Compare
(failure will be fixed by merging up to master) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice addition :)
src/Symfony/Component/Security/Guard/AuthenticatorInterface.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Authentication/Provider/DaoAuthenticationProvider.php
Show resolved
Hide resolved
547bc81
to
7f6f36e
Compare
ping @symfony/deciders |
|
||
$repository = $this->getRepository(); | ||
if ($repository instanceof PasswordUpgraderInterface) { | ||
$repository->upgradePassword($user, $newEncodedPassword); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the idea would be that users would make their UserRepository implement this, right? Hmm, I guess there’s no generic way to do this... I mean, we could have them configure a “password” field and use that to make the query for them... though I don’t love more yaml config. And.. we can’t make a trait generic enough to do this. I guess best I can think of us add this to the repository automatically in make:user. It’s also a bit unfortunate that (unless you use the maker) you could silently “miss out” on this feature by not implementing this interface. Again, this is more unhelpful pondering than solution :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Persistency is always custom, there is no single method we can provide to do it.
Requiring setPassword()
on the entity wouldn't make it persist.
And yes, this must be opt-in, because not everyone will want/have the auth to write to the backend.
At this point, you need to review the maker-bundle PR:
symfony/maker-bundle#389
Description ----------- In Symfony 4.3, a new security encoder named `auto` was introduced. It will choose the best password hashing algorithm based on what Symfony and/or the PHP community decides. Currently this would mean as of PHP 7.2 if you did compile your PHP using libsodium, you'll have argon2 available. I wanted to make sure my setup benefits from the strongest algorithms available so I've implemented the `auto` configuration by default and it will fall back to the current `bcrypt` configuration in case you are not yet on Symfony 4.3. Of course `auto` may still take `bcrypt` in case your system does not support libsodium. While implementing I noticed that we still use the password hashing API directly instead of relying on the Symfony components. This means you can configure a different algorithm in the security configuration but it will never work 😄 So I fixed this by replacing all our direct password hashing API calls with the underlying Symfony security components. BTW: I had to remove the usage of `password_needs_rehash()` to completely rely on the Symfony encoder configured. This means right now you cannot automatically upgrade which is why currently the `SodiumPasswordEncoder` will also verify bcrypt passwords. Symfony will address this in 4.4 so we can (symfony/symfony#31843) completely rely on what Symfony is doing very soon. As of now, there are only `bcrypt` and `argon2` anyway and those will be handled properly. Commits ------- c2c9708 Make sure the password widgets use the configured security encoder and support argon2 and others 12883f1 Replaced direct usage of password_* methods f7872ee Fixed class usage 55aa55d Fixed UserPasswordCommand tests 62b6531 Fix the coding style
Description ----------- In Symfony 4.3, a new security encoder named `auto` was introduced. It will choose the best password hashing algorithm based on what Symfony and/or the PHP community decides. Currently this would mean as of PHP 7.2 if you did compile your PHP using libsodium, you'll have argon2 available. I wanted to make sure my setup benefits from the strongest algorithms available so I've implemented the `auto` configuration by default and it will fall back to the current `bcrypt` configuration in case you are not yet on Symfony 4.3. Of course `auto` may still take `bcrypt` in case your system does not support libsodium. While implementing I noticed that we still use the password hashing API directly instead of relying on the Symfony components. This means you can configure a different algorithm in the security configuration but it will never work 😄 So I fixed this by replacing all our direct password hashing API calls with the underlying Symfony security components. BTW: I had to remove the usage of `password_needs_rehash()` to completely rely on the Symfony encoder configured. This means right now you cannot automatically upgrade which is why currently the `SodiumPasswordEncoder` will also verify bcrypt passwords. Symfony will address this in 4.4 so we can (symfony/symfony#31843) completely rely on what Symfony is doing very soon. As of now, there are only `bcrypt` and `argon2` anyway and those will be handled properly. Commits ------- c2c97083 Make sure the password widgets use the configured security encoder and support argon2 and others 12883f1b Replaced direct usage of password_* methods f7872ee9 Fixed class usage 55aa55d9 Fixed UserPasswordCommand tests 62b6531e Fix the coding style
Description ----------- In Symfony 4.3, a new security encoder named `auto` was introduced. It will choose the best password hashing algorithm based on what Symfony and/or the PHP community decides. Currently this would mean as of PHP 7.2 if you did compile your PHP using libsodium, you'll have argon2 available. I wanted to make sure my setup benefits from the strongest algorithms available so I've implemented the `auto` configuration by default and it will fall back to the current `bcrypt` configuration in case you are not yet on Symfony 4.3. Of course `auto` may still take `bcrypt` in case your system does not support libsodium. While implementing I noticed that we still use the password hashing API directly instead of relying on the Symfony components. This means you can configure a different algorithm in the security configuration but it will never work 😄 So I fixed this by replacing all our direct password hashing API calls with the underlying Symfony security components. BTW: I had to remove the usage of `password_needs_rehash()` to completely rely on the Symfony encoder configured. This means right now you cannot automatically upgrade which is why currently the `SodiumPasswordEncoder` will also verify bcrypt passwords. Symfony will address this in 4.4 so we can (symfony/symfony#31843) completely rely on what Symfony is doing very soon. As of now, there are only `bcrypt` and `argon2` anyway and those will be handled properly. Commits ------- c2c97083 Make sure the password widgets use the configured security encoder and support argon2 and others 12883f1b Replaced direct usage of password_* methods f7872ee9 Fixed class usage 55aa55d9 Fixed UserPasswordCommand tests 62b6531e Fix the coding style
Anyone to approve this PR and finish the story? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
want it :)
7f6f36e
to
8bf14a4
Compare
src/Symfony/Component/Security/Guard/AuthenticatorInterface.php
Outdated
Show resolved
Hide resolved
This PR was merged into the 4.4 branch. Discussion ---------- [Ldap] Add security LdapUser and provider | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - Moves `LdapUserProvider` from `Security\Core` to the Ldap component, the provider now deals with a new `LdapUser` aware of its ldap `Entry` (should help in #31843). Commits ------- 6736cdf [Ldap] Add security LdapUser and provider
e319f54
to
067d4fb
Compare
067d4fb
to
5b60588
Compare
Comments addressed, PR ready. |
5b60588
to
2cfc5c7
Compare
Thank you @nicolas-grekas. |
…ations (nicolas-grekas) This PR was merged into the 4.4 branch. Discussion ---------- [Security] add support for opportunistic password migrations | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #31139 | License | MIT | Doc PR | - | Maker PR | symfony/maker-bundle#389 With this last piece, we'll provide opportunistic password migrations out of the box. This finishes the story drafted in #31153, see there for more info. Commits ------- 2cfc5c7 [Security] add support for opportunistic password migrations
With this last piece, we'll provide opportunistic password migrations out of the box.
This finishes the story drafted in #31153, see there for more info.