Skip to content

Commit

Permalink
vc: qemu: Add option to change entropy source
Browse files Browse the repository at this point in the history
This adds a config option to choose the VM entropy
source.

Fixes: kata-containers#702

Signed-off-by: Jose Carlos Venegas Munoz <jose.carlos.venegas.munoz@intel.com>
  • Loading branch information
jcvenegas committed Sep 25, 2018
1 parent e39a734 commit 23747f2
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ DEFMEMSLOTS := 10
DEFBRIDGES := 1
#Default network model
DEFNETWORKMODEL := macvtap
#Default entropy source
DEFENTROPYSOURCE := /dev/urandom

DEFDISABLEBLOCK := false
DEFBLOCKSTORAGEDRIVER := virtio-scsi
Expand Down Expand Up @@ -222,6 +224,8 @@ USER_VARS += DEFENABLEDEBUG
USER_VARS += DEFDISABLENESTINGCHECKS
USER_VARS += DEFMSIZE9P
USER_VARS += DEFHOTPLUGVFIOONROOTBUS
USER_VARS += DEFENTROPYSOURCE


V = @
Q = $(V:1=)
Expand Down Expand Up @@ -323,6 +327,7 @@ const defaultEnableDebug bool = $(DEFENABLEDEBUG)
const defaultDisableNestingChecks bool = $(DEFDISABLENESTINGCHECKS)
const defaultMsize9p uint32 = $(DEFMSIZE9P)
const defaultHotplugVFIOOnRootBus bool = $(DEFHOTPLUGVFIOONROOTBUS)
const defaultEntropySource = "$(DEFENTROPYSOURCE)"

// Default config file used by stateless systems.
var defaultRuntimeConfiguration = "$(CONFIG_PATH)"
Expand Down Expand Up @@ -413,6 +418,7 @@ $(GENERATED_FILES): %: %.in Makefile VERSION
-e "s|@DEFDISABLENESTINGCHECKS@|$(DEFDISABLENESTINGCHECKS)|g" \
-e "s|@DEFMSIZE9P@|$(DEFMSIZE9P)|g" \
-e "s|@DEFHOTPLUGONROOTBUS@|$(DEFHOTPLUGVFIOONROOTBUS)|g" \
-e "s|@DEFENTROPYSOURCE@|$(DEFENTROPYSOURCE)|g" \
$< > $@

