Skip to content

Commit 61d461f

Browse files
committed
mtca: add sequencing
This is a partial implementation: it doesn't really write to tile storage, or calculate realistic hashes. In Loop(), take the current contents of the pool, "sequence" them by increasing the tree size and generating a fake root hash randomly, and write a new checkpoint row. Add a new table, `latestCheckpoints`. This has a single row per log, referring to the latest checkpoint. This allows us to take an exclusive lock while signing to prevent signing split views.
1 parent 22f2649 commit 61d461f

19 files changed

Lines changed: 803 additions & 24 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ test/secrets/mtpublisher_dburl
5555
test/secrets/revoker_dburl
5656
test/secrets/sa_dburl
5757
test/secrets/sa_ro_dburl
58+
test/secrets/mtca1_dburl

cmd/boulder-mtca/main.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ package notmain
44

55
import (
66
"context"
7+
"database/sql"
78
"flag"
9+
"log/slog"
810
"os"
911

1012
"github.com/jmhodges/clock"
1113

14+
"github.com/letsencrypt/borp"
1215
"github.com/letsencrypt/boulder/blog"
1316
"github.com/letsencrypt/boulder/cmd"
1417
bgrpc "github.com/letsencrypt/boulder/grpc"
@@ -23,6 +26,8 @@ type Config struct {
2326

2427
GRPCMTCA *cmd.GRPCServerConfig
2528

29+
DB cmd.DBConfig
30+
2631
// Issuer holds the configuration for a single MTCA instance with a single mtcaID.
2732
// We run a separate process for each issuer.
2833
// TODO: the issuance package parses the CA certificate as a self-signed X.509
@@ -39,6 +44,9 @@ func main() {
3944
grpcAddr := flag.String("addr", "", "gRPC listen address override")
4045
debugAddr := flag.String("debug-addr", "", "Debug server address override")
4146
configFile := flag.String("config", "", "File path to the configuration file for this service")
47+
initLog := flag.Bool("init-log", false, "Initialize log metadata in the database and exit")
48+
initLogForTest := flag.Bool("init-log-for-test", false, "For testing: initialize log metadata (ignoring errors), then serve")
49+
4250
flag.Parse()
4351
if *configFile == "" {
4452
flag.Usage()
@@ -68,14 +76,41 @@ func main() {
6876
issuer, err := issuance.LoadIssuer(c.MTCA.Issuer, clk)
6977
cmd.FailOnError(err, "Loading issuer")
7078

71-
mtcaImpl := mtca.New(issuer)
79+
url, err := c.MTCA.DB.URL()
80+
cmd.FailOnError(err, "Reading DB URL")
81+
db, err := sql.Open("mysql", url)
82+
cmd.FailOnError(err, "Opening DB")
83+
dbMap := &borp.DbMap{Db: db, Dialect: borp.MySQLDialect{}}
84+
85+
mtcaImpl, err := mtca.New(issuer, dbMap, logger)
86+
cmd.FailOnError(err, "Building MTCA")
87+
88+
if *initLog {
89+
err = mtcaImpl.InitLog(context.Background())
90+
cmd.FailOnError(err, "Initializing log")
91+
return
92+
}
93+
if *initLogForTest {
94+
err = mtcaImpl.InitLog(context.Background())
95+
if err != nil {
96+
logger.Info(context.Background(),
97+
"Non-fatal error initializing MTC log DB for test",
98+
slog.String("info", err.Error()))
99+
}
100+
}
72101

73102
srv := bgrpc.NewServer(c.MTCA.GRPCMTCA, logger).Add(
74103
&mtcapb.MTCA_ServiceDesc, mtcaImpl)
75104

76105
start, err := srv.Build(tlsConfig, scope, clk)
77106
cmd.FailOnError(err, "Unable to setup MTCA gRPC server")
78107

108+
ctx, cancel := context.WithCancel(context.Background())
109+
// Cancel will be called after start() returns, which happens after GracefulStop() returns.
110+
// That means all inflight RPCs will be done, which means the last of the pool has been sequenced.
111+
defer cancel()
112+
go mtcaImpl.Loop(ctx)
113+
79114
cmd.FailOnError(start(), "MTCA gRPC service failed")
80115
}
81116

0 commit comments

Comments
 (0)