Skip to content

Commit cb6effa

Browse files
authored
Add keyHashToSerial cleanup to boulder-janitor (letsencrypt#5194)
This adds a new job type (and corresponding config) to the janitor to clean up old rows from the `keyHashToSerial` table. Rows in this table are no longer relevant after their corresponding certificate has expired. Fixes letsencrypt#4792
1 parent 65443f8 commit cb6effa

File tree

6 files changed

+64
-1
lines changed

6 files changed

+64
-1
lines changed

cmd/boulder-janitor/config.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ type Config struct {
7171
// CertificatesPerName describes a cleanup job for the certificatesPerName table.
7272
CertificatesPerName CleanupConfig
7373

74+
// KeyHashToSerial describes a cleanup job for the keyHashToSerial table.
75+
KeyHashToSerial CleanupConfig
76+
7477
// Orders describes a cleanup job for the orders table and related rows
7578
// (requestedNames, orderToAuthz2, orderFqdnSets).
7679
Orders CleanupConfig
@@ -83,7 +86,13 @@ func (c Config) Valid() error {
8386
if c.Janitor.DebugAddr == "" {
8487
return errEmptyMetricsAddr
8588
}
86-
jobConfigs := []CleanupConfig{c.Janitor.Certificates, c.Janitor.CertificateStatus, c.Janitor.CertificatesPerName}
89+
jobConfigs := []CleanupConfig{
90+
c.Janitor.Certificates,
91+
c.Janitor.CertificateStatus,
92+
c.Janitor.CertificatesPerName,
93+
c.Janitor.KeyHashToSerial,
94+
c.Janitor.Orders,
95+
}
8796
for _, cc := range jobConfigs {
8897
if err := cc.Valid(); err != nil {
8998
return err

cmd/boulder-janitor/janitor.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ func newJobs(
9696
}
9797
jobs = append(jobs, newCertificatesPerNameJob(dbMap, logger, clk, config))
9898
}
99+
if config.Janitor.KeyHashToSerial.Enabled {
100+
jobs = append(jobs, newKeyHashToSerialJob(dbMap, logger, clk, config))
101+
}
99102
if config.Janitor.Orders.Enabled {
100103
jobs = append(jobs, newOrdersJob(dbMap, logger, clk, config.Janitor.Orders))
101104
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package main
2+
3+
import (
4+
"github.com/jmhodges/clock"
5+
"github.com/letsencrypt/boulder/db"
6+
blog "github.com/letsencrypt/boulder/log"
7+
)
8+
9+
// newKeyHashToSerialJob returns a batchedDBJob configured to delete expired
10+
// rows from the keyHashToSerial table.
11+
func newKeyHashToSerialJob(
12+
dbMap db.DatabaseMap,
13+
log blog.Logger,
14+
clk clock.Clock,
15+
config Config) *batchedDBJob {
16+
purgeBefore := config.Janitor.KeyHashToSerial.GracePeriod.Duration
17+
workQuery := `SELECT id, certNotAfter AS expires FROM keyHashToSerial
18+
WHERE
19+
id > :startID
20+
LIMIT :limit`
21+
log.Debugf("Creating KeyHashToSerial job from config: %#v", config.Janitor.KeyHashToSerial)
22+
return &batchedDBJob{
23+
db: dbMap,
24+
log: log,
25+
clk: clk,
26+
purgeBefore: purgeBefore,
27+
workSleep: config.Janitor.KeyHashToSerial.WorkSleep.Duration,
28+
batchSize: config.Janitor.KeyHashToSerial.BatchSize,
29+
maxDPS: config.Janitor.KeyHashToSerial.MaxDPS,
30+
parallelism: config.Janitor.KeyHashToSerial.Parallelism,
31+
table: "keyHashToSerial",
32+
workQuery: workQuery,
33+
}
34+
}

test/config-next/janitor.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
"parallelism": 2,
3131
"maxDPS": 50
3232
},
33+
"keyHashToSerial": {
34+
"enabled": true,
35+
"gracePeriod": "2184h",
36+
"batchSize": 100,
37+
"workSleep": "500ms",
38+
"parallelism": 2,
39+
"maxDPS": 50
40+
},
3341
"orders": {
3442
"enabled": true,
3543
"gracePeriod": "2184h",

test/config/janitor.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@
3030
"parallelism": 2,
3131
"maxDPS": 50
3232
},
33+
"keyHashToSerial": {
34+
"enabled": true,
35+
"gracePeriod": "2184h",
36+
"batchSize": 100,
37+
"workSleep": "500ms",
38+
"parallelism": 2,
39+
"maxDPS": 50
40+
},
3341
"orders": {
3442
"enabled": true,
3543
"gracePeriod": "2184h",

test/sa_db_users.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ GRANT SELECT,DELETE ON authz2 TO 'purger'@'localhost';
6363
GRANT SELECT,DELETE ON certificates TO 'janitor'@'localhost';
6464
GRANT SELECT,DELETE ON certificateStatus TO 'janitor'@'localhost';
6565
GRANT SELECT,DELETE ON certificatesPerName TO 'janitor'@'localhost';
66+
GRANT SELECT,DELETE ON keyHashToSerial TO 'janitor'@'localhost';
6667
GRANT SELECT,DELETE ON orders TO 'janitor'@'localhost';
6768
GRANT SELECT,DELETE ON requestedNames TO 'janitor'@'localhost';
6869
GRANT SELECT,DELETE ON orderFqdnSets TO 'janitor'@'localhost';

0 commit comments

Comments
 (0)