Bug 2321307 - ldapsearch with otp broken
Summary: ldapsearch with otp broken
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Fedora
Classification: Fedora
Component: freeipa
Version: rawhide
Hardware: All
OS: Linux
unspecified
high
Target Milestone: ---
Assignee: IPA Maintainers
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2024-10-23 15:32 UTC by wp
Modified: 2024-12-11 02:45 UTC (History)
8 users (show)

Fixed In Version: freeipa-4.12.2-7.fc42 freeipa-4.12.2-2.fc40 freeipa-4.12.2-6.fc41
Clone Of:
Environment:
Last Closed: 2024-12-04 21:54:22 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)
directory server debug output (89.62 KB, text/plain)
2024-10-24 07:49 UTC, wp
no flags Details
pwduser directory server debug output (58.10 KB, text/plain)
2024-10-29 07:39 UTC, wp
no flags Details


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker FREEIPA-11670 0 None None None 2024-10-23 15:33:21 UTC

Description wp 2024-10-23 15:32:58 UTC
Description of problem:
ldap searches are broken when running ipa version 4.12 and users configured to use OTP tokens.

Version-Release number of selected component (if applicable):
4.12.2-1

How reproducible:
easy reproducible running different versions


Steps to Reproduce:
1. install ipa-server version 4.10, create user, add token, enable password+otp for this user -> ldapsearch using authenticated bind works using password+token as password 
2. upgrade to ipa-server version 4.12, run ldapsearch using authenticated bind, you can login to ldap server without token (just enter password)


Actual results:
when upgraded (or newly installed) ipa version 4.12 you can bypass OTP authentication using ldapsearch and password authentication even if OTP is activated for this user.

Expected results:
keep behavior as it's currently on 4.10: if authentication type password+OTP is activated for user -> enforce authentication using pwd+OTP

Additional info:

Comment 1 Alexander Bokovoy 2024-10-23 16:59:11 UTC
'Enable password+otp for this user' -- does it mean you have enabled *both* 'password' and 'otp' authentication types? If you have enabled both password and otp methods, then LDAP will be accepting password-only as well.

The change in FreeIPA 4.12 is documented in RHEL 9.4.z release notes:
https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/9/html-single/9.4_release_notes/index#new-features-identity-management

---------
Enforcing OTP usage for all LDAP clients

With the release of the RHBA-2024:2558 advisory, in RHEL IdM, you can now set the default behavior for LDAP server authentication of user accounts with two-factor (OTP) authentication configured. If OTP is enforced, LDAP clients cannot authenticate against an LDAP server using single factor authentication (a password) for users that have associated OTP tokens. This method is already enforced through the Kerberos backend by using a special LDAP control with OID 2.16.840.1.113730.3.8.10.7 without any data.

    To enforce OTP usage for all LDAP clients, administrators can use the following command:

    $ ipa config-mod --addattr ipaconfigstring=EnforceLDAPOTP

    To change back to the previous OTP behavior for all LDAP clients, use the following command:

    $ ipa config-mod --delattr ipaconfigstring=EnforceLDAPOTP
---------

Can you check if adding EnforceLDAPTOP configuration is doing what you need?

Comment 2 wp 2024-10-23 18:32:14 UTC
The behavior changes when using EnforceLDAPOTP:
If user is configured to use pwd+OTP: login works as expected
If user is configured to use only pwd: login fails

But this does not solve the issue as not all users are configured to use pwd+OTP (like application users).

Comment 3 wp 2024-10-23 18:48:27 UTC
Sorry for misleading information: 
Enable password+otp for this user' -> means checkbox at user level is set only to menu item "two factor authentication (password+token)"

Comment 4 Alexander Bokovoy 2024-10-24 06:16:37 UTC
Ok, so I'd need some logs to debug for the non-enforced use case. Suppose you don't use EnforceLDAPOTP, in order to allow non-OTP users to bind to LDAP.

