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>
105 lines
2.8 KiB
Go
105 lines
2.8 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
package cli
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/sha512"
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/google/go-tpm-tools/proto/attest"
|
|
"github.com/spf13/cobra"
|
|
"github.com/ultravioletrs/cocos/pkg/attestation/gcp"
|
|
"google.golang.org/protobuf/encoding/protojson"
|
|
"google.golang.org/protobuf/proto"
|
|
)
|
|
|
|
var (
|
|
isJsonAttestation bool
|
|
// 0o744 file permission gives RWX permission to the user and only the R permission to others.
|
|
filePermission os.FileMode = 0o744
|
|
)
|
|
|
|
func (cli *CLI) NewAttestationPolicyCmd() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "policy",
|
|
Short: "Change attestation policy",
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
_ = cmd.Help()
|
|
},
|
|
}
|
|
|
|
cmd.AddCommand(cli.NewCreateCoRIMCmd())
|
|
|
|
return cmd
|
|
}
|
|
|
|
func (cli *CLI) NewDownloadGCPOvmfFile() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "download",
|
|
Short: "Download GCP OVMF file",
|
|
Example: `download <bin_vtmp_attestation_report_file>`,
|
|
Args: cobra.ExactArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
attestationBin, err := os.ReadFile(args[0])
|
|
if err != nil {
|
|
printError(cmd, "Error reading attestation report file: %v ❌ ", err)
|
|
return
|
|
}
|
|
|
|
attestation := &attest.Attestation{}
|
|
|
|
if isJsonAttestation {
|
|
if err := protojson.Unmarshal(attestationBin, attestation); err != nil {
|
|
printError(cmd, "Error converting JSON attestation to binary: %v ❌", err)
|
|
return
|
|
}
|
|
} else {
|
|
if err := proto.Unmarshal(attestationBin, attestation); err != nil {
|
|
printError(cmd, "Error unmarshaling attestation report: %v ❌ ", err)
|
|
return
|
|
}
|
|
}
|
|
|
|
attestationPB := attestation.GetSevSnpAttestation()
|
|
|
|
measurement, err := gcp.Extract384BitMeasurement(attestationPB)
|
|
if err != nil {
|
|
printError(cmd, "Error extracting 384-bit measurement: %v ❌ ", err)
|
|
return
|
|
}
|
|
|
|
launchEndorsement, err := gcp.GetLaunchEndorsement(cmd.Context(), measurement)
|
|
if err != nil {
|
|
printError(cmd, "Error getting launch endorsement: %v ❌ ", err)
|
|
return
|
|
}
|
|
|
|
ovmf, err := gcp.DownloadOvmfFile(cmd.Context(), fmt.Sprintf("%x", launchEndorsement.Digest))
|
|
if err != nil {
|
|
printError(cmd, "Error downloading OVMF file: %v ❌ ", err)
|
|
return
|
|
}
|
|
|
|
sum384 := sha512.Sum384(ovmf)
|
|
|
|
if !bytes.Equal(sum384[:], launchEndorsement.Digest) {
|
|
printError(cmd, "Error OVMF file does not match the measurement: %v ❌ ", fmt.Errorf("digest mismatch"))
|
|
} else {
|
|
cmd.Println("OVMF firmware in vm is unmodified ✅")
|
|
}
|
|
|
|
if err := os.WriteFile("ovmf.fd", ovmf, filePermission); err != nil {
|
|
printError(cmd, "Error writing OVMF file: %v ❌ ", err)
|
|
return
|
|
}
|
|
|
|
cmd.Println("OVMF file downloaded successfully ✅")
|
|
},
|
|
}
|
|
|
|
cmd.Flags().BoolVarP(&isJsonAttestation, "json", "j", false, "Use JSON attestation report instead of binary")
|
|
return cmd
|
|
}
|