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_tdomain with a unique MCS category pair; with AppArmor, each guest gets a generated profile. Settingsecurity_driver="none"removes the barrier between guests. - Never run QEMU as root. Both QEMU and libvirt maintainers say this plainly; set
userandgrouptoqemuinqemu.confand 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
| URI | Daemon runs as | Who can connect | Risk |
|---|---|---|---|
qemu:///session | The connecting user | Same UID only | Guests have the user's own privileges; no escalation by connecting |
qemu:///system (read-write socket) | root | Controlled by socket mode, group, polkit | Root-equivalent: can attach host devices and files to guests |
qemu:///system (read-only socket) | root | By default any local user | Information disclosure about guests and host |
qemu+tls://host/system | root | Clients with certificates from the trusted CA, optionally filtered by DN | Default accepts any certificate the CA issued |
qemu+tcp:// on 16509 | root | SASL clients | Unencrypted 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_groupandunix_sock_rw_permswiden it to a group. Membership of that group (oftenlibvirt) is root on the host, and should be reviewed as such. - polkit:
auth_unix_rwdefaults to polkit on most distributions, with actionsorg.libvirt.unix.manageandorg.libvirt.unix.monitor. Rules live in/etc/polkit-1/rules.d. - SASL: Set per listener with
auth_unix_ro,auth_unix_rwandauth_tls; mechanisms inmech_listin/etc/sasl2/libvirt.conf. GSSAPI (Kerberos) is the default and the only one considered secure over plain TCP.scram-sha-256is available for passwords, but its user database/etc/libvirt/passwd.dbholds passwords in clear text. DIGEST-MD5 and SCRAM-SHA-1 are discouraged. - Fine-grained ACLs: libvirt's access control framework defaults to the
nonedriver, which performs no checks. Settingaccess_drivers = [ "polkit" ]in the daemon configuration enables per-object permissions such asdomain:start,domain:migrate,domain:screenshot,storage-vol:data-readandsecretobjects. 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.
| Role | Access | Control |
|---|---|---|
| Host administrator | Root shell, daemon configuration | Named accounts through PAM or a PAM-integrated bastion, no shared root |
| VM operator | Start, stop, console for a subset of guests | polkit ACL driver with per-domain rules instead of libvirt group membership |
| Monitoring | Read-only state | Read-only socket or org.libvirt.unix.monitor |
| Orchestrator (Nova, Proxmox, automation) | Full API, often remote | TLS client certificate with tls_allowed_dn_list, rotated and inventoried |
| Daemon administration | Admin 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
migratecan spawn processes andblockdev-addcan 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.pemand 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 settls_allowed_dn_listand use a CA dedicated to libvirt. Never setno_verify=1in 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 thelibvirtgroup is a root key for that host. - libvirt secrets: Disk encryption passphrases and Ceph or iSCSI credentials are stored as libvirt
secretobjects. 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:
| Layer | Mechanism | Key settings |
|---|---|---|
| POSIX identity | QEMU runs as an unprivileged user | user = "qemu", group = "qemu" in /etc/libvirt/qemu.conf; without it QEMU runs as root:root |
| SELinux sVirt | Per-guest domain system_u:system_r:svirt_t:s0:cX,cY and matching svirt_image_t file labels | Dynamic labelling (default) relabels exclusive disks at start; shared disks get svirt_image_t:s0, read-only disks svirt_content_t:s0 |
| AppArmor sVirt | Per-guest profile generated by virt-aa-helper | /etc/apparmor.d/libvirt/libvirt-<uuid> and TEMPLATE |
| cgroups | Per-guest device ACL and resource limits | Default devices limited to /dev/null, /dev/kvm, /dev/urandom and similar, plus assigned disks; CPU, memory and I/O limits |
| seccomp | QEMU -sandbox filters unneeded system calls | Controlled from libvirt by seccomp_sandbox in qemu.conf |
| Namespaces | Private mount namespace with only granted device nodes | Enabled by libvirt by default on current releases |
- Do not disable the driver:
security_driver="none"disables sVirt on both SELinux and AppArmor hosts. Prefersecurity_require_confined = 1so guests fail to start rather than run unconfined. - Network file systems: NFS and other unlabelled file systems need the
virt_use_nfsboolean or acontextmount 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:
virtlogdmanages 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_tdomains (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.conforvirt*d.conf, polkit rules, membership of thelibvirtgroup, 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.
| Metric | Target |
|---|---|
Running guests confined by sVirt (svirt_t or per-guest AppArmor profile) | 100% |
| Hosts with QEMU running as root | Zero |
| Hosts with TCP 16509 listening | Zero in production |
Accounts in the libvirt group or with polkit manage rights | Reviewed quarterly, trending down |
| Guests with PCI passthrough | Inventoried with owner and justification |
| Hosts patched for current QEMU and kernel security fixes | Within patch SLA |
Hardening baseline
- Move to modular daemons: libvirt plans to retire the monolithic
libvirtdin favour ofvirtqemud,virtnetworkd,virtstoragedand friends, withvirtproxydfor 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. - Lock the local socket: Remove broad group access, enable polkit and the polkit ACL driver for operators.
- Remote access over TLS only: Keep
libvirtd-tcp.socketandvirtproxyd-tcp.socketdisabled; enable the TLS socket only after certificates andtls_allowed_dn_listare in place. - Confine QEMU: Non-root user and group, SELinux enforcing or AppArmor profiles loaded, sVirt required, seccomp on.
- 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.
- 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.
- Harden the host: Minimal install, no other workloads, kernel and QEMU patched together. See the Linux Server Hardening Guide.
- 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
| Control | Framework reference |
|---|---|
| sVirt, seccomp, cgroups per guest | NIST SP 800-53 SC-39 Process Isolation, AC-6 Least Privilege |
| Management, migration and storage networks | NIST SP 800-53 SC-7; CSF 2.0 PR.IR-01; ISO/IEC 27001:2022 A.8.22 |
| Hardened daemon and QEMU configuration | NIST SP 800-53 CM-6, CM-7; CIS Controls v8.1 Control 4 |
| Logging of guest and API activity | NIST SP 800-53 AU-2, AU-12; CSF 2.0 DE.CM-09 |
| Guest escape | ATT&CK T1611; T1068 Exploitation for Privilege Escalation |
Common misconfigurations
- Everyone in the
libvirtgroup: 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_tcpon 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:qemuon every host. - Verify every running guest is in a unique
svirt_tcategory or AppArmor profile, and setsecurity_require_confined. - Audit
libvirtgroup membership and polkit rules; enable the polkit ACL driver for scoped operators. - Disable TCP 16509; require TLS with
tls_allowed_dn_listand 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
- libvirt: QEMU/KVM/HVF hypervisor driver
- libvirt: Connection authentication
- libvirt: Client access control
- libvirt: Libvirt daemons
- libvirt: Secure usage of libvirt
- libvirt: TLS x509 certificate configuration
- QEMU: Security
- Linux kernel: Linux Security Module Usage
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