From 18ebd1116d706d9f2a3a9c2dca16681a4f138362 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Thu, 30 Jan 2020 21:22:47 +1100 Subject: [PATCH] certmonger: support dnsname as request search criterion We need to be able to filter Certmonger tracking requests by the DNS names defined for the request. The goal is to add the 'ipa-ca.$DOMAIN' alias to the HTTP certificate tracking requests, so we will use that name as a search criterion. Implement support for this. As a result of this commit it will be easy to add support for subset match of other Certmonger request list properties. Just add the property name to the ARRAY_PROPERTIES list (and update the 'criteria' description in the module docstring!) Part of: https://pagure.io/freeipa/issue/8186 Reviewed-By: Rob Crittenden --- ipalib/install/certmonger.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/ipalib/install/certmonger.py b/ipalib/install/certmonger.py index bda5672d9..ddde00d46 100644 --- a/ipalib/install/certmonger.py +++ b/ipalib/install/certmonger.py @@ -46,6 +46,10 @@ DBUS_CM_REQUEST_IF = 'org.fedorahosted.certmonger.request' DBUS_CM_CA_IF = 'org.fedorahosted.certmonger.ca' DBUS_PROPERTY_IF = 'org.freedesktop.DBus.Properties' +# These properties, if encountered in search criteria, result in a +# subset test instead of equality test. +ARRAY_PROPERTIES = ['template-hostname'] + """ Certmonger helper routines. @@ -67,6 +71,10 @@ behaviour: Test equality against the nickname of the CA (a.k.a. request helper) object for the request. +``template-hostname`` + Must be an iterable of DNS names. Tests that the given values + are a subset of the values defined on the Certmonger request. + """ @@ -210,11 +218,18 @@ def _get_requests(criteria): criteria.get('ca-name')) ca = _cm_dbus_object(cm.bus, cm, ca_path, DBUS_CM_CA_IF, DBUS_CM_IF) - value = ca.obj_if.get_nickname() + if criteria[criterion] != ca.obj_if.get_nickname(): + break + elif criterion in ARRAY_PROPERTIES: + # perform subset test + expect = set(criteria[criterion]) + got = request.prop_if.Get(DBUS_CM_REQUEST_IF, criterion) + if not expect.issubset(got): + break else: value = request.prop_if.Get(DBUS_CM_REQUEST_IF, criterion) - if value != criteria[criterion]: - break + if criteria[criterion] != value: + break else: requests.append(request)