mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-09-18 20:14:48 -04:00
AB#2111 Deploy activation service on cluster init (#205)
* Deploy activation service on cluster init * Use base image with CA certificates for activation service * Improve KMS server Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
parent
84ca9e3070
commit
4842d29aff
29 changed files with 542 additions and 102 deletions
|
@ -5,53 +5,62 @@ import (
|
|||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"github.com/edgelesssys/constellation/internal/constants"
|
||||
"github.com/edgelesssys/constellation/internal/file"
|
||||
"github.com/edgelesssys/constellation/internal/grpc/grpc_klog"
|
||||
"github.com/edgelesssys/constellation/kms/server/kmsapi"
|
||||
"github.com/edgelesssys/constellation/kms/server/kmsapi/kmsproto"
|
||||
"github.com/edgelesssys/constellation/kms/server/setup"
|
||||
"github.com/spf13/afero"
|
||||
"go.uber.org/zap"
|
||||
"k8s.io/klog/v2"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func main() {
|
||||
port := flag.String("p", "9000", "Port gRPC server listens on")
|
||||
port := flag.String("port", "9000", "Port gRPC server listens on")
|
||||
masterSecretPath := flag.String("master-secret", "/constellation/constellation-mastersecret.base64", "Path to the Constellation master secret")
|
||||
|
||||
klog.InitFlags(nil)
|
||||
flag.Parse()
|
||||
defer klog.Flush()
|
||||
|
||||
klog.V(2).Infof("\nConstellation Key Management Service\nVersion: %s", constants.VersionInfo)
|
||||
|
||||
masterKey, err := readMainSecret(*masterSecretPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to read master secret: %v", err)
|
||||
klog.Exitf("Failed to read master secret: %v", err)
|
||||
}
|
||||
|
||||
conKMS, err := setup.SetUpKMS(context.Background(), setup.NoStoreURI, setup.ClusterKMSURI)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to setup KMS: %v", err)
|
||||
klog.Exitf("Failed to setup KMS: %v", err)
|
||||
}
|
||||
|
||||
if err := conKMS.CreateKEK(context.Background(), "Constellation", masterKey); err != nil {
|
||||
log.Fatalf("Failed to create KMS KEK from MasterKey: %v", err)
|
||||
klog.Exitf("Failed to create KMS KEK from MasterKey: %v", err)
|
||||
}
|
||||
|
||||
lis, err := net.Listen("tcp", net.JoinHostPort("0.0.0.0", *port))
|
||||
lis, err := net.Listen("tcp", net.JoinHostPort("", *port))
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to listen: %v", err)
|
||||
klog.Exitf("Failed to listen: %v", err)
|
||||
}
|
||||
|
||||
srv := kmsapi.New(&zap.Logger{}, conKMS)
|
||||
|
||||
// TODO: Launch server with aTLS to allow attestation for clients.
|
||||
grpcServer := grpc.NewServer()
|
||||
grpcServer := grpc.NewServer(
|
||||
grpc.UnaryInterceptor(grpc_klog.LogGRPC(2)),
|
||||
)
|
||||
|
||||
kmsproto.RegisterAPIServer(grpcServer, srv)
|
||||
|
||||
klog.V(2).Infof("Starting key management service on %s", lis.Addr().String())
|
||||
if err := grpcServer.Serve(lis); err != nil {
|
||||
log.Fatalf("Failed to serve: %s", err)
|
||||
klog.Exitf("Failed to serve: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"go.uber.org/zap"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"k8s.io/klog/v2"
|
||||
)
|
||||
|
||||
// API resembles an encryption key management api server through logger, CloudKMS and proto-unimplemented server.
|
||||
|
@ -30,16 +31,19 @@ func New(logger *zap.Logger, conKMS kms.CloudKMS) *API {
|
|||
func (a *API) GetDataKey(ctx context.Context, in *kmsproto.GetDataKeyRequest) (*kmsproto.GetDataKeyResponse, error) {
|
||||
// Error on 0 key length
|
||||
if in.Length == 0 {
|
||||
klog.Error("GetDataKey: requested key length is zero")
|
||||
return nil, status.Error(codes.InvalidArgument, "can't derive key with length zero")
|
||||
}
|
||||
|
||||
// Error on empty DataKeyId
|
||||
if in.DataKeyId == "" {
|
||||
return nil, status.Error(codes.InvalidArgument, "no data key id specified")
|
||||
klog.Error("GetDataKey: no data key ID specified")
|
||||
return nil, status.Error(codes.InvalidArgument, "no data key ID specified")
|
||||
}
|
||||
|
||||
key, err := a.conKMS.GetDEK(ctx, "Constellation", "key-"+in.DataKeyId, int(in.Length))
|
||||
if err != nil {
|
||||
klog.Errorf("GetDataKey: failed to get data key: %v", err)
|
||||
return nil, status.Errorf(codes.Internal, "%v", err)
|
||||
}
|
||||
return &kmsproto.GetDataKeyResponse{DataKey: key}, nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue