Skip to content

Commit c330eb4

Browse files
committed
address comments
1 parent 6823b7b commit c330eb4

File tree

7 files changed

+186
-94
lines changed

7 files changed

+186
-94
lines changed

cmd/aws/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ var (
6161
dbPassword = flag.String("db_password", "", "AuroraDB password")
6262
dbMaxConns = flag.Int("db_max_conns", 0, "Maximum connections to the database, defaults to 0, i.e unlimited")
6363
dbMaxIdle = flag.Int("db_max_idle_conns", 2, "Maximum idle database connections in the connection pool, defaults to 2")
64-
inMemoryAntispamCacheSize = flag.Uint("inmemory_antispam_cache_size", 2<<10, "Maximum number of entries to keep in the in-memory antispam cache.")
64+
inMemoryAntispamCacheSize = flag.Uint("inmemory_antispam_cache_size", 256<<10, "Maximum number of entries to keep in the in-memory antispam cache.")
6565
rootsPemFile = flag.String("roots_pem_file", "", "Path to the file containing root certificates that are acceptable to the log. The certs are served through get-roots endpoint.")
6666
rejectExpired = flag.Bool("reject_expired", false, "If true then the certificate validity period will be checked against the current time during the validation of submissions. This will cause expired certificates to be rejected.")
6767
rejectUnexpired = flag.Bool("reject_unexpired", false, "If true then CTFE rejects certificates that are either currently valid or not yet valid.")
@@ -157,7 +157,7 @@ func newAWSStorage(ctx context.Context, signer note.Signer) (*storage.CTStorage,
157157
}
158158
}
159159

160-
appender, _, _, err := tessera.NewAppender(ctx, driver, tessera.NewAppendOptions().
160+
appender, _, reader, err := tessera.NewAppender(ctx, driver, tessera.NewAppendOptions().
161161
WithCheckpointSigner(signer).
162162
WithCTLayout().
163163
WithAntispam(*inMemoryAntispamCacheSize, antispam))
@@ -170,7 +170,7 @@ func newAWSStorage(ctx context.Context, signer note.Signer) (*storage.CTStorage,
170170
return nil, fmt.Errorf("failed to initialize AWS issuer storage: %v", err)
171171
}
172172

173-
return storage.NewCTStorage(appender, issuerStorage)
173+
return storage.NewCTStorage(appender, issuerStorage, reader)
174174
}
175175

176176
type timestampFlag struct {

cmd/gcp/main.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ var (
5454
origin = flag.String("origin", "", "Origin of the log, for checkpoints and the monitoring prefix.")
5555
bucket = flag.String("bucket", "", "Name of the bucket to store the log in.")
5656
spannerDB = flag.String("spanner_db_path", "", "Spanner database path: projects/{projectId}/instances/{instanceId}/databases/{databaseId}.")
57-
spannerAntispamDB = flag.String("spanner_antispam_db_path", "", "EXPERIMENTAL: Spanner antispam deduplication database path projects/{projectId}/instances/{instanceId}/databases/{databaseId}.")
58-
inMemoryAntispamCacheSize = flag.Uint("inmemory_antispam_cache_size", 2<<10, "Maximum number of entries to keep in the in-memory antispam cache.")
57+
spannerAntispamDB = flag.String("spanner_antispam_db_path", "", "Spanner antispam deduplication database path projects/{projectId}/instances/{instanceId}/databases/{databaseId}.")
58+
inMemoryAntispamCacheSize = flag.Uint("inmemory_antispam_cache_size", 256<<10, "Maximum number of entries to keep in the in-memory antispam cache.")
5959
rootsPemFile = flag.String("roots_pem_file", "", "Path to the file containing root certificates that are acceptable to the log. The certs are served through get-roots endpoint.")
6060
rejectExpired = flag.Bool("reject_expired", false, "If true then the certificate validity period will be checked against the current time during the validation of submissions. This will cause expired certificates to be rejected.")
6161
rejectUnexpired = flag.Bool("reject_unexpired", false, "If true then CTFE rejects certificates that are either currently valid or not yet valid.")
@@ -160,7 +160,6 @@ func newGCPStorage(ctx context.Context, signer note.Signer) (*storage.CTStorage,
160160
}
161161

162162
var antispam tessera.Antispam
163-
// Persistent antispam is currently experimental, so there's no terraform or documentation yet!
164163
if *spannerAntispamDB != "" {
165164
antispam, err = gcp_as.NewAntispam(ctx, *spannerAntispamDB, gcp_as.AntispamOpts{})
166165
if err != nil {
@@ -175,7 +174,7 @@ func newGCPStorage(ctx context.Context, signer note.Signer) (*storage.CTStorage,
175174

176175
// TODO(phbnf): figure out the best way to thread the `shutdown` func NewAppends returns back out to main so we can cleanly close Tessera down
177176
// when it's time to exit.
178-
appender, _, _, err := tessera.NewAppender(ctx, driver, opts)
177+
appender, _, reader, err := tessera.NewAppender(ctx, driver, opts)
179178
if err != nil {
180179
return nil, fmt.Errorf("failed to initialize GCP Tessera appender: %v", err)
181180
}
@@ -185,7 +184,7 @@ func newGCPStorage(ctx context.Context, signer note.Signer) (*storage.CTStorage,
185184
return nil, fmt.Errorf("failed to initialize GCP issuer storage: %v", err)
186185
}
187186

188-
return storage.NewCTStorage(appender, issuerStorage)
187+
return storage.NewCTStorage(appender, issuerStorage, reader)
189188
}
190189

191190
type timestampFlag struct {

internal/ct/ctlog.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
"github.com/transparency-dev/static-ct/internal/types/rfc6962"
1212
"github.com/transparency-dev/static-ct/storage"
13-
tessera "github.com/transparency-dev/trillian-tessera"
1413
"github.com/transparency-dev/trillian-tessera/ctonly"
1514
"k8s.io/klog/v2"
1615
)
@@ -35,7 +34,7 @@ type signSCT func(leaf *rfc6962.MerkleTreeLeaf) (*rfc6962.SignedCertificateTimes
3534
// Storage provides functions to store certificates in a static-ct-api log.
3635
type Storage interface {
3736
// Add assigns an index to the provided Entry, stages the entry for integration, and returns a future for the assigned index.
38-
Add(context.Context, *ctonly.Entry) tessera.IndexFuture
37+
Add(context.Context, *ctonly.Entry) (idx uint64, timestamp uint64, err error)
3938
// AddIssuerChain stores every the chain certificate in a content-addressable store under their sha256 hash.
4039
AddIssuerChain(context.Context, []*x509.Certificate) error
4140
}

internal/ct/handlers.go

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,11 @@ func (a appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
118118
originAttr := originKey.String(a.log.origin)
119119
operationAttr := operationKey.String(a.name)
120120
reqCounter.Add(r.Context(), 1, metric.WithAttributes(originAttr, operationAttr))
121-
startTime := a.opts.TimeSource.Now()
121+
startTime := time.Now()
122122
logCtx := a.opts.RequestLog.start(r.Context())
123123
a.opts.RequestLog.origin(logCtx, a.log.origin)
124124
defer func() {
125-
latency := a.opts.TimeSource.Now().Sub(startTime).Seconds()
125+
latency := time.Since(startTime).Seconds()
126126
reqDuration.Record(r.Context(), latency, metric.WithAttributes(originAttr, operationAttr, codeKey.Int(statusCode)))
127127
}()
128128

@@ -146,7 +146,7 @@ func (a appHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
146146
}
147147

148148
// impose a deadline on this onward request.
149-
ctx, cancel := context.WithDeadline(logCtx, deadlineTime(a.opts))
149+
ctx, cancel := context.WithTimeout(logCtx, a.opts.Deadline)
150150
defer cancel()
151151

152152
var err error
@@ -178,6 +178,7 @@ type HandlerOptions struct {
178178
// or returned to the user containing the full error message.
179179
MaskInternalErrors bool
180180
// TimeSource indicated the system time and can be injfected for testing.
181+
// TODO(phbnf): hide inside the log
181182
TimeSource TimeSource
182183
}
183184

@@ -274,18 +275,19 @@ func addChainInternal(ctx context.Context, opts *HandlerOptions, log *log, w htt
274275
}
275276

276277
klog.V(2).Infof("%s: %s => storage.Add", log.origin, method)
277-
index, err := log.storage.Add(ctx, entry)()
278+
index, dedupedTimeMillis, err := log.storage.Add(ctx, entry)
278279
if err != nil {
279280
if errors.Is(err, tessera.ErrPushback) {
280281
w.Header().Add("Retry-After", "1")
281282
return http.StatusServiceUnavailable, fmt.Errorf("received pushback from Tessera sequencer: %v", err)
282283
}
283284
return http.StatusInternalServerError, fmt.Errorf("couldn't store the leaf: %v", err)
284285
}
286+
entry.Timestamp = dedupedTimeMillis
285287

286288
// Always use the returned leaf as the basis for an SCT.
287289
var loggedLeaf rfc6962.MerkleTreeLeaf
288-
leafValue := entry.MerkleTreeLeaf(index.Index)
290+
leafValue := entry.MerkleTreeLeaf(index)
289291
if rest, err := tls.Unmarshal(leafValue, &loggedLeaf); err != nil {
290292
return http.StatusInternalServerError, fmt.Errorf("failed to reconstruct MerkleTreeLeaf: %s", err)
291293
} else if len(rest) > 0 {
@@ -312,7 +314,7 @@ func addChainInternal(ctx context.Context, opts *HandlerOptions, log *log, w htt
312314
klog.V(3).Infof("%s: %s <= SCT", log.origin, method)
313315
if sct.Timestamp == timeMillis {
314316
lastSCTTimestamp.Record(ctx, otel.Clamp64(sct.Timestamp), metric.WithAttributes(originKey.String(log.origin)))
315-
lastSCTIndex.Record(ctx, otel.Clamp64(index.Index), metric.WithAttributes(originKey.String(log.origin)))
317+
lastSCTIndex.Record(ctx, otel.Clamp64(index), metric.WithAttributes(originKey.String(log.origin)))
316318
}
317319

318320
return http.StatusOK, nil
@@ -355,11 +357,6 @@ func getRoots(ctx context.Context, opts *HandlerOptions, log *log, w http.Respon
355357
return http.StatusOK, nil
356358
}
357359

358-
// deadlineTime calculates the future time a request should expire based on our config.
359-
func deadlineTime(opts *HandlerOptions) time.Time {
360-
return opts.TimeSource.Now().Add(opts.Deadline)
361-
}
362-
363360
// marshalAndWriteAddChainResponse is used by add-chain and add-pre-chain to create and write
364361
// the JSON response to the client
365362
func marshalAndWriteAddChainResponse(sct *rfc6962.SignedCertificateTimestamp, w http.ResponseWriter) error {

0 commit comments

Comments
 (0)