Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 1 commit into from
Aug 5, 2019

Conversation

nicolas-grekas
Copy link
Member

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.

@nicolas-grekas
Copy link
Member Author

(failure will be fixed by merging up to master)

Copy link
Contributor

@noniagriconomie noniagriconomie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice addition :)

@nicolas-grekas
Copy link
Member Author

ping @symfony/deciders


$repository = $this->getRepository();
if ($repository instanceof PasswordUpgraderInterface) {
$repository->upgradePassword($user, $newEncodedPassword);
Copy link
Member

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

Copy link
Member Author

@nicolas-grekas nicolas-grekas Jun 25, 2019

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

leofeyer pushed a commit to contao/contao that referenced this pull request Jun 27, 2019
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
leofeyer pushed a commit to contao/manager-bundle that referenced this pull request Jun 27, 2019
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
leofeyer pushed a commit to contao/core-bundle that referenced this pull request Jun 27, 2019
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
@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Jul 11, 2019

Anyone to approve this PR and finish the story?

Copy link
Contributor

@ro0NL ro0NL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

want it :)

@nicolas-grekas nicolas-grekas changed the title [Security] add PasswordUpgraderInterface for opportunistic password migrations [Security] add support for opportunistic password migrations Jul 30, 2019
fabpot added a commit that referenced this pull request Aug 5, 2019
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
@nicolas-grekas nicolas-grekas force-pushed the sec-pwd-upgrader branch 2 times, most recently from e319f54 to 067d4fb Compare August 5, 2019 08:18
@nicolas-grekas
Copy link
Member Author

Comments addressed, PR ready.
I updated symfony/maker-bundle#389 too.

@chalasr
Copy link
Member

chalasr commented Aug 5, 2019

Thank you @nicolas-grekas.

@chalasr chalasr merged commit 2cfc5c7 into symfony:4.4 Aug 5, 2019
chalasr pushed a commit that referenced this pull request Aug 5, 2019
…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
@nicolas-grekas nicolas-grekas deleted the sec-pwd-upgrader branch August 6, 2019 16:00
@nicolas-grekas nicolas-grekas modified the milestones: next, 4.4 Oct 27, 2019
This was referenced Nov 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants