Password expiration enforcement for passwordless authentication#

Overview#

MIT krb5 checks pw_expiration in validate_as_request() before pre-authentication runs. At that point the KDC does not know which authentication method will be used. For users who have both password-based and passwordless methods configured (e.g. password + PKINIT), the KDC would reject the AS-REQ before the passwordless method even gets a chance to run.

FreeIPA solves this by deferring the password expiration check for passwordless-capable users to the kdcpolicy plugin, which runs after pre-authentication, when the actual method used is known.

Use Cases#

A user has both password and PKINIT authentication configured. Their password has expired, but they want to authenticate using their certificate. Without special handling, the KDC rejects the request with CLIENT KEY EXPIRED before PKINIT pre-authentication can run.

The same problem applies to users with RADIUS, external IdP, or passkey methods configured alongside a password.

Design#

MIT krb5 baseline#

In vanilla MIT krb5, password expiration is enforced in validate_as_request() (in kdc_util.c), which runs at the VALIDATE_POL stage of AS-REQ processing, before pre-authentication:

if (client->pw_expiration && ts_after(kdc_time, client->pw_expiration) &&
    !isflagset(server->attributes, KRB5_KDB_PWCHANGE_SERVICE)) {
    *status = "CLIENT KEY EXPIRED";
    return KRB5KDC_ERR_KEY_EXP;
}

This check includes two exemptions:

  • KRB5_KDB_PWCHANGE_SERVICE: the target service is kadmin/changepw, allowing users with expired passwords to obtain a ticket to change their password.

  • KRB5_KDB_REQUIRES_PWCHANGE: users flagged with this attribute can only authenticate to password change services.

The kdcpolicy plugin (check_as callback) runs after pre-authentication at the ENCR_REP stage. Vanilla MIT krb5 does not ship a plugin that performs password expiration checks at this stage.

@startuml
title AS-REQ password expiration flow — vanilla MIT krb5

participant "Client" as C
participant "KDC\n(do_as_req)" as KDC
participant "validate_as_request()" as VAL
participant "check_padata()" as PA
participant "kdcpolicy plugin\n(check_as)" as POL

C -> KDC : AS-REQ
activate KDC

== Stage: VALIDATE_POL ==

KDC -> VAL : validate_as_request(client, server)
activate VAL

alt client->pw_expiration == 0 OR now <= pw_expiration
    VAL --> KDC : OK
else now > client->pw_expiration
    alt server has KRB5_KDB_PWCHANGE_SERVICE
        note right of VAL
            Exemption for kadmin/changepw:
            allow expired-password users
            to obtain a ticket to change
            their password
        end note
        VAL --> KDC : OK
    else server is NOT a pwchange service
        VAL --> KDC : KRB5KDC_ERR_KEY_EXP\n"CLIENT KEY EXPIRED"
        KDC --> C : KRB_ERROR(KEY_EXP)
    end
end
deactivate VAL

== Stage: ISSUE_TKT ==

KDC -> PA : Run pre-authentication
activate PA
PA --> KDC : auth indicators\n(e.g. "pkinit", "hardened", none, ...)
deactivate PA

== Stage: ENCR_REP ==

KDC -> POL : check_as(client, server, auth_indicators)
activate POL
note right of POL
    Vanilla MIT krb5 has no
    kdcpolicy plugin by default.
    No additional pw_expiration
    check here.
end note
POL --> KDC : OK (lifetime constraints only)
deactivate POL

KDC --> C : AS-REP (ticket)
deactivate KDC
@enduml

FreeIPA two-phase approach#

Phase 1: before pre-authentication#

When ipadb_parse_ldap_entry() loads a client principal, it checks whether the user has any passwordless authentication method available (RADIUS, PKINIT, IDP, or passkey). If so, it clears entry->pw_expiration to 0 so that validate_as_request() will not reject the AS-REQ. The real expiration value is preserved in ied->pw_expiration (the IPA-specific e-data attached to the principal entry).

For users with only password-based methods, entry->pw_expiration is set normally and validate_as_request() enforces it with its built-in exemptions.

