0fcb1e
From 20ff7c16022793c707f6c2b8fb38a801870bc0e2 Mon Sep 17 00:00:00 2001
0fcb1e
From: Rob Crittenden <rcritten@redhat.com>
0fcb1e
Date: Wed, 8 Feb 2023 10:42:58 -0500
0fcb1e
Subject: [PATCH] Fix setting values of 0 in ACME pruning
0fcb1e
0fcb1e
Replace comparisons of "if value" with "if value is not None"
0fcb1e
in order to handle 0.
0fcb1e
0fcb1e
Add a short reference to the man page to indicat that a cert
0fcb1e
or request retention time of 0 means remove at the next
0fcb1e
execution.
0fcb1e
0fcb1e
Also indicate that the search time limit is in seconds.
0fcb1e
0fcb1e
Fixes: https://pagure.io/freeipa/issue/9325
0fcb1e
0fcb1e
Signed-off-by: Rob Crittenden <rcritten@redhat.com>
0fcb1e
Reviewed-By: Francisco Trivino <ftrivino@redhat.com>
0fcb1e
---
0fcb1e
 doc/designs/expired_certificate_pruning.md |  4 ++--
0fcb1e
 install/tools/man/ipa-acme-manage.1        |  8 +++----
0fcb1e
 ipaserver/install/ipa_acme_manage.py       | 28 +++++++++++-----------
0fcb1e
 3 files changed, 20 insertions(+), 20 deletions(-)
0fcb1e
0fcb1e
diff --git a/doc/designs/expired_certificate_pruning.md b/doc/designs/expired_certificate_pruning.md
0fcb1e
index a23e452696ba2a150c4ad5a3e57360ae0a16a338..35ead7b00145b5df44caf542cba277f0e6e08b6a 100644
0fcb1e
--- a/doc/designs/expired_certificate_pruning.md
0fcb1e
+++ b/doc/designs/expired_certificate_pruning.md
0fcb1e
@@ -67,11 +67,11 @@ There are four values each that can be managed for pruning certificates and requ
0fcb1e
 * expired cert/incomplete request time
0fcb1e
 * time unit
0fcb1e
 * LDAP search size limit
0fcb1e
-* LDAP search time limit
0fcb1e
+* LDAP search time limit (in seconds)
0fcb1e
 
0fcb1e
 The first two configure when an expired certificate or incomplete request will be deleted. The unit can be one of: minute, hour, day, year. By default it is 30 days.
0fcb1e
 
0fcb1e
-The LDAP limits control how many entries are returned and how long the search can take. By default it is 1000 entries and unlimited time.
0fcb1e
+The LDAP limits control how many entries are returned and how long the search can take. By default it is 1000 entries and unlimited time (0 == unlimited, unit is seconds).
0fcb1e
 
0fcb1e
 ### Configuration settings
0fcb1e
 
0fcb1e
diff --git a/install/tools/man/ipa-acme-manage.1 b/install/tools/man/ipa-acme-manage.1
0fcb1e
index e6cec4e4a7fd460c514a72456a2dc9a2e3682ebd..b8383c14f482698d2bcc8b08f0c0bf5882c3c298 100644
0fcb1e
--- a/install/tools/man/ipa-acme-manage.1
0fcb1e
+++ b/install/tools/man/ipa-acme-manage.1
0fcb1e
@@ -79,7 +79,7 @@ For example, "0 0 1 * *" schedules the job to run at 12:00am on the first
0fcb1e
 day of each month.
0fcb1e
 .TP
0fcb1e
 \fB\-\-certretention=CERTRETENTION\fR
0fcb1e
-Certificate retention time. The default is 30.
0fcb1e
+Certificate retention time. The default is 30. A value of 0 will remove expired certificates with no delay.
0fcb1e
 .TP
0fcb1e
 \fB\-\-certretentionunit=CERTRETENTIONUNIT\fR
0fcb1e
 Certificate retention units. Valid units are: minute, hour, day, year.
0fcb1e
@@ -89,10 +89,10 @@ The default is days.
0fcb1e
 LDAP search size limit searching for expired certificates. The default is 1000. This is a client-side limit. There may be additional server-side limitations.
0fcb1e
 .TP
0fcb1e
 \fB\-\-certsearchtimelimit=CERTSEARCHTIMELIMIT\fR
0fcb1e
-LDAP search time limit searching for expired certificates. The default is 0, no limit. This is a client-side limit. There may be additional server-side limitations.
0fcb1e
+LDAP search time limit (seconds) searching for expired certificates. The default is 0, no limit. This is a client-side limit. There may be additional server-side limitations.
0fcb1e
 .TP
0fcb1e
 \fB\-\-requestretention=REQUESTRETENTION\fR
0fcb1e
-Request retention time. The default is 30.
0fcb1e
+Request retention time. The default is 30. A value of 0 will remove expired requests with no delay.
0fcb1e
 .TP
0fcb1e
 \fB\-\-requestretentionunit=REQUESTRETENTIONUNIT\fR
0fcb1e
 Request retention units. Valid units are: minute, hour, day, year.
0fcb1e
@@ -102,7 +102,7 @@ The default is days.
0fcb1e
 LDAP search size limit searching for unfulfilled requests. The default is 1000. There may be additional server-side limitations.
0fcb1e
 .TP
0fcb1e
 \fB\-\-requestsearchtimelimit=REQUESTSEARCHTIMELIMIT\fR
