mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
67f939fc66
* manager, cli and agent vtpm support * rebase and changed atls for vtpm * deleted unused code * changed chekproto.yaml script so it find the manager proto file correctly * fixe manager proto version * fix agent tests * fix server agent test * fix attestation test * fix attestation test gofumpt * created dummy RWC for TPM * fix comment * add default PCR values * rebase main * fix rust ci and missing header * changed embedded attestation to VMPL 2 * fix unused impot * fix pkg test * address attestation type * fix agent attestation test * add prc15 check * fix comments * fix cli tests * add doc * add mock for LeveledQuoteProvider when SEV-SNP device is not found Signed-off-by: Sammy Oina <sammyoina@gmail.com> * fix manager reading attestation policy * refactor PCR value checks and update attestation policy values Signed-off-by: Sammy Oina <sammyoina@gmail.com> * fix tests for sev and grpc --------- Signed-off-by: Sammy Oina <sammyoina@gmail.com> Co-authored-by: Sammy Oina <sammyoina@gmail.com>
97 lines
2.2 KiB
Go
97 lines
2.2 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package server
|
|
|
|
import (
|
|
context "context"
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"github.com/ultravioletrs/cocos/agent"
|
|
agentgrpc "github.com/ultravioletrs/cocos/agent/api/grpc"
|
|
"github.com/ultravioletrs/cocos/agent/auth"
|
|
"github.com/ultravioletrs/cocos/internal/server"
|
|
grpcserver "github.com/ultravioletrs/cocos/internal/server/grpc"
|
|
"github.com/ultravioletrs/cocos/pkg/attestation/quoteprovider"
|
|
"google.golang.org/grpc"
|
|
"google.golang.org/grpc/reflection"
|
|
)
|
|
|
|
const (
|
|
svcName = "agent"
|
|
defSvcGRPCPort = "7002"
|
|
)
|
|
|
|
type AgentServer interface {
|
|
Start(cfg agent.AgentConfig, cmp agent.Computation) error
|
|
Stop() error
|
|
}
|
|
|
|
type agentServer struct {
|
|
gs server.Server
|
|
logger *slog.Logger
|
|
svc agent.Service
|
|
}
|
|
|
|
func NewServer(logger *slog.Logger, svc agent.Service) AgentServer {
|
|
return &agentServer{
|
|
logger: logger,
|
|
svc: svc,
|
|
}
|
|
}
|
|
|
|
func (as *agentServer) Start(cfg agent.AgentConfig, cmp agent.Computation) error {
|
|
if cfg.Port == "" {
|
|
cfg.Port = defSvcGRPCPort
|
|
}
|
|
|
|
agentGrpcServerConfig := server.AgentConfig{
|
|
ServerConfig: server.ServerConfig{
|
|
BaseConfig: server.BaseConfig{
|
|
Host: cfg.Host,
|
|
Port: cfg.Port,
|
|
CertFile: cfg.CertFile,
|
|
KeyFile: cfg.KeyFile,
|
|
ServerCAFile: cfg.ServerCAFile,
|
|
ClientCAFile: cfg.ClientCAFile,
|
|
},
|
|
},
|
|
AttestedTLS: cfg.AttestedTls,
|
|
}
|
|
|
|
registerAgentServiceServer := func(srv *grpc.Server) {
|
|
reflection.Register(srv)
|
|
agent.RegisterAgentServiceServer(srv, agentgrpc.NewServer(as.svc))
|
|
}
|
|
|
|
authSvc, err := auth.New(cmp)
|
|
if err != nil {
|
|
as.logger.WithGroup(cmp.ID).Error(fmt.Sprintf("failed to create auth service %s", err.Error()))
|
|
return err
|
|
}
|
|
|
|
qp, err := quoteprovider.GetLeveledQuoteProvider()
|
|
if err != nil {
|
|
as.logger.Error(fmt.Sprintf("failed to create quote provider %s", err.Error()))
|
|
return err
|
|
}
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
as.gs = grpcserver.New(ctx, cancel, svcName, agentGrpcServerConfig, registerAgentServiceServer, as.logger, qp, authSvc)
|
|
|
|
go func() {
|
|
err := as.gs.Start()
|
|
if err != nil {
|
|
as.logger.Error(fmt.Sprintf("failed to start grpc server %s", err.Error()))
|
|
}
|
|
}()
|
|
|
|
return nil
|
|
}
|
|
|
|
func (as *agentServer) Stop() error {
|
|
return as.gs.Stop()
|
|
}
|