Skip to content

Commit cc048d0

Browse files
committed
PoC for go-nvtrust
1 parent c90d686 commit cc048d0

File tree

10 files changed

+540
-227
lines changed

10 files changed

+540
-227
lines changed

go.work

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
go 1.23.0
1+
go 1.24.0
2+
3+
toolchain go1.24.8
24

35
use (
46
.

go.work.sum

Lines changed: 271 additions & 8 deletions
Large diffs are not rendered by default.

launcher/container_runner.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package launcher
33

44
import (
55
"context"
6+
cryptorand "crypto/rand"
67
"encoding/json"
78
"errors"
89
"fmt"
@@ -16,7 +17,9 @@ import (
1617
"time"
1718

1819
"cloud.google.com/go/compute/metadata"
20+
"github.com/NVIDIA/go-nvml/pkg/nvml"
1921
"github.com/cenkalti/backoff/v4"
22+
trustgpu "github.com/confidentsecurity/go-nvtrust/pkg/gonvtrust/gpu"
2023
"github.com/containerd/containerd"
2124
"github.com/containerd/containerd/cio"
2225
"github.com/containerd/containerd/containers"
@@ -81,6 +84,54 @@ const (
8184
// Default OOM score for a CS container.
8285
const defaultOOMScore = 1000
8386

87+
func collectGpuAttestation(logger logging.Logger) {
88+
handler := &trustgpu.DefaultNVMLHandler{}
89+
gpuAdmin, err := trustgpu.NewNvmlGPUAdmin(handler)
90+
if err != nil {
91+
logger.Error("Failed to create GPU admin: %v\n", err)
92+
}
93+
defer gpuAdmin.Shutdown()
94+
95+
// Generate a random nonce (32 bytes)
96+
nonce := make([]byte, 32)
97+
if _, err := cryptorand.Read(nonce); err != nil {
98+
logger.Error("Failed to generate nonce: %v\n", err)
99+
}
100+
101+
deviceInfos, err := gpuAdmin.CollectEvidence(nonce)
102+
if err != nil {
103+
logger.Error("Failed to collect GPU evidence\n: %w", err)
104+
}
105+
106+
for i := range deviceInfos {
107+
device, ret := handler.DeviceGetHandleByIndex(i)
108+
if ret != nvml.SUCCESS {
109+
logger.Error("Failed to get GPU device: %w\n", nvml.ErrorString(ret))
110+
}
111+
uuid, ret := device.GetUUID()
112+
if ret != nvml.SUCCESS {
113+
logger.Error("Failed to get UUID: %w\n", nvml.ErrorString(ret))
114+
}
115+
116+
vbiosVersion, ret := device.GetVbiosVersion()
117+
if ret != nvml.SUCCESS {
118+
logger.Error("Failed to get vbios version: %w\n", nvml.ErrorString(ret))
119+
}
120+
121+
driverVersion, ret := handler.SystemGetDriverVersion()
122+
if ret != nvml.SUCCESS {
123+
logger.Error("Failed to get vbios version: %w\n", nvml.ErrorString(ret))
124+
}
125+
logger.Info("Found GPU UUID [%s] at index %d\n", uuid, i)
126+
logger.Info("Found GPU VBIOS version [%s] at index %d\n", vbiosVersion, i)
127+
logger.Info("Found GPU DRIVER version [%s] at index %d\n", driverVersion, i)
128+
// The following attestation data can be accessed by device Info
129+
// logger.Info("Found GPU Arch [%s] at index %d\n", deviceInfo.Arch(), i)
130+
// logger.Info("Found GPU attetation data size [%d] at index %d\n", len(deviceInfo.AttestationReport()), i)
131+
// logger.Info("Found GPU attestation cert chain data [%s] at index %d\n", b64CertChainData, i)
132+
}
133+
}
134+
84135
// NewRunner returns a runner.
85136
func NewRunner(ctx context.Context, cdClient *containerd.Client, token oauth2.Token, launchSpec spec.LaunchSpec, mdsClient *metadata.Client, tpm io.ReadWriteCloser, logger logging.Logger, serialConsole *os.File) (*ContainerRunner, error) {
86137
image, err := initImage(ctx, cdClient, launchSpec, token)
@@ -375,6 +426,7 @@ func (r *ContainerRunner) measureCELEvents(ctx context.Context) error {
375426
if err := r.measureGPUCCMode(ccModeCmd, devToolsCmd); err != nil {
376427
return fmt.Errorf("failed to measure GPU CC mode status: %v", err)
377428
}
429+
collectGpuAttestation(r.logger)
378430
}
379431

380432
separator := cel.CosTlv{

launcher/go.mod

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
module github.com/google/go-tpm-tools/launcher
22

3-
go 1.23.0
3+
go 1.24.0
4+
5+
toolchain go1.24.8
46

57
require (
6-
cloud.google.com/go/compute/metadata v0.5.2
7-
cloud.google.com/go/logging v1.12.0
8+
cloud.google.com/go/compute/metadata v0.8.0
9+
cloud.google.com/go/logging v1.13.0
810
cos.googlesource.com/cos/tools.git v0.0.0-20250414225215-0cf736c0714c
11+
github.com/NVIDIA/go-nvml v0.13.0-1
912
github.com/cenkalti/backoff/v4 v4.3.0
13+
github.com/confidentsecurity/go-nvtrust v0.2.2
1014
github.com/containerd/containerd v1.7.23
1115
github.com/containerd/containerd/v2 v2.0.1
1216
github.com/coreos/go-systemd/v22 v22.5.0
1317
github.com/golang-jwt/jwt/v4 v4.5.1
14-
github.com/google/go-cmp v0.6.0
18+
github.com/google/go-cmp v0.7.0
1519
github.com/google/go-configfs-tsm v0.3.3-0.20240919001351-b4b5b84fdcbc
1620
github.com/google/go-tdx-guest v0.3.2-0.20241009005452-097ee70d0843
1721
github.com/google/go-tpm v0.9.0
@@ -20,18 +24,18 @@ require (
2024
github.com/opencontainers/go-digest v1.0.0
2125
github.com/opencontainers/image-spec v1.1.0
2226
github.com/opencontainers/runtime-spec v1.2.0
23-
golang.org/x/oauth2 v0.23.0
24-
google.golang.org/api v0.205.0
25-
google.golang.org/genproto/googleapis/api v0.0.0-20241015192408-796eee8c2d53
26-
google.golang.org/protobuf v1.35.1
27+
golang.org/x/oauth2 v0.30.0
28+
google.golang.org/api v0.247.0
29+
google.golang.org/genproto/googleapis/api v0.0.0-20250818200422-3122310a409c
30+
google.golang.org/protobuf v1.36.7
2731
)
2832

2933
require (
30-
cloud.google.com/go v0.116.0 // indirect
31-
cloud.google.com/go/auth v0.10.1 // indirect
32-
cloud.google.com/go/auth/oauth2adapt v0.2.5 // indirect
33-
cloud.google.com/go/confidentialcomputing v1.8.0 // indirect
34-
cloud.google.com/go/longrunning v0.6.1 // indirect
34+
cloud.google.com/go v0.120.0 // indirect
35+
cloud.google.com/go/auth v0.16.4 // indirect
36+
cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect
37+
cloud.google.com/go/confidentialcomputing v1.10.1 // indirect
38+
cloud.google.com/go/longrunning v0.6.7 // indirect
3539
github.com/AdaLogics/go-fuzz-headers v0.0.0-20240806141605-e8a1dd7889d6 // indirect
3640
github.com/AdamKorcz/go-118-fuzz-build v0.0.0-20231105174938-2b5cbb29f3e2 // indirect
3741
github.com/Microsoft/go-winio v0.6.2 // indirect
@@ -49,23 +53,21 @@ require (
4953
github.com/distribution/reference v0.6.0 // indirect
5054
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
5155
github.com/felixge/httpsnoop v1.0.4 // indirect
52-
github.com/go-logr/logr v1.4.2 // indirect
56+
github.com/go-logr/logr v1.4.3 // indirect
5357
github.com/go-logr/stdr v1.2.2 // indirect
5458
github.com/godbus/dbus/v5 v5.1.0 // indirect
5559
github.com/gogo/protobuf v1.3.2 // indirect
5660
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
57-
github.com/golang/protobuf v1.5.4 // indirect
5861
github.com/google/certificate-transparency-go v1.1.2 // indirect
59-
github.com/google/gce-tcb-verifier v0.2.3-0.20240905212129-12f728a62786 // indirect
6062
github.com/google/go-attestation v0.5.1 // indirect
6163
github.com/google/go-eventlog v0.0.2-0.20241003021507-01bb555f7cba // indirect
6264
github.com/google/go-sev-guest v0.13.0 // indirect
6365
github.com/google/go-tspi v0.3.0 // indirect
6466
github.com/google/logger v1.1.1 // indirect
65-
github.com/google/s2a-go v0.1.8 // indirect
67+
github.com/google/s2a-go v0.1.9 // indirect
6668
github.com/google/uuid v1.6.0 // indirect
67-
github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect
68-
github.com/googleapis/gax-go/v2 v2.13.0 // indirect
69+
github.com/googleapis/enterprise-certificate-proxy v0.3.6 // indirect
70+
github.com/googleapis/gax-go/v2 v2.15.0 // indirect
6971
github.com/klauspost/compress v1.17.11 // indirect
7072
github.com/moby/locker v1.0.1 // indirect
7173
github.com/moby/sys/mountinfo v0.7.2 // indirect
@@ -77,22 +79,22 @@ require (
7779
github.com/pkg/errors v0.9.1 // indirect
7880
github.com/sirupsen/logrus v1.9.3 // indirect
7981
go.opencensus.io v0.24.0 // indirect
80-
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.56.0 // indirect
81-
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect
82-
go.opentelemetry.io/otel v1.31.0 // indirect
83-
go.opentelemetry.io/otel/metric v1.31.0 // indirect
84-
go.opentelemetry.io/otel/trace v1.31.0 // indirect
82+
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
83+
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 // indirect
84+
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect
85+
go.opentelemetry.io/otel v1.36.0 // indirect
86+
go.opentelemetry.io/otel/metric v1.36.0 // indirect
87+
go.opentelemetry.io/otel/trace v1.36.0 // indirect
8588
go.uber.org/multierr v1.11.0 // indirect
86-
golang.org/x/crypto v0.35.0 // indirect
87-
golang.org/x/exp v0.0.0-20240531132922-fd00a4e0eefc // indirect
88-
golang.org/x/net v0.36.0 // indirect
89-
golang.org/x/sync v0.11.0 // indirect
90-
golang.org/x/sys v0.30.0 // indirect
91-
golang.org/x/text v0.22.0 // indirect
92-
golang.org/x/time v0.7.0 // indirect
93-
google.golang.org/genproto v0.0.0-20241021214115-324edc3d5d38 // indirect
94-
google.golang.org/genproto/googleapis/rpc v0.0.0-20241021214115-324edc3d5d38 // indirect
95-
google.golang.org/grpc v1.67.1 // indirect
89+
golang.org/x/crypto v0.41.0 // indirect
90+
golang.org/x/net v0.43.0 // indirect
91+
golang.org/x/sync v0.16.0 // indirect
92+
golang.org/x/sys v0.35.0 // indirect
93+
golang.org/x/text v0.28.0 // indirect
94+
golang.org/x/time v0.12.0 // indirect
95+
google.golang.org/genproto v0.0.0-20250603155806-513f23925822 // indirect
96+
google.golang.org/genproto/googleapis/rpc v0.0.0-20250818200422-3122310a409c // indirect
97+
google.golang.org/grpc v1.74.2 // indirect
9698
)
9799

98100
replace (

0 commit comments

Comments
 (0)