Join our Newsletter — 33% off our NHI Course
Home› Guides› KVM and libvirt Security Guide: sVirt, QEMU Sandboxing…
Guide Endpoint Security

KVM and libvirt Security Guide: sVirt, QEMU Sandboxing and Host Hardening

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 8 November 2026 13 min read
On this page

On a KVM host, anyone with a read-write connection to the system libvirt daemon is effectively root, and every guest is an untrusted program feeding data into a QEMU process on the host. KVM, QEMU and libvirt sit underneath Red Hat Enterprise Linux virtualisation, OpenStack Nova, Proxmox VE and many home-grown private clouds, so the same few settings decide whether a guest compromise stays inside the guest. This guide explains who can control a libvirt host and how, how sVirt labelling, cgroups and seccomp confine each QEMU process, how to secure remote management, migration and disk images, and what to log. It is written for Linux platform engineers, cloud operators and security architects running KVM in production.

This is an independent guide from NHI Mgmt Group, based on libvirt's public documentation as of November 2026. It is not sponsored or reviewed by libvirt. Product features change, so confirm settings against libvirt's current documentation.

Key takeaways

  • The management socket is a root credential. libvirt's own documentation says a read-write connection to a system-mode daemon is effectively root-equivalent, so socket permissions, polkit rules and remote authentication are privileged access controls.
  • Keep sVirt on. With SELinux, each guest runs in its own svirt_t domain with a unique MCS category pair; with AppArmor, each guest gets a generated profile. Setting security_driver="none" removes the barrier between guests.
  • Never run QEMU as root. Both QEMU and libvirt maintainers say this plainly; set user and group to qemu in qemu.conf and stack MAC, cgroups, namespaces and seccomp on top.
  • Treat guest data as hostile. Disable format probing, reject untrusted images with backing files, and never mount guest images on the host.
  • Isolate the planes. Management (16514 TLS), migration and storage traffic belong on networks guests cannot reach, with encrypted migration.

How identity and access work in KVM and libvirt

KVM is the kernel module; QEMU is the per-guest user-space process that emulates devices; libvirt is the management layer that starts QEMU, labels resources and exposes an API. Access control therefore happens at the libvirt API, not in KVM itself.

Connection modes

URIDaemon runs asWho can connectRisk
qemu:///sessionThe connecting userSame UID onlyGuests have the user's own privileges; no escalation by connecting
qemu:///system (read-write socket)rootControlled by socket mode, group, polkitRoot-equivalent: can attach host devices and files to guests
qemu:///system (read-only socket)rootBy default any local userInformation disclosure about guests and host
qemu+tls://host/systemrootClients with certificates from the trusted CA, optionally filtered by DNDefault accepts any certificate the CA issued
qemu+tcp:// on 16509rootSASL clientsUnencrypted unless GSSAPI; libvirt documents it for test debugging only

Authentication options

  • UNIX socket permissions: Without polkit, the read-write socket is mode 0700 (root only). unix_sock_group and unix_sock_rw_perms widen it to a group. Membership of that group (often libvirt) is root on the host, and should be reviewed as such.
  • polkit: auth_unix_rw defaults to polkit on most distributions, with actions org.libvirt.unix.manage and org.libvirt.unix.monitor. Rules live in /etc/polkit-1/rules.d.
  • SASL: Set per listener with auth_unix_ro, auth_unix_rw and auth_tls; mechanisms in mech_list in /etc/sasl2/libvirt.conf. GSSAPI (Kerberos) is the default and the only one considered secure over plain TCP. scram-sha-256 is available for passwords, but its user database /etc/libvirt/passwd.db holds passwords in clear text. DIGEST-MD5 and SCRAM-SHA-1 are discouraged.
  • Fine-grained ACLs: libvirt's access control framework defaults to the none driver, which performs no checks. Setting access_drivers = [ "polkit" ] in the daemon configuration enables per-object permissions such as domain:start, domain:migrate, domain:screenshot, storage-vol:data-read and secret objects. Use this where operators should manage some guests but not all.

Admin roles and privileged access

Map people and tools to the narrowest connection they need.

RoleAccessControl
Host administratorRoot shell, daemon configurationNamed accounts through PAM or a PAM-integrated bastion, no shared root
VM operatorStart, stop, console for a subset of guestspolkit ACL driver with per-domain rules instead of libvirt group membership
MonitoringRead-only stateRead-only socket or org.libvirt.unix.monitor
Orchestrator (Nova, Proxmox, automation)Full API, often remoteTLS client certificate with tls_allowed_dn_list, rotated and inventoried
Daemon administrationAdmin socket (libvirt-admin-sock or virt*d-admin-sock)Root only; can reconfigure the daemon and disconnect clients
  • Remember the console: Graphical consoles (VNC, SPICE) and the QEMU monitor are privileged. QEMU's security documentation warns that monitor commands such as migrate can spawn processes and blockdev-add can expose host files to a guest. Keep the monitor on a local UNIX socket managed by libvirt.
  • Insiders and contractors: Hypervisor operators can read any guest's memory and disks. Limit who holds these roles and log their sessions. See the Insider Threat from Fake IT Workers Guide.

