Skip to content

Let LDAP users change their password with PUT /passwd - #115

Open
toolonghere wants to merge 1 commit into
grommunio:masterfrom
toolonghere:ldap-password-change
Open

toolonghere wants to merge 1 commit into
grommunio:masterfrom
toolonghere:ldap-password-change

Conversation

@toolonghere

Copy link
Copy Markdown
Contributor

Type: enhancement

This pull request contains the code for the design in #109. It closes #109.

  • What it does: LDAP imported users can change their password with PUT /passwd, for example from grommunio-web.
  • Default: off. Without the new parameters, PUT /passwd operates as before.
  • Also: an optional password policy for a new password that a user sets. It applies to local and LDAP users. The defaults do not set limits.

The change

  • options.ldapPasswordChange (default: false). When it is set to true, the API binds as the user with the current password. It changes the password on that connection.
    • OpenLDAP and other servers: the Password Modify extended operation (RFC 3062). The server makes the hash.
    • ActiveDirectory template: unicodePwd.
  • Read-only service account: the service account does not write. The access control and the password policy of the directory apply.
  • Conditions: the user must have the changePassword privilege and an active account. gromox uses the same 2 conditions for a password change (exch/mysql_adaptor/mysql_adaptor.cpp).
  • Directory not available: without sign-in, the response is the same 503 "Authentication service not available" as for the login (24b0ea3). The log gives the cause.
  • Encryption: the connection must be ldaps:// or STARTTLS with a verified certificate, for all servers in the list. If not, the API does not send a password, and the response is 503. If the connection stops, the API does not start it again.
  • options.passwordPolicy: minLength, minCharClasses, forbidUsername and blocklist (a file, 1 password on each line). It applies only to PUT /passwd, not to a password that an administrator sets.
  • Documentation: conf.d/README.md gives the options. It also gives a recommendation for OpenLDAP: limit password writes by the user to the hosts that operate the Admin API (by self peername.ip=<address> write).

Responses for an LDAP user

Condition Response
Incorrect or empty current password 401 (with user) or 403 (signed in), the same as for local users
No changePassword privilege, account not active, or the directory rejects the write (result 50) 403
Rejected by the policy, or by the directory (result 19 or 53) 400 with the cause
No encrypted and verified connection, or the blocklist cannot be read 503

grommunio/grommunio-web#200 (open) lets grommunio-web show the cause for 400 and 403.

Not in this change

  • authUser() does not change.
  • PUT /passwd for local users does not examine the changePassword privilege. I did not change this. I can send 1 more pull request if you want the same condition for local users.

Tests

  • 2 new test files with the same structure as tests/test_permissions*.py: tests/test_passwordpolicy.py (7 tests) and tests/test_ldap_password.py (13 tests). The LDAP tests use mock connections and do not use a server. Without ldap3, they are skipped.
  • 1 new test in tests/test_login.py: PUT /passwd with ldapPasswordChange and a directory that is not available gives the generic 503.
  • On a test system with admin-api 1.21.53 and OpenLDAP 2.6 with ppolicy, I sent PUT /passwd with user, as grommunio-web does:
Test Result
Incorrect current password / empty current password 401 / 401
User without changePassword / account not active 403 / 403
Too short / blocklist line in uppercase 400 / 400
Local user: too short / incorrect current password 400 / 401
Correct change 200. The new password binds. The password from before the change does not bind
Password equal to the user name: forbidUsername off / on 400 from the directory policy / 400 from the API
Blocklist cannot be read 503
ldapPasswordChange off 400 "Cannot modify LDAP imported user", as before

I did not do a test of the signed-in path for an LDAP user. My test system has no LDAP administrator.

I installed a previous version of this change on my server on 30 September. It uses OpenLDAP 2.6.

I prepared this change with an AI assistant (Claude). I examined the code and each changed line, and I did the tests on a test system. Antigravity (Google's AI assistant) did an inspection of it.

Before this change, PUT /passwd rejected all LDAP imported users.

Add options.ldapPasswordChange (default: false). When it is set to true, the
API binds as the user with the current password and changes the password
on that connection:
- the Password Modify extended operation (RFC 3062) for OpenLDAP and
  other servers
- unicodePwd for the ActiveDirectory template

The service account can have read-only access. The user must have the
changePassword privilege and an active account. If the connection is
not encrypted with a verified certificate, the API does not send a
password.

Add options.passwordPolicy for a new password that the user sets with
PUT /passwd, for local and LDAP users. The defaults do not set limits.

References: grommunio#109
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.

Let LDAP-linked users change their password from grommunio-web

1 participant