Skip to content

Commit b82d667

Browse files
authored
mtca: add S3 connection (#8885)
1 parent 0a4b400 commit b82d667

6 files changed

Lines changed: 58 additions & 4 deletions

File tree

cmd/boulder-mtca/main.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/jmhodges/clock"
1515

1616
"github.com/letsencrypt/borp"
17+
"github.com/letsencrypt/boulder/bs3"
1718
"github.com/letsencrypt/boulder/cmd"
1819
"github.com/letsencrypt/boulder/config"
1920
bgrpc "github.com/letsencrypt/boulder/grpc"
@@ -28,7 +29,8 @@ type Config struct {
2829

2930
GRPCMTCA *cmd.GRPCServerConfig
3031

31-
DB cmd.DBConfig
32+
DB cmd.DBConfig `validate:"required"`
33+
S3 bs3.Config `validate:"required"`
3234

3335
// Issuer holds the configuration for a single MTCA instance with a single mtcaID.
3436
// We run a separate process for each issuer.
@@ -90,7 +92,15 @@ func main() {
9092
cmd.FailOnError(err, "Opening DB")
9193
dbMap := &borp.DbMap{Db: db, Dialect: borp.MySQLDialect{}}
9294

93-
mtcaImpl, err := mtca.New(issuer, c.MTCA.SequencingPeriod.Duration, dbMap, logger)
95+
s3c, err := bs3.FromConfig(c.MTCA.S3, logger)
96+
cmd.FailOnError(err, "Loading S3 config")
97+
98+
mtcaImpl, err := mtca.New(
99+
issuer,
100+
c.MTCA.SequencingPeriod.Duration,
101+
dbMap,
102+
s3c,
103+
logger)
94104
cmd.FailOnError(err, "Building MTCA")
95105

96106
if *initLog && *initLogForTest {

mtca/mtca.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"sync"
1515
"time"
1616

17+
"github.com/aws/aws-sdk-go-v2/service/s3"
1718
"github.com/letsencrypt/borp"
1819

1920
corepb "github.com/letsencrypt/boulder/core/proto"
@@ -30,7 +31,13 @@ var ErrCheckpointNotReady = errors.New("not ready - no mirror signature")
3031
var _ mtcapb.MTCAServer = &mtca{}
3132

3233
// New creates a new MTCA service.
33-
func New(issuer *issuance.Issuer, sequencingPeriod time.Duration, dbMap *borp.DbMap, logger blog.Logger) (*mtca, error) {
34+
func New(
35+
issuer *issuance.Issuer,
36+
sequencingPeriod time.Duration,
37+
dbMap *borp.DbMap,
38+
s3c simpleS3,
39+
logger blog.Logger,
40+
) (*mtca, error) {
3441
mtcaID, err := getMTCAID(issuer.Cert.Certificate)
3542
if err != nil {
3643
return nil, err
@@ -50,6 +57,7 @@ func New(issuer *issuance.Issuer, sequencingPeriod time.Duration, dbMap *borp.Db
5057
sequencingPeriod: sequencingPeriod,
5158

5259
db: initDB(dbMap),
60+
s3c: s3c,
5361
log: logger,
5462
}, nil
5563
}
@@ -67,11 +75,20 @@ type mtca struct {
6775
// TODO: decide whether we want to route this through the SA or an SA-like object,
6876
// or keep a direct DB connection from the MTCA.
6977
db *db.WrappedMap
78+
s3c simpleS3
7079
log blog.Logger
7180

7281
pool *pool
7382
}
7483

84+
// simpleS3 matches the subset of the s3.Client interface which we use, to allow
85+
// simpler mocking in tests.
86+
type simpleS3 interface {
87+
PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error)
88+
GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error)
89+
Bucket() string
90+
}
91+
7592
func getMTCAID(issuerCert *x509.Certificate) (string, error) {
7693
testingTrustAnchorIDOID := asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 44363, 47, 1}
7794
for _, attribute := range issuerCert.Subject.Names {

mtca/mtca_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"testing"
1818
"time"
1919

20+
"github.com/aws/aws-sdk-go-v2/service/s3"
2021
"github.com/jmhodges/clock"
2122
"github.com/letsencrypt/borp"
2223

@@ -53,7 +54,7 @@ func setup() (*mtca, func(), error) {
5354

5455
logger := blog.NewMock()
5556

56-
mtca, err := New(issuer, 100*time.Millisecond, dbMap, logger)
57+
mtca, err := New(issuer, 100*time.Millisecond, dbMap, &fakeS3{}, logger)
5758
if err != nil {
5859
return nil, nil, err
5960
}
@@ -317,3 +318,18 @@ DgQIBAaC3xMBAgEwCgYIKoZIzj0EAwIDQQAwPgIdAMebuq7759hyFC3hjrVUEaXk
317318
t.Errorf("getMTCAID(): got %s, want %s", mtcaID, expected)
318319
}
319320
}
321+
322+
type fakeS3 struct {
323+
}
324+
325+
func (f *fakeS3) PutObject(ctx context.Context, params *s3.PutObjectInput, optFns ...func(*s3.Options)) (*s3.PutObjectOutput, error) {
326+
return nil, fmt.Errorf("unimplemented")
327+
}
328+
329+
func (f *fakeS3) GetObject(ctx context.Context, params *s3.GetObjectInput, optFns ...func(*s3.Options)) (*s3.GetObjectOutput, error) {
330+
return nil, fmt.Errorf("unimplemented")
331+
}
332+
333+
func (f *fakeS3) Bucket() string {
334+
return "fake bucket"
335+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[default]
2+
region=us-west-1

test/config-next/mtca.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
"db": {
55
"dbConnectFile": "test/secrets/mtca1_dburl"
66
},
7+
"s3": {
8+
"s3endpoint": "http://boulder-minio:9000",
9+
"s3bucket": "boulder-mtc-tiles",
10+
"awsConfigFile": "test/config-next/mtca-s3-config.ini",
11+
"awsCredsFile": "test/secrets/mtca-s3-creds.ini"
12+
},
713
"tls": {
814
"caCertFile": "test/certs/ipki/minica.pem",
915
"certFile": "test/certs/ipki/mtca.boulder/cert.pem",

test/secrets/mtca-s3-creds.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[default]
2+
aws_access_key_id=minioadmin
3+
aws_secret_access_key=minioadmin

0 commit comments

Comments
 (0)