For privileged session control patterns, see the Privileged Access Management Guide.

Integrations, API tokens and service accounts

  • TLS client certificates: Orchestrators authenticate with a client key at /etc/pki/libvirt/private/clientkey.pem and certificate /etc/pki/libvirt/clientcert.pem; the server key is at /etc/pki/libvirt/private/serverkey.pem. The default server configuration accepts any client with a certificate from the CA, so set tls_allowed_dn_list and use a CA dedicated to libvirt. Never set no_verify=1 in client URIs outside a lab.
  • Kerberos keytabs: GSSAPI needs a libvirt/<host>@<REALM> principal and a keytab at /etc/libvirt/krb5.tab. Protect and rotate it like any host keytab. See the Linux Service Accounts and Keytab Management Guide.
  • SSH transport: qemu+ssh:// URIs inherit the remote user's rights. An automation key for a user in the libvirt group is a root key for that host.
  • libvirt secrets: Disk encryption passphrases and Ceph or iSCSI credentials are stored as libvirt secret objects. Restrict who can read them with the ACL driver.
  • Guest-side credentials: Cloud-init data, guest agent channels and metadata services cross the guest boundary. Treat anything injected into guests as visible to the guest's administrator.

Each of these is a machine identity that can control a hypervisor. Record owner, scope and rotation for every one, and prefer short-lived certificates issued by automation over long-lived keys copied between hosts. When an orchestrator is decommissioned, revoke its certificate and remove its DN from tls_allowed_dn_list on every host in the same change. See the Machine Identity, PKI and Certificate Lifecycle Guide and the NHI Authentication Guide.

Guest confinement: sVirt, cgroups and seccomp

QEMU's documentation states its security goal: a malicious guest must not escape into the QEMU host process or reach other guests' data. It treats only the virtualisation use case (an accelerator such as KVM with listed machine types such as pc and q35 on x86) as a security boundary; pure TCG emulation is not one. Layer the confinement:

LayerMechanismKey settings
POSIX identityQEMU runs as an unprivileged useruser = "qemu", group = "qemu" in /etc/libvirt/qemu.conf; without it QEMU runs as root:root
SELinux sVirtPer-guest domain system_u:system_r:svirt_t:s0:cX,cY and matching svirt_image_t file labelsDynamic labelling (default) relabels exclusive disks at start; shared disks get svirt_image_t:s0, read-only disks svirt_content_t:s0
AppArmor sVirtPer-guest profile generated by virt-aa-helper/etc/apparmor.d/libvirt/libvirt-<uuid> and TEMPLATE
cgroupsPer-guest device ACL and resource limitsDefault devices limited to /dev/null, /dev/kvm, /dev/urandom and similar, plus assigned disks; CPU, memory and I/O limits
seccompQEMU -sandbox filters unneeded system callsControlled from libvirt by seccomp_sandbox in qemu.conf
NamespacesPrivate mount namespace with only granted device nodesEnabled by libvirt by default on current releases
  • Do not disable the driver: security_driver="none" disables sVirt on both SELinux and AppArmor hosts. Prefer security_require_confined = 1 so guests fail to start rather than run unconfined.
  • Network file systems: NFS and other unlabelled file systems need the virt_use_nfs boolean or a context mount option. Dynamic labels may not propagate during migration on these, so libvirt suggests static labels there. Do not "fix" denials by switching SELinux to permissive.
  • Capabilities: Since libvirt 6.0.0, QEMU running as root keeps all capabilities, whereas non-root QEMU has none. That change makes running as root even worse than it used to be.
  • Device passthrough: QEMU classes PCI and USB passthrough devices as untrusted input. VFIO assignment gives the guest direct DMA to the device, so use it only with an IOMMU enabled and only for tenants you trust with that hardware.

Guest escape maps to ATT&CK T1611 Escape to Host. For the MAC systems underneath sVirt, see the SELinux Guide and the AppArmor Guide.

Choosing between SELinux and AppArmor confinement

The choice usually follows the distribution: RHEL, Fedora and their derivatives ship SELinux with sVirt policy; Ubuntu and SUSE-family systems commonly use AppArmor. SELinux sVirt gives strong separation by MCS category without per-guest policy files, and the labels are visible with ps -eZ and ls -Z, which makes verification easy at scale. AppArmor generates a profile per guest from a template, which is simpler to read and tune but depends on virt-aa-helper correctly listing every file a guest needs. Small estates should stay with the distribution default rather than switch; large clouds should standardise on one so that detection content and runbooks are written once.

Confidential computing

sVirt protects guests from each other, not from the host. Where tenants must be protected from host administrators, memory encryption technologies such as AMD SEV or Intel TDX are the relevant control, and libvirt exposes launch security settings for them. Treat these as a separate design decision with their own attestation process rather than a hardening toggle.

Logging and detection

  • Daemon and guest logs: virtlogd manages QEMU guest logs with size limits and rotation; keep it running while guests run, and ship logs centrally.
  • Host audit: Collect Linux audit records for AVC denials on svirt_t domains (a denial from a guest's QEMU process is a possible escape attempt or a misconfiguration) and libvirt's own virtualisation audit events for guest start, stop and resource assignment. See the Linux Logging and auditd for Defenders Guide.
  • Configuration changes: Alert on edits to qemu.conf, libvirtd.conf or virt*d.conf, polkit rules, membership of the libvirt group, and new domain XML that adds <hostdev>, host file systems or <seclabel type='none'>.
  • Network: Flag connections to 16509 and 16514 from anything other than orchestrators, and any migration traffic outside the migration network.
MetricTarget
Running guests confined by sVirt (svirt_t or per-guest AppArmor profile)100%
Hosts with QEMU running as rootZero
Hosts with TCP 16509 listeningZero in production
Accounts in the libvirt group or with polkit manage rightsReviewed quarterly, trending down
Guests with PCI passthroughInventoried with owner and justification
Hosts patched for current QEMU and kernel security fixesWithin patch SLA

Hardening baseline

  1. Move to modular daemons: libvirt plans to retire the monolithic libvirtd in favour of virtqemud, virtnetworkd, virtstoraged and friends, with virtproxyd for remote access. Migrate with guests stopped or live-migrated away. With socket activation, socket permissions are set in systemd units (SocketMode, SocketGroup), not in the daemon configuration file.
  2. Lock the local socket: Remove broad group access, enable polkit and the polkit ACL driver for operators.
  3. Remote access over TLS only: Keep libvirtd-tcp.socket and virtproxyd-tcp.socket disabled; enable the TLS socket only after certificates and tls_allowed_dn_list are in place.
  4. Confine QEMU: Non-root user and group, SELinux enforcing or AppArmor profiles loaded, sVirt required, seccomp on.
  5. Treat disk images as untrusted: Specify disk formats explicitly so the host never probes a guest-writable raw disk (a guest can write a qcow2 header pointing at host files); reject uploaded images with backing files; check logical size limits; inspect contents only with libguestfs or a throwaway VM.
  6. Separate networks: Dedicated management, migration and storage addresses reachable only by virtualisation hosts; encrypted migration (TLS or tunnelled through libvirt RPC); encrypt images on network storage.
  7. Harden the host: Minimal install, no other workloads, kernel and QEMU patched together. See the Linux Server Hardening Guide.
  8. Test and roll back: Pilot each change on one host with representative guests, watch AVC denials, and keep previous configuration files under version control for quick reversal.

Framework mapping

ControlFramework reference
sVirt, seccomp, cgroups per guestNIST SP 800-53 SC-39 Process Isolation, AC-6 Least Privilege
Management, migration and storage networksNIST SP 800-53 SC-7; CSF 2.0 PR.IR-01; ISO/IEC 27001:2022 A.8.22
Hardened daemon and QEMU configurationNIST SP 800-53 CM-6, CM-7; CIS Controls v8.1 Control 4
Logging of guest and API activityNIST SP 800-53 AU-2, AU-12; CSF 2.0 DE.CM-09
Guest escapeATT&CK T1611; T1068 Exploitation for Privilege Escalation

Common misconfigurations

  • Everyone in the libvirt group: Convenient for developers, but it grants root on the host to each member.
  • sVirt switched off: security_driver="none" or SELinux permissive after an NFS label problem, leaving every guest able to reach every other guest's disks after an escape.
  • Plain TCP management: listen_tcp on 16509 with minimal SASL settings, left over from testing; use TLS or the local socket instead.
  • Any certificate accepted: TLS enabled with a shared enterprise CA and no tls_allowed_dn_list, so any internal certificate can drive the hypervisor.
  • Format probing on uploaded images: Allowing auto-detection on tenant-supplied raw images, opening host file reads through crafted backing files.
  • Flat networks: Migration and management on the guest network, exposing guest memory in transit. Hypervisor management planes are a repeat ransomware target; see the ESXi Ransomware Playbook for the response pattern, which applies equally to KVM estates.

Practitioner checklist

  • Confirm QEMU runs as qemu:qemu on every host.
  • Verify every running guest is in a unique svirt_t category or AppArmor profile, and set security_require_confined.
  • Audit libvirt group membership and polkit rules; enable the polkit ACL driver for scoped operators.
  • Disable TCP 16509; require TLS with tls_allowed_dn_list and a dedicated CA for remote access.
  • Inventory TLS client certificates, keytabs, SSH keys and libvirt secrets with owners and rotation dates.
  • Specify disk formats explicitly and reject untrusted images with backing files.
  • Place management, migration and storage on isolated networks and encrypt migration.
  • Plan the move to modular daemons and set socket permissions in systemd units.
  • Ship virtlogd output, audit AVC denials and libvirt configuration changes to the SIEM.

Standards and references

Related NHI Mgmt Group resources: Hypervisor and Virtualisation Security Guide · Proxmox VE Security Hardening Guide · Red Hat Enterprise Linux Security Hardening Guide · SELinux Guide · VMware ESXi Hardening Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 8 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.