@startuml
title AS-REQ password expiration flow — FreeIPA KDB plugin (common stages)

participant "Client" as C
participant "KDC\n(do_as_req)" as KDC
participant "ipadb_parse_ldap_entry()\n[IPA]" as LDAP
participant "validate_as_request()\n[MIT krb5]" as VAL
participant "check_padata()\n[MIT krb5]" as PA

C -> KDC : AS-REQ
activate KDC

== Stage: principal lookup ==

KDC -> LDAP : get_principal(client)
activate LDAP

alt user has passwordless method\n(RADIUS | PKINIT | IDP | PASSKEY)
    LDAP -> LDAP : entry->pw_expiration = 0\nied->pw_expiration = real value
    note right of LDAP
        Clear pw_expiration so
        validate_as_request() won't
        reject before pre-auth runs.
        Preserve real value in e_data.
    end note
else user has password-only methods
    LDAP -> LDAP : entry->pw_expiration = real value\nied->pw_expiration = real value
end

LDAP --> KDC : client entry
deactivate LDAP

== Stage: VALIDATE_POL ==

KDC -> VAL : validate_as_request(client, server)
activate VAL

alt user has passwordless method (entry->pw_expiration == 0)
    note right of VAL
        Check skipped entirely:
        pw_expiration is 0, condition
        short-circuits to false.
        **All** exemptions are also
        bypassed (PWCHANGE_SERVICE,
        REQUIRES_PWCHANGE).
    end note
    VAL --> KDC : OK (check skipped)
else user has password-only methods (entry->pw_expiration == real value)
    note right of VAL
        Normal MIT krb5 check runs
        with PWCHANGE_SERVICE exemption.
        If expired & not pwchange svc:
        KRB5KDC_ERR_KEY_EXP returned.
    end note
    VAL --> KDC : OK or KRB5KDC_ERR_KEY_EXP
end
deactivate VAL

== Stage: ISSUE_TKT ==

KDC -> PA : Run pre-authentication
activate PA
PA --> KDC : auth indicators\n(e.g. "pkinit", "hardened", ...)
deactivate PA

ref over C, PA
    Continued at ENCR_REP stage
end ref
@enduml

Phase 2: after pre-authentication (kdcpolicy plugin)#

After pre-authentication completes, the KDC calls ipa_kdcpolicy_check_as() at the ENCR_REP stage. At this point, the authentication indicators reveal which method was actually used. The plugin enforces password expiration for password-based methods using the preserved ied->pw_expiration value.

Because validate_as_request() was bypassed for passwordless-capable users, the plugin must replicate its exemptions:

  • KRB5_KDB_PWCHANGE_SERVICE: if the target service has this attribute, password expiration is not enforced, allowing users with expired passwords to change their password.

  • KRB5_KDB_REQUIRES_PWCHANGE: if the client has this attribute and the target is not a password change service (already excluded above), the request is rejected with KRB5KDC_ERR_KEY_EXP.

  • Passwordless method used: if the authentication indicator corresponds to a passwordless method (pkinit, radius, idp, passkey), password expiration is not enforced since the password was not used.

@startuml
title AS-REQ password expiration — FreeIPA KDB plugin (ENCR_REP stage)

participant "Client" as C
participant "KDC\n(do_as_req)" as KDC
participant "ipa_kdcpolicy_check_as()\n[IPA]" as POL

C -> KDC : AS-REQ
activate KDC

ref over C, POL
    principal lookup,
    validate_as_request(),
    check_padata()
end ref

== Stage: ENCR_REP ==

KDC -> POL : check_as(client, server, auth_indicators)
activate POL

POL -> POL : Determine passwordless_auth\nfrom auth indicators

alt passwordless_auth == true\n(pkinit, radius, idp, passkey)
    note right of POL
        Password expiration not enforced.
        Passwordless method doesn't use
        the password, so expiration is
        irrelevant.
    end note
    POL --> KDC : OK
    KDC --> C : AS-REP (ticket)
