Skip to content

Finish password expiration#224

Merged
brosner merged 20 commits into
masterfrom
expiry-docs
Sep 19, 2016
Merged

Finish password expiration#224
brosner merged 20 commits into
masterfrom
expiry-docs

Conversation

@grahamu

@grahamu grahamu commented Sep 10, 2016

Copy link
Copy Markdown
Contributor

This pull request completes password expiration functionality.

  • Add management command for setting user-specific password expiry.
  • Add management command for setting user password history.
  • Add documentation for password expiration.
  • Add Django admin configuration for PasswordExpiry, PasswordHistory models.
  • Add "password expired" message using contrib.messages.
  • Add middleware which checks for expired password.
  • Comprehensive tests.

Add mgmt command for setting user-specific password expiry.
Add documentation for password expiry.
@coveralls

coveralls commented Sep 10, 2016

Copy link
Copy Markdown

Coverage Status

Coverage decreased (-0.5%) to 68.791% when pulling d4d0939 on expiry-docs into 1a5cab5 on master.

Revise model migration.
Add user_password_history command.
Add management command tests.
Improve password tests.
Add Django admin functionality for new PasswordExpiry
and PasswordHistory models.
@coveralls

coveralls commented Sep 13, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+1.05%) to 70.36% when pulling 23edd12 on expiry-docs into 1a5cab5 on master.

Use middleware to detect password expiration and redirect to
password change page if expired.
Added to CHANGELOG.md.
Removed outdated docs/changelog.rst.
Added documentation for password middleware.
@coveralls

coveralls commented Sep 13, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.2%) to 72.532% when pulling c9c73d8 on expiry-docs into 1a5cab5 on master.

@coveralls

coveralls commented Sep 13, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.4%) to 72.727% when pulling ac43310 on expiry-docs into 1a5cab5 on master.

@coveralls

coveralls commented Sep 13, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.2%) to 72.532% when pulling 527b9cc on expiry-docs into 1a5cab5 on master.

@coveralls

coveralls commented Sep 13, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.2%) to 72.532% when pulling 527b9cc on expiry-docs into 1a5cab5 on master.

@coveralls

coveralls commented Sep 13, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.2%) to 72.532% when pulling 527b9cc on expiry-docs into 1a5cab5 on master.

Add "Password is expired" message.
Add `password_expired` signal.
Update signals documentation.
Improve verbose plural model name.
@coveralls

coveralls commented Sep 13, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.3%) to 72.611% when pulling f69f798 on expiry-docs into 1a5cab5 on master.

@coveralls

coveralls commented Sep 13, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.4%) to 72.708% when pulling 06c4309 on expiry-docs into 1a5cab5 on master.

@coveralls

coveralls commented Sep 13, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.2%) to 72.553% when pulling 2954278 on expiry-docs into 1a5cab5 on master.

If middleware detects expired password, add "?next="
to redirect URL with expected page.
Improve creation of redirect URL with "next" value.
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.5%) to 72.766% when pulling 40d419d on expiry-docs into 1a5cab5 on master.

3 similar comments
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.5%) to 72.766% when pulling 40d419d on expiry-docs into 1a5cab5 on master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.5%) to 72.766% when pulling 40d419d on expiry-docs into 1a5cab5 on master.

@coveralls

coveralls commented Sep 13, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.5%) to 72.766% when pulling 40d419d on expiry-docs into 1a5cab5 on master.

@grahamu grahamu changed the title WIP Expand password expiration tests, fix logic, add docs Finish password expiration Sep 13, 2016
@grahamu

grahamu commented Sep 13, 2016

Copy link
Copy Markdown
Contributor Author

@brosner this is complete and ready for final thorough review, thanks!

@coveralls

coveralls commented Sep 13, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.5%) to 72.766% when pulling 83c9efc on expiry-docs into 1a5cab5 on master.

@grahamu

grahamu commented Sep 14, 2016

Copy link
Copy Markdown
Contributor Author

Hmm, seems like we need management command documentation.

@coveralls

coveralls commented Sep 14, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.5%) to 72.766% when pulling b557fd7 on expiry-docs into 1a5cab5 on master.

3 similar comments
@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.5%) to 72.766% when pulling b557fd7 on expiry-docs into 1a5cab5 on master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.5%) to 72.766% when pulling b557fd7 on expiry-docs into 1a5cab5 on master.

