mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-04 06:54:28 +01:00
runtime: enable sandbox feature on qemu
Enable "-sandbox on" in qemu can introduce another protect layer on the host, to make the secure container more secure. The default option is disable because this feature may introduce some performance cost, even though user can enable /proc/sys/net/core/bpf_jit_enable to reduce the impact. Fixes: #2266 Signed-off-by: Feng Wang <feng.wang@databricks.com>
This commit is contained in:
@@ -629,30 +629,32 @@ func (q *qemu) CreateVM(ctx context.Context, id string, network Network, hypervi
|
||||
// some devices configuration may also change kernel params, make sure this is called afterwards
|
||||
Params: q.kernelParameters(),
|
||||
}
|
||||
q.checkBpfEnabled()
|
||||
|
||||
qemuConfig := govmmQemu.Config{
|
||||
Name: fmt.Sprintf("sandbox-%s", q.id),
|
||||
UUID: q.state.UUID,
|
||||
Path: qemuPath,
|
||||
Ctx: q.qmpMonitorCh.ctx,
|
||||
Uid: q.config.Uid,
|
||||
Gid: q.config.Gid,
|
||||
Groups: q.config.Groups,
|
||||
Machine: machine,
|
||||
SMP: smp,
|
||||
Memory: memory,
|
||||
Devices: devices,
|
||||
CPUModel: cpuModel,
|
||||
Kernel: kernel,
|
||||
RTC: rtc,
|
||||
QMPSockets: qmpSockets,
|
||||
Knobs: knobs,
|
||||
Incoming: incoming,
|
||||
VGA: "none",
|
||||
GlobalParam: "kvm-pit.lost_tick_policy=discard",
|
||||
Bios: firmwarePath,
|
||||
PFlash: pflash,
|
||||
PidFile: filepath.Join(q.config.VMStorePath, q.id, "pid"),
|
||||
Name: fmt.Sprintf("sandbox-%s", q.id),
|
||||
UUID: q.state.UUID,
|
||||
Path: qemuPath,
|
||||
Ctx: q.qmpMonitorCh.ctx,
|
||||
Uid: q.config.Uid,
|
||||
Gid: q.config.Gid,
|
||||
Groups: q.config.Groups,
|
||||
Machine: machine,
|
||||
SMP: smp,
|
||||
Memory: memory,
|
||||
Devices: devices,
|
||||
CPUModel: cpuModel,
|
||||
SeccompSandbox: q.config.SeccompSandbox,
|
||||
Kernel: kernel,
|
||||
RTC: rtc,
|
||||
QMPSockets: qmpSockets,
|
||||
Knobs: knobs,
|
||||
Incoming: incoming,
|
||||
VGA: "none",
|
||||
GlobalParam: "kvm-pit.lost_tick_policy=discard",
|
||||
Bios: firmwarePath,
|
||||
PFlash: pflash,
|
||||
PidFile: filepath.Join(q.config.VMStorePath, q.id, "pid"),
|
||||
}
|
||||
|
||||
qemuConfig.Devices, qemuConfig.Bios, err = q.arch.appendProtectionDevice(qemuConfig.Devices, firmwarePath, firmwareVolumePath)
|
||||
@@ -689,6 +691,25 @@ func (q *qemu) CreateVM(ctx context.Context, id string, network Network, hypervi
|
||||
return err
|
||||
}
|
||||
|
||||
func (q *qemu) checkBpfEnabled() {
|
||||
if q.config.SeccompSandbox != "" {
|
||||
out, err := os.ReadFile("/proc/sys/net/core/bpf_jit_enable")
|
||||
if err != nil {
|
||||
q.Logger().WithError(err).Warningf("failed to get bpf_jit_enable status")
|
||||
return
|
||||
}
|
||||
enabled, err := strconv.Atoi(string(out))
|
||||
if err != nil {
|
||||
q.Logger().WithError(err).Warningf("failed to convert bpf_jit_enable status to integer")
|
||||
return
|
||||
}
|
||||
if enabled == 0 {
|
||||
q.Logger().Warningf("bpf_jit_enable is disabled. " +
|
||||
"It's recommended to turn on bpf_jit_enable to reduce the performance impact of QEMU seccomp sandbox.")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (q *qemu) vhostFSSocketPath(id string) (string, error) {
|
||||
return utils.BuildSocketPath(q.config.VMStorePath, id, vhostFSSocket)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user