mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
c1cbcec851
CI / lint (push) Has been cancelled
CI / test (agent) (push) Has been cancelled
CI / test (cli) (push) Has been cancelled
CI / test (cmd) (push) Has been cancelled
CI / test (internal) (push) Has been cancelled
CI / test (manager, true) (push) Has been cancelled
CI / test (pkg) (push) Has been cancelled
CI / upload-coverage (push) Has been cancelled
* feat: Introduce Go-based CoRIM generation and deprecate Rust attestation policy scripts. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Update dependencies and refactor attestation policy handling Signed-off-by: Sammy Oina <sammyoina@gmail.com> * refactor: Migrate attestation verification to use CoRIM and remove deprecated policy handling and EAT verification tests. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Removed the `tdx` and `sev-snp` attestation policy scripts and their build configurations, along with related build and installation steps from the main Makefile. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * chore: Remove Rust CI workflow and Cargo Dependabot configuration, and enhance Go test setup for attestation policy paths. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * refactor: Use WriteString instead of Write([]byte) for writing policy file content in test. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Refactor `ca-bundle` command to fetch bundles by product string using a configurable HTTP getter with improved error handling, and simplify `attestation_policy` command usage. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * fix: ignore return value of cmd.Help() Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Implement CoRIM generation for Azure and GCP attestation policies and add a CLI command to download and verify GCP OVMF files. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Upgrade Python virtual environment setup to include setuptools and wheel, append computation ID to Docker container names, and improve test robustness with error assertions and conditional skips for runtime tests. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * test: Enhance attestation verification tests, including CoRIM integration and specific platform types like Azure SNP, vTPM, TDX, and IGVM. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Add comprehensive test cases for `VerifyWithCoRIM` including success and measurement mismatch, and refine reference value validation. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Add Azure and TDX attestation verification tests and abstract external service dependencies for improved testability. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * feat: Add new test cases for Azure measurement extraction, EAT platform types, IGVM measurement stopping, vTPM CoRIM verification, and GCP OVMF download CLI. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * test: enhance CLI CoRIM generation and ATLS certificate verification tests, and refactor the Azure MAA client to use an interface. Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: Sammy Oina <sammyoina@gmail.com>
171 lines
4.8 KiB
Go
171 lines
4.8 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
package cli
|
|
|
|
import (
|
|
"os"
|
|
"time"
|
|
|
|
"github.com/fatih/color"
|
|
"github.com/spf13/cobra"
|
|
"github.com/ultravioletrs/cocos/manager"
|
|
)
|
|
|
|
const (
|
|
serverURL = "server-url"
|
|
serverCA = "server-ca"
|
|
clientKey = "client-key"
|
|
clientCrt = "client-crt"
|
|
caUrl = "ca-url"
|
|
logLevel = "log-level"
|
|
ttlFlag = "ttl"
|
|
)
|
|
|
|
var (
|
|
agentCVMServerUrl string
|
|
agentCVMServerCA string
|
|
agentCVMClientKey string
|
|
agentCVMClientCrt string
|
|
agentCVMCaUrl string
|
|
agentLogLevel string
|
|
ttl time.Duration
|
|
awsAccessKeyId string
|
|
awsSecretAccessKey string
|
|
awsEndpointUrl string
|
|
awsRegion string
|
|
aaKbsParams string
|
|
)
|
|
|
|
func (c *CLI) NewCreateVMCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "create-vm",
|
|
Short: "Create a new virtual machine",
|
|
Example: `create-vm`,
|
|
Args: cobra.ExactArgs(0),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
if c.connectErr != nil {
|
|
printError(cmd, "Failed to connect to manager: %v ❌ ", c.connectErr)
|
|
return
|
|
}
|
|
if c.managerClient == nil {
|
|
if err := c.InitializeManagerClient(cmd); err != nil {
|
|
printError(cmd, "Failed to connect to manager: %v ❌ ", err)
|
|
return
|
|
}
|
|
}
|
|
defer c.Close()
|
|
|
|
createReq, err := loadCerts()
|
|
if err != nil {
|
|
printError(cmd, "Error loading certs: %v ❌ ", err)
|
|
return
|
|
}
|
|
|
|
createReq.AgentCvmServerUrl = agentCVMServerUrl
|
|
createReq.AgentLogLevel = agentLogLevel
|
|
createReq.AgentCvmCaUrl = agentCVMCaUrl
|
|
createReq.AwsAccessKeyId = awsAccessKeyId
|
|
createReq.AwsSecretAccessKey = awsSecretAccessKey
|
|
createReq.AwsEndpointUrl = awsEndpointUrl
|
|
createReq.AwsRegion = awsRegion
|
|
createReq.AaKbsParams = aaKbsParams
|
|
|
|
if ttl > 0 {
|
|
createReq.Ttl = ttl.String()
|
|
}
|
|
|
|
cmd.Println("🔗 Creating a new virtual machine")
|
|
|
|
res, err := c.managerClient.CreateVm(cmd.Context(), createReq)
|
|
if err != nil {
|
|
printError(cmd, "Error creating virtual machine: %v ❌ ", err)
|
|
return
|
|
}
|
|
|
|
cmd.Println(color.New(color.FgGreen).Sprintf("✅ Virtual machine created successfully with id %s and port %s", res.CvmId, res.ForwardedPort))
|
|
},
|
|
}
|
|
|
|
cmd.Flags().StringVar(&agentCVMServerUrl, serverURL, "", "CVM server URL")
|
|
cmd.Flags().StringVar(&agentCVMServerCA, serverCA, "", "CVM server CA")
|
|
cmd.Flags().StringVar(&agentCVMClientKey, clientKey, "", "CVM client key")
|
|
cmd.Flags().StringVar(&agentCVMClientCrt, clientCrt, "", "CVM client crt")
|
|
cmd.Flags().StringVar(&agentCVMCaUrl, caUrl, "", "CVM CA service URL")
|
|
cmd.Flags().StringVar(&agentLogLevel, logLevel, "", "Agent Log level")
|
|
cmd.Flags().DurationVar(&ttl, ttlFlag, 0, "TTL for the VM")
|
|
cmd.Flags().StringVar(&awsAccessKeyId, "aws-access-key-id", "", "AWS Access Key ID for S3/MinIO")
|
|
cmd.Flags().StringVar(&awsSecretAccessKey, "aws-secret-access-key", "", "AWS Secret Access Key for S3/MinIO")
|
|
cmd.Flags().StringVar(&awsEndpointUrl, "aws-endpoint-url", "", "AWS Endpoint URL (for MinIO or custom S3)")
|
|
cmd.Flags().StringVar(&awsRegion, "aws-region", "", "AWS Region")
|
|
cmd.Flags().StringVar(&aaKbsParams, "aa-kbs-params", "", "Attestation Agent KBS Parameters (e.g. protocol=http,type=kbs,url=http://... or just type=sample)")
|
|
if err := cmd.MarkFlagRequired(serverURL); err != nil {
|
|
printError(cmd, "Error marking flag as required: %v ❌ ", err)
|
|
return cmd
|
|
}
|
|
|
|
return cmd
|
|
}
|
|
|
|
func (c *CLI) NewRemoveVMCmd() *cobra.Command {
|
|
return &cobra.Command{
|
|
Use: "remove-vm",
|
|
Short: "Remove a virtual machine",
|
|
Example: `remove-vm <cvm_id>`,
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
if c.connectErr != nil {
|
|
printError(cmd, "Failed to connect to manager: %v ❌ ", c.connectErr)
|
|
return
|
|
}
|
|
if c.managerClient == nil {
|
|
if err := c.InitializeManagerClient(cmd); err != nil {
|
|
printError(cmd, "Failed to connect to manager: %v ❌ ", err)
|
|
return
|
|
}
|
|
}
|
|
defer c.Close()
|
|
|
|
cmd.Println("🔗 Removing virtual machine")
|
|
|
|
_, err := c.managerClient.RemoveVm(cmd.Context(), &manager.RemoveReq{CvmId: args[0]})
|
|
if err != nil {
|
|
printError(cmd, "Error removing virtual machine: %v ❌ ", err)
|
|
return
|
|
}
|
|
|
|
cmd.Println(color.New(color.FgGreen).Sprintf("✅ Virtual machine removed successfully"))
|
|
},
|
|
}
|
|
}
|
|
|
|
func fileReader(path string) ([]byte, error) {
|
|
if path == "" {
|
|
return nil, nil
|
|
}
|
|
|
|
return os.ReadFile(path)
|
|
}
|
|
|
|
func loadCerts() (*manager.CreateReq, error) {
|
|
clientKey, err := fileReader(agentCVMClientKey)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
clientCrt, err := fileReader(agentCVMClientCrt)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
serverCA, err := fileReader(agentCVMServerCA)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &manager.CreateReq{
|
|
AgentCvmServerCaCert: serverCA,
|
|
AgentCvmClientKey: clientKey,
|
|
AgentCvmClientCert: clientCrt,
|
|
}, nil
|
|
}
|