Can you please provide:

 - output of 'ipa user-show non-enforced-user'
 - directory server logs when LDAP bind is done with non-enforced-user

Ideally, for the directory server, if you could activate plugin debugging -- see https://www.port389.org/docs/389ds/FAQ/faq#troubleshooting, then we'd see internal searches IPA plugins do during the bind.

Comment 5 wp 2024-10-24 07:49:20 UTC
Created attachment 2053404 [details]
directory server debug output

Comment 6 wp 2024-10-24 07:50:13 UTC
output of ipa user-show:
# ipa user-show otpuser
  User login: otpuser
  First name: otp
  Last name: user
  Home directory: /home/otpuser
  Login shell: /bin/sh
  Principal name: otpuser
  Principal alias: otpuser
  Email address: otpuser
  UID: 736400003
  GID: 736400003
  User authentication types: otp
  Account disabled: False
  Password: True
  Member of groups: ipausers
  Kerberos keys available: True

Comment 7 wp 2024-10-25 07:14:07 UTC
just verified on latest available version on Fedora (freeipa-server-4.12.2-5) that the error also exists on this version

Comment 8 Alexander Bokovoy 2024-10-28 09:16:37 UTC
I am a bit confused. You have provided the debugging output for authentication of the user that actually has OTP token and does not have password-authentication allowed. 

Can you please provide the same for the user who has password authentication allowed (and do this in the mode where EnforceLDAPOTP is not enabled)?

Comment 9 Alexander Bokovoy 2024-10-28 09:44:36 UTC
What I see from the debug log:

1. An attempt to authenticate as otp user starts:
    if (!syncreq && !ipapwd_pre_bind_otp(dn, entry,
                                         credentials, otpreq, &notokens)) {
        /* We got here because ipapwd_pre_bind_otp() returned false,
         * it means that either token verification failed or
         * a rule for empty tokens failed current policy. */
        if (!(notokens || (otpreq == OTP_IS_NOT_REQUIRED)))
            goto invalid_creds;
    }

2. In ipapwd_pre_bind_otp() we get into token verification because we see this debug message:
Oct 24 09:42:51 idmtest.domain.lcl ns-slapd[14797]: [24/Oct/2024:09:42:51.879140460 +0200] - DEBUG - ipa-pwd-extop - Attempting OTP authentication for 'uid=otpuser,cn=users,cn=accounts,dc=domain,dc=lcl'.

3. ipa-pwd-extop plugin searches for OTP tokens for this user and finds one:
Oct 24 09:42:52 idmtest.domain.lcl ns-slapd[14797]: [24/Oct/2024:09:42:52.306549078 +0200] - DEBUG - ldbm_back_next_search_entry - filter test value 0 ipatokenuniqueid=e0187bde-e6c9-4fd6-b56c-e67431475535,cn=otp,dc=domain,dc=lcl

4. At this point we are go to validate the token by the call to otp_token_validate_berval(). If token verification succeeded, we return true. We'll keep notokens set to 'false'.

5. As ipapwd_pre_bind_otp() returned true, we go to authenticate the password by calling ipapwd_authenticate()

6. In the logs we see this debug message from ipapwd_write_krb_keys():
Oct 24 09:42:52 idmtest.domain.lcl ns-slapd[14797]: [24/Oct/2024:09:42:52.463071722 +0200] - DEBUG - ipa-pwd-extop - kerberos key already present in user entry: uid=otpuser,cn=users,cn=accounts,dc=domain,dc=lcl

this means a call to ipapwd_authenticate() was successful, so we get to next step which detects that Kerberos key is already in the entry and we don't need to perform a migration process. It is not important here, we'd just exist ipapwd_write_krb_keys().

So we definitely authenticated both OTP value and the password in this debug trace.

Comment 10 Alexander Bokovoy 2024-10-28 09:59:17 UTC
otp_token_validate_berval() looks into each allowed token definition and uses last X characters of the password credential passed as X digits of the code to try. If it cannot get those digits converted into the code to try, we'll return 'false'.

