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

[16.0][MIG/IMP] password_security #482

Merged
merged 65 commits into from
Oct 10, 2023

Conversation

astirpe
Copy link
Member

@astirpe astirpe commented Feb 20, 2023

Together with the module migration, I'm proposing a revised version of the module:

@astirpe astirpe force-pushed the 16_mig_password_security branch 3 times, most recently from da0bc38 to 567ba27 Compare February 20, 2023 12:31
@astirpe astirpe marked this pull request as ready for review February 20, 2023 12:34
@astirpe astirpe mentioned this pull request Feb 20, 2023
22 tasks
@amh-mw
Copy link

amh-mw commented Mar 2, 2023

@astirpe Nice job; tremendous amount of work. It feels like it should be six pull requests. If you would be willing to break it up, I'd be willing to review all the parts. I think it's a bit dangerous to do it all in one go, especially with the unit tests being rewritten. How would you feel about fixing each of the items you marked for back-porting in 15.0 as separate pull requests and getting those merged first, so that your migration commit isn't quite so expansive?

@astirpe
Copy link
Member Author

astirpe commented Mar 3, 2023

@amh-mw, yes that's a good idea!

I backported two of the fixes: #491 (constraint of password_estimate range) and #492 (Reset Password issue)

The fix for #89 is the one already discussed in #448 and that's still an open PR.

The fix for #141 is just a consequence of the complete rewrite of the mocked tests.

For the rest, I don't think the other points should be backported to V15.
Once the above PRs for V15 will be merged, I will include the related commits in this PR. Is that ok for you?

@astirpe astirpe force-pushed the 16_mig_password_security branch from fc7b216 to 1d6eb79 Compare March 3, 2023 11:48
@amh-mw
Copy link

amh-mw commented Mar 3, 2023

Once the above PRs for V15 will be merged, I will include the related commits in this PR. Is that ok for you?

I think it would make more sense to rebase against 15.0 afterwards, so that you just have the one migration commit.

@astirpe astirpe force-pushed the 16_mig_password_security branch 3 times, most recently from 9155e59 to 6eab9a5 Compare March 8, 2023 08:29
Copy link

@amh-mw amh-mw left a comment

Choose a reason for hiding this comment

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

Just poking around a bit while waiting for the maintainers to merge the 15.0 pull requests. I'll give it a more thorough review after.

"Characters",
default=12,
help="Minimum number of characters",
)
Copy link

Choose a reason for hiding this comment

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

Do you need to provide a migration for this field? Maybe something like:

ICP = self.env['ir.config_parameter']
ICP.set_param('auth_password_policy.minlength', max(
    ICP.get_param('auth_password_policy.minlength'),
    *self.env['res.company'].search([]).mapped('password_length'))
))

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, seems a good idea 👍 Thanks!

Copy link
Member Author

@astirpe astirpe Mar 10, 2023

Choose a reason for hiding this comment

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

Implemented. Migration tests could be executed locally by adding password_length = fields.Integer(default=12) to res.company

password_security/controllers/main.py Outdated Show resolved Hide resolved
@@ -14,10 +14,10 @@
<field name="arch" type="xml">
<!-- We hide Odoo's minlength sections so it does not create confusion -->
<xpath expr="//label[@for='minlength']/../.." position="attributes">
<attribute name="style">display: none</attribute>
<attribute name="invisible">1</attribute>
Copy link

Choose a reason for hiding this comment

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

Seems weird to continue to hide minlength now that it has been adopted over password_length.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's just because I wanted to embed the minlength inside the group of fields "Password Policy"

<div class="mt16">
<span>
Minimum number of characters
<field name="minlength" class="oe_inline" />
</span>

This way it looks&feels better, otherwise the minlength will stay detached from the rest of the fields.

Copy link
Contributor

Choose a reason for hiding this comment

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

How about instead of removing the entire box that contains the label, we reuse it? There might have been some customization within the settings box that gets removed otherwise.

