Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Commit

Permalink
Fix/misc (#862)
Browse files Browse the repository at this point in the history
* MySQL compatable SQL

* Mark not found errors properly

* Skip tests in sqlite mode

* variable rename

* Add URL for available domains

* split log and map admin clients

* Add min and max interval to domain info output

* Add vrf key handler

* Refresh domain list periodically

This change allows the sequencer to detect new domains.
This is especially important when a Key Transparency cluster is
being brought up for the first time since the sequencer starts before
any domains have been initialized.

* fixup tests

* Code review
  • Loading branch information
gdbelvin committed Nov 22, 2017
1 parent 0025f9a commit e715077
Show file tree
Hide file tree
Showing 13 changed files with 159 additions and 77 deletions.
8 changes: 4 additions & 4 deletions cmd/keytransparency-monitor/main.go
Expand Up @@ -70,10 +70,10 @@ func main() {
if err != nil { if err != nil {
glog.Exitf("Error Dialing %v: %v", ktURL, err) glog.Exitf("Error Dialing %v: %v", ktURL, err)
} }
ktclient := gpb.NewKeyTransparencyServiceClient(cc) ktClient := gpb.NewKeyTransparencyServiceClient(cc)
mcc := gpb.NewMutationServiceClient(cc) mClient := gpb.NewMutationServiceClient(cc)


config, err := ktclient.GetDomainInfo(ctx, &pb.GetDomainInfoRequest{DomainId: *domainID}) config, err := ktClient.GetDomainInfo(ctx, &pb.GetDomainInfoRequest{DomainId: *domainID})
if err != nil { if err != nil {
glog.Exitf("Could not read domain info %v:", err) glog.Exitf("Could not read domain info %v:", err)
} }
Expand All @@ -87,7 +87,7 @@ func main() {
store := fake.NewMonitorStorage() store := fake.NewMonitorStorage()


// Create monitoring background process. // Create monitoring background process.
mon, err := monitor.NewFromConfig(mcc, config, signer, store) mon, err := monitor.NewFromConfig(mClient, config, signer, store)
if err != nil { if err != nil {
glog.Exitf("Failed to initialize monitor: %v", err) glog.Exitf("Failed to initialize monitor: %v", err)
} }
Expand Down
13 changes: 8 additions & 5 deletions cmd/keytransparency-sequencer/main.go
Expand Up @@ -18,6 +18,7 @@ import (
"context" "context"
"database/sql" "database/sql"
"flag" "flag"
"time"


"github.com/google/keytransparency/core/adminserver" "github.com/google/keytransparency/core/adminserver"
"github.com/google/keytransparency/core/mutator/entry" "github.com/google/keytransparency/core/mutator/entry"
Expand All @@ -41,8 +42,9 @@ var (
serverDBPath = flag.String("db", "db", "Database connection string") serverDBPath = flag.String("db", "db", "Database connection string")


// Info to connect to the trillian map and log. // Info to connect to the trillian map and log.
mapURL = flag.String("map-url", "", "URL of Trilian Map Server") mapURL = flag.String("map-url", "", "URL of Trillian Map Server")
logURL = flag.String("log-url", "", "URL of Trillian Log Server for Signed Map Heads") logURL = flag.String("log-url", "", "URL of Trillian Log Server for Signed Map Heads")
refresh = flag.Duration("domain-refresh", 5*time.Second, "Time to detect new domain")
) )


func openDB() *sql.DB { func openDB() *sql.DB {
Expand Down Expand Up @@ -70,7 +72,8 @@ func main() {
} }
tlog := trillian.NewTrillianLogClient(lconn) tlog := trillian.NewTrillianLogClient(lconn)
tmap := trillian.NewTrillianMapClient(mconn) tmap := trillian.NewTrillianMapClient(mconn)
tadmin := trillian.NewTrillianAdminClient(mconn) logAdmin := trillian.NewTrillianAdminClient(lconn)
mapAdmin := trillian.NewTrillianAdminClient(mconn)


// Database tables // Database tables
sqldb := openDB() sqldb := openDB()
Expand All @@ -91,12 +94,12 @@ func main() {
keygen := func(ctx context.Context, spec *keyspb.Specification) (proto.Message, error) { keygen := func(ctx context.Context, spec *keyspb.Specification) (proto.Message, error) {
return der.NewProtoFromSpec(spec) return der.NewProtoFromSpec(spec)
} }
adminServer := adminserver.New(adminStorage, tadmin, keygen) adminServer := adminserver.New(adminStorage, logAdmin, mapAdmin, keygen)
glog.Infof("Signer starting") glog.Infof("Signer starting")


// Run servers // Run servers
ctx := context.Background() ctx := context.Background()
signer.StartSequencingAll(ctx) signer.StartSequencingAll(ctx, *refresh)
run(adminServer) run(adminServer)


glog.Errorf("Signer exiting") glog.Errorf("Signer exiting")
Expand Down
14 changes: 8 additions & 6 deletions cmd/keytransparency-sequencer/server.go
Expand Up @@ -18,24 +18,26 @@ import (
"flag" "flag"
"net/http" "net/http"


"github.com/google/keytransparency/cmd/serverutil"

"github.com/golang/glog" "github.com/golang/glog"
"github.com/prometheus/client_golang/prometheus/promhttp" "github.com/prometheus/client_golang/prometheus/promhttp"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/credentials" "google.golang.org/grpc/credentials"
"google.golang.org/grpc/reflection" "google.golang.org/grpc/reflection"


"github.com/google/keytransparency/cmd/serverutil" gpb "github.com/google/keytransparency/core/proto/keytransparency_v1_grpc"
ktpb "github.com/google/keytransparency/core/proto/keytransparency_v1_grpc" _ "github.com/google/trillian/crypto/keys/der/proto"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
) )


var ( var (
addr = flag.String("metrics-addr", ":8081", "The ip:port to publish metrics on") addr = flag.String("addr", ":8080", "The ip:port to serve on")
keyFile = flag.String("tls-key", "genfiles/server.key", "TLS private key file") keyFile = flag.String("tls-key", "genfiles/server.key", "TLS private key file")
certFile = flag.String("tls-cert", "genfiles/server.crt", "TLS cert file") certFile = flag.String("tls-cert", "genfiles/server.crt", "TLS cert file")
) )


func run(svr ktpb.KeyTransparencyAdminServiceServer) { func run(svr gpb.KeyTransparencyAdminServiceServer) {
// Wire up gRPC and HTTP servers. // Wire up gRPC and HTTP servers.
creds, err := credentials.NewServerTLSFromFile(*certFile, *keyFile) creds, err := credentials.NewServerTLSFromFile(*certFile, *keyFile)
if err != nil { if err != nil {
Expand All @@ -51,15 +53,15 @@ func run(svr ktpb.KeyTransparencyAdminServiceServer) {
glog.Exitf("Failed opening cert file %v: %v", *certFile, err) glog.Exitf("Failed opening cert file %v: %v", *certFile, err)
} }
gwmux, err := serverutil.GrpcGatewayMux(*addr, tcreds, gwmux, err := serverutil.GrpcGatewayMux(*addr, tcreds,
ktpb.RegisterKeyTransparencyAdminServiceHandlerFromEndpoint) gpb.RegisterKeyTransparencyAdminServiceHandlerFromEndpoint)
if err != nil { if err != nil {
glog.Exitf("Failed setting up REST proxy: %v", err) glog.Exitf("Failed setting up REST proxy: %v", err)
} }
mux := http.NewServeMux() mux := http.NewServeMux()
mux.Handle("/metrics", promhttp.Handler()) mux.Handle("/metrics", promhttp.Handler())
mux.Handle("/", gwmux) mux.Handle("/", gwmux)


ktpb.RegisterKeyTransparencyAdminServiceServer(grpcServer, svr) gpb.RegisterKeyTransparencyAdminServiceServer(grpcServer, svr)
reflection.Register(grpcServer) reflection.Register(grpcServer)
grpc_prometheus.Register(grpcServer) grpc_prometheus.Register(grpcServer)
grpc_prometheus.EnableHandlingTimeHistogram() grpc_prometheus.EnableHandlingTimeHistogram()
Expand Down
1 change: 1 addition & 0 deletions cmd/keytransparency-server/main.go
Expand Up @@ -40,6 +40,7 @@ import (


gpb "github.com/google/keytransparency/core/proto/keytransparency_v1_grpc" gpb "github.com/google/keytransparency/core/proto/keytransparency_v1_grpc"
gauth "github.com/google/keytransparency/impl/google/authentication" gauth "github.com/google/keytransparency/impl/google/authentication"
_ "github.com/google/trillian/crypto/keys/der/proto"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus" grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
) )


Expand Down
36 changes: 20 additions & 16 deletions core/adminserver/admin_server.go
Expand Up @@ -82,17 +82,19 @@ var (
) )


type server struct { type server struct {
storage adminstorage.Storage storage adminstorage.Storage
client tpb.TrillianAdminClient logAdmin tpb.TrillianAdminClient
keygen keys.ProtoGenerator mapAdmin tpb.TrillianAdminClient
keygen keys.ProtoGenerator
} }


// New returns a KeyTransparencyAdminService implementation. // New returns a KeyTransparencyAdminService implementation.
func New(storage adminstorage.Storage, client tpb.TrillianAdminClient, keygen keys.ProtoGenerator) gpb.KeyTransparencyAdminServiceServer { func New(storage adminstorage.Storage, logAdmin, mapAdmin tpb.TrillianAdminClient, keygen keys.ProtoGenerator) gpb.KeyTransparencyAdminServiceServer {
return &server{ return &server{
storage: storage, storage: storage,
client: client, logAdmin: logAdmin,
keygen: keygen, mapAdmin: mapAdmin,
keygen: keygen,
} }
} }


Expand Down Expand Up @@ -124,20 +126,22 @@ func (s *server) ListDomains(ctx context.Context, in *pb.ListDomainsRequest) (*p


// fetchDomainInfo converts an amdin.Domain object into a pb.Domain object by fetching the relevant info from Trillian. // fetchDomainInfo converts an amdin.Domain object into a pb.Domain object by fetching the relevant info from Trillian.
func (s *server) fetchDomainInfo(ctx context.Context, d *adminstorage.Domain) (*pb.Domain, error) { func (s *server) fetchDomainInfo(ctx context.Context, d *adminstorage.Domain) (*pb.Domain, error) {
logTree, err := s.client.GetTree(ctx, &tpb.GetTreeRequest{TreeId: d.LogID}) logTree, err := s.logAdmin.GetTree(ctx, &tpb.GetTreeRequest{TreeId: d.LogID})
if err != nil { if err != nil {
return nil, err return nil, err
} }
mapTree, err := s.client.GetTree(ctx, &tpb.GetTreeRequest{TreeId: d.MapID}) mapTree, err := s.mapAdmin.GetTree(ctx, &tpb.GetTreeRequest{TreeId: d.MapID})
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &pb.Domain{ return &pb.Domain{
DomainId: d.Domain, DomainId: d.Domain,
Log: logTree, Log: logTree,
Map: mapTree, Map: mapTree,
Vrf: d.VRF, Vrf: d.VRF,
Deleted: d.Deleted, MinInterval: ptypes.DurationProto(d.MinInterval),
MaxInterval: ptypes.DurationProto(d.MaxInterval),
Deleted: d.Deleted,
}, nil }, nil
} }


Expand Down Expand Up @@ -177,13 +181,13 @@ func (s *server) CreateDomain(ctx context.Context, in *pb.CreateDomainRequest) (
// Create Trillian keys. // Create Trillian keys.
logTreeArgs := *logArgs logTreeArgs := *logArgs
logTreeArgs.Tree.Description = fmt.Sprintf("KT domain %s's SMH Log", in.GetDomainId()) logTreeArgs.Tree.Description = fmt.Sprintf("KT domain %s's SMH Log", in.GetDomainId())
logTree, err := s.client.CreateTree(ctx, &logTreeArgs) logTree, err := s.logAdmin.CreateTree(ctx, &logTreeArgs)
if err != nil { if err != nil {
return nil, fmt.Errorf("CreateTree(log): %v", err) return nil, fmt.Errorf("CreateTree(log): %v", err)
} }
mapTreeArgs := *mapArgs mapTreeArgs := *mapArgs
mapTreeArgs.Tree.Description = fmt.Sprintf("KT domain %s's Map", in.GetDomainId()) mapTreeArgs.Tree.Description = fmt.Sprintf("KT domain %s's Map", in.GetDomainId())
mapTree, err := s.client.CreateTree(ctx, &mapTreeArgs) mapTree, err := s.mapAdmin.CreateTree(ctx, &mapTreeArgs)
if err != nil { if err != nil {
return nil, fmt.Errorf("CreateTree(map): %v", err) return nil, fmt.Errorf("CreateTree(map): %v", err)
} }
Expand Down
7 changes: 6 additions & 1 deletion core/adminserver/admin_server_test.go
Expand Up @@ -25,6 +25,7 @@ import (
"github.com/google/trillian" "github.com/google/trillian"
"github.com/google/trillian/crypto/keys/der" "github.com/google/trillian/crypto/keys/der"
"github.com/google/trillian/crypto/keyspb" "github.com/google/trillian/crypto/keyspb"
"github.com/google/trillian/storage/testdb"
"github.com/google/trillian/testonly/integration" "github.com/google/trillian/testonly/integration"


pb "github.com/google/keytransparency/core/proto/keytransparency_v1_proto" pb "github.com/google/keytransparency/core/proto/keytransparency_v1_proto"
Expand All @@ -37,6 +38,10 @@ func vrfKeyGen(ctx context.Context, spec *keyspb.Specification) (proto.Message,
} }


func TestCreateRead(t *testing.T) { func TestCreateRead(t *testing.T) {
// We can only run the integration tests if there is a MySQL instance available.
if provider := testdb.Default(); !provider.IsMySQL() {
t.Skipf("Skipping map integration test, SQL driver is %v", provider.Driver)
}
ctx := context.Background() ctx := context.Background()
storage := fake.NewAdminStorage() storage := fake.NewAdminStorage()


Expand All @@ -45,7 +50,7 @@ func TestCreateRead(t *testing.T) {
if err != nil { if err != nil {
t.Fatalf("Failed to create trillian map server: %v", err) t.Fatalf("Failed to create trillian map server: %v", err)
} }
svr := New(storage, mapEnv.AdminClient, vrfKeyGen) svr := New(storage, mapEnv.AdminClient, mapEnv.AdminClient, vrfKeyGen)


for _, tc := range []struct { for _, tc := range []struct {
domainID string domainID string
Expand Down
9 changes: 7 additions & 2 deletions core/keyserver/keyserver.go
Expand Up @@ -17,6 +17,7 @@ package keyserver


import ( import (
"context" "context"
"database/sql"


"github.com/google/keytransparency/core/adminstorage" "github.com/google/keytransparency/core/adminstorage"
"github.com/google/keytransparency/core/authentication" "github.com/google/keytransparency/core/authentication"
Expand All @@ -31,6 +32,7 @@ import (
"github.com/golang/protobuf/proto" "github.com/golang/protobuf/proto"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status"


authzpb "github.com/google/keytransparency/core/proto/authorization_proto" authzpb "github.com/google/keytransparency/core/proto/authorization_proto"
tpb "github.com/google/keytransparency/core/proto/keytransparency_v1_proto" tpb "github.com/google/keytransparency/core/proto/keytransparency_v1_proto"
Expand Down Expand Up @@ -358,9 +360,12 @@ func (s *Server) GetDomainInfo(ctx context.Context, in *tpb.GetDomainInfoRequest
return nil, grpc.Errorf(codes.InvalidArgument, "Please specify a domain_id") return nil, grpc.Errorf(codes.InvalidArgument, "Please specify a domain_id")
} }
domain, err := s.admin.Read(ctx, in.DomainId, false) domain, err := s.admin.Read(ctx, in.DomainId, false)
if err != nil { if err == sql.ErrNoRows {
glog.Errorf("adminstorage.Read(%v): %v", in.DomainId, err) glog.Errorf("adminstorage.Read(%v): %v", in.DomainId, err)
return nil, grpc.Errorf(codes.Internal, "Cannot fetch domain info") return nil, status.Errorf(codes.NotFound, "Domain %v not found", in.DomainId)
} else if err != nil {
glog.Errorf("adminstorage.Read(%v): %v", in.DomainId, err)
return nil, grpc.Errorf(codes.Internal, "Cannot fetch domain info for %v", in.DomainId)
} }


logTree, err := s.tadmin.GetTree(ctx, &trillian.GetTreeRequest{TreeId: domain.LogID}) logTree, err := s.tadmin.GetTree(ctx, &trillian.GetTreeRequest{TreeId: domain.LogID})
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e715077

Please sign in to comment.