+
Skip to content

Conversation

WashingtonKK
Copy link
Contributor

@WashingtonKK WashingtonKK commented Nov 1, 2024

What type of PR is this?

This is a refactor of agent and manager grpc configs.

What does this do?

  • Introduced a new configuration structure for gRPC clients and servers, enhancing integration and management of settings.

Which issue(s) does this PR fix/relate to?

Have you included tests for your changes?

Yes

Did you document any new/modified feature?

Notes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should not be tracked

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these changes are not needed

Comment on lines 24 to 26
CertFile string `env:"SERVER_CERT" envDefault:""`
KeyFile string `env:"SERVER_KEY" envDefault:""`
ServerCAFile string `env:"SERVER_CA_CERTS" envDefault:""`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be part of server base config

Comment on lines 66 to 85
type BaseConfig struct {
URL string `env:"URL" envDefault:"localhost:7001"`
Timeout time.Duration `env:"TIMEOUT" envDefault:"60s"`
}

type ManagerConfig struct {
BaseConfig
ClientCert string `env:"CLIENT_CERT" envDefault:""`
ClientKey string `env:"CLIENT_KEY" envDefault:""`
ServerCAFile string `env:"SERVER_CA_CERTS" envDefault:""`
BackendInfo string `env:"BACKEND_INFO" envDefault:""`
ClientTLS bool `env:"CLIENT_TLS" envDefault:"false"`

}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need cli config as well(agent client)

var _ Client = (*client)(nil)

func NewClient(cfg Config) (Client, error) {
func NewClient(cfg ManagerConfig) (Client, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should handle both manager and agent client configs

@drasko
Copy link
Contributor

drasko commented Nov 1, 2024

Fix the title

@WashingtonKK WashingtonKK changed the title cocos 209 (DRAFT) COCOS - 209 - Restructure agent and manager gRPC config Nov 2, 2024
@WashingtonKK WashingtonKK marked this pull request as draft November 2, 2024 09:04
Copy link

codecov bot commented Nov 3, 2024

Codecov Report

Attention: Patch coverage is 76.92308% with 30 lines in your changes missing coverage. Please review.

Project coverage is 66.38%. Comparing base (92a4f8b) to head (58dc3ef).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
internal/server/grpc/grpc.go 74.02% 13 Missing and 7 partials ⚠️
pkg/clients/grpc/connect.go 89.13% 4 Missing and 1 partial ⚠️
internal/server/server.go 0.00% 4 Missing ⚠️
cli/sdk.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #297      +/-   ##
==========================================
+ Coverage   66.15%   66.38%   +0.23%     
==========================================
  Files          53       53              
  Lines        4328     4349      +21     
==========================================
+ Hits         2863     2887      +24     
+ Misses       1195     1192       -3     
  Partials      270      270              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@WashingtonKK WashingtonKK changed the title (DRAFT) COCOS - 209 - Restructure agent and manager gRPC config COCOS - 209 - Restructure agent and manager gRPC config Nov 3, 2024
@WashingtonKK WashingtonKK marked this pull request as ready for review November 3, 2024 21:14
@WashingtonKK WashingtonKK self-assigned this Nov 3, 2024

func New(ctx context.Context, cancel context.CancelFunc, name string, config server.Config, registerService serviceRegister, logger *slog.Logger, qp client.QuoteProvider, authSvc auth.Authenticator) server.Server {
listenFullAddress := fmt.Sprintf("%s:%s", config.Host, config.Port)
func New(ctx context.Context, cancel context.CancelFunc, name string, config server.AgentConfig, registerService serviceRegister, logger *slog.Logger, qp client.QuoteProvider, authSvc auth.Authenticator) server.Server {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is used by computations server which is different from agent, use interface type and type assertion things specific to agent server


func New(ctx context.Context, cancel context.CancelFunc, name string, config server.Config, registerService serviceRegister, logger *slog.Logger, qp client.QuoteProvider, authSvc auth.Authenticator) server.Server {
listenFullAddress := fmt.Sprintf("%s:%s", config.Host, config.Port)
func New(ctx context.Context, cancel context.CancelFunc, name string, config server.AgentConfig, registerService serviceRegister, logger *slog.Logger, qp client.QuoteProvider, authSvc auth.Authenticator) server.Server {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function is used by computations server which is different from agent, use interface type and type assertion things specific to agent server

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can create a custom interface with a method such as getBaseConfig, and then do type assertion for specific fields like attested tls

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can create a custom interface with a method such as getBaseConfig, and then do type assertion for specific fields like attested tls

// NewAgentClient creates new agent gRPC client instance.
func NewAgentClient(ctx context.Context, cfg grpc.Config) (grpc.Client, agent.AgentServiceClient, error) {
client, err := grpc.NewClient(cfg)
func NewAgentClient(ctx context.Context, cfg server.AgentConfig) (grpc.Client, agent.AgentServiceClient, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client and server config are distinct

// NewAgentClient creates new agent gRPC client instance.
func NewAgentClient(ctx context.Context, cfg grpc.Config) (grpc.Client, agent.AgentServiceClient, error) {
client, err := grpc.NewClient(cfg)
func NewAgentClient(ctx context.Context, cfg server.AgentConfig) (grpc.Client, agent.AgentServiceClient, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client and server config are distinct

// NewAgentClient creates new agent gRPC client instance.
func NewAgentClient(ctx context.Context, cfg grpc.Config) (grpc.Client, agent.AgentServiceClient, error) {
client, err := grpc.NewClient(cfg)
func NewAgentClient(ctx context.Context, cfg server.AgentConfig) (grpc.Client, agent.AgentServiceClient, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client and server config are distinct

// NewAgentClient creates new agent gRPC client instance.
func NewAgentClient(ctx context.Context, cfg grpc.Config) (grpc.Client, agent.AgentServiceClient, error) {
client, err := grpc.NewClient(cfg)
func NewAgentClient(ctx context.Context, cfg server.AgentConfig) (grpc.Client, agent.AgentServiceClient, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

client and server config are distinct


type ManagerConfig struct {
grpc.BaseConfig
BackendInfo string `env:"BACKEND_INFO" envDefault:""`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

manager client config is not configured using backendinfo, this exclusive to agent client(CLI). also clienttls should be part of base client config

Comment on lines 65 to 67
BackendInfo string `env:"BACKEND_INFO" envDefault:""`
ClientTLS bool `env:"CLIENT_TLS" envDefault:"false"`
AttestedTLS bool `env:"ATTESTED_TLS" envDefault:"false"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backendinfo and attested tls are only for agent client(CLI). This needs to bbe distinguished. Use interfaces for configuration purposes. clienttls is common for all clients and should be part of base config

Comment on lines 65 to 67
BackendInfo string `env:"BACKEND_INFO" envDefault:""`
ClientTLS bool `env:"CLIENT_TLS" envDefault:"false"`
AttestedTLS bool `env:"ATTESTED_TLS" envDefault:"false"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

backendinfo and attested tls are only for agent client(CLI). This needs to bbe distinguished. Use interfaces for configuration purposes. clienttls is common for all clients and should be part of base config

@WashingtonKK WashingtonKK force-pushed the cocos-209 branch 2 times, most recently from 6e7b198 to 9cf4c5f Compare November 29, 2024 07:37

type ManagerClientConfig struct {
ClientConfig
AttestedTLS bool `env:"ATTESTED_TLS" envDefault:"false"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

manager cannot have attested TLS

Comment on lines 133 to 137
grpcServerConfig := server.ServerConfig{
BaseConfig: server.BaseConfig{
URL: fmt.Sprintf("localhost:%s", defaultPort),
},
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

env only has host and port, so set url in code after parsing config


type AgentClientConfig struct {
ClientConfig
AttestationPolicy string `env:"ATTESTATION_POLICY" envDefault:""`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

attested tls bool?

CertFile string `env:"SERVER_CERT" envDefault:""`
KeyFile string `env:"SERVER_KEY" envDefault:""`
ClientCAFile string `env:"CLIENT_CA_CERTS" envDefault:""`
ClientTLS bool `env:"CLIENT_TLS" envDefault:"false"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this added

Comment on lines 62 to 63
CertFile string `env:"SERVER_CERT" envDefault:""`
KeyFile string `env:"SERVER_KEY" envDefault:""`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

server certs are not used on client

}
switch s := cfg.(type) {
case AgentClientConfig:
if s.ClientTLS {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is breaking existing functionality

case AgentClientConfig:
if s.AttestedTLS {
err := ReadAttestationPolicy(s.AttestationPolicy, &quoteprovider.AttConfigurationSEVSNP)
if err != nil {
return nil, secure, errors.Wrap(fmt.Errorf("failed to read Attestation Policy"), err)
}

tlsConfig := &tls.Config{
InsecureSkipVerify: true,
VerifyPeerCertificate: verifyPeerCertificateATLS,
tlsConfig := &tls.Config{
InsecureSkipVerify: true,
VerifyPeerCertificate: verifyPeerCertificateATLS,
}
tc = credentials.NewTLS(tlsConfig)
opts = append(opts, grpc.WithContextDialer(CustomDialer))
secure = withaTLS
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will fail if agentconfig is any other config other than atls

Comment on lines 78 to 77
func (s ClientConfig) GetBaseConfig() BaseConfig {
return s.BaseConfig
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need both client and base config, clients are only two CLI(Agent) and manager

}
default:
conf := cfg.GetBaseConfig()
if conf.ServerCAFile != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

repeated in loadTLSConfig

opts = append(opts, grpc.WithContextDialer(CustomDialer))
secure = withaTLS
} else {
if s.ServerCAFile != "" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

enhance clients

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

restructure config

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

refactor

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

rebase

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

rebase

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

use separate configuration

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

fix tests

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

fix config

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

refactor

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

Lint

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

fix tests

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

add tests

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

add test case

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

add test case

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

refactor

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

further refactor'

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

add tests

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>

rebase

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
}

func TestServerStartWithTLSFile(t *testing.T) {
func TestServerStartWithTLS(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do not rename the test name here

assert.Contains(t, logContent, "TestServer service gRPC server listening at localhost:0 with TLS")
}

func TestServerStartWithMTLS(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Already in another test cas

Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Copy link
Contributor

@drasko drasko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@drasko drasko merged commit ec426e5 into ultravioletrs:main Dec 4, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature: Restructure Configuration for Manager and Agent Services

3 participants

点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载