Something like this?

<!-- Remove label for uniform styling -->
<xpath expr="//label[@for='minlength']" position="replace"/>


<!-- Add an id for easier lookup -->
<xpath expr="//field[@name='minlength']/ancestor::div[hasclass('o_setting_box')]" position="attributes">
    <attribute name="id">password_policy</attribute>
</xpath>

<!-- Move the settings box to desired location -->
<xpath expr="//div[@id='enable_password_reset']" position="after">
    <xpath expr="//div[@id='password_policy']" position="move"/>
</xpath>


<!-- Ensure our settings will come before any former customization -->
<xpath expr="//div[@id='password_policy']//div[hasclass('o_setting_right_pane')]/*" position="before">
    <!-- Add all the settings here -->
    <span id="minlength">
         Minimum number of characters
    </span>
</xpath>


<!-- Add oe_inline attribute to minlength -->
<xpath expr="//field[@name='minlength']" position="attributes">
  <attribute name="class">oe_inline</attribute>
</xpath>

<!-- Move the minlength field to desired location -->
<xpath expr="//span[@id='minlength']" position="inside">
    <xpath expr="//field[@name='minlength']" position="move"/>
</xpath>

It might seem like a lot of work, but I personally feel like we should try to minimize making nodes disappear

Copy link
Member Author

@astirpe astirpe Jul 25, 2023

Choose a reason for hiding this comment

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

Yes thanks! Done in b72dde1, would you check?

Copy link
Contributor

Choose a reason for hiding this comment

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

Looks mostly good to me! There's the comment that still says

I don't know if you wanted the password_security settings to come before or after the previous nodes.

@astirpe astirpe force-pushed the 16_mig_password_security branch 2 times, most recently from 4e7f7cf to b6ed288 Compare March 10, 2023 09:59
@astirpe
Copy link
Member Author

astirpe commented Mar 10, 2023

No idea why OCB test now fails. Maybe a temporary glitch?

@Abranes
Copy link
Member

Abranes commented Apr 12, 2023

@astirpe Could you rebase from 16.0 to resolve the conflicts?

@astirpe astirpe force-pushed the 16_mig_password_security branch from fe8f04b to 1f3bb89 Compare April 12, 2023 09:23
@astirpe
Copy link
Member Author

astirpe commented Apr 12, 2023

Still test in OCB failing, I cannot even reproduce the failure with OCB locally.

lasley and others added 8 commits April 18, 2023 13:06
* [ADD] res_users_password_security: New module
* Create new module to lock down user passwords

* [REF] res_users_password_security: PR Review fixes
* Also add beta pass history rule

* [ADD] res_users_password_security: Pass history and min time
* Add pass history memory and threshold
* Add minimum time for pass resets through web reset

* Begin controller tests

* Fix copyright, wrong year for new file

* Add tests for password_security_home
* Left to do web_auth_reset_password

* Fix minimum reset threshold and finish tests

* Bug fixes per review

* [REF] password_security: PR review improvements
* Change tech name to password_security
* Use new except format
* Limit 1 & new api
* Cascade deletion for pass history

* [REF] password_security: Fix travis + style
* Fix travis errors
* self to cls
* Better variable names in tests