else passwordless_auth == false\n(password, hardened, otp, or no indicator)

    alt server->attributes & KRB5_KDB_PWCHANGE_SERVICE
        note right of POL
            Exempt kadmin/changepw from
            password expiration, mirroring
            validate_as_request() behavior.
        end note
        POL --> KDC : OK
        KDC --> C : AS-REP (ticket)
    else client->attributes & KRB5_KDB_REQUIRES_PWCHANGE
        note right of POL
            Enforce REQUIRES_PWCHANGE,
            mirroring validate_as_request().
            Server is not a pwchange service
            (already checked above).
        end note
        POL --> KDC : KRB5KDC_ERR_KEY_EXP\n"REQUIRED PWCHANGE"
        KDC --> C : KRB_ERROR(KEY_EXP)
    else ied->pw_expiration == 0 OR now <= ied->pw_expiration
        POL --> KDC : OK
        KDC --> C : AS-REP (ticket)
    else now > ied->pw_expiration
        POL --> KDC : KRB5KDC_ERR_KEY_EXP\n"CLIENT KEY EXPIRED"
        KDC --> C : KRB_ERROR(KEY_EXP)
    end

end

deactivate POL
deactivate KDC
@enduml

Check distribution#

Scenario

validate_as_request()

ipa_kdcpolicy_check_as()

Password-only user, password not expired

Passes

Passes (no-op)

Password-only user, password expired

Rejects (with PWCHANGE_SERVICE exemption)

Not reached

Passwordless-capable user, passwordless method used

Skipped (pw_expiration=0)

Passes (passwordless)

Passwordless-capable user, password used, not expired

Skipped (pw_expiration=0)

Passes

Passwordless-capable user, password used, expired

Skipped (pw_expiration=0)

Rejects (with PWCHANGE_SERVICE exemption)

Any user targeting kadmin/changepw

Exempted

Exempted

Impact on password change policy#

Clearing entry->pw_expiration also affects the password change flow. When a user changes their password, ipadb_change_pwd() calls ipadb_check_pw_policy(), which passes the expiration value to ipapwd_check_policy(). That function uses the expiration value to detect admin password resets: when an admin resets a user’s password, krbPasswordExpiration is set equal to krbLastPwdChange, and ipapwd_check_policy() uses this to bypass the min_pwd_life check.

For passwordless-capable users, db_entry->pw_expiration is 0, which breaks this detection: the comparison pwd_expiration != last_pwd_change always evaluates to true (since last_pwd_change is non-zero), causing the minimum password age to be enforced even after an admin reset. To avoid this, ipadb_check_pw_policy() must use ied->pw_expiration instead of db_entry->pw_expiration.

@startuml
title Password change flow — FreeIPA KDB plugin

participant "Client" as C
participant "KDC" as KDC
participant "ipadb_check_pw_policy()\n[IPA]" as PWP

C -> KDC : kpasswd request
activate KDC

KDC -> KDC : ipadb_change_pwd()
activate KDC #DarkSalmon

KDC -> PWP : ipapwd_check_policy(...,\nied->pw_expiration, ...)
activate PWP
note right of PWP
    Must use ied->pw_expiration
    (the real value from LDAP),
    not db_entry->pw_expiration
    (which is 0 for passwordless-
    capable users).
end note
PWP --> KDC : policy result
deactivate PWP

deactivate KDC

KDC --> C : password change result
deactivate KDC
@enduml

Implementation#

Relevant source files#

  • daemons/ipa-kdb/ipa_kdb_principals.c — ipadb_parse_ldap_entry(): clears entry->pw_expiration for passwordless-capable users, preserves real value in ied->pw_expiration.

  • daemons/ipa-kdb/ipa_kdb_kdcpolicy.c — ipa_kdcpolicy_check_as(): enforces password expiration after pre-authentication with PWCHANGE_SERVICE and REQUIRES_PWCHANGE exemptions.

  • daemons/ipa-kdb/ipa_kdb_passwords.c — ipadb_check_pw_policy(): password policy check during password changes, must use ied->pw_expiration for correct min_pwd_life admin-reset detection.

  • daemons/ipa-kdb/ipa_kdb.h — struct ipadb_e_data: the pw_expiration field preserving the real expiration value.