generate-config: $(CONFIG)
Expand Down
10 changes: 10 additions & 0 deletions cli/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type hypervisor struct {
KernelParams string `toml:"kernel_params"`
MachineType string `toml:"machine_type"`
BlockDeviceDriver string `toml:"block_device_driver"`
EntropySource string `toml:"entropy_source"`
NumVCPUs int32 `toml:"default_vcpus"`
DefaultMaxVCPUs uint32 `toml:"default_maxvcpus"`
MemorySize uint32 `toml:"default_memory"`
Expand Down Expand Up @@ -208,6 +209,14 @@ func (h hypervisor) machineType() string {
return h.MachineType
}

func (h hypervisor) GetEntropySource() string {
if h.EntropySource == "" {
return defaultEntropySource
}

return h.EntropySource
}

func (h hypervisor) defaultVCPUs() uint32 {
numCPUs := goruntime.NumCPU()

Expand Down Expand Up @@ -403,6 +412,7 @@ func newQemuHypervisorConfig(h hypervisor) (vc.HypervisorConfig, error) {
DefaultMaxVCPUs: h.defaultMaxVCPUs(),
MemorySize: h.defaultMemSz(),
MemSlots: h.defaultMemSlots(),
EntropySource: h.GetEntropySource(),
DefaultBridges: h.defaultBridges(),
DisableBlockDeviceUse: h.DisableBlockDeviceUse,
MemPrealloc: h.MemPrealloc,
Expand Down
4 changes: 4 additions & 0 deletions cli/config/configuration.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,10 @@ enable_iothreads = @DEFENABLEIOTHREADS@
# If host doesn't support vhost_net, set to true. Thus we won't create vhost fds for nics.
# Default false
#disable_vhost_net = true
#
# Default entropy source.
# The path to a host source of entropy (including a real hardware RNG)
#entropy_source= "@DEFENTROPYSOURCE@"

[factory]
# VM templating support. Once enabled, new VMs are created from template
Expand Down
1 change: 1 addition & 0 deletions cli/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ func createAllRuntimeConfigFiles(dir, hypervisor string) (config testRuntimeConf
HotplugVFIOOnRootBus: hotplugVFIOOnRootBus,
Msize9p: defaultMsize9p,
MemSlots: defaultMemSlots,
EntropySource: defaultEntropySource,
}

agentConfig := vc.KataAgentConfig{}
Expand Down
4 changes: 3 additions & 1 deletion cli/kata-env.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
//
// XXX: Increment for every change to the output format
// (meaning any change to the EnvInfo type).
const formatVersion = "1.0.17"
const formatVersion = "1.0.18"

// MetaInfo stores information on the format of the output itself
type MetaInfo struct {
Expand Down Expand Up @@ -81,6 +81,7 @@ type HypervisorInfo struct {
Version string
Path string
BlockDeviceDriver string
EntropySource string
Msize9p uint32
MemorySlots uint32
Debug bool
Expand Down Expand Up @@ -319,6 +320,7 @@ func getHypervisorInfo(config oci.RuntimeConfig) HypervisorInfo {
Msize9p: config.HypervisorConfig.Msize9p,
UseVSock: config.HypervisorConfig.UseVSock,
MemorySlots: config.HypervisorConfig.MemSlots,
EntropySource: config.HypervisorConfig.EntropySource,
}
}

Expand Down
1 change: 1 addition & 0 deletions cli/kata-env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ func getExpectedHypervisor(config oci.RuntimeConfig) HypervisorInfo {
Msize9p: config.HypervisorConfig.Msize9p,
MemorySlots: config.HypervisorConfig.MemSlots,
Debug: config.HypervisorConfig.Debug,
EntropySource: config.HypervisorConfig.EntropySource,
}
}

Expand Down
2 changes: 2 additions & 0 deletions virtcontainers/device/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ type VFIODev struct {
type RNGDev struct {
// ID is used to identify the device in the hypervisor options.
ID string
// Filename is the file to use as entropy source.
Filename string
}

// VhostUserDeviceAttrs represents data shared by most vhost-user devices
Expand Down
4 changes: 4 additions & 0 deletions virtcontainers/hypervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,10 @@ type HypervisorConfig struct {
// BootFromTemplate is true.
DevicesStatePath string

// EntropySource is the path to a host source of
// entropy (/dev/random, /dev/urandom or real hardware RNG device)
EntropySource string

// customAssets is a map of assets.
// Each value in that map takes precedence over the configured assets.
// For example, if there is a value for the "kernel" key in this map,
Expand Down
3 changes: 2 additions & 1 deletion virtcontainers/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,8 @@ func (q *qemu) createSandbox() error {
}
// Add RNG device to hypervisor
rngDev := config.RNGDev{
ID: rngID,
ID: rngID,
Filename: q.config.EntropySource,
}
qemuConfig.Devices = q.arch.appendRNGDevice(qemuConfig.Devices, rngDev)

Expand Down
3 changes: 2 additions & 1 deletion virtcontainers/qemu_arch_base.go
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ func (q *qemuArchBase) appendVFIODevice(devices []govmmQemu.Device, vfioDev conf
func (q *qemuArchBase) appendRNGDevice(devices []govmmQemu.Device, rngDev config.RNGDev) []govmmQemu.Device {
devices = append(devices,
govmmQemu.RngDevice{
ID: rngDev.ID,
ID: rngDev.ID,
Filename: rngDev.Filename,
},
)

Expand Down

0 comments on commit 23747f2

Please sign in to comment.