#7835 Cert revocation for services and hosts is inefficient
Opened by cheimes. Modified

Issue

The cert revokation logic for service and host certificates is inefficient and slow. When IPA deletes a host, it revokes all certs for the host as well as all certificates for all services of the removed host. For each service and host revokation, the command retrieves all from Dogtag. This can take very long in a setup with a couple of hundred thousand certs and a couple of services on each host. See https://bugzilla.redhat.com/show_bug.cgi?id=1658280

Internally service_del uses cert_find(service=principal) to find all certificates that are associated with the service. cert_find runs three different queries: cert_search, ca_search, and ldap_search.

For cert_find() of services, only ldap_search is relevant. It uses an efficient query with an LDAP filter "(&(&(objectClass=krbprincipal)(objectClass=krbprincipalaux)(objectClass=krbticketpolicyaux)(objectClass=ipaobject)(objectClass=ipaservice)(objectClass=pkiuser))(krbPrincipalName=...)(userCertificate=*))" attrs="userCertificate" to find the service certs.

However the cert_find() executes the ca_search subquery first. It uses ra.find() method fetches information for all certs from Dogtag. There is no filtering by hostname or service. For example an ipa service-del call Dogtag's XML-RCP endpoint /ca/rest/certs/search?size=2147483647 with POST request

<CertSearchRequest>
  <serialNumberRangeInUse>true</serialNumberRangeInUse>
  <subjectInUse>false</subjectInUse>
  <matchExactly>false</matchExactly>
  <revokedByInUse>false</revokedByInUse>
  <revokedOnInUse>false</revokedOnInUse>
  <revocationReasonInUse>false</revocationReasonInUse>
  <issuedByInUse>false</issuedByInUse>
  <issuedOnInUse>false</issuedOnInUse>
  <validNotBeforeInUse>false</validNotBeforeInUse>
  <validNotAfterInUse>false</validNotAfterInUse>
  <validityLengthInUse>false</validityLengthInUse>
  <certTypeInUse>false</certTypeInUse>
</CertSearchRequest>

Steps to Reproduce

  1. create a host with host cert and a couple of services with a service cert
  2. watch Dogtag's access log
  3. delete host

Actual behavior

IPA runs /ca/rest/certs/search for each service entry and the host

Expected behavior

The service and host revokation cases should be optimized and not require a cert search

Version/Release/Distribution

4.7.2

Additional info:

The host and service certs are stored in LDAP inside the host and service entry. There is no need to search CA. A more efficient implementation could look like this:

  • fetch usercertificate for the service / host principal
  • for each cert, get cacn for cert.
  • if cacn references the CA or a LWCA subca, revoke the certificate

Metadata Update from @cheimes:
- Custom field rhbz adjusted to https://bugzilla.redhat.com/show_bug.cgi?id=1658280

@gparente proposed another optimization. He suggested to filter out revoked certs. However cert-find does not yet support filtering for non-revoked certs, e.g. ipa cert-find --revoked=false.

master:

  • ae74d348c3da580264c56441c136af3fc6ae58df Add workaround for slow host/service del
  • 6cd37542e6c563ddd8595d488712935a4d6b17bf Optimize cert remove case

Metadata Update from @abbra:
- Custom field rhbz adjusted to https://bugzilla.redhat.com/show_bug.cgi?id=1658280, https://bugzilla.redhat.com/show_bug.cgi?id=1669012 (was: https://bugzilla.redhat.com/show_bug.cgi?id=1658280)

Issue linked to Bugzilla: Bug 1669012

Metadata Update from @cheimes:
- Issue set to the milestone: FreeIPA 4.6 (was: 0.0 NEEDS_TRIAGE)

ipa-4-6:

  • 1e842f0fea290cbf8935eea79ea16e17650b7328 Add workaround for slow host/service del
  • 9a0783f5ac8a2c7426b4db3a818fa6583bab16e1 Optimize cert remove case

ipa-4-7:

  • a243bd56a65e47b03ee3ba772413b580aeb35ba9 Add workaround for slow host/service del
  • 2ccd4da44b5d66298bf1d4938fa3dc6ce2dbfa84 Optimize cert remove case

The workaround has landed in 4.6, 4.7, and master. Since it's a workaround, I'm leaving this ticket open.

ipa-4-7:

  • 11907edc71f352f5b6960ed8c175099aac792e4c Adapt cert-find performance workaround for users

ipa-4-6:

  • b480a8a979682cb1613783904f9471dc18a5f207 Adapt cert-find performance workaround for users

master:

  • 09426f8ed5ebc27d01ecbfd808fabdc0c4430854 Add ability to search on certificate revocation status
  • aa1350384ad6a7d6b2f6056d99fbb43c5c5a6be7 Only request VALID certs when revoking certs for a host/service

master:

  • c5e827401045dbecabcbe7b800add66a3729c80d Revert "Only request VALID certs when revoking certs for a host/service"

ipa-4-9:

  • 6031b8a2109ab1963d395a63541ddb3a8799fd9f Add ability to search on certificate revocation status
Metadata