mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-07-17 08:53:26 +00:00
Merge pull request #11057 from mythi/tdx-qgs-uds
runtime: qemu: add support to use TDX QGS via Unix Domain Sockets
This commit is contained in:
commit
8779abd0a1
@ -45,6 +45,8 @@ type Machine struct {
|
|||||||
const (
|
const (
|
||||||
// MachineTypeMicrovm is the QEMU microvm machine type for amd64
|
// MachineTypeMicrovm is the QEMU microvm machine type for amd64
|
||||||
MachineTypeMicrovm string = "microvm"
|
MachineTypeMicrovm string = "microvm"
|
||||||
|
// (fixed) Unix Domain Socket Path served by Intel TDX Quote Generation Service
|
||||||
|
qgsSocketPath string = "/var/run/tdx-qgs/qgs.socket"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -316,7 +318,7 @@ type Object struct {
|
|||||||
// Prealloc enables memory preallocation
|
// Prealloc enables memory preallocation
|
||||||
Prealloc bool
|
Prealloc bool
|
||||||
|
|
||||||
// QgsPort defines Intel Quote Generation Service port exposed from the host
|
// QgsPort defines Intel TDX Quote Generation Service port configuration
|
||||||
QgsPort uint32
|
QgsPort uint32
|
||||||
|
|
||||||
// SnpIdBlock is the 96-byte, base64-encoded blob to provide the ‘ID Block’ structure
|
// SnpIdBlock is the 96-byte, base64-encoded blob to provide the ‘ID Block’ structure
|
||||||
@ -336,7 +338,7 @@ func (object Object) Valid() bool {
|
|||||||
case MemoryBackendEPC:
|
case MemoryBackendEPC:
|
||||||
return object.ID != "" && object.Size != 0
|
return object.ID != "" && object.Size != 0
|
||||||
case TDXGuest:
|
case TDXGuest:
|
||||||
return object.ID != "" && object.File != "" && object.DeviceID != "" && object.QgsPort != 0
|
return object.ID != "" && object.File != "" && object.DeviceID != ""
|
||||||
case SEVGuest:
|
case SEVGuest:
|
||||||
fallthrough
|
fallthrough
|
||||||
case SNPGuest:
|
case SNPGuest:
|
||||||
@ -436,8 +438,9 @@ func (object Object) QemuParams(config *Config) []string {
|
|||||||
|
|
||||||
type SocketAddress struct {
|
type SocketAddress struct {
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Cid string `json:"cid"`
|
Cid string `json:"cid,omitempty"`
|
||||||
Port string `json:"port"`
|
Port string `json:"port,omitempty"`
|
||||||
|
Path string `json:"path,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TdxQomObject struct {
|
type TdxQomObject struct {
|
||||||
@ -472,8 +475,16 @@ func (this *TdxQomObject) String() string {
|
|||||||
return string(b)
|
return string(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getQgsSocketAddress(portNum uint32) SocketAddress {
|
||||||
|
if portNum == 0 {
|
||||||
|
return SocketAddress{Type: "unix", Path: qgsSocketPath}
|
||||||
|
}
|
||||||
|
|
||||||
|
return SocketAddress{Type: "vsock", Cid: fmt.Sprint(VsockHostCid), Port: fmt.Sprint(portNum)}
|
||||||
|
}
|
||||||
|
|
||||||
func prepareTDXObject(object Object) string {
|
func prepareTDXObject(object Object) string {
|
||||||
qgsSocket := SocketAddress{"vsock", fmt.Sprint(VsockHostCid), fmt.Sprint(object.QgsPort)}
|
qgsSocket := getQgsSocketAddress(object.QgsPort)
|
||||||
tdxObject := TdxQomObject{
|
tdxObject := TdxQomObject{
|
||||||
string(object.Type), // qom-type
|
string(object.Type), // qom-type
|
||||||
object.ID, // id
|
object.ID, // id
|
||||||
|
@ -127,6 +127,27 @@ func TestAppendDeviceNVDIMM(t *testing.T) {
|
|||||||
testAppend(object, deviceNVDIMMString, t)
|
testAppend(object, deviceNVDIMMString, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
tdxObjectVsock = `-object {"qom-type":"tdx-guest","id":"tdx","quote-generation-socket":{"type":"vsock","cid":"2","port":"4050"}}`
|
||||||
|
tdxObjectUnix = `-object {"qom-type":"tdx-guest","id":"tdx","quote-generation-socket":{"type":"unix","path":"/var/run/tdx-qgs/qgs.socket"}}`
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTdxQuoteSocket(t *testing.T) {
|
||||||
|
object := Object{
|
||||||
|
Type: TDXGuest,
|
||||||
|
ID: "tdx",
|
||||||
|
File: "unused",
|
||||||
|
DeviceID: "unused",
|
||||||
|
QgsPort: 0,
|
||||||
|
}
|
||||||
|
|
||||||
|
testAppend(object, tdxObjectUnix, t)
|
||||||
|
|
||||||
|
object.QgsPort = 4050
|
||||||
|
|
||||||
|
testAppend(object, tdxObjectVsock, t)
|
||||||
|
}
|
||||||
|
|
||||||
var objectEPCString = "-object memory-backend-epc,id=epc0,size=65536,prealloc=on"
|
var objectEPCString = "-object memory-backend-epc,id=epc0,size=65536,prealloc=on"
|
||||||
|
|
||||||
func TestAppendEPCObject(t *testing.T) {
|
func TestAppendEPCObject(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user