-
Notifications
You must be signed in to change notification settings - Fork 12
COCOS - 209 - Restructure agent and manager gRPC config #297
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
.vscode/launch.json
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should not be tracked
There was a problem hiding this comment.
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
internal/server/server.go
Outdated
CertFile string `env:"SERVER_CERT" envDefault:""` | ||
KeyFile string `env:"SERVER_KEY" envDefault:""` | ||
ServerCAFile string `env:"SERVER_CA_CERTS" envDefault:""` |
There was a problem hiding this comment.
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
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"` | ||
|
||
} |
There was a problem hiding this comment.
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)
pkg/clients/grpc/connect.go
Outdated
var _ Client = (*client)(nil) | ||
|
||
func NewClient(cfg Config) (Client, error) { | ||
func NewClient(cfg ManagerConfig) (Client, error) { |
There was a problem hiding this comment.
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
Fix the title |
ed5284e
to
335a90c
Compare
Codecov ReportAttention: Patch coverage is
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. |
335a90c
to
8c9e4fe
Compare
internal/server/grpc/grpc.go
Outdated
|
||
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 { |
There was a problem hiding this comment.
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
internal/server/grpc/grpc.go
Outdated
|
||
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
pkg/clients/grpc/agent/agent.go
Outdated
// 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) { |
There was a problem hiding this comment.
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
pkg/clients/grpc/agent/agent.go
Outdated
// 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) { |
There was a problem hiding this comment.
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
pkg/clients/grpc/agent/agent.go
Outdated
// 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) { |
There was a problem hiding this comment.
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
pkg/clients/grpc/agent/agent.go
Outdated
// 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) { |
There was a problem hiding this comment.
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
pkg/clients/grpc/manager/manager.go
Outdated
|
||
type ManagerConfig struct { | ||
grpc.BaseConfig | ||
BackendInfo string `env:"BACKEND_INFO" envDefault:""` |
There was a problem hiding this comment.
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
pkg/clients/grpc/connect.go
Outdated
BackendInfo string `env:"BACKEND_INFO" envDefault:""` | ||
ClientTLS bool `env:"CLIENT_TLS" envDefault:"false"` | ||
AttestedTLS bool `env:"ATTESTED_TLS" envDefault:"false"` |
There was a problem hiding this comment.
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
pkg/clients/grpc/connect.go
Outdated
BackendInfo string `env:"BACKEND_INFO" envDefault:""` | ||
ClientTLS bool `env:"CLIENT_TLS" envDefault:"false"` | ||
AttestedTLS bool `env:"ATTESTED_TLS" envDefault:"false"` |
There was a problem hiding this comment.
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
6e7b198
to
9cf4c5f
Compare
pkg/clients/grpc/connect.go
Outdated
|
||
type ManagerClientConfig struct { | ||
ClientConfig | ||
AttestedTLS bool `env:"ATTESTED_TLS" envDefault:"false"` |
There was a problem hiding this comment.
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
grpcServerConfig := server.ServerConfig{ | ||
BaseConfig: server.BaseConfig{ | ||
URL: fmt.Sprintf("localhost:%s", defaultPort), | ||
}, | ||
} |
There was a problem hiding this comment.
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:""` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attested tls bool?
pkg/clients/grpc/connect.go
Outdated
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"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why was this added
pkg/clients/grpc/connect.go
Outdated
CertFile string `env:"SERVER_CERT" envDefault:""` | ||
KeyFile string `env:"SERVER_KEY" envDefault:""` |
There was a problem hiding this comment.
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
pkg/clients/grpc/connect.go
Outdated
} | ||
switch s := cfg.(type) { | ||
case AgentClientConfig: | ||
if s.ClientTLS { |
There was a problem hiding this comment.
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
pkg/clients/grpc/connect.go
Outdated
case AgentClientConfig: | ||
if s.AttestedTLS { | ||
err := ReadAttestationPolicy(s.AttestationPolicy, "eprovider.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 | ||
} |
There was a problem hiding this comment.
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
pkg/clients/grpc/connect.go
Outdated
func (s ClientConfig) GetBaseConfig() BaseConfig { | ||
return s.BaseConfig | ||
} |
There was a problem hiding this comment.
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
pkg/clients/grpc/connect.go
Outdated
} | ||
default: | ||
conf := cfg.GetBaseConfig() | ||
if conf.ServerCAFile != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
repeated in loadTLSConfig
pkg/clients/grpc/connect.go
Outdated
opts = append(opts, grpc.WithContextDialer(CustomDialer)) | ||
secure = withaTLS | ||
} else { | ||
if s.ServerCAFile != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
811e3df
to
3553ddb
Compare
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>
3553ddb
to
28c7511
Compare
internal/server/grpc/grpc_test.go
Outdated
} | ||
|
||
func TestServerStartWithTLSFile(t *testing.T) { | ||
func TestServerStartWithTLS(t *testing.T) { |
There was a problem hiding this comment.
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
internal/server/grpc/grpc_test.go
Outdated
assert.Contains(t, logContent, "TestServer service gRPC server listening at localhost:0 with TLS") | ||
} | ||
|
||
func TestServerStartWithMTLS(t *testing.T) { |
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
What type of PR is this?
This is a refactor of agent and manager grpc configs.
What does this do?
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