Skip to content

Commit 6584af3

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

File tree

14 files changed

+580
-261
lines changed

14 files changed

+580
-261
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/agent/agent.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ import (
99
"bytes"
1010
"context"
1111
"crypto"
12+
"crypto/sha256"
1213
"encoding/base64"
14+
"encoding/hex"
1315
"fmt"
1416
"io"
1517
"net/http"
@@ -24,6 +26,8 @@ import (
2426
tg "github.com/google/go-tdx-guest/client"
2527
tlabi "github.com/google/go-tdx-guest/client/linuxabi"
2628

29+
"github.com/NVIDIA/go-nvml/pkg/nvml"
30+
"github.com/confidentsecurity/go-nvtrust/pkg/gonvtrust/gpu"
2731
"github.com/google/go-tpm-tools/cel"
2832
"github.com/google/go-tpm-tools/client"
2933
"github.com/google/go-tpm-tools/internal"
@@ -223,6 +227,14 @@ func (a *agent) AttestWithClient(ctx context.Context, opts AttestAgentOpts, clie
223227
v.IntermediateCerts = certChain
224228
v.AkCert = a.fetchedAK.CertDERBytes()
225229
req.TDCCELAttestation = v
230+
// log TDCCEL attestation data
231+
a.logger.Info(fmt.Sprintf("TDX nonce: [%s]\n", hex.EncodeToString(req.Challenge.Nonce)))
232+
a.logger.Info(fmt.Sprintf("CCEL data: [%s]\n", base64.StdEncoding.EncodeToString(v.CcelData)))
233+
a.logger.Info(fmt.Sprintf("CCEL ACPI table data: [%s]\n", base64.StdEncoding.EncodeToString(v.CcelAcpiTable)))
234+
a.logger.Info(fmt.Sprintf("TDX quote: [%s]\n", base64.StdEncoding.EncodeToString(v.TdQuote)))
235+
a.logger.Info(fmt.Sprintf("CEL data: [%s]\n", base64.StdEncoding.EncodeToString(v.CanonicalEventLog)))
236+
// collect GPU attestation
237+
a.collectGpuAttestation(challenge.Nonce)
226238
default:
227239
return nil, fmt.Errorf("received an unsupported attestation type! %v", v)
228240
}
@@ -406,3 +418,48 @@ func (c *sigsCache) get() []oci.Signature {
406418
defer c.mu.RUnlock()
407419
return c.items
408420
}
421+
422+
func (a *agent) collectGpuAttestation(nonce []byte) {
423+
handler := &gpu.DefaultNVMLHandler{}
424+
gpuAdmin, err := gpu.NewNvmlGPUAdmin(handler)
425+
if err != nil {
426+
a.logger.Error(fmt.Sprintf("Failed to create GPU admin: %v\n", err))
427+
}
428+
defer gpuAdmin.Shutdown()
429+
430+
// The 34-byte raw nonce follows TPM 2.0 specs. We need to convert it to 32 bytes for Nvidia to meet SPDM specs.
431+
nvNonce := sha256.Sum256(nonce)
432+
deviceInfos, err := gpuAdmin.CollectEvidence(nvNonce[:])
433+
if err != nil {
434+
a.logger.Error(fmt.Sprintf("Failed to collect GPU evidence\n: %v", err))
435+
}
436+
437+
for i, deviceInfo := range deviceInfos {
438+
device, ret := handler.DeviceGetHandleByIndex(i)
439+
if ret != nvml.SUCCESS {
440+
a.logger.Error(fmt.Sprintf("Failed to get GPU device: %v\n", nvml.ErrorString(ret)))
441+
}
442+
uuid, ret := device.GetUUID()
443+
if ret != nvml.SUCCESS {
444+
a.logger.Error(fmt.Sprintf("Failed to get UUID: %v\n", nvml.ErrorString(ret)))
445+
}
446+
447+
vbiosVersion, ret := device.GetVbiosVersion()
448+
if ret != nvml.SUCCESS {
449+
a.logger.Error(fmt.Sprintf("Failed to get vbios version: %v\n", nvml.ErrorString(ret)))
450+
}
451+
452+
driverVersion, ret := handler.SystemGetDriverVersion()
453+
if ret != nvml.SUCCESS {
454+
a.logger.Error(fmt.Sprintf("Failed to get vbios version: %v\n", nvml.ErrorString(ret)))
455+
}
456+
a.logger.Info(fmt.Sprintf("NV nonce is [%s] \n", hex.EncodeToString(nvNonce[:])))
457+
a.logger.Info(fmt.Sprintf("Found GPU UUID [%s] at index %d\n", uuid, i))
458+
a.logger.Info(fmt.Sprintf("Found GPU VBIOS version [%s] at index %d\n", vbiosVersion, i))
459+
a.logger.Info(fmt.Sprintf("Found GPU DRIVER version [%s] at index %d\n", driverVersion, i))
460+
a.logger.Info(fmt.Sprintf("Found GPU Arch [%s] at index %d\n", deviceInfo.Arch(), i))
461+
a.logger.Info(fmt.Sprintf("Found GPU attetation data [%s] at index %d\n", base64.StdEncoding.EncodeToString(deviceInfo.AttestationReport()), i))
462+
b64CertChainData, _ := deviceInfo.Certificate().EncodeBase64()
463+
a.logger.Info(fmt.Sprintf("Found GPU attestation cert chain data [%s] at index %d\n", b64CertChainData, i))
464+
}
465+
}

launcher/cloudbuild.yaml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,21 @@ steps:
101101
--substitutions _IMAGE_NAME=${OUTPUT_IMAGE_PREFIX}-debug-${OUTPUT_IMAGE_SUFFIX},_IMAGE_PROJECT=${PROJECT_ID}
102102
exit
103103
104-
- name: 'gcr.io/cloud-builders/gcloud'
105-
id: HttpServerTests
106-
waitFor: ['DebugImageBuild']
107-
env:
108-
- 'OUTPUT_IMAGE_PREFIX=${_OUTPUT_IMAGE_PREFIX}'
109-
- 'OUTPUT_IMAGE_SUFFIX=${_OUTPUT_IMAGE_SUFFIX}'
110-
- 'PROJECT_ID=$PROJECT_ID'
111-
script: |
112-
#!/usr/bin/env bash
104+
# - name: 'gcr.io/cloud-builders/gcloud'
105+
# id: HttpServerTests
106+
# waitFor: ['DebugImageBuild']
107+
# env:
108+
# - 'OUTPUT_IMAGE_PREFIX=${_OUTPUT_IMAGE_PREFIX}'
109+
# - 'OUTPUT_IMAGE_SUFFIX=${_OUTPUT_IMAGE_SUFFIX}'
110+
# - 'PROJECT_ID=$PROJECT_ID'
111+
# script: |
112+
# #!/usr/bin/env bash
113113

114-
cd launcher/image/test
115-
echo "running http server tests on ${OUTPUT_IMAGE_PREFIX}-debug-${OUTPUT_IMAGE_SUFFIX}"
116-
gcloud builds submit --config=test_http_server.yaml --region us-west1 \
117-
--substitutions _IMAGE_NAME=${OUTPUT_IMAGE_PREFIX}-debug-${OUTPUT_IMAGE_SUFFIX},_IMAGE_PROJECT=${PROJECT_ID}
118-
exit
114+
# cd launcher/image/test
115+
# echo "running http server tests on ${OUTPUT_IMAGE_PREFIX}-debug-${OUTPUT_IMAGE_SUFFIX}"
116+
# gcloud builds submit --config=test_http_server.yaml --region us-west1 \
117+
# --substitutions _IMAGE_NAME=${OUTPUT_IMAGE_PREFIX}-debug-${OUTPUT_IMAGE_SUFFIX},_IMAGE_PROJECT=${PROJECT_ID}
118+
# exit
119119

120120
- name: 'gcr.io/cloud-builders/gcloud'
121121
id: DebugImageTests

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)