Ecosyste.ms: Advisories
An open API service providing security vulnerability metadata for many open source software ecosystems.
Security Advisories: GSA_kwCzR0hTQS00YzQ5LTlmcGMtaGMzds4ABCNb
lxd CA certificate sign check bypass
Summary
If a server.ca
file is present in LXD_DIR
at LXD start up, LXD is in "PKI mode". In this mode, only TLS clients that have a CA-signed certificate should be able to authenticate with LXD.
We have discovered that if a client that sends a non-CA signed certificate during the TLS handshake, that client is able to authenticate with LXD if their certificate is present in the trust store.
- The LXD Go client (and by extension lxc
) does not send non-CA signed certificates during the handshake.
- A manual client (e.g. cURL
) might send a non-CA signed certificate during the handshake.
Versions affected
LXD 4.0 and above.
Details
When PKI mode was added to LXD it was intended that all client and server certificates must be signed by the certificate authority (see https://github.com/canonical/lxd/pull/2070/commits/84d917bdcca6fe1e3191ce47f1597c7d094e1909).
In PKI mode, the TLS listener configuration is altered to add the CA certificate but the ClientAuth
field of tls.Config
is not changed. The ClientAuth
field is set to tls.RequestClientCert
, which configures the TLS connection to request a certificate from the client, but not require one. This is necessary because untrusted requests are allowed for some endpoints.
If a client certificate is present in the trust store before PKI mode is enabled, calls to LXD using that certificate fail when using the Go client for LXD. I believe that what is happening is as follows:
- During the TLS handshake, the server requests a certificate from the client. The server includes in it's request a list of acceptable CAs.
- The go client receives the request from the server, but does not have any certificates that match what the server requires, and so does not send any.
- The server considers the handshake complete because it does not absolutely require the client certificate (see above).
- In the
(*Daemon).Authenticate
method, when checking for TLS clients, there are noPeerCertificates
in the request. Soutil.CheckTrustState
is never called and the request is denied.
Importantly, the above does not apply if the client sends a certificate during the handshake anyway. If this occurs and the certificate is present in the trust store, the request is trusted and is allowed to continue. It is possible to do this using cURL*.
PoC
The follow snippet demonstrates the vulnerability:
# Install/initialize LXD
$ snap install lxd --channel 5.21/stable
$ lxd init --auto
$ lxc config set core.https_address=127.0.0.1:8443
# Add a certificate to the trust store before enabling PKI.
$ token="$(lxc config trust add --name ca-test --quiet)"
$ lxc remote add tls "${token}"
# Use easyrsa for configuring CA: https://github.com/OpenVPN/easy-rsa
$ cp -R /usr/share/easy-rsa "/tmp/pki"
$ export EASYRSA_KEY_SIZE=4096
$ cd /tmp/pki
$ ./easyrsa init-pki
$ echo "lxd" | ./easyrsa build-ca nopass
$ cp pki/ca.crt /var/snap/lxd/common/lxd/server.ca
# Restart daemon.
$ systemctl reload snap.lxd.daemon
# Using curl with the client certificate we expect a 403 Forbidden response.
# Instead we get a 200 OK and we are able to view the response body.
$ cat ~/snap/lxd/common/config/client.crt ~/snap/lxd/common/config/client.key > ~/snap/lxd/common/config/client.pem
$ curl -s --cert ~/snap/lxd/common/config/client.pem --cacert /var/snap/lxd/common/lxd/server.crt https://127.0.0.1:8443/1.0" | jq '.metadata.config."core.https_address"'
Impact
I believe this has a low impact for the following reasons:
- PKI mode is unlikely to have a large user base.
- PKI is likely to be configured at start up without any previous certificates in the trust store.
- Authentication is not bypassed entirely, the client certificate must already be trusted.
Notes
- I am not certain why cURL sends the certificate during the handshake but we can see it in the logs:
* Trying 127.0.0.1:8443...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to 127.0.0.1 (127.0.0.1) port 8443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* CAfile: /var/lib/lxd/server.crt
* CApath: /etc/ssl/certs
* TLSv1.0 (OUT), TLS header, Certificate Status (22):
} [5 bytes data]
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
} [512 bytes data]
0 0 0 0 0 0 0 0 --:--:-- 0:00:03 --:--:-- 0* TLSv1.2 (IN), TLS header, Certificate Status (22):
{ [5 bytes data]
* TLSv1.3 (IN), TLS handshake, Server hello (2):
{ [122 bytes data]
* TLSv1.2 (IN), TLS header, Finished (20):
{ [5 bytes data]
* TLSv1.2 (IN), TLS header, Supplemental data (23):
{ [5 bytes data]
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
{ [15 bytes data]
* TLSv1.2 (IN), TLS header, Supplemental data (23):
{ [5 bytes data]
* TLSv1.3 (IN), TLS handshake, Request CERT (13):
{ [69 bytes data]
* TLSv1.2 (IN), TLS header, Supplemental data (23):
{ [5 bytes data]
* TLSv1.3 (IN), TLS handshake, Certificate (11):
{ [496 bytes data]
* TLSv1.2 (IN), TLS header, Supplemental data (23):
{ [5 bytes data]
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
{ [111 bytes data]
* TLSv1.2 (IN), TLS header, Supplemental data (23):
{ [5 bytes data]
* TLSv1.3 (IN), TLS handshake, Finished (20):
{ [36 bytes data]
* TLSv1.2 (OUT), TLS header, Finished (20):
} [5 bytes data]
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
} [1 bytes data]
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
} [5 bytes data]
* TLSv1.3 (OUT), TLS handshake, Certificate (11): <<<<<<<<< HERE
} [455 bytes data]
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
} [5 bytes data]
* TLSv1.3 (OUT), TLS handshake, CERT verify (15):
} [111 bytes data]
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
} [5 bytes data]
* TLSv1.3 (OUT), TLS handshake, Finished (20):
} [36 bytes data]
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server accepted to use h2
* Server certificate:
* subject: O=LXD; CN=root@RUBIX
* start date: Apr 2 15:27:39 2024 GMT
* expire date: Mar 31 15:27:39 2034 GMT
* subjectAltName: host "127.0.0.1" matched cert's IP address!
* issuer: O=LXD; CN=root@RUBIX
* SSL certificate verify ok.
* Using HTTP2, server supports multiplexing
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
} [5 bytes data]
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
} [5 bytes data]
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
} [5 bytes data]
* Using Stream ID: 1 (easy handle 0x601ce9c4feb0)
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
} [5 bytes data]
> GET /1.0 HTTP/2
> Host: 127.0.0.1:8443
> user-agent: curl/7.81.0
> accept: */*
>
* TLSv1.2 (IN), TLS header, Supplemental data (23):
{ [5 bytes data]
* TLSv1.3 (IN), TLS handshake, Newsession Ticket (4):
{ [569 bytes data]
* TLSv1.2 (IN), TLS header, Supplemental data (23):
{ [5 bytes data]
* Connection state changed (MAX_CONCURRENT_STREAMS == 250)!
* TLSv1.2 (OUT), TLS header, Supplemental data (23):
} [5 bytes data]
* TLSv1.2 (IN), TLS header, Supplemental data (23):
{ [5 bytes data]
* TLSv1.2 (IN), TLS header, Supplemental data (23):
{ [5 bytes data]
* TLSv1.2 (IN), TLS header, Supplemental data (23):
{ [5 bytes data]
< HTTP/2 200
< content-type: application/json
< etag: "a1147bd1cd26e0b98e4c4400be3c17d5de3d865a045b6e609c6a8ee1aba8c1a1"
< date: Mon, 17 Jun 2024 21:25:46 GMT
<
* TLSv1.2 (IN), TLS header, Supplemental data (23):
{ [5 bytes data]
* TLSv1.2 (IN), TLS header, Supplemental data (23):
{ [5 bytes data]
* TLSv1.2 (IN), TLS header, Supplemental data (23):
{ [5 bytes data]
100 11659 0 11659 0 0 3401 0 --:--:-- 0:00:03 --:--:-- 3402
* Connection #0 to host 127.0.0.1 left intact
Permalink: https://github.com/advisories/GHSA-4c49-9fpc-hc3vJSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS00YzQ5LTlmcGMtaGMzds4ABCNb
Source: GitHub Advisory Database
Origin: Unspecified
Severity: Low
Classification: General
Published: 8 days ago
Updated: 6 days ago
CVSS Score: 3.8
CVSS vector: CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:C/C:L/I:N/A:N
EPSS Percentage: 0.00043
EPSS Percentile: 0.10595
Identifiers: GHSA-4c49-9fpc-hc3v, CVE-2024-6156
References:
- https://github.com/canonical/lxd/security/advisories/GHSA-4c49-9fpc-hc3v
- https://nvd.nist.gov/vuln/detail/CVE-2024-6156
- https://github.com/canonical/lxd/commit/92468bb60f4f1edf38ff0434414bea4f28afa711
- https://www.cve.org/CVERecord?id=CVE-2024-6156
- https://pkg.go.dev/vuln/GO-2024-3312
- https://github.com/advisories/GHSA-4c49-9fpc-hc3v
Blast Radius: 0.0
Affected Packages
go:github.com/canonical/lxd
Dependent packages: 25Dependent repositories: 1
Downloads:
Affected Version Ranges: < 0.0.0-20240708073652-5a492a3f0036
Fixed in: 0.0.0-20240708073652-5a492a3f0036
All affected versions: 0.0.0-20230831071803-b3f644a1c2e3, 0.0.0-20230831121237-1af2f0a4f0d8, 0.0.0-20230831122301-df37eebd8450, 0.0.0-20230901073441-b23c0292f163, 0.0.0-20230901080312-16ec502b1318, 0.0.0-20230901103641-023e4e31c093, 0.0.0-20230904093241-addea19ecc01, 0.0.0-20230904122353-010f6fb8997c, 0.0.0-20230904152157-b113a6cbc9e3, 0.0.0-20230904160058-a977a54025bb, 0.0.0-20230905150901-5938ad989d5f, 0.0.0-20230905155827-047578d681b8, 0.0.0-20230905181304-41707cd7a201, 0.0.0-20230905183532-9753bfc271c7, 0.0.0-20230906070316-f0be0b9da62b, 0.0.0-20230906180525-bbd424b78d32, 0.0.0-20230907154505-db6cec5bfbbf, 0.0.0-20230907175125-07070ec4f964, 0.0.0-20230908200628-227bc5cd75eb, 0.0.0-20230911124201-82b3b0d4a053, 0.0.0-20230912070624-1d38f5d9d8ca, 0.0.0-20230912071027-b3da6fe20693, 0.0.0-20230912094428-9f1e8f4cb306, 0.0.0-20230912121018-46e7c8297bf3, 0.0.0-20230912170532-9d97a60cedd1, 0.0.0-20230913061507-f0a5c0323606, 0.0.0-20230913101255-e1a678aab2c6, 0.0.0-20230913114527-f9db8d521511, 0.0.0-20230913132058-3fe1b0679011, 0.0.0-20230914075744-288dac4b002d, 0.0.0-20230915071655-aa86b8244bb6, 0.0.0-20230915080313-68158489c347, 0.0.0-20230915123906-881163dc7a26, 0.0.0-20230915152527-f4faf3d838eb, 0.0.0-20230915154121-b3fd3c824b5e, 0.0.0-20230915202554-8185f8a7acc1, 0.0.0-20230918100249-998be5af2656, 0.0.0-20230918104700-87fbf8a2beac, 0.0.0-20230918135908-774ad5a88066, 0.0.0-20230918204126-82678b56a630, 0.0.0-20230919074104-fd28846a8e3c, 0.0.0-20230921091703-d7c2a5113344, 0.0.0-20230921150321-79e4136c7d64, 0.0.0-20230922052624-2d8481712055, 0.0.0-20230922131720-618965cf58da, 0.0.0-20230922143838-5c7e84319533, 0.0.0-20230922154101-8a78b655ba2d, 0.0.0-20230924142342-b3e17a96ea3b, 0.0.0-20230925095712-a700a2fc7396, 0.0.0-20230925122558-b8564e463cc1, 0.0.0-20230925180245-8bb5dc0e6822, 0.0.0-20230925202117-188c290d29fc, 0.0.0-20231029190415-18b3c3f349ab, 0.0.0-20231031051956-f61bc3739b84, 0.0.0-20231031160315-447eeea27d98, 0.0.0-20231101233808-96403815db18, 0.0.0-20231102061221-e57a0702e26c, 0.0.0-20231201123857-337b24adab26, 0.0.0-20231203080533-7617d6c7e162, 0.0.0-20231204092102-8f87d18a2865, 0.0.0-20231204093333-9923bc04cda8, 0.0.0-20231204145429-fdc3dc68d9ed, 0.0.0-20231205100600-b06a6703a301, 0.0.0-20231205160015-f7e0bc669ef1, 0.0.0-20231205164416-571c1cbf57cd, 0.0.0-20231205175623-4c8460f80761, 0.0.0-20231205191428-41d5ea920a6a, 0.0.0-20231211092350-688b120a1e07, 0.0.0-20231211100845-09de04f2e79f, 0.0.0-20231211112742-0e4aac486f74, 0.0.0-20231211123743-7294d23f5359, 0.0.0-20231212101442-459484256f5b, 0.0.0-20231212113801-b4c82b11b490, 0.0.0-20231212113931-6b2c9592e968, 0.0.0-20231212131820-00ab49c314c2, 0.0.0-20231212150554-000b1ab2a9e1, 0.0.0-20231214113525-e676fc63c50a, 0.0.0-20240108092319-f3435b041544, 0.0.0-20240108092759-33ab6592a631, 0.0.0-20240108095351-8f920ac525f9, 0.0.0-20240108112534-97792f744ecf, 0.0.0-20240109094929-38ae187ff3d6, 0.0.0-20240115081802-6605050f32f5, 0.0.0-20240117170353-cf9bf2ac0720, 0.0.0-20240117205844-6dc565afb093, 0.0.0-20240118201344-de3f21eeddcf, 0.0.0-20240119094724-5382a2e0709e, 0.0.0-20240119100126-4c05ae43c7e6, 0.0.0-20240119113415-a50a2b36bafb, 0.0.0-20240119113453-4d5ac96bbb45, 0.0.0-20240119133049-4a784760c1ef, 0.0.0-20240119141916-9ffad539f10d, 0.0.0-20240119155232-a7735a9faa4b, 0.0.0-20240119160358-dda97dcbb434, 0.0.0-20240119180521-91efd07d9064, 0.0.0-20240122081125-d3c1928d0c79, 0.0.0-20240122112805-56c051643d53, 0.0.0-20240122132731-675b31b3253d, 0.0.0-20240123104505-1f42fd0d4737, 0.0.0-20240123211146-a89022240be2, 0.0.0-20240124090112-6612e64073cb, 0.0.0-20240125082032-6da9e0ff0540
All unaffected versions: