Skip to content
Snippets Groups Projects
Unverified Commit 6cef9e45 authored by Lily Sturmann's avatar Lily Sturmann Committed by GitHub
Browse files

Use active tree on server startup (#727)

parent befbcc04
No related branches found
No related tags found
No related merge requests found
......@@ -113,7 +113,7 @@ var serveCmd = &cobra.Command{
log.Logger.Fatalf("unable get sharding details from sharding config: %v", err)
}
api.ConfigureAPI(ranges)
api.ConfigureAPI(ranges, treeID)
server.ConfigureAPI()
http.Handle("/metrics", promhttp.Handler())
......
......@@ -66,7 +66,7 @@ type API struct {
certChainPem string // PEM encoded timestamping cert chain
}
func NewAPI(ranges sharding.LogRanges) (*API, error) {
func NewAPI(ranges sharding.LogRanges, treeID uint) (*API, error) {
logRPCServer := fmt.Sprintf("%s:%d",
viper.GetString("trillian_log_server.address"),
viper.GetUint("trillian_log_server.port"))
......@@ -78,16 +78,17 @@ func NewAPI(ranges sharding.LogRanges) (*API, error) {
logAdminClient := trillian.NewTrillianAdminClient(tConn)
logClient := trillian.NewTrillianLogClient(tConn)
tLogID := viper.GetInt64("trillian_log_server.tlog_id")
if tLogID == 0 {
log.Logger.Info("No tree ID specified, attempting to intitialize one")
tid := int64(treeID)
if tid == 0 {
log.Logger.Info("No tree ID specified, attempting to create a new tree")
t, err := createAndInitTree(ctx, logAdminClient, logClient)
if err != nil {
return nil, errors.Wrap(err, "create and init tree")
}
tLogID = t.TreeId
tid = t.TreeId
}
ranges.SetActive(tLogID)
log.Logger.Infof("Starting Rekor server with active tree %v", tid)
ranges.SetActive(tid)
rekorSigner, err := signer.New(ctx, viper.GetString("rekor_server.signer"))
if err != nil {
......@@ -140,7 +141,7 @@ func NewAPI(ranges sharding.LogRanges) (*API, error) {
return &API{
// Transparency Log Stuff
logClient: logClient,
logID: tLogID,
logID: tid,
logRanges: ranges,
// Signing/verifying fields
pubkey: string(pubkey),
......@@ -159,11 +160,11 @@ var (
storageClient storage.AttestationStorage
)
func ConfigureAPI(ranges sharding.LogRanges) {
func ConfigureAPI(ranges sharding.LogRanges, treeID uint) {
cfg := radix.PoolConfig{}
var err error
api, err = NewAPI(ranges)
api, err = NewAPI(ranges, treeID)
if err != nil {
log.Logger.Panic(err)
}
......
......@@ -281,7 +281,7 @@ func GetLogEntryByUUIDHandler(params entries.GetLogEntryByUUIDParams) middleware
var tid int64
tidString, err := sharding.GetTreeIDFromIDString(params.EntryUUID)
if err != nil {
// If EntryID is plain UUID, assume no sharding and use ActiveIndex. The ActiveIndex
// If EntryID is plain UUID, assume no sharding and use ActiveTreeID. The ActiveTreeID
// will == the tlog_id if a tlog_id is passed in at server startup.
if err.Error() == "cannot get treeID from plain UUID" {
tid = api.logRanges.ActiveTreeID()
......
......@@ -320,21 +320,6 @@ func (t *TrillianClient) getConsistencyProof(firstSize, lastSize int64) *Respons
}
func createAndInitTree(ctx context.Context, adminClient trillian.TrillianAdminClient, logClient trillian.TrillianLogClient) (*trillian.Tree, error) {
// First look for and use an existing tree
trees, err := adminClient.ListTrees(ctx, &trillian.ListTreesRequest{})
if err != nil {
return nil, errors.Wrap(err, "list trees")
}
for _, t := range trees.Tree {
if t.TreeType == trillian.TreeType_LOG {
log.Logger.Infof("Found existing tree with ID: %v", t.TreeId)
return t, nil
}
}
log.Logger.Infof("No existing tree found, attempting to create a new one")
// Otherwise create and initialize one
t, err := adminClient.CreateTree(ctx, &trillian.CreateTreeRequest{
Tree: &trillian.Tree{
TreeType: trillian.TreeType_LOG,
......
......@@ -16,12 +16,13 @@
package sharding
import (
"errors"
"fmt"
"io/ioutil"
"strings"
"github.com/ghodss/yaml"
"github.com/pkg/errors"
"github.com/sigstore/rekor/pkg/log"
)
type LogRanges struct {
......@@ -38,6 +39,7 @@ type LogRange struct {
func NewLogRanges(path string, treeID uint) (LogRanges, error) {
if path == "" {
log.Logger.Info("No config file specified, skipping init of logRange map")
return LogRanges{}, nil
}
if treeID == 0 {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment