-
Notifications
You must be signed in to change notification settings - Fork 13
NOISSUE - Update cocos to match certs changes #520
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
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #520 +/- ##
==========================================
+ Coverage 67.67% 67.81% +0.14%
==========================================
Files 76 76
Lines 6833 6792 -41
==========================================
- Hits 4624 4606 -18
+ Misses 1860 1844 -16
+ Partials 349 342 -7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
pkg/atls/atls.go
Outdated
| certsEndpoint := "certs" | ||
| csrEndpoint := "csrs" | ||
| endpoint := fmt.Sprintf("%s/%s/%s", certsEndpoint, csrEndpoint, cvmId) | ||
| endpoint := fmt.Sprintf("%s/%s/%s/%s", domainId, certsEndpoint, csrEndpoint, cvmId) |
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.
let's import and use sdk directly. Import sdk in main.go if caURL is provided and pass the sdk to internal or where needed. if not provided use the fallback. we don't need to duplicate sdk methods in am-certs
cmd/agent/main.go
Outdated
| CertsURL: cfg.CAUrl, | ||
| HostURL: cfg.CAUrl, |
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 looks like it will result in an error if both are provided, or update certs sdk, since it only needs one url
cmd/agent/main.go
Outdated
| HostURL: cfg.CAUrl, | ||
| } | ||
|
|
||
| crtSDK := certsSDK.NewSDK(ctrsdkconfig) |
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.
only init sdk if url is provided, otherwise agent should use default
cmd/agent/main.go
Outdated
| } | ||
|
|
||
| mc, err := cvmsapi.NewClient(pc, svc, eventsLogsQueue, logger, server.NewServer(logger, svc, cfg.AgentGrpcHost, cfg.CAUrl, cfg.CVMId), storageDir, reconnectFn, cvmGRPCClient) | ||
| mc, err := cvmsapi.NewClient(pc, svc, eventsLogsQueue, logger, server.NewServer(logger, svc, cfg.AgentGrpcHost, crtSDK, cfg.CAUrl, cfg.CVMId, cfg.DomainId), storageDir, reconnectFn, cvmGRPCClient) |
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.
update the function signature now that sdk is being passed remove redundant values
internal/server/grpc/grpc.go
Outdated
| var _ server.Server = (*Server)(nil) | ||
|
|
||
| func New(ctx context.Context, cancel context.CancelFunc, name string, config server.ServerConfiguration, registerService serviceRegister, logger *slog.Logger, authSvc auth.Authenticator, caUrl string, cvmId string) server.Server { | ||
| func New(ctx context.Context, cancel context.CancelFunc, name string, config server.ServerConfiguration, registerService serviceRegister, logger *slog.Logger, authSvc auth.Authenticator, casdk sdk.SDK, caUrl, cvmId string, domainId string) 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.
remove values we no longer need
internal/server/grpc/grpc.go
Outdated
| var _ server.Server = (*Server)(nil) | ||
|
|
||
| func New(ctx context.Context, cancel context.CancelFunc, name string, config server.ServerConfiguration, registerService serviceRegister, logger *slog.Logger, authSvc auth.Authenticator, caUrl string, cvmId string) server.Server { | ||
| func New(ctx context.Context, cancel context.CancelFunc, name string, config server.ServerConfiguration, registerService serviceRegister, logger *slog.Logger, authSvc auth.Authenticator, casdk sdk.SDK, caUrl, cvmId string, domainId string) 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.
remove values we no longer need
internal/server/grpc/grpc.go
Outdated
| var _ server.Server = (*Server)(nil) | ||
|
|
||
| func New(ctx context.Context, cancel context.CancelFunc, name string, config server.ServerConfiguration, registerService serviceRegister, logger *slog.Logger, authSvc auth.Authenticator, caUrl string, cvmId string) server.Server { | ||
| func New(ctx context.Context, cancel context.CancelFunc, name string, config server.ServerConfiguration, registerService serviceRegister, logger *slog.Logger, authSvc auth.Authenticator, casdk sdk.SDK, caUrl, cvmId string, domainId string) 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.
remove values we no longer need
internal/server/grpc/grpc.go
Outdated
| tlsConfig := &tls.Config{ | ||
| ClientAuth: tls.NoClientCert, | ||
| GetCertificate: atls.GetCertificate(s.caUrl, s.cvmId), | ||
| GetCertificate: atls.GetCertificate(s.caSDK, s.caUrl, s.cvmId, s.domainId), |
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 are you passing caurl and sdk at the same time
pkg/atls/atls.go
Outdated
| url := fmt.Sprintf("%s/%s?%s", caUrl, endpoint, query_string) | ||
|
|
||
| _, body, err := processRequest(http.MethodPost, url, data, nil, http.StatusOK) | ||
| cert, err := caSDK.IssueFromCSR(cvmId, ttlString, string(csr.CSR), domainId, "") |
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.
which value is empty string
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.
also shouldn't this be IssueFromCSRInternal absmach/certs#156 (comment)
pkg/atls/atls.go
Outdated
| url := fmt.Sprintf("%s/%s?%s", caUrl, endpoint, query_string) | ||
|
|
||
| _, body, err := processRequest(http.MethodPost, url, data, nil, http.StatusOK) | ||
| cert, err := caSDK.IssueFromCSRInternal(cvmId, ttlString, string(csr.CSR)) |
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.
there should be a token/secret
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 is yet to be added on certs.
test/cvms/main.go
Outdated
| caSDK := sdk.NewSDK(sdk.Config{ | ||
| CertsURL: caUrl, | ||
| }) |
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.
test cvm server does not use this, only agent, remove
|
@WashingtonKK Please rebase. |
1 similar comment
|
@WashingtonKK Please rebase. |
drasko
left a comment
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
| LogLevel string `env:"AGENT_LOG_LEVEL" envDefault:"debug"` | ||
| Vmpl int `env:"AGENT_VMPL" envDefault:"2"` | ||
| AgentGrpcHost string `env:"AGENT_GRPC_HOST" envDefault:"0.0.0.0"` | ||
| CAUrl string `env:"AGENT_CVM_CA_URL" envDefault:""` | ||
| CVMId string `env:"AGENT_CVM_ID" envDefault:""` | ||
| DomainId string `env:"AGENT_DOMAIN_ID" envDefault:""` | ||
| CertsToken string `env:"AGENT_CERTS_TOKEN" envDefault:""` | ||
| AgentMaaURL string `env:"AGENT_MAA_URL" envDefault:"https://sharedeus2.eus2.attest.azure.net"` | ||
| AgentOSBuild string `env:"AGENT_OS_BUILD" envDefault:"UVC"` | ||
| AgentOSDistro string `env:"AGENT_OS_DISTRO" envDefault:"UVC"` | ||
| AgentOSType string `env:"AGENT_OS_TYPE" envDefault:"UVC"` |
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.
update agent service readme, also open a pr in cocos docs
manager/service.go
Outdated
| agentCvmClientKey = "AGENT_CVM_GRPC_CLIENT_KEY" | ||
| agentCvmServerCaCertKey = "AGENT_CVM_GRPC_SERVER_CA_CERTS" | ||
| agentCvmId = "AGENT_CVM_ID" | ||
| agentDomainId = "AGENT_DOMAIN_ID" |
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.
what about ca token
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.
also test to make sure this works from manager since this contant seems to be missing
manager/service.go
Outdated
| agentLogLevelKey: req.AgentLogLevel, | ||
| agentCvmGrpcUrlKey: req.AgentCvmServerUrl, | ||
| agentCvmId: id, | ||
| agentDomainId: req.DomainId, |
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, test manager with agent
pkg/atls/atls.go
Outdated
| type CSRRequest struct { | ||
| CSR string `json:"csr,omitempty"` | ||
| } |
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.
import from certs
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.
We do not have the CSRRequest on certs.
pkg/atls/atls.go
Outdated
| } | ||
|
|
||
| func (c *CAClient) processRequest(method, reqURL string, data []byte, headers map[string]string, expectedRespCodes ...int) (http.Header, []byte, errors.SDKError) { | ||
| func (c *CAClient) processRequest(method, reqURL string, data []byte, headers map[string]string, token string, expectedRespCodes ...int) (http.Header, []byte, errors.SDKError) { |
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.
use sdk as stated in a previous comment we don't need to redifine this here
test/cvms/main.go
Outdated
| domainId string | ||
| cvmId string |
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 are not defined here, since you don't send them to agent and do not use them for anything
test/cvms/main.go
Outdated
| flagSet.StringVar(&cvmId, "cvm-id", "", "UUID for a CVM, must be specified if aTLS is used") | ||
| flagSet.StringVar(&domainId, "domain-id", "", "Domain ID for the attestation service, must be specified if aTLS is used") |
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
pkg/atls/atls.go
Outdated
|
|
||
| func (c *CAClient) RequestCertificate(csrMetadata certs.CSRMetadata, privateKey *ecdsa.PrivateKey, cvmID string, ttl time.Duration) ([]byte, error) { | ||
| func (c *CAClient) RequestCertificate(csrMetadata certs.CSRMetadata, privateKey *ecdsa.PrivateKey, cvmID, domainId string, ttl time.Duration) ([]byte, error) { | ||
| csr, sdkerr := certscli.CreateCSR(csrMetadata, privateKey) |
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.
one of the first comments on this pr was to remove cli
|
@WashingtonKK Please rebase. |
| | AGENT_CVM_GRPC_SERVER_KEY | Path to gRPC server key in pem format | "" | | ||
| | AGENT_CVM_GRPC_SERVER_CA_CERTS | Path to gRPC server CA certificate | "" | | ||
| | AGENT_CVM_GRPC_CLIENT_CA_CERTS | Path to gRPC client CA certificate | "" | | ||
| | AGENT_CVM_CA_URL | URL for CA service, if provided it will be used for certificate generation, used only with aTLS at the moment | "" | |
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.
domain id is missing
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.
DomainId is not used.
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.
Remove it from agent
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
pkg/atls/atls_test.go
Outdated
| generator, err := NewProvider(nil, attestation.SNPvTPM, caURL, cvmID) | ||
| assert.NoError(t, err) | ||
| assert.NotNil(t, generator) | ||
| // Skip CA-signed test for now as it requires actual SDK implementation |
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.
use mocked sdk, do not skip tests
SammyOina
left a comment
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.
more comments
cmd/agent/main.go
Outdated
| AgentGrpcHost string `env:"AGENT_GRPC_HOST" envDefault:"0.0.0.0"` | ||
| CAUrl string `env:"AGENT_CVM_CA_URL" envDefault:""` | ||
| CVMId string `env:"AGENT_CVM_ID" envDefault:""` | ||
| DomainId string `env:"AGENT_DOMAIN_ID" 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.
this is unused
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.
cmd/agent/main.go
Outdated
| AgentGrpcHost string `env:"AGENT_GRPC_HOST" envDefault:"0.0.0.0"` | ||
| CAUrl string `env:"AGENT_CVM_CA_URL" envDefault:""` | ||
| CVMId string `env:"AGENT_CVM_ID" envDefault:""` | ||
| DomainId string `env:"AGENT_DOMAIN_ID" 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.
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
Signed-off-by: WashingtonKK <washingtonkigan@gmail.com>
What type of PR is this?
What does this do?
Which issue(s) does this PR fix/relate to?
Have you included tests for your changes?
Did you document any new/modified feature?
Notes