* [FIX] password_security: Fix travis errors
* Bump versions
* Installable to True
* Add Usage section to ReadMe w/ Runbot link
* `_crypt_context` now directly exposes the `CryptContext`
* Change all instances of openerp to odoo
* Add current time as password_write_date for admin user in demo, disabling the reset prompt - fixes OCA#652
* Switch security to be on correct model to fix OCA#674
…ord invalid (#859)

* [FIX] password_security: Fix password stored

* [REF] password_security: use a unified check_password private method to validate rules and history password
@astirpe astirpe force-pushed the 16_mig_password_security branch 2 times, most recently from 00def53 to bd08c50 Compare July 26, 2023 11:11
@astirpe astirpe force-pushed the 16_mig_password_security branch 2 times, most recently from 58adcf5 to a00ab39 Compare July 26, 2023 11:26
@cmarrero
Copy link

After upgrade and enter Settings gives the following error with the refactor:

RPC_ERROR
Odoo Server Error
Traceback (most recent call last):
File "/Users/cmarrero/PycharmProjects/odoo/odoo/http.py", line 1584, in _serve_db
return service_model.retrying(self._serve_ir_http, self.env)
File "/Users/cmarrero/PycharmProjects/odoo/odoo/service/model.py", line 133, in retrying
result = func()
File "/Users/cmarrero/PycharmProjects/odoo/odoo/http.py", line 1611, in _serve_ir_http
response = self.dispatcher.dispatch(rule.endpoint, args)
File "/Users/cmarrero/PycharmProjects/odoo/odoo/http.py", line 1815, in dispatch
result = self.request.registry['ir.http']._dispatch(endpoint)
File "/Users/cmarrero/PycharmProjects/odoo/addons/website/models/ir_http.py", line 235, in _dispatch
response = super()._dispatch(endpoint)
File "/Users/cmarrero/PycharmProjects/odoo/odoo/addons/base/models/ir_http.py", line 154, in _dispatch
result = endpoint(**request.params)
File "/Users/cmarrero/PycharmProjects/odoo/odoo/http.py", line 697, in route_wrapper
result = endpoint(self, *args, **params_ok)
File "/Users/cmarrero/PycharmProjects/odoo/addons/web/controllers/dataset.py", line 42, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/Users/cmarrero/PycharmProjects/odoo/addons/web/controllers/dataset.py", line 33, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/Users/cmarrero/PycharmProjects/odoo/odoo/api.py", line 457, in call_kw
result = _call_kw_model(method, model, args, kwargs)
File "/Users/cmarrero/PycharmProjects/odoo/odoo/api.py", line 430, in _call_kw_model
result = method(recs, *args, **kwargs)
File "/Users/cmarrero/PycharmProjects/odoo/odoo/addons/base/models/ir_ui_view.py", line 2491, in get_views
result['views'] = {
File "/Users/cmarrero/PycharmProjects/odoo/odoo/addons/base/models/ir_ui_view.py", line 2492, in
v_type: self.get_view(
File "/Users/cmarrero/PycharmProjects/odoo/odoo/addons/base/models/ir_ui_view.py", line 2676, in get_view
result = dict(self._get_view_cache(view_id, view_type, **options))
File "", line 2, in _get_view_cache
File "/Users/cmarrero/PycharmProjects/odoo/odoo/tools/cache.py", line 90, in lookup
value = d[key] = self.method(*args, **kwargs)
File "/Users/cmarrero/PycharmProjects/odoo/odoo/addons/base/models/ir_ui_view.py", line 2636, in _get_view_cache
arch, view = self._get_view(view_id, view_type, **options)
File "/Users/cmarrero/PycharmProjects/odoo/addons/web/models/models.py", line 245, in _get_view
arch, view = super()._get_view(view_id, view_type, **options)
File "/Users/cmarrero/PycharmProjects/odoo/odoo/addons/base/models/ir_ui_view.py", line 2583, in _get_view
arch = view._get_combined_arch()
File "/Users/cmarrero/PycharmProjects/odoo/odoo/addons/base/models/ir_ui_view.py", line 999, in _get_combined_arch
arch = root.with_prefetch(tree_views._prefetch_ids)._combine(hierarchy)
File "/Users/cmarrero/PycharmProjects/odoo/odoo/addons/base/models/ir_ui_view.py", line 940, in _combine
combined_arch = view.apply_inheritance_specs(combined_arch, arch)
File "/Users/cmarrero/PycharmProjects/odoo/odoo/addons/base/models/ir_ui_view.py", line 877, in apply_inheritance_specs
self._raise_view_error(str(e), specs_tree)
File "/Users/cmarrero/PycharmProjects/odoo/odoo/addons/base/models/ir_ui_view.py", line 754, in _raise_view_error
raise err from from_exception
ValueError: Element '' cannot be located in parent view

The above server error caused the following client error:
RPC_ERROR: Odoo Server Error
at makeErrorFromResponse (http://localhost:8069/web/assets/10737-0b43f28/web.assets_backend.min.js:985:163)
at XMLHttpRequest. (http://localhost:8069/web/assets/10737-0b43f28/web.assets_backend.min.js:993:13)

@astirpe
Copy link
Member Author

astirpe commented Jul 27, 2023

@cmarrero if you are getting the error in a production server I would suggest you to restore the old code (before the config settings refactoring).

Instead if you are on a test server you can try this:

  • Login as admin with enabled developer mode
  • Go to Settings > Technical > User interface > Views
  • Search view named "res.config.settings.form.password_security" and delete it
  • Go to Apps
  • Search module Password Security and click on Upgrade button
  • Verify that the view named "res.config.settings.form.password_security" is re-created
  • Check whether the error does not occur again

@astirpe
Copy link
Member Author

astirpe commented Jul 27, 2023

I just found out that when a new user is trying to signup by entering a very large password, there is a critical performance issue.
It's caused by the adoption of zxcvbn library, in particular the execution of this line https://github.com/dwolfhub/zxcvbn-python/blob/master/zxcvbn/__init__.py#L25 is very slow. That could potentially cause a DDOS attack in my opinion.

Probably that's also the reason of #487 but I didn't investigate in deep that issue.

So I'm going to remove the password estimate check functionality from this module and also remove the dependency on zxcvbn, because the password estimation is already provided by "Password Meter" widget by standard Odoo.

I hope is ok with you all.

@hwangh95
Copy link
Contributor

hwangh95 commented Aug 2, 2023

Are there any updates on this PR? Or is it good to go?

@astirpe
Copy link
Member Author

astirpe commented Aug 2, 2023

Would be good for me if this PR gets merged soon

Copy link
Contributor

@hwangh95 hwangh95 left a comment

Choose a reason for hiding this comment

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

Small UI change

password_security/views/res_config_settings_views.xml Outdated Show resolved Hide resolved
@zuher83
Copy link

zuher83 commented Aug 15, 2023

Ready to migrate ?

@antonag32
Copy link

Hello, is there anything left to do before merging? I could help with any tasks left.

@thomaspaulb
Copy link
Contributor

/ocabot migration password_security

/ocabot merge nobump

@OCA-git-bot
Copy link
Contributor

What a great day to merge this nice PR. Let's do it!
Prepared branch 16.0-ocabot-merge-pr-482-by-thomaspaulb-bump-nobump, awaiting test results.

@OCA-git-bot OCA-git-bot merged commit 8d18d8f into OCA:16.0 Oct 10, 2023
@OCA-git-bot
Copy link
Contributor

Congratulations, your PR was merged at 283776a. Thanks a lot for contributing to OCA. ❤️

amh-mw added a commit to amh-mw/server-auth that referenced this pull request Sep 4, 2024
This reverts commit c8d5d68 which
should not have been removed as part of the migration.
OCA#482
amh-mw added a commit to amh-mw/server-auth that referenced this pull request Sep 4, 2024
This reverts commit c8d5d68 which
should not have been removed as part of the migration to 15.0.
OCA#482
amh-mw added a commit to amh-mw/server-auth that referenced this pull request Sep 4, 2024
This reverts commit c8d5d68 which
should not have removed password_estimate as part of the migration
to 16.0.

OCA#482
SiesslPhillip pushed a commit to grueneerde/OCA-server-auth that referenced this pull request Nov 20, 2024
Syncing from upstream OCA/server-auth (16.0)
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.