Skip to content

Commit

Permalink
Fetch platform certificates by calling libvirt API
Browse files Browse the repository at this point in the history
This reverts fetching of the certs from the node labeller. If fetched
directly in virt-launcher context that will automatically handle
certificates rotation since the API call will return the most recent
state.

Signed-off-by: Vasiliy Ulyanov <[email protected]>
  • Loading branch information
vasiliy-ul committed Jun 23, 2023
1 parent 38424c8 commit a32b3f0
Show file tree
Hide file tree
Showing 8 changed files with 2 additions and 84 deletions.
2 changes: 0 additions & 2 deletions cmd/virt-handler/virt-handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,8 +392,6 @@ func (app *virtHandlerApp) Run() {
recorder,
vmiSourceInformer,
app.VirtShareDir,
nodeLabellerController.SEV.PDH,
nodeLabellerController.SEV.CertChain,
)

promdomain.SetupDomainStatsCollector(app.virtCli, app.VirtShareDir, app.HostOverride, app.MaxRequestsInFlight, vmiSourceInformer)
Expand Down
4 changes: 0 additions & 4 deletions cmd/virt-launcher/node-labeller/node-labeller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,6 @@ virtqemud -d

virsh domcapabilities --machine $MACHINE --arch $ARCH --virttype $VIRTTYPE > /var/lib/kubevirt-node-labeller/virsh_domcapabilities.xml

if grep "sev supported='yes'" /var/lib/kubevirt-node-labeller/virsh_domcapabilities.xml; then
virsh nodesevinfo > /var/lib/kubevirt-node-labeller/nodesevinfo
fi

cp -r /usr/share/libvirt/cpu_map /var/lib/kubevirt-node-labeller

# hypervisor-cpu-baseline command only works on x86
Expand Down
49 changes: 0 additions & 49 deletions pkg/virt-handler/node-labeller/cpu_plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
package nodelabeller

import (
"bufio"
"encoding/xml"
"fmt"
"os"
Expand Down Expand Up @@ -210,15 +209,6 @@ func (n *NodeLabeller) getDomCapabilities() (HostDomCapabilities, error) {
hostDomCapabilities.SEV.SupportedES = "no"
}

if err == nil && hostDomCapabilities.SEV.Supported == "yes" {
if pdh, certChain, err := n.parseNodeSEVInfo(n.nodeSEVInfoFileName); err != nil {
return HostDomCapabilities{}, err
} else {
hostDomCapabilities.SEV.PDH = pdh
hostDomCapabilities.SEV.CertChain = certChain
}
}

return hostDomCapabilities, err
}