In case only password is passed and no token value, the conversion of last X characters as digits will fail. Of course, there is a possibility that a password ends with X characters that are actually digits and then are the same as a next token values expected by this token, but that already is a stretch given this bug report.

Since we passed through the validation, it was successful.

Comment 11 wp 2024-10-29 07:39:04 UTC
Created attachment 2054205 [details]
pwduser directory server debug output

I created new user "pwduser" and did ldapsearch using it's credentials.

# ipa user-show pwduser
  User login: pwduser
  First name: pwd
  Last name: user
  Home directory: /home/pwduser
  Login shell: /bin/sh
  Principal name: pwduser
  Principal alias: pwduser
  Email address: pwduser
  UID: 736400004
  GID: 736400004
  Account disabled: False
  Password: True
  Member of groups: ipausers
  Kerberos keys available: True

Please find log attached.

Comment 12 Alexander Bokovoy 2024-10-29 08:57:59 UTC
Thanks. I reproduced the issue.

Comment 13 wp 2024-11-15 10:24:16 UTC
Did you identify the issue?

Comment 14 Alexander Bokovoy 2024-11-15 11:47:47 UTC
Sadly, not yet.

Comment 15 Alexander Bokovoy 2024-12-03 20:17:05 UTC
I submitted https://github.com/freeipa/freeipa/pull/7618 upstream.

Comment 16 Fedora Update System 2024-12-04 20:41:51 UTC
FEDORA-2024-860c80c29c (freeipa-4.12.2-7.fc42) has been submitted as an update to Fedora 42.
https://bodhi.fedoraproject.org/updates/FEDORA-2024-860c80c29c

Comment 17 Fedora Update System 2024-12-04 21:54:22 UTC
FEDORA-2024-860c80c29c (freeipa-4.12.2-7.fc42) has been pushed to the Fedora 42 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 18 Fedora Update System 2024-12-09 08:07:07 UTC
FEDORA-2024-f033eb5f2b (freeipa-4.12.2-6.fc41) has been submitted as an update to Fedora 41.
https://bodhi.fedoraproject.org/updates/FEDORA-2024-f033eb5f2b

Comment 19 Fedora Update System 2024-12-09 08:37:44 UTC
FEDORA-2024-aaa7dc08df (freeipa-4.12.2-2.fc40) has been submitted as an update to Fedora 40.
https://bodhi.fedoraproject.org/updates/FEDORA-2024-aaa7dc08df

Comment 20 Fedora Update System 2024-12-10 02:02:51 UTC
FEDORA-2024-f033eb5f2b has been pushed to the Fedora 41 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2024-f033eb5f2b`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2024-f033eb5f2b

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 21 Fedora Update System 2024-12-10 05:15:28 UTC
FEDORA-2024-aaa7dc08df has been pushed to the Fedora 40 testing repository.
Soon you'll be able to install the update with the following command:
`sudo dnf upgrade --enablerepo=updates-testing --refresh --advisory=FEDORA-2024-aaa7dc08df`
You can provide feedback for this update here: https://bodhi.fedoraproject.org/updates/FEDORA-2024-aaa7dc08df

See also https://fedoraproject.org/wiki/QA:Updates_Testing for more information on how to test updates.

Comment 22 Fedora Update System 2024-12-11 02:25:18 UTC
FEDORA-2024-aaa7dc08df (freeipa-4.12.2-2.fc40) has been pushed to the Fedora 40 stable repository.
If problem still persists, please make note of it in this bug report.

Comment 23 Fedora Update System 2024-12-11 02:45:06 UTC
FEDORA-2024-f033eb5f2b (freeipa-4.12.2-6.fc41) has been pushed to the Fedora 41 stable repository.
If problem still persists, please make note of it in this bug report.


Note You need to log in before you can comment on or make changes to this bug.