[packages/lxd] Up to 6.10.1
arekm
arekm at pld-linux.org
Sun Nov 1 23:24:36 CET 2026
commit 4415b1ac3ed1b7bb01aeb8e2ad90a66b02005e7a
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Sun Nov 1 22:44:31 2026 +0100
Up to 6.10.1
Fixes CVE-2026-97335, CVE-2026-87799, CVE-2026-87798, CVE-2026-86335,
CVE-2026-86334, CVE-2026-85526, CVE-2026-85185, CVE-2026-66897,
CVE-2026-63300, CVE-2026-63299, CVE-2026-63298, CVE-2026-63297,
CVE-2026-63296, CVE-2026-63295, CVE-2026-63294, CVE-2026-63293,
CVE-2026-62420, CVE-2026-55622, CVE-2026-55621, CVE-2026-48769,
CVE-2026-48755, CVE-2026-48752, CVE-2026-48751, CVE-2026-48750,
CVE-2026-48749, CVE-2026-34179, CVE-2026-34178, CVE-2026-34177,
CVE-2026-28385, CVE-2026-28384, CVE-2026-9640, CVE-2026-9639,
CVE-2025-64507, CVE-2025-54291, CVE-2025-54290, CVE-2025-54289,
CVE-2025-54288, CVE-2025-54287, CVE-2025-54286.
lxd-dnsmasq.conf | 4 +
lxd-leaf-cert-auth.patch | 623 +++++++++++++++++++++++++++++++++++++++++++++++
lxd.service | 4 +-
lxd.spec | 125 ++++++----
4 files changed, 713 insertions(+), 43 deletions(-)
---
diff --git a/lxd.spec b/lxd.spec
index e0cc522..6a81d09 100644
--- a/lxd.spec
+++ b/lxd.spec
@@ -1,36 +1,44 @@
Summary: Fast, dense and secure container and virtual machine management
Name: lxd
-Version: 5.21.3
-Release: 3
+Version: 6.10.1
+Release: 1
License: AGPL v3.0
Group: Applications/System
Source0: https://github.com/canonical/lxd/archive/refs/tags/%{name}-%{version}.tar.gz
-# Source0-md5: 7dab2698e4cfbb3f8aba388e97152f98
+# Source0-md5: 76c77c5cedf3fefe2351e5bb90dc4af8
Source1: %{name}.service
Source2: %{name}.init
Source3: %{name}.sysconfig
Source4: %{name}.sh
-URL: http://linuxcontainers.org/
+# cd %{name}-%{name}-%{version}
+# go mod vendor
+# tar cJf ../%{name}-vendor-%{version}.tar.xz vendor
+Source5: %{name}-vendor-%{version}.tar.xz
+# Source5-md5: 7b4d3b97dde7e67358341d1d0c9e600c
+Source6: %{name}-dnsmasq.conf
+Patch0: %{name}-leaf-cert-auth.patch
+URL: https://canonical.com/lxd/
BuildRequires: acl-devel
-%ifarch %{x8664} arm aarch64 ppc64
-BuildRequires: criu-devel >= 1.7
-%endif
BuildRequires: dqlite-devel >= 1.18.0
-BuildRequires: golang >= 1.23
-BuildRequires: libco-devel
-BuildRequires: libuv-devel
-BuildRequires: lxc-devel >= 3.0
+BuildRequires: golang >= 1.27.1
+BuildRequires: libcap-devel
+BuildRequires: lxc-devel >= 5.0.0
BuildRequires: pkgconfig
-BuildRequires: raft-devel >= 0.14.0
-BuildRequires: rpmbuild(macros) >= 1.228
+BuildRequires: rpmbuild(macros) >= 1.644
+BuildRequires: sqlite3-devel
BuildRequires: udev-devel
Requires(post,preun): /sbin/chkconfig
+# usermod --add-subuids
+Requires(post): shadow >= 4.9
Requires(postun): /usr/sbin/groupdel
Requires(pre): /usr/bin/getgid
Requires(pre): /usr/sbin/groupadd
-Requires: dnsmasq
+Requires(post,preun,postun): systemd-units >= 38
+# /etc/dnsmasq.d read by default config
+Requires: dnsmasq >= 2.93-3
Requires: iproute2
-Requires: libcgroup
+# preferred firewall backend for managed networks (NAT, DHCP, ACLs)
+Requires: nftables
Requires: rc-scripts >= 0.4.0.10
Requires: rsync
Requires: squashfs
@@ -39,9 +47,20 @@ Requires: squashfs-tools-ng
Requires: tar
Requires: uidmap
Requires: uname(release) >= 4.1
+Requires: systemd-units >= 38
Requires: xz
+Suggests: %{name}-agent = %{version}-%{release}
+Suggests: cdrkit-mkisofs
+Suggests: edk2-ovmf
+Suggests: lxcfs
+Suggests: qemu-img >= 8.2.2
+%ifarch %{x8664}
+Suggests: qemu-system-x86 >= 8.2.2
+%endif
+Suggests: swtpm
+Suggests: virtiofsd >= 1.10.0
Provides: group(lxd)
-ExclusiveArch: %{ix86} %{x8664} %{arm}
+ExclusiveArch: %{ix86} %{x8664} %{arm} aarch64
BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
%define _enable_debug_packages 0
@@ -54,10 +73,9 @@ BuildRoot: %{tmpdir}/%{name}-%{version}-root-%(id -u -n)
%description
LXD is a next generation system container and virtual machine manager.
-Specifically, it is made of three components:
+Specifically, it is made of two components:
- A system-wide daemon (lxd)
- A command line client (lxc)
-- An OpenStack Nova plugin (nova-compute-lxd)
The daemon exports a REST API both locally and if enabled, over the
network.
@@ -68,18 +86,18 @@ multiple container hosts and easily give you an overview of all the
containers on your network, let you create some more where you want
them and even move them around while they are running.
-The OpenStack plugin then allows you to use your lxd hosts as compute
-nodes, running workloads on containers rather than virtual machines.
-
%package agent
Summary: LXD Agent
+Group: Applications/System
%description agent
-This package contains lxd-agent program to be used inside virtual
-machines (not containers) managed by LXD.
+This package contains lxd-agent, a statically linked program that LXD
+injects into the virtual machines (not containers) it manages. Install
+it on the LXD host.
%package tools
Summary: LXD Tools
+Group: Applications/System
%description tools
This package contains lxd extra tools
@@ -99,43 +117,57 @@ bash-completion for %{name}
Bashowe dopełnianie parametrów dla %{name}
%prep
-%setup -q -n %{name}-%{name}-%{version}
+%setup -q -n %{name}-%{name}-%{version} -a5
+%patch -P0 -p1
%build
export GOPATH=$(pwd)/_dist
export GOBIN=$GOPATH/bin
# flags from ArchLinux package
-export GOFLAGS="-buildmode=pie -trimpath"
+export GOFLAGS="-buildmode=pie -trimpath -mod=vendor"
+export GOCACHE=$(pwd)/.go-cache
+export CGO_CPPFLAGS="%{rpmcppflags}"
+export CGO_CFLAGS="%{rpmcflags}"
+export CGO_LDFLAGS="%{rpmldflags}"
export CGO_LDFLAGS_ALLOW="-Wl,-z,now"
-%goinstall -tags libsqlite3 ./...
-CGO_ENABLED=0 %goinstall -tags netgo ./lxd-migrate/...
-%goinstall -tags agent ./lxd-agent/...
+# cgo and tags as in upstream Makefile
+%goinstall -tags libsqlite3 ./lxd
+%goinstall ./lxc ./fuidshift
+CGO_ENABLED=0 %goinstall -tags netgo ./lxd-user ./lxd-benchmark
+# lxd-agent runs in VM guests and lxd-convert on migration sources of any
+# distribution: fully static, and PIE would add an ld.so interpreter
+CGO_ENABLED=0 GOFLAGS="-trimpath -mod=vendor" %goinstall -tags netgo ./lxd-convert
+CGO_ENABLED=0 GOFLAGS="-trimpath -mod=vendor" %goinstall -tags agent,netgo ./lxd-agent
+
+# the client wants a writable config dir even for completion and manpage
+export LXD_CONF=$(pwd)/.lxd-conf
+$GOBIN/lxc completion bash > lxc.bash
+install -d man
+$GOBIN/lxc manpage man
+$GOBIN/lxd manpage man
# conflict
mv doc/README.md doc/README.doc.md
%install
rm -rf $RPM_BUILD_ROOT
-install -d $RPM_BUILD_ROOT{%{_bindir},%{_sbindir},%{_mandir}/man1,/etc/{rc.d/init.d,sysconfig},%{systemdunitdir}} \
+install -d $RPM_BUILD_ROOT{%{_bindir},%{_sbindir},%{_mandir}/man1,/etc/{rc.d/init.d,sysconfig,dnsmasq.d},%{systemdunitdir}} \
$RPM_BUILD_ROOT%{_libexecdir} \
$RPM_BUILD_ROOT%{bash_compdir} \
$RPM_BUILD_ROOT/var/lib/%{name}/{containers,devices,devlxd,images,security,shmounts,snapshots} \
$RPM_BUILD_ROOT/var/log/%{name}
-# lxd refuses to start containter without this directory
-install -d $RPM_BUILD_ROOT%{_libdir}/%{name}/rootfs
-
install -p _dist/bin/{lxd,lxd-user,lxd-agent} $RPM_BUILD_ROOT%{_sbindir}
-install -p _dist/bin/{lxc,fuidshift,lxc-to-lxd,lxd-benchmark,lxd-migrate} $RPM_BUILD_ROOT%{_bindir}
+install -p _dist/bin/{lxc,fuidshift,lxd-benchmark,lxd-convert} $RPM_BUILD_ROOT%{_bindir}
-# FIXME: it seems that bash completions must be named as command (lxc), so
-# it conflicts with lxc completions (bash-completion-lxc)
-install -p scripts/bash/lxd-client $RPM_BUILD_ROOT%{bash_compdir}/lxc
+cp -p lxc.bash $RPM_BUILD_ROOT%{bash_compdir}/lxc
+cp -p man/*.1 $RPM_BUILD_ROOT%{_mandir}/man1
cp -p %{SOURCE1} $RPM_BUILD_ROOT%{systemdunitdir}
install -p %{SOURCE2} $RPM_BUILD_ROOT/etc/rc.d/init.d/%{name}
cp -p %{SOURCE3} $RPM_BUILD_ROOT/etc/sysconfig/%{name}
+cp -p %{SOURCE6} $RPM_BUILD_ROOT/etc/dnsmasq.d/%{name}.conf
install -p %{SOURCE4} $RPM_BUILD_ROOT%{_libexecdir}/lxd-wrapper
@@ -143,8 +175,19 @@ install -p %{SOURCE4} $RPM_BUILD_ROOT%{_libexecdir}/lxd-wrapper
%groupadd -g 273 %{name}
%post
+# unprivileged containers need a subordinate id range for root; PLD's
+# /etc/subuid and /etc/subgid ship without one
+if ! grep -qs '^root:' /etc/subuid; then
+ /usr/sbin/usermod --add-subuids 1000000-1000999999 root
+fi
+if ! grep -qs '^root:' /etc/subgid; then
+ /usr/sbin/usermod --add-subgids 1000000-1000999999 root
+fi
+# a running system dnsmasq reads /etc/dnsmasq.d/%{name}.conf only at start
+%service -q dnsmasq restart
+%systemd_service_restart dnsmasq.service
/sbin/chkconfig --add %{name}
-%service -n %{name} restart
+# no service restart here: stopping lxd runs "lxd shutdown", which stops every instance
%systemd_post %{name}.service
@@ -168,13 +211,14 @@ rm -rf $RPM_BUILD_ROOT
%defattr(644,root,root,755)
%doc README.md AUTHORS doc/*
%config(noreplace) %verify(not md5 mtime size) /etc/sysconfig/%{name}
+%config(noreplace) %verify(not md5 mtime size) /etc/dnsmasq.d/%{name}.conf
%attr(754,root,root) /etc/rc.d/init.d/%{name}
%attr(755,root,root) %{_bindir}/lxc
%attr(755,root,root) %{_sbindir}/lxd
%attr(755,root,root) %{_sbindir}/lxd-user
%{systemdunitdir}/%{name}.service
-%dir %attr(750,root,root) %{_libdir}/%{name}
-%dir %attr(750,root,root) %{_libdir}/%{name}/rootfs
+%{_mandir}/man1/lxc*.1*
+%{_mandir}/man1/lxd*.1*
%attr(750,root,root) %{_libexecdir}/%{name}-wrapper
%dir %attr(750,root,logs) /var/log/%{name}
%dir %attr(711,root,lxd) /var/lib/%{name}
@@ -193,9 +237,8 @@ rm -rf $RPM_BUILD_ROOT
%files tools
%defattr(644,root,root,755)
%attr(755,root,root) %{_bindir}/fuidshift
-%attr(755,root,root) %{_bindir}/lxc-to-lxd
%attr(755,root,root) %{_bindir}/lxd-benchmark
-%attr(755,root,root) %{_bindir}/lxd-migrate
+%attr(755,root,root) %{_bindir}/lxd-convert
%files -n bash-completion-%{name}
%defattr(644,root,root,755)
diff --git a/lxd-dnsmasq.conf b/lxd-dnsmasq.conf
new file mode 100644
index 0000000..da42a7b
--- /dev/null
+++ b/lxd-dnsmasq.conf
@@ -0,0 +1,4 @@
+# Make a system-wide dnsmasq bind to explicit interfaces and leave the
+# LXD bridge alone; lxd runs its own dnsmasq on lxdbr0.
+bind-interfaces
+except-interface=lxdbr0
diff --git a/lxd-leaf-cert-auth.patch b/lxd-leaf-cert-auth.patch
new file mode 100644
index 0000000..0acd157
--- /dev/null
+++ b/lxd-leaf-cert-auth.patch
@@ -0,0 +1,623 @@
+Authenticate TLS clients by the leaf certificate only; a client could present a
+trusted certificate it holds no key for as a chain member (GHSA-99jp-jwmc-65p4).
+https://github.com/canonical/lxd/pull/19426
+
+diff --git a/lxd-agent/server.go b/lxd-agent/server.go
+index 4328aa814b9f..03c2676a16bf 100644
+--- a/lxd-agent/server.go
++++ b/lxd-agent/server.go
+@@ -10,6 +10,7 @@ import (
+ "net/http"
+ "time"
+
++ "github.com/canonical/lxd/lxd/request"
+ "github.com/canonical/lxd/lxd/response"
+ "github.com/canonical/lxd/lxd/util"
+ "github.com/canonical/lxd/shared"
+@@ -106,14 +107,13 @@ func createCmd(restAPI *http.ServeMux, version string, c APIEndpoint, cert *x509
+ }
+
+ func authenticate(r *http.Request, cert *x509.Certificate) bool {
+- clientCerts := map[string]x509.Certificate{"0": *cert}
+-
+- for _, cert := range r.TLS.PeerCertificates {
+- trusted, _ := util.CheckMutualTLS(*cert, clientCerts)
+- if trusted {
+- return true
+- }
++ peerCertificate, err := request.GetPeerCertificate(r)
++ if err != nil {
++ return false
+ }
+
+- return false
++ clientCerts := map[string]x509.Certificate{"0": *cert}
++
++ trusted, _ := util.CheckMutualTLS(*peerCertificate, clientCerts)
++ return trusted
+ }
+diff --git a/lxd/api_vsock.go b/lxd/api_vsock.go
+index 65ab3023fed6..7560604270c5 100644
+--- a/lxd/api_vsock.go
++++ b/lxd/api_vsock.go
+@@ -10,6 +10,7 @@ import (
+ "github.com/canonical/lxd/lxd/db"
+ "github.com/canonical/lxd/lxd/db/cluster"
+ "github.com/canonical/lxd/lxd/instance"
++ "github.com/canonical/lxd/lxd/request"
+ "github.com/canonical/lxd/lxd/state"
+ "github.com/canonical/lxd/lxd/util"
+ "github.com/canonical/lxd/shared/api"
+@@ -81,11 +82,14 @@ func authenticateAgentCert(s *state.State, r *http.Request) (bool, instance.Inst
+ agentCert := inst.(instance.VM).AgentCertificate()
+ trustedCerts := map[string]x509.Certificate{"0": *agentCert}
+
+- for _, cert := range r.TLS.PeerCertificates {
+- trusted, _ = util.CheckMutualTLS(*cert, trustedCerts)
+- if trusted {
+- return true, inst, nil
+- }
++ peerCertificate, err := request.GetPeerCertificate(r)
++ if err != nil {
++ return false, nil, err
++ }
++
++ trusted, _ = util.CheckMutualTLS(*peerCertificate, trustedCerts)
++ if trusted {
++ return true, inst, nil
+ }
+
+ return false, nil, nil
+diff --git a/lxd/certificates.go b/lxd/certificates.go
+index 35c274c1c06e..c424cd2477a5 100644
+--- a/lxd/certificates.go
++++ b/lxd/certificates.go
+@@ -625,15 +625,10 @@ func certificatesPost(d *Daemon, r *http.Request) response.Response {
+
+ return response.OperationResponse(op)
+ } else if r.TLS != nil {
+- // Add client's certificate.
+- if len(r.TLS.PeerCertificates) < 1 {
+- // This can happen if the client doesn't send a client certificate or if the server is in
+- // CA mode. We rely on this check to prevent non-CA trusted client certificates from being
+- // added when in CA mode.
++ cert, err = request.GetPeerCertificate(r)
++ if err != nil {
+ return response.BadRequest(errors.New("No client certificate provided"))
+ }
+-
+- cert = r.TLS.PeerCertificates[len(r.TLS.PeerCertificates)-1]
+ } else {
+ return response.BadRequest(errors.New("Cannot use TLS data on non-TLS link"))
+ }
+@@ -1170,15 +1165,12 @@ func certificateDelete(d *Daemon, r *http.Request) response.Response {
+ certInfo.Name: *cert,
+ }
+
+- trusted := false
+- for _, i := range r.TLS.PeerCertificates {
+- trusted, _ = util.CheckMutualTLS(*i, trustedCerts)
+-
+- if trusted {
+- break
+- }
++ peerCertificate, err := request.GetPeerCertificate(r)
++ if err != nil {
++ return response.Forbidden(errors.New("Certificate cannot be deleted"))
+ }
+
++ trusted, _ := util.CheckMutualTLS(*peerCertificate, trustedCerts)
+ if !trusted {
+ return response.Forbidden(errors.New("Certificate cannot be deleted"))
+ }
+diff --git a/lxd/cluster/tls.go b/lxd/cluster/tls.go
+index d6dce4f7c62e..d8b9c5741e60 100644
+--- a/lxd/cluster/tls.go
++++ b/lxd/cluster/tls.go
+@@ -9,6 +9,7 @@ import (
+ "time"
+
+ "github.com/canonical/lxd/lxd/identity"
++ "github.com/canonical/lxd/lxd/request"
+ "github.com/canonical/lxd/lxd/util"
+ "github.com/canonical/lxd/shared"
+ "github.com/canonical/lxd/shared/logger"
+@@ -63,7 +64,8 @@ func tlsCheckCert(r *http.Request, networkCert *shared.CertInfo, serverCert *sha
+ panic(fmt.Sprintf("Invalid keypair material: %v", err))
+ }
+
+- if r.TLS == nil {
++ peerCertificate, err := request.GetPeerCertificate(r)
++ if err != nil {
+ return false
+ }
+
+@@ -75,24 +77,22 @@ func tlsCheckCert(r *http.Request, networkCert *shared.CertInfo, serverCert *sha
+ trustedServerCerts := map[string]x509.Certificate{serverCert.Fingerprint(): *trustedServerCert}
+ cachedIdentityTypeCertificateServer := cache.GetServerCertificates()
+
+- for _, i := range r.TLS.PeerCertificates {
+- // Trust our own server certificate. This allows Dqlite to start with a connection back to this
+- // member before the database is available. It also allows us to switch the server certificate to
+- // the network certificate during cluster upgrade to per-server certificates, and it be trusted.
+- trusted, _ := util.CheckMutualTLS(*i, trustedServerCerts)
+- if trusted {
+- return true
+- }
+-
+- // Check the trusted server certficates list provided.
+- trusted, _ = util.CheckMutualTLS(*i, cachedIdentityTypeCertificateServer)
+- if trusted {
+- return true
+- }
+-
+- logger.Errorf("Invalid client certificate %v (%v) from %v", i.Subject, shared.CertFingerprint(i), r.RemoteAddr)
++ // Trust our own server certificate. This allows Dqlite to start with a connection back to this
++ // member before the database is available. It also allows us to switch the server certificate to
++ // the network certificate during cluster upgrade to per-server certificates, and it be trusted.
++ trusted, _ := util.CheckMutualTLS(*peerCertificate, trustedServerCerts)
++ if trusted {
++ return true
++ }
++
++ // Check the trusted server certificate list provided.
++ trusted, _ = util.CheckMutualTLS(*peerCertificate, cachedIdentityTypeCertificateServer)
++ if trusted {
++ return true
+ }
+
++ logger.Errorf("Invalid client certificate %v (%v) from %v", peerCertificate.Subject, shared.CertFingerprint(peerCertificate), r.RemoteAddr)
++
+ return false
+ }
+
+diff --git a/lxd/daemon.go b/lxd/daemon.go
+index 1d5cb610a9ba..ba150f986071 100644
+--- a/lxd/daemon.go
++++ b/lxd/daemon.go
+@@ -449,7 +449,8 @@ func extractEntitlementsFromQuery(r *http.Request, entityType entity.Type, allow
+ // event because they may originate from a server-side fault (e.g. an
+ // unreachable IdP).
+ func (d *Daemon) Authenticate(w http.ResponseWriter, r *http.Request, oidcVerifier *oidc.Verifier, allowUntrusted bool) (*request.RequestorArgs, error) {
+- if r.TLS == nil {
++ peerCertificate, err := request.GetPeerCertificate(r)
++ if err != nil && errors.Is(err, request.ErrNoTLS) {
+ // For a socket, the server is listening on a file, but the client does not have an address.
+ // Since there is no address, the kernel uses an unnamed unix socket address.
+ // An unnamed or abstract Unix socket address is rendered as '@'.
+@@ -486,21 +487,14 @@ func (d *Daemon) Authenticate(w http.ResponseWriter, r *http.Request, oidcVerifi
+ clusterUUID := d.globalConfig.ClusterUUID()
+ d.globalConfigMu.Unlock()
+
+- // Request has TLS. If client sent a peer certificate, check mTLS and CA.
+- if len(r.TLS.PeerCertificates) > 0 {
+- // Convert list of peer certificates to map.
+- peerCertificateFingerprints := make([]string, 0, len(r.TLS.PeerCertificates))
+- peerCertificates := make(map[string]x509.Certificate, len(r.TLS.PeerCertificates))
+- for _, c := range r.TLS.PeerCertificates {
+- f := shared.CertFingerprint(c)
+- peerCertificates[f] = *c
+- peerCertificateFingerprints = append(peerCertificateFingerprints, f)
+- }
++ // If client sent a peer certificate, check mTLS and CA.
++ if peerCertificate != nil {
++ peerCertificateFingerprint := shared.CertFingerprint(peerCertificate)
+
+ // Anonymous function to call for each certificate type and it's associated protocol.
+ authTLS := func(protocol string, certGetter func(...string) map[string]x509.Certificate) (*request.RequestorArgs, error) {
+ // Did the client send any certificates we recognise?
+- matchedCerts := certGetter(peerCertificateFingerprints...)
++ matchedCerts := certGetter(peerCertificateFingerprint)
+ if len(matchedCerts) == 0 {
+ // If not, they are not authenticated, but there is no error.
+ return nil, nil
+@@ -516,19 +510,19 @@ func (d *Daemon) Authenticate(w http.ResponseWriter, r *http.Request, oidcVerifi
+ }
+
+ // We've recognised the fingerprint of the caller certificate, but now we need to perform a full mTLS check.
+- trusted, _ := util.CheckMutualTLS(peerCertificates[matchedFingerprint], matchedCerts)
++ trusted, _ := util.CheckMutualTLS(*peerCertificate, matchedCerts)
+ if trusted {
+ // If there is a server.ca file, then all client certificates must be signed by it.
+ // This does not apply to server certificates.
+ if protocol != request.ProtocolCluster && d.endpoints.NetworkCert().CA() != nil {
+- trusted, _, _ = util.CheckCASignature(peerCertificates[matchedFingerprint], d.endpoints.NetworkCert())
++ trusted, _, _ = util.CheckCASignature(*peerCertificate, d.endpoints.NetworkCert())
+ if !trusted {
+ return nil, nil
+ }
+ }
+
+ // Get expiration date of the matched certificate.
+- certExpiresAt := peerCertificates[matchedFingerprint].NotAfter.UTC()
++ certExpiresAt := peerCertificate.NotAfter.UTC()
+
+ return &request.RequestorArgs{
+ Trusted: trusted,
+@@ -570,15 +564,13 @@ func (d *Daemon) Authenticate(w http.ResponseWriter, r *http.Request, oidcVerifi
+ // Lastly, check if core.trust_ca_certificates is true. If so, allow all CA signed certificates without checking
+ // mTLS.
+ if d.endpoints.NetworkCert().CA() != nil && trustCACertificates {
+- for f, cert := range peerCertificates {
+- trusted, _, _ := util.CheckCASignature(cert, d.endpoints.NetworkCert())
+- if trusted {
+- return &request.RequestorArgs{
+- Trusted: true,
+- Username: f,
+- Protocol: request.ProtocolPKI,
+- }, nil
+- }
++ trusted, _, _ := util.CheckCASignature(*peerCertificate, d.endpoints.NetworkCert())
++ if trusted {
++ return &request.RequestorArgs{
++ Trusted: true,
++ Username: peerCertificateFingerprint,
++ Protocol: request.ProtocolPKI,
++ }, nil
+ }
+ }
+ }
+@@ -624,7 +616,7 @@ func (d *Daemon) Authenticate(w http.ResponseWriter, r *http.Request, oidcVerifi
+ // caller. Emit only when the endpoint requires authentication; anonymous
+ // requests (no peer cert, no bearer, no OIDC header) also reach this
+ // point and intentionally do not emit.
+- if !allowUntrusted && len(r.TLS.PeerCertificates) > 0 {
++ if !allowUntrusted && peerCertificate != nil {
+ loginFail := security.AuthnLoginFail.WithSuffix(string(api.AuthenticationMethodTLS)).
+ UserEvent(r.Context(), security.LevelWarning, "TLS authentication failure")
+ d.events.SendSecurity(loginFail)
+diff --git a/lxd/identities.go b/lxd/identities.go
+index a6deb9ff7f1b..b092da8341e4 100644
+--- a/lxd/identities.go
++++ b/lxd/identities.go
+@@ -373,20 +373,25 @@ func identitiesTLSPost(d *Daemon, r *http.Request) response.Response {
+ }
+
+ if !requestor.IsTrusted() {
+- return createIdentityTLSUntrusted(r.Context(), s, r.TLS.PeerCertificates, networkCert, req, notify)
++ peerCertificate, err := request.GetPeerCertificate(r)
++ if err != nil {
++ return response.BadRequest(errors.New("No client certificate provided"))
++ }
++
++ return createIdentityTLSUntrusted(r.Context(), s, peerCertificate, networkCert, req, notify)
+ }
+
+- var peerCertificates []*x509.Certificate
++ var peerCertificate *x509.Certificate
+ idType, err := requestor.CallerIdentityType()
+ if err == nil {
+- if idType.Name() == api.IdentityTypeBearerTokenInitialUI && r.TLS != nil {
+- // When authenticated as the initial UI identity, allow creating a TLS identity from the presented peer certificate.
++ if idType.Name() == api.IdentityTypeBearerTokenInitialUI {
+ // This allows LXD UI to establish mTLS by injecting a client certificate during initial UI bearer-token access.
+- peerCertificates = r.TLS.PeerCertificates
++ // When authenticated as the initial UI identity, allow creating a TLS identity from the presented peer certificate.
++ peerCertificate, _ = request.GetPeerCertificate(r)
+ }
+ }
+
+- return createIdentityTLSTrusted(r.Context(), s, peerCertificates, networkCert, req, notify)
++ return createIdentityTLSTrusted(r.Context(), s, peerCertificate, networkCert, req, notify)
+ }
+
+ // swagger:operation POST /1.0/auth/identities/bearer identities identities_post_bearer
+@@ -738,7 +743,7 @@ func identityBearerTokenDelete(d *Daemon, r *http.Request) response.Response {
+ }
+
+ // createIdentityTLSUntrusted handles requests to create an identity when the caller is not trusted.
+-func createIdentityTLSUntrusted(ctx context.Context, s *state.State, peerCertificates []*x509.Certificate, networkCert *shared.CertInfo, req api.IdentitiesTLSPost, notify identityNotificationFunc) response.Response {
++func createIdentityTLSUntrusted(ctx context.Context, s *state.State, peerCertificate *x509.Certificate, networkCert *shared.CertInfo, req api.IdentitiesTLSPost, notify identityNotificationFunc) response.Response {
+ // If not trusted a token must be provided.
+ if req.TrustToken == "" {
+ return response.Forbidden(errors.New("Trust token required"))
+@@ -749,15 +754,8 @@ func createIdentityTLSUntrusted(ctx context.Context, s *state.State, peerCertifi
+ return response.Forbidden(errors.New("Only trust token must be provided"))
+ }
+
+- // If not trusted get the certificate from the request TLS config.
+- if len(peerCertificates) < 1 {
+- return response.BadRequest(errors.New("No client certificate provided"))
+- }
+-
+- cert := peerCertificates[len(peerCertificates)-1]
+-
+ // Validate certificate.
+- err := certificateValidate(networkCert, cert)
++ err := certificateValidate(networkCert, peerCertificate)
+ if err != nil {
+ return response.BadRequest(err)
+ }
+@@ -776,13 +774,13 @@ func createIdentityTLSUntrusted(ctx context.Context, s *state.State, peerCertifi
+
+ // Activate the pending identity with the certificate.
+ err = s.DB.Cluster.Transaction(ctx, func(ctx context.Context, tx *db.ClusterTx) error {
+- return dbCluster.ActivateTLSIdentity(ctx, tx.Tx(), identifier, cert)
++ return dbCluster.ActivateTLSIdentity(ctx, tx.Tx(), identifier, peerCertificate)
+ })
+ if err != nil {
+ return response.SmartError(err)
+ }
+
+- fingerprint := shared.CertFingerprint(cert)
++ fingerprint := shared.CertFingerprint(peerCertificate)
+
+ // Activation replaces the pending UUID identifier with the cert
+ // fingerprint in the database, so the event must reference the
+@@ -796,7 +794,7 @@ func createIdentityTLSUntrusted(ctx context.Context, s *state.State, peerCertifi
+ }
+
+ // createIdentityTLSTrusted handles requests to create an identity when the caller is trusted.
+-func createIdentityTLSTrusted(ctx context.Context, s *state.State, peerCertificates []*x509.Certificate, networkCert *shared.CertInfo, req api.IdentitiesTLSPost, notify identityNotificationFunc) response.Response {
++func createIdentityTLSTrusted(ctx context.Context, s *state.State, peerCertificate *x509.Certificate, networkCert *shared.CertInfo, req api.IdentitiesTLSPost, notify identityNotificationFunc) response.Response {
+ // Check if the caller has permission to create identities.
+ err := s.Authorizer.CheckPermission(ctx, entity.ServerURL(), auth.EntitlementCanCreateIdentities)
+ if err != nil {
+@@ -824,12 +822,11 @@ func createIdentityTLSTrusted(ctx context.Context, s *state.State, peerCertifica
+ }
+
+ cert := req.Certificate
+- if cert == "" && len(peerCertificates) > 0 {
++ if cert == "" && peerCertificate != nil {
+ // Use peer certificate if no certificate was provided in the request body.
+- peerCert := peerCertificates[len(peerCertificates)-1]
+ peerCertPEM := &pem.Block{
+ Type: "CERTIFICATE",
+- Bytes: peerCert.Raw,
++ Bytes: peerCertificate.Raw,
+ }
+
+ cert = string(pem.EncodeToMemory(peerCertPEM))
+diff --git a/lxd/request/request.go b/lxd/request/request.go
+index e214c6b8da76..f39de1a3d675 100644
+--- a/lxd/request/request.go
++++ b/lxd/request/request.go
+@@ -2,11 +2,20 @@ package request
+
+ import (
+ "context"
++ "crypto/x509"
++ "errors"
+ "net"
++ "net/http"
+
+ "github.com/canonical/lxd/shared/api"
+ )
+
++// ErrNoCertificate is returned if the request does not contain a certificate.
++var ErrNoCertificate = errors.New("No certificate present in request")
++
++// ErrNoTLS is returned if the request does not have a TLS connection.
++var ErrNoTLS = errors.New("No TLS connection state")
++
+ // CreateRequestor extracts the lifecycle event requestor data from the provided context.
+ func CreateRequestor(ctx context.Context) *api.EventLifecycleRequestor {
+ requestor, err := GetRequestorAuditor(ctx)
+@@ -22,3 +31,16 @@ func CreateRequestor(ctx context.Context) *api.EventLifecycleRequestor {
+ func SaveConnectionInContext(ctx context.Context, connection net.Conn) context.Context {
+ return context.WithValue(ctx, CtxConn, connection)
+ }
++
++// GetPeerCertificate returns the first peer certificate in the request TLS connection states peer certificate list.
++func GetPeerCertificate(r *http.Request) (*x509.Certificate, error) {
++ if r.TLS == nil {
++ return nil, api.StatusErrorf(http.StatusBadRequest, "%w", ErrNoTLS)
++ }
++
++ if len(r.TLS.PeerCertificates) == 0 {
++ return nil, api.StatusErrorf(http.StatusBadRequest, "%w", ErrNoCertificate)
++ }
++
++ return r.TLS.PeerCertificates[0], nil
++}
+diff --git a/lxd/request/request_test.go b/lxd/request/request_test.go
+new file mode 100644
+index 000000000000..0385785ac816
+--- /dev/null
++++ b/lxd/request/request_test.go
+@@ -0,0 +1,68 @@
++package request
++
++import (
++ "crypto/tls"
++ "crypto/x509"
++ "net/http"
++ "testing"
++
++ "github.com/stretchr/testify/require"
++
++ "github.com/canonical/lxd/shared/api"
++)
++
++func TestGetPeerCertificate(t *testing.T) {
++ certA := &x509.Certificate{Raw: []byte("certA")}
++ certB := &x509.Certificate{Raw: []byte("certB")}
++
++ tests := []struct {
++ name string
++ tlsState *tls.ConnectionState
++ wantCert *x509.Certificate
++ wantErr error
++ wantErrCode int
++ }{
++ {
++ name: "no TLS connection",
++ wantErr: ErrNoTLS,
++ wantErrCode: http.StatusBadRequest,
++ },
++ {
++ name: "TLS with empty peer certificates",
++ tlsState: &tls.ConnectionState{
++ PeerCertificates: []*x509.Certificate{},
++ },
++ wantErr: ErrNoCertificate,
++ wantErrCode: http.StatusBadRequest,
++ },
++ {
++ name: "TLS with single certificate",
++ tlsState: &tls.ConnectionState{
++ PeerCertificates: []*x509.Certificate{certA},
++ },
++ wantCert: certA,
++ },
++ {
++ name: "TLS with certificate chain",
++ tlsState: &tls.ConnectionState{
++ PeerCertificates: []*x509.Certificate{certA, certB},
++ },
++ wantCert: certA,
++ },
++ }
++
++ for _, tt := range tests {
++ t.Run(tt.name, func(t *testing.T) {
++ req, err := http.NewRequest(http.MethodGet, "/", nil)
++ require.NoError(t, err)
++ req.TLS = tt.tlsState
++
++ cert, err := GetPeerCertificate(req)
++ require.ErrorIs(t, err, tt.wantErr)
++ require.Equal(t, tt.wantCert, cert)
++ if err != nil && tt.wantErrCode != 0 {
++ require.True(t, api.StatusErrorCheck(err, tt.wantErrCode))
++ }
++ })
++ }
++}
+diff --git a/test/suites/auth.sh b/test/suites/auth.sh
+index fbf9b3b4f34f..0666074d1bfe 100644
+--- a/test/suites/auth.sh
++++ b/test/suites/auth.sh
+@@ -187,7 +187,63 @@ test_authorization() {
+ lxc query /1.0/auth/identities/oidc/test-user at example.com | jq --exit-status '.groups == []'
+ lxc auth identity group add oidc/test-user at example.com test-group
+
+- # Test fine-grained TLS identity creation
++ # Test certificate chain handling with trust tokens and authentication.
++ sub_test "TLS identity certificate chain handling during onboarding and authentication"
++
++ # 1. Generate an untrusted client leaf and an arbitrary target certificate.
++ gen_cert_and_key "chain_leaf"
++ gen_cert_and_key "chain_target"
++
++ # shellcheck disable=SC2153
++ leaf_fingerprint="$(cert_fingerprint "${LXD_CONF}/chain_leaf.crt")"
++ target_fingerprint="$(cert_fingerprint "${LXD_CONF}/chain_target.crt")"
++
++ # Build a multi-certificate chain: [leaf, target].
++ cat "${LXD_CONF}/chain_leaf.crt" "${LXD_CONF}/chain_target.crt" > "${TEST_DIR}/chain_injected.pem"
++
++ # 2. Issue a TLS identity trust token.
++ chain_token="$(lxc auth identity create tls/chain-user --quiet --group test-group)"
++
++ # 3. Attempt onboarding using the multi-certificate chain.
++ # The client proves ownership of chain_leaf.key during the TLS handshake.
++ curl -k -s \
++ --cert "${TEST_DIR}/chain_injected.pem" \
++ --key "${LXD_CONF}/chain_leaf.key" \
++ -X POST \
++ -H "Content-Type: application/json" \
++ --data "{\"trust_token\": \"${chain_token}\"}" \
++ "https://${LXD_ADDR}/1.0/auth/identities/tls" | jq --exit-status '.type == "sync" and .status_code == 200'
++
++ # 4. Assert that the activated identity matches the LEAF certificate, NOT the injected secondary certificate.
++ lxc auth identity list --format csv | grep -xF "tls,Client certificate,chain-user,${leaf_fingerprint},test-group"
++ ! lxc auth identity list --format csv | grep -F "${target_fingerprint}" || false
++
++ # 5. Assert that the client presenting the chain signed by chain_leaf.key is now authenticated.
++ curl -k -s \
++ --cert "${TEST_DIR}/chain_injected.pem" \
++ --key "${LXD_CONF}/chain_leaf.key" \
++ "https://${LXD_ADDR}/1.0" | jq --exit-status '.metadata.auth == "trusted"'
++
++ # 6. Assert that a client using chain_target.key is NOT authenticated (it was never trusted).
++ curl -k -s \
++ --cert "${LXD_CONF}/chain_target.crt" \
++ --key "${LXD_CONF}/chain_target.key" \
++ "https://${LXD_ADDR}/1.0" | jq --exit-status '.metadata.auth == "untrusted"'
++
++ # 7. Assert that an untrusted leaf bundling an already trusted certificate cannot authenticate.
++ # An attacker generates their own keypair and bundles the newly trusted 'chain_leaf.crt' into their chain.
++ gen_cert_and_key "untrusted_attacker"
++ cat "${LXD_CONF}/untrusted_attacker.crt" "${LXD_CONF}/chain_leaf.crt" > "${TEST_DIR}/spoofed_chain.pem"
++
++ curl -k -s \
++ --cert "${TEST_DIR}/spoofed_chain.pem" \
++ --key "${LXD_CONF}/untrusted_attacker.key" \
++ "https://${LXD_ADDR}/1.0" | jq --exit-status '.metadata.auth == "untrusted"'
++
++ # Clean up identity and temporary certificates.
++ lxc auth identity delete "tls/${leaf_fingerprint}"
++ rm "${TEST_DIR}/chain_injected.pem" "${TEST_DIR}/spoofed_chain.pem"
++ rm "${LXD_CONF}"/{chain_leaf,chain_target,untrusted_attacker}.{crt,key}
+
+ # Cannot create identities that are not tls
+ ! lxc auth identity create oidc/jane.doe at example.com || false
+diff --git a/test/suites/tls_restrictions.sh b/test/suites/tls_restrictions.sh
+index a3d5375636c0..030ff41a33da 100644
+--- a/test/suites/tls_restrictions.sh
++++ b/test/suites/tls_restrictions.sh
+@@ -2,6 +2,63 @@ test_tls_restrictions() {
+ ensure_import_testimage
+ ensure_has_localhost_remote "${LXD_ADDR}"
+
++ # Test certificate chain handling with trust tokens and authentication.
++ sub_test "TLS client certificate chain handling during onboarding and authentication"
++
++ # 1. Generate an untrusted client leaf and an arbitrary target certificate.
++ gen_cert_and_key "chain_leaf"
++ gen_cert_and_key "chain_target"
++ leaf_fingerprint="$(cert_fingerprint "${LXD_CONF}/chain_leaf.crt")"
++ leaf_fingerprint_short=$(echo "${leaf_fingerprint}" | cut -c1-12)
++ target_fingerprint="$(cert_fingerprint "${LXD_CONF}/chain_target.crt")"
++
++ # Build a multi-certificate chain: [leaf, target].
++ cat "${LXD_CONF}/chain_leaf.crt" "${LXD_CONF}/chain_target.crt" > "${TEST_DIR}/chain_injected.pem"
++
++ # 2. Issue a TLS client trust token.
++ chain_token="$(lxc config trust add --name chain-user --quiet)"
++
++ # 3. Attempt onboarding using the multi-certificate chain.
++ # The client proves ownership of chain_leaf.key during the TLS handshake.
++ curl -k -s \
++ --cert "${TEST_DIR}/chain_injected.pem" \
++ --key "${LXD_CONF}/chain_leaf.key" \
++ -X POST \
++ -H "Content-Type: application/json" \
++ --data "{\"trust_token\": \"${chain_token}\"}" \
++ "https://${LXD_ADDR}/1.0/certificates" | jq --exit-status '.type == "sync" and .status_code == 200'
++
++ # 4. Assert that the activated identity matches the LEAF certificate, NOT the injected secondary certificate.
++ lxc config trust list --format csv | grep -F "client,chain-user,chain_leaf.local,${leaf_fingerprint_short}"
++ ! lxc config trust list --format csv | grep -F "$(echo "${target_fingerprint}" | cut -c1-12)" || false
++
++ # 5. Assert that the client presenting the chain signed by chain_leaf.key is now authenticated.
++ curl -k -s \
++ --cert "${TEST_DIR}/chain_injected.pem" \
++ --key "${LXD_CONF}/chain_leaf.key" \
++ "https://${LXD_ADDR}/1.0" | jq --exit-status '.metadata.auth == "trusted"'
++
++ # 6. Assert that a client using chain_target.key is NOT authenticated (it was never trusted).
++ curl -k -s \
++ --cert "${LXD_CONF}/chain_target.crt" \
++ --key "${LXD_CONF}/chain_target.key" \
++ "https://${LXD_ADDR}/1.0" | jq --exit-status '.metadata.auth == "untrusted"'
++
++ # 7. Assert that an untrusted leaf bundling an already trusted certificate cannot authenticate.
++ # An attacker generates their own keypair and bundles the newly trusted 'chain_leaf.crt' into their chain.
++ gen_cert_and_key "untrusted_attacker"
++ cat "${LXD_CONF}/untrusted_attacker.crt" "${LXD_CONF}/chain_leaf.crt" > "${TEST_DIR}/spoofed_chain.pem"
++
++ curl -k -s \
++ --cert "${TEST_DIR}/spoofed_chain.pem" \
++ --key "${LXD_CONF}/untrusted_attacker.key" \
++ "https://${LXD_ADDR}/1.0" | jq --exit-status '.metadata.auth == "untrusted"'
++
++ # Clean up identity and temporary certificates.
++ lxc config trust remove "${leaf_fingerprint}"
++ rm "${TEST_DIR}/chain_injected.pem" "${TEST_DIR}/spoofed_chain.pem"
++ rm "${LXD_CONF}"/{chain_leaf,chain_target,untrusted_attacker}.{crt,key}
++
+ gen_cert_and_key "metrics"
+
+ # Ensure type=metrics certificates cannot access anything besides /1.0/metrics.
diff --git a/lxd.service b/lxd.service
index faee0d0..8ac19dc 100644
--- a/lxd.service
+++ b/lxd.service
@@ -1,11 +1,11 @@
[Unit]
Description=LXD Container Hypervisor
-Documentation=http://linuxcontainers.org
+Documentation=https://canonical.com/lxd/docs/latest/
After=network.target
[Service]
Type=simple
-ExecStart=/usr/sbin/lxd daemon
+ExecStart=/usr/sbin/lxd daemon --group lxd
ExecStop=/usr/sbin/lxd shutdown
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=infinity
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/packages/lxd.git/commitdiff/4415b1ac3ed1b7bb01aeb8e2ad90a66b02005e7a
More information about the pld-cvs-commit
mailing list