Expand Down Expand Up @@ -259,42 +249,3 @@ func (n *NodeLabeller) getStructureFromXMLFile(path string, structure interface{

return xml.Unmarshal(rawFile, structure)
}

func (n *NodeLabeller) parseNodeSEVInfo(fileName string) (pdh string, certChain string, err error) {
file, err := os.Open(filepath.Join(n.volumePath, fileName))
if err != nil {
return "", "", err
}
defer file.Close()

scanner := bufio.NewScanner(file)
for scanner.Scan() {
line := scanner.Text()
if len(line) == 0 {
continue
}
fields := strings.Split(line, ":")
if len(fields) != 2 {
return "", "", fmt.Errorf("failed to parse '%s'", line)
}
switch strings.TrimSpace(fields[0]) {
case "pdh":
pdh = strings.TrimSpace(fields[1])
case "cert-chain":
certChain = strings.TrimSpace(fields[1])
}
}
if err := scanner.Err(); err != nil {
return "", "", err
}

if pdh == "" {
return "", "", fmt.Errorf("pdh not found")
}

if certChain == "" {
return "", "", fmt.Errorf("cert-chain not found")
}

return pdh, certChain, nil
}
5 changes: 0 additions & 5 deletions pkg/virt-handler/node-labeller/cpu_plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ var _ = BeforeSuite(func() {
logger: log.DefaultLogger(),
volumePath: "testdata",
domCapabilitiesFileName: "virsh_domcapabilities.xml",
nodeSEVInfoFileName: "nodesevinfo",
hostCPUModel: hostCPUModel{requiredFeatures: make(map[string]bool, 0)},
}
})
Expand Down Expand Up @@ -187,8 +186,6 @@ var _ = Describe("Node-labeller config", func() {
Expect(nlController.SEV.CBitPos).To(Equal(uint(47)))
Expect(nlController.SEV.ReducedPhysBits).To(Equal(uint(1)))
Expect(nlController.SEV.MaxGuests).To(Equal(uint(15)))
Expect(nlController.SEV.PDH).To(Equal("AAABBBCCC"))
Expect(nlController.SEV.CertChain).To(Equal("DDDEEEFFF"))

if withES {
Expect(nlController.SEV.SupportedES).To(Equal("yes"))
Expand All @@ -204,8 +201,6 @@ var _ = Describe("Node-labeller config", func() {
Expect(nlController.SEV.MaxGuests).To(BeZero())
Expect(nlController.SEV.SupportedES).To(Equal("no"))
Expect(nlController.SEV.MaxESGuests).To(BeZero())
Expect(nlController.SEV.PDH).To(Equal(""))
Expect(nlController.SEV.CertChain).To(Equal(""))
}
},
Entry("when only SEV is supported", true, false),
Expand Down
2 changes: 0 additions & 2 deletions pkg/virt-handler/node-labeller/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,6 @@ type SEVConfiguration struct {
MaxGuests uint `xml:"maxGuests"`
MaxESGuests uint `xml:"maxESGuests"`
SupportedES string `xml:"-"`
PDH string
CertChain string
}

type KSMConfiguration struct {
Expand Down
2 changes: 0 additions & 2 deletions pkg/virt-handler/node-labeller/node_labeller.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ type NodeLabeller struct {
cpuModelVendor string
volumePath string
domCapabilitiesFileName string
nodeSEVInfoFileName string
capabilities *api.Capabilities
hostCPUModel hostCPUModel
SEV SEVConfiguration
Expand All @@ -109,7 +108,6 @@ func newNodeLabeller(clusterConfig *virtconfig.ClusterConfig, clientset kubecli.
queue: workqueue.NewNamedRateLimitingQueue(workqueue.DefaultControllerRateLimiter(), "virt-handler-node-labeller"),
volumePath: volumePath,
domCapabilitiesFileName: "virsh_domcapabilities.xml",
nodeSEVInfoFileName: "nodesevinfo",
hostCPUModel: hostCPUModel{requiredFeatures: make(map[string]bool, 0)},
KSM: KSMConfiguration{SysfsFilePath: ksmSysFsFilePath},
}
Expand Down
7 changes: 0 additions & 7 deletions pkg/virt-handler/node-labeller/testdata/nodesevinfo

This file was deleted.

15 changes: 2 additions & 13 deletions pkg/virt-handler/rest/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,13 @@ type LifecycleHandler struct {
recorder record.EventRecorder
vmiInformer cache.SharedIndexInformer
virtShareDir string
pdh string
certChain string
}

func NewLifecycleHandler(recorder record.EventRecorder, vmiInformer cache.SharedIndexInformer, virtShareDir, pdh, certChain string) *LifecycleHandler {
func NewLifecycleHandler(recorder record.EventRecorder, vmiInformer cache.SharedIndexInformer, virtShareDir string) *LifecycleHandler {
return &LifecycleHandler{
recorder: recorder,
vmiInformer: vmiInformer,
virtShareDir: virtShareDir,
pdh: pdh,
certChain: certChain,
}
}

Expand Down Expand Up @@ -247,7 +243,7 @@ func (lh *LifecycleHandler) getVMILauncherClient(request *restful.Request, respo
}

func (lh *LifecycleHandler) SEVFetchCertChainHandler(request *restful.Request, response *restful.Response) {
/*vmi, client, err := lh.getVMILauncherClient(request, response)
vmi, client, err := lh.getVMILauncherClient(request, response)
if err != nil {
return
}
Expand All @@ -259,13 +255,6 @@ func (lh *LifecycleHandler) SEVFetchCertChainHandler(request *restful.Request, r
log.Log.Object(vmi).Reason(err).Error("Failed to get SEV platform info")
response.WriteError(http.StatusInternalServerError, err)
return
}*/

log.Log.Infof("Retrieving SEV platform info")

sevPlatformInfo := v1.SEVPlatformInfo{
PDH: lh.pdh,
CertChain: lh.certChain,
}

response.WriteEntity(sevPlatformInfo)
Expand Down

0 comments on commit a32b3f0

Please sign in to comment.