0fcb1e
-LDAP search time limit searching for unfulfilled requests. The default is 0, no limit. There may be additional server-side limitations.
0fcb1e
+LDAP search time limit (seconds) searching for unfulfilled requests. The default is 0, no limit. There may be additional server-side limitations.
0fcb1e
 .TP
0fcb1e
 \fB\-\-config\-show\fR
0fcb1e
 Show the current pruning configuration
0fcb1e
diff --git a/ipaserver/install/ipa_acme_manage.py b/ipaserver/install/ipa_acme_manage.py
0fcb1e
index b7b2111d9edcec2580aa4a485d7a7340146ff065..e7c35ff6fb5b7a30ac9e2c0c18f8db805cf06ee9 100644
0fcb1e
--- a/ipaserver/install/ipa_acme_manage.py
0fcb1e
+++ b/ipaserver/install/ipa_acme_manage.py
0fcb1e
@@ -207,14 +207,14 @@ class IPAACMEManage(AdminTool):
0fcb1e
                         self.options.enable,
0fcb1e
                         self.options.disable,
0fcb1e
                         self.options.cron,
0fcb1e
-                        self.options.certretention,
0fcb1e
+                        self.options.certretention is not None,
0fcb1e
                         self.options.certretentionunit,
0fcb1e
-                        self.options.requestretention,
0fcb1e
+                        self.options.requestretention is not None,
0fcb1e
                         self.options.requestretentionunit,
0fcb1e
-                        self.options.certsearchsizelimit,
0fcb1e
-                        self.options.certsearchtimelimit,
0fcb1e
-                        self.options.requestsearchsizelimit,
0fcb1e
-                        self.options.requestsearchtimelimit,
0fcb1e
+                        self.options.certsearchsizelimit is not None,
0fcb1e
+                        self.options.certsearchtimelimit is not None,
0fcb1e
+                        self.options.requestsearchsizelimit is not None,
0fcb1e
+                        self.options.requestsearchtimelimit is not None,
0fcb1e
                     ]
0fcb1e
                 )
0fcb1e
                 and (self.options.config_show or self.options.run)
0fcb1e
@@ -226,7 +226,7 @@ class IPAACMEManage(AdminTool):
0fcb1e
             elif self.options.cron:
0fcb1e
                 if len(self.options.cron.split()) != 5:
0fcb1e
                     self.option_parser.error("Invalid format for --cron")
0fcb1e
-                # dogtag does no validation when setting an option so
0fcb1e
+                # dogtag does no validation when setting this option so
0fcb1e
                 # do the minimum. The dogtag cron is limited compared to
0fcb1e
                 # crontab(5).
0fcb1e
                 opt = self.options.cron.split()
0fcb1e
@@ -255,7 +255,7 @@ class IPAACMEManage(AdminTool):
0fcb1e
                 'pki-server', command,
0fcb1e
                 f'{prefix}.{directive}'
0fcb1e
             ]
0fcb1e
-            if value:
0fcb1e
+            if value is not None:
0fcb1e
                 args.extend([str(value)])
0fcb1e
             logger.debug(args)
0fcb1e
             result = run(args, raiseonerr=False, capture_output=True,
0fcb1e
@@ -350,28 +350,28 @@ class IPAACMEManage(AdminTool):
0fcb1e
 
0fcb1e
         # pki-server ca-config-set can only set one option at a time so
0fcb1e
         # loop through all the options and set what is there.
0fcb1e
-        if self.options.certretention:
0fcb1e
+        if self.options.certretention is not None:
0fcb1e
             ca_config_set('certRetentionTime',
0fcb1e
                           self.options.certretention)
0fcb1e
         if self.options.certretentionunit:
0fcb1e
             ca_config_set('certRetentionUnit',
0fcb1e
                           self.options.certretentionunit)
0fcb1e
-        if self.options.certsearchtimelimit:
0fcb1e
+        if self.options.certsearchtimelimit is not None:
0fcb1e
             ca_config_set('certSearchTimeLimit',
0fcb1e
                           self.options.certsearchtimelimit)
0fcb1e
-        if self.options.certsearchsizelimit:
0fcb1e
+        if self.options.certsearchsizelimit is not None:
0fcb1e
             ca_config_set('certSearchSizeLimit',
0fcb1e
                           self.options.certsearchsizelimit)
0fcb1e
-        if self.options.requestretention:
0fcb1e
+        if self.options.requestretention is not None:
0fcb1e
             ca_config_set('requestRetentionTime',
0fcb1e
                           self.options.requestretention)
0fcb1e
         if self.options.requestretentionunit:
0fcb1e
             ca_config_set('requestRetentionUnit',
0fcb1e
                           self.options.requestretentionunit)
0fcb1e
-        if self.options.requestsearchsizelimit:
0fcb1e
+        if self.options.requestsearchsizelimit is not None:
0fcb1e
             ca_config_set('requestSearchSizeLimit',
0fcb1e
                           self.options.requestsearchsizelimit)
0fcb1e
-        if self.options.requestsearchtimelimit:
0fcb1e
+        if self.options.requestsearchtimelimit is not None:
0fcb1e
             ca_config_set('requestSearchTimeLimit',
0fcb1e
                           self.options.requestsearchtimelimit)
0fcb1e
         if self.options.cron:
0fcb1e
-- 
0fcb1e
2.39.1
0fcb1e