@coveralls

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.5%) to 72.766% when pulling b557fd7 on expiry-docs into 1a5cab5 on master.

@grahamu

grahamu commented Sep 14, 2016

Copy link
Copy Markdown
Contributor Author

@brosner besides code review you can test this for real by cloning the latest cloudspotting "dua-password-expiry" branch, pinax/cloudspotting#14, currently found at:

pinax/cloudspotting@c7e4e53

Install and run cloudspotting as per docs (specifying latest hash of that branch), create a couple users, play around with management commands user_password_history and user_password_expiry, change ACCOUNT_PASSWORD_EXPIRY in settings.py to 60 (one minute), etc. Try to bust the system. Thanks.

@coveralls

coveralls commented Sep 15, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.5%) to 72.766% when pulling 1f44952 on expiry-docs into 1a5cab5 on master.

@coveralls

coveralls commented Sep 15, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.5%) to 72.766% when pulling 55ae160 on expiry-docs into 1a5cab5 on master.

@coveralls

coveralls commented Sep 15, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.5%) to 72.766% when pulling 1e0d672 on expiry-docs into 1a5cab5 on master.

@grahamu grahamu left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

These areas would appreciate thoughtful consideration, thanks.

user.password_expiry.expiry = expire
user.password_expiry.save()

return "User \"{}\" password expiration set to {} seconds".format(username, expire)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This handle_label method works fine for one or a handful of users, but doesn't scale nicely for a large userbase or for all users in a system. Should we improve this mechanism or leave be until someone complains?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'm not sure of the particulars of the use case driving these changes, but I think it'd be useful to set an expiration for all users if

  • adding the middleware to an existing project using DUA and wanting to set a "baseline" expiration for all existing users
  • enforcing a reset for all users in response to some kind of security breach

I don't have a strong opinion on that functionality being required from the get-go, and perhaps a new issue to track that functionality is useful and it can be added later when required.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jwegner your first point is handled by the global setting ACCOUNT_PASSWORD_EXPIRY, which is used by default if password expiration is enabled and the user does not have their own PasswordExpiry instance. Good thought on the second case, but I'd prefer to track the idea separately.

Comment thread account/middleware.py Outdated
messages.WARNING,
_("Your password has expired. Please save a new password.")
)
redirect_field_name = "next" # fragile!

@grahamu grahamu Sep 15, 2016

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This redirect field name reference ("next") is quite fragile because if the project uses a different string this will break. Note that the redirect field name in classes protected by LoginRequiredMixin and methods protected by login_required default to "next" but can be overridden by class attribute or by invocation parameter. However this code is middleware with no way to set/reset the redirect field name.

To resolve this fragility I suggest using an account global, something like ACCOUNT_REDIRECT_FIELD_NAME.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I agree with removing fragility and standardizing that field name.

We might consider relying on / aliasing from django.contrib.auth.REDIRECT_FIELD_NAME, but still allowing the the overrides on the existing classes/methods above.

So REDIRECT_FIELD_NAME is the default unless overridden.

('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('password', models.CharField(max_length=255)),
('timestamp', models.DateTimeField(auto_now=True)),
('timestamp', models.DateTimeField(default=django.utils.timezone.now)),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

auto_now=True does not work for timestamp field because we need to set the timestamp explicitly when creating PasswordHistory via management command.

Comment thread docs/changelog.rst
---

* initial release
* if migrating from Pinax; see :ref:`migration`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This file appeared to be an orphan, superseded by /CHANGELOG.md.

@coveralls

coveralls commented Sep 15, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.5%) to 72.766% when pulling d16099b on expiry-docs into 1a5cab5 on master.

Allow customization, but use REDIRECT_FIELD_NAME as default.
@grahamu

grahamu commented Sep 19, 2016

Copy link
Copy Markdown
Contributor Author

@jacobwegner how does this look with regard to next page redirect?

@coveralls

coveralls commented Sep 19, 2016

Copy link
Copy Markdown

Coverage Status

Coverage increased (+3.4%) to 72.753% when pulling 32b7623 on expiry-docs into 1a5cab5 on master.

@brosner brosner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am happy with the direction here. This will be an excellent addition to DUA 2.0.

@brosner brosner merged commit c4a40be into master Sep 19, 2016
@brosner brosner deleted the expiry-docs branch September 19, 2016 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants