KubeVirt mTLS Certificate Architecture#
KubeVirt enforces mutual TLS (mTLS) across all internal component boundaries. The central implementation lives in pkg/util/tls/tls.go and pkg/util/tls/ca-manager.go. Certificate managers are initialized at startup from filesystem paths (via pkg/certificates/bootstrap/cert-manager.go) , and CA bundles are loaded from a Kubernetes ConfigMap (kubevirt-ca by default) watched via an informer-backed CA manager .
Component Identity and CN Naming#
When certificates are issued by KubeVirt's own CA (non-externally-managed mode), peer identity is encoded in the certificate's Common Name using a structured format :
kubevirt.io:system:<role>:<component>
- role is
client(for outgoing connections) ornode(for server-side node identity) - component is the component name:
virt-handler,migration,monitoring, etc.
The verifyPeerCert function validates this CN after chain verification. Accepted CN types are parameterized per endpoint: the virt-handler server accepts virt-handler CNs , the migration server accepts a configurable list (defaulting to ["virt-handler", "migration"]) , and the vmstats endpoint accepts monitoring .
virt-handler TLS Configuration#
virt-handler maintains four distinct TLS configurations, set up in setupTLS:
| Config | Function | CN Types Accepted |
|---|---|---|
serverTLSConfig | Console/lifecycle API (port 8186) | ["virt-handler"] |
migrationServerTLSConfig | Migration target server | configurable via --migration-cn-types |
migrationClientTLSConfig | Migration source client (dedicated cert) | peer must be virt-handler |
vmStatsTLSConfig | VM statistics endpoint (port 8187) | ["monitoring"] |
promTLSConfig | Prometheus metrics (port 8185) | client cert optional (VerifyClientCertIfGiven) |
Three separate certificate managers back these configs — one for the server cert, one dedicated to migration, and one for vsock client identity — all loaded from distinct filesystem paths .
Dedicated Migration Certificate (PR #15949)#
As of PR #15949 / #16168, migration mTLS uses a dedicated migration certificate rather than reusing the handler's server cert. During a canary upgrade, the migration server accepts both virt-handler and migration CNs simultaneously to allow rolling upgrades without dropping live migrations. Once all handlers are updated, the old client cert path is removed (see #18698).
virt-api TLS (Aggregated API)#
virt-api uses SetupTLSWithCertManager with tls.VerifyClientCertIfGiven . For the aggregated API server path, it uses a separate KubernetesCAManager that reads allowed CNs from the requestheader-allowed-names key in the kube-system/extension-apiserver-authentication ConfigMap . When this list is non-empty, the peer certificate CN is validated against it; an empty list disables CN enforcement .
CA Manager Architecture#
Two CA manager types share a common informer-backed base :
ClientCAManager(NewCAManager) — Reads a PEM CA bundle from a named ConfigMap key and builds anx509.CertPool. Used by all virt-handler mTLS setups with thekubevirt-caConfigMap .KubernetesCAManager(NewKubernetesClientCAManager) — ExtendsClientCAManagerwithGetCNs(), readingrequestheader-allowed-namesfromkube-system/extension-apiserver-authentication. Used by virt-api for aggregated API CN enforcement .
Both managers cache by ConfigMap ResourceVersion to avoid redundant parsing .
⚠️ Security Audit Finding: CN Bypass in Externally-Managed Mode (LOW-4)#
The Quarkslab/OSTIF security audit identified LOW-4: when virt-handler is started with --externally-managed, verifyPeerCert skips the CN check entirely and accepts any certificate that validates against the configured intermediate CA pool :
if externallyManaged {
return nil // CN check is never reached
}
This affects all four virt-handler TLS configs (server, migration server, migration client, vmstats). The --externally-managed flag enables intermediate certificate chain support for PKI environments that use their own CA hierarchy ; as a side effect it drops the identity check. The audit report is available at the OSTIF site. As of this writing, no fix has been merged (#19286).
A related finding, LOW-13 (#19287), reports that the virt-operator webhook does not require client certificates and is reachable from arbitrary pods.
TLS Version and Cipher Configuration#
The minimum TLS version defaults to TLS 1.2 and is configurable via KubeVirt.spec.configuration.tlsConfiguration. Cipher suites and minimum version are applied at connection time from the live KubeVirt CR, so changes take effect without a restart .
Key Source Files#
| File | Purpose |
|---|---|
pkg/util/tls/tls.go | TLS config builders, verifyPeerCert, cipher/version helpers |
pkg/util/tls/ca-manager.go | CA pool and CN list managers |
cmd/virt-handler/virt-handler.go | virt-handler TLS wiring (setupTLS, cert paths, flags) |
pkg/virt-api/api.go | virt-api TLS setup |
pkg/certificates/bootstrap/cert-manager.go | File-backed and Secret-backed certificate managers |