Skip to content

Commit d1acfeb

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 c1ab6e1 commit d1acfeb

19 files changed

Lines changed: 805 additions & 25 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: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@ package notmain
44

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

1012
"github.com/jmhodges/clock"
1113

12-
"github.com/letsencrypt/boulder/blog"
1314
"github.com/letsencrypt/boulder/cmd"
1415
bgrpc "github.com/letsencrypt/boulder/grpc"
1516
"github.com/letsencrypt/boulder/issuance"
1617
mtca "github.com/letsencrypt/boulder/mtca"
1718
mtcapb "github.com/letsencrypt/boulder/mtca/proto"
19+
20+
"github.com/letsencrypt/borp"
21+
"github.com/letsencrypt/boulder/blog"
1822
)
1923

2024
type Config struct {
@@ -23,6 +27,8 @@ type Config struct {
2327

2428
GRPCMTCA *cmd.GRPCServerConfig
2529

30+
DB cmd.DBConfig
31+
2632
// Issuer holds the configuration for a single MTCA instance with a single mtcaID.
2733
// We run a separate process for each issuer.
2834
// TODO: the issuance package parses the CA certificate as a self-signed X.509
@@ -39,6 +45,9 @@ func main() {
3945
grpcAddr := flag.String("addr", "", "gRPC listen address override")
4046
debugAddr := flag.String("debug-addr", "", "Debug server address override")
4147
configFile := flag.String("config", "", "File path to the configuration file for this service")
48+
initLog := flag.Bool("init-log", false, "Initialize log metadata in the database and exit")
49+
initLogForTest := flag.Bool("init-log-for-test", false, "For testing: initialize log metadata (ignoring errors), then serve")
50+
4251
flag.Parse()
4352
if *configFile == "" {
4453
flag.Usage()
@@ -68,14 +77,41 @@ func main() {
6877
issuer, err := issuance.LoadIssuer(c.MTCA.Issuer, clk)
6978
cmd.FailOnError(err, "Loading issuer")
7079

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

73103
srv := bgrpc.NewServer(c.MTCA.GRPCMTCA, logger).Add(
74104
&mtcapb.MTCA_ServiceDesc, mtcaImpl)
75105

76106
start, err := srv.Build(tlsConfig, scope, clk)
77107
cmd.FailOnError(err, "Unable to setup MTCA gRPC server")
78108

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

0 commit comments

Comments
 (0)