mirror of
https://github.com/ultravioletrs/cocos.git
synced 2026-06-23 04:10:25 +00:00
27db9b29eb
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
* Added GPU evidence collection * Added GPU evidence verification * Added make command for nvattest helper * Added command for installing all services * changed attestion-service.service so it knows where the helper is * Possible IGVM script bug * Possible bug * Bug * bug * Revert "bug" This reverts commitd81d67e73d. * Revert "Bug" This reverts commit5e566d53c1. * Revert "Possible bug" This reverts commit47d13fe583. * Revert "Possible IGVM script bug" This reverts commit3fb1b79537. * Revert "changed attestion-service.service so it knows where the helper is" This reverts commitf9f11ed183. * Revert "Added command for installing all services" This reverts commit5dcf7a5c0a. * NOISSUE - Enforce binding label check (#589) * NOISSUE - Implement extensible resource downloader framework with support for S3, GCS, and OCI sources (#590) * feat: implement extensible resource downloader framework with support for S3, GCS, and OCI sources Signed-off-by: SammyOina <sammyoina@gmail.com> * refactor: improve resource URL parsing and add support for bare OCI image references Signed-off-by: Sammy Oina <sammyoina@gmail.com> * fix: add empty string check and slash requirement for OCI image inference, and update python unit tests with event mock expectations Signed-off-by: Sammy Oina <sammyoina@gmail.com> * refactor: introduce OCIClient interface, add test coverage for decryption, and improve resource download error handling Signed-off-by: Sammy Oina <sammyoina@gmail.com> * chore: remove trailing whitespace in OCI downloader and HTTP tests Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: SammyOina <sammyoina@gmail.com> Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Refactored baed on comments * Added GPU evidence collection * Added GPU evidence verification * Added make command for nvattest helper * Added command for installing all services * changed attestion-service.service so it knows where the helper is * Possible IGVM script bug * Possible bug * Bug * bug * Revert "bug" This reverts commitd81d67e73d. * Revert "Bug" This reverts commit5e566d53c1. * Revert "Possible bug" This reverts commit47d13fe583. * Revert "Possible IGVM script bug" This reverts commit3fb1b79537. * Revert "changed attestion-service.service so it knows where the helper is" This reverts commitf9f11ed183. * Revert "Added command for installing all services" This reverts commit5dcf7a5c0a. * Refactored baed on comments * fixed lint error * fixed tests * Fixed according to comments * COCOS-584 - Support multiple kbs (#587) * feat: Implement per-resource KBS configuration, allowing algorithms and datasets to specify individual KBS URLs. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * refactor: Encapsulate CLI error handling and CVM certificate paths within the CLI struct, and add algorithm type to agent's algorithm structure. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * style: Remove blank lines and fix indentation in CLI commands. Signed-off-by: Sammy Oina <sammyoina@gmail.com> * refactor: Update downloadAndDecryptGenericResource to accept KBS URL as a parameter and adjust related tests Signed-off-by: Sammy Oina <sammyoina@gmail.com> * refactor: group CLI configuration into structured types and simplify skopeo decryption key handling Signed-off-by: Sammy Oina <sammyoina@gmail.com> --------- Signed-off-by: Sammy Oina <sammyoina@gmail.com> * Added GPU evidence collection * Added GPU evidence verification * Added make command for nvattest helper * Added command for installing all services * changed attestion-service.service so it knows where the helper is * Possible IGVM script bug * Possible bug * Bug * bug * Revert "bug" This reverts commitd81d67e73d. * Revert "Bug" This reverts commit5e566d53c1. * Revert "Possible bug" This reverts commit47d13fe583. * Revert "Possible IGVM script bug" This reverts commit3fb1b79537. * Revert "changed attestion-service.service so it knows where the helper is" This reverts commitf9f11ed183. * Revert "Added command for installing all services" This reverts commit5dcf7a5c0a. * Refactored baed on comments * Added GPU evidence collection * Added GPU evidence verification * Added make command for nvattest helper * Added command for installing all services * changed attestion-service.service so it knows where the helper is * Possible IGVM script bug * Possible bug * Bug * bug * Revert "bug" This reverts commitd81d67e73d. * Revert "Bug" This reverts commit5e566d53c1. * Revert "Possible bug" This reverts commit47d13fe583. * Revert "Possible IGVM script bug" This reverts commit3fb1b79537. * Revert "changed attestion-service.service so it knows where the helper is" This reverts commitf9f11ed183. * Revert "Added command for installing all services" This reverts commit5dcf7a5c0a. * Refactored baed on comments * fixed lint error * fixed tests * Fixed according to comments --------- Signed-off-by: SammyOina <sammyoina@gmail.com> Signed-off-by: Sammy Oina <sammyoina@gmail.com> Co-authored-by: Danko Miladinovic <72250944+danko-miladinovic@users.noreply.github.com> Co-authored-by: Sammy Kerata Oina <44265300+SammyOina@users.noreply.github.com>
142 lines
3.6 KiB
Go
142 lines
3.6 KiB
Go
// Copyright (c) Ultraviolet
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package gpu
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"os/exec"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func fakeExecCommandContext(_ context.Context, name string, arg ...string) *exec.Cmd {
|
|
args := append([]string{"-test.run=TestGPUHelperProcess", "--", name}, arg...)
|
|
cmd := exec.Command(os.Args[0], args...)
|
|
cmd.Env = append(os.Environ(), "GO_WANT_GPU_HELPER_PROCESS=1")
|
|
return cmd
|
|
}
|
|
|
|
func TestGPUHelperProcess(t *testing.T) {
|
|
if os.Getenv("GO_WANT_GPU_HELPER_PROCESS") != "1" {
|
|
return
|
|
}
|
|
|
|
args := os.Args
|
|
for i := range args {
|
|
if args[i] == "--" {
|
|
args = args[i+1:]
|
|
break
|
|
}
|
|
}
|
|
|
|
if len(args) == 0 {
|
|
fmt.Fprintln(os.Stderr, "missing helper name")
|
|
os.Exit(2)
|
|
}
|
|
|
|
switch args[0] {
|
|
case "helper-error":
|
|
fmt.Fprintln(os.Stderr, "simulated helper failure")
|
|
os.Exit(1)
|
|
case "helper-invalid-json":
|
|
fmt.Fprintln(os.Stdout, "{not-json")
|
|
os.Exit(0)
|
|
case "helper-empty-evidence":
|
|
fmt.Fprintln(os.Stdout, `{"vendor":"nvidia","evidence_format":"nvat-json"}`)
|
|
os.Exit(0)
|
|
default:
|
|
var req helperRequest
|
|
if err := json.NewDecoder(os.Stdin).Decode(&req); err != nil {
|
|
fmt.Fprintln(os.Stderr, err.Error())
|
|
os.Exit(1)
|
|
}
|
|
if req.Mode != "collect" {
|
|
fmt.Fprintln(os.Stderr, "unexpected helper mode")
|
|
os.Exit(1)
|
|
}
|
|
|
|
resp := helperResponse{
|
|
Vendor: "nvidia",
|
|
EvidenceFormat: "nvat-json",
|
|
EvidenceJSON: json.RawMessage(fmt.Sprintf(`{"nonce_hex":"%s","evidence":"ok"}`, req.NonceHex)),
|
|
}
|
|
if err := json.NewEncoder(os.Stdout).Encode(resp); err != nil {
|
|
fmt.Fprintln(os.Stderr, err.Error())
|
|
os.Exit(1)
|
|
}
|
|
os.Exit(0)
|
|
}
|
|
}
|
|
|
|
func TestNewCommandCollector(t *testing.T) {
|
|
collector, err := NewCommandCollector("helper", time.Second)
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, collector)
|
|
|
|
collector, err = NewCommandCollector("", time.Second)
|
|
assert.Error(t, err)
|
|
assert.Nil(t, collector)
|
|
}
|
|
|
|
func TestCommandCollectorCollect(t *testing.T) {
|
|
collector, err := NewCommandCollector("helper-success", time.Second)
|
|
require.NoError(t, err)
|
|
|
|
cmdCollector, ok := collector.(*commandCollector)
|
|
require.True(t, ok)
|
|
cmdCollector.SetExecCommandContext(fakeExecCommandContext)
|
|
|
|
evidence, err := collector.Collect(context.Background(), []byte{0xaa, 0xbb, 0xcc})
|
|
require.NoError(t, err)
|
|
assert.Equal(t, DefaultVendor, evidence.Vendor)
|
|
assert.Equal(t, DefaultEvidenceFormat, evidence.EvidenceFormat)
|
|
assert.Equal(t, []byte{0xaa, 0xbb, 0xcc}, evidence.Nonce)
|
|
assert.JSONEq(t, `{"nonce_hex":"aabbcc","evidence":"ok"}`, string(evidence.RawEvidence))
|
|
}
|
|
|
|
func TestCommandCollectorCollectErrors(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
helperName string
|
|
wantErr string
|
|
}{
|
|
{
|
|
name: "helper process failure",
|
|
helperName: "helper-error",
|
|
wantErr: "gpu helper failed: simulated helper failure",
|
|
},
|
|
{
|
|
name: "invalid json response",
|
|
helperName: "helper-invalid-json",
|
|
wantErr: "failed to decode GPU helper response",
|
|
},
|
|
{
|
|
name: "missing evidence payload",
|
|
helperName: "helper-empty-evidence",
|
|
wantErr: "gpu helper response did not contain evidence_json",
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
collector, err := NewCommandCollector(tt.helperName, time.Second)
|
|
require.NoError(t, err)
|
|
|
|
cmdCollector, ok := collector.(*commandCollector)
|
|
require.True(t, ok)
|
|
cmdCollector.SetExecCommandContext(fakeExecCommandContext)
|
|
|
|
_, err = collector.Collect(context.Background(), []byte{0xaa})
|
|
require.Error(t, err)
|
|
assert.Contains(t, err.Error(), tt.wantErr)
|
|
})
|
|
}
|
|
}
|