mirror of
https://github.com/tailscale/tailscale.git
synced 2026-12-04 23:52:20 -08:00
ipn/ipnlocal: report client metrics for PQ vs classic Serve TLS handshakes
Add two clientmetric counters in serveTLSConfig when terminating TLS for Serve and Funnel connections (both HTTPS Serve and TLS-terminated TCP forwarding), excluding ACME tls-alpn-01 challenge handshakes: - serve_tls_pq - serve_tls_classic Updates tailscale/corp#52720 Change-Id: I411a45118adba722ec5bd2f80baf224df611793c Signed-off-by: James Tucker <[email protected]>
This commit is contained in:
1 parent
5f104edef0
commit
44fc559bf8
2 files changed
+105
-3
No files matched your search
+25
-3
@@ -41,6 +41,7 @@ import (
|
||||
"tailscale.com/net/netaddr"
|
||||
"tailscale.com/net/netmon"
|
||||
"tailscale.com/net/netutil"
|
||||
"tailscale.com/net/tlsdial"
|
||||
"tailscale.com/syncs"
|
||||
"tailscale.com/tailcfg"
|
||||
"tailscale.com/tailcfg/peercap"
|
||||
@@ -1588,6 +1589,7 @@ func (b *LocalBackend) getTLSServeCertForPort(port uint16, forVIPService tailcfg
|
||||
// TLS listeners. nextProtos is the ALPN list to advertise for normal
|
||||
// handshakes; it should be serveTLSNextProtos for HTTPS Serve and nil for
|
||||
// TLS-terminated TCP forwarding where we don't know the backend protocol.
|
||||
// Completed non-ACME handshakes are counted by [recordServeTLSConnection].
|
||||
// During an ACME tls-alpn-01 renewal, GetConfigForClient clones the base config
|
||||
// and temporarily prepends acme-tls/1, but only for the exact SNI with a pending
|
||||
// challenge certificate. This keeps ordinary Serve traffic from advertising
|
||||
@@ -1595,8 +1597,9 @@ func (b *LocalBackend) getTLSServeCertForPort(port uint16, forVIPService tailcfg
|
||||
// GetCertificate is called.
|
||||
func (b *LocalBackend) serveTLSConfig(getCert func(*tls.ClientHelloInfo) (*tls.Certificate, error), nextProtos []string) *tls.Config {
|
||||
base := &tls.Config{
|
||||
GetCertificate: getCert,
|
||||
NextProtos: nextProtos,
|
||||
GetCertificate: getCert,
|
||||
NextProtos: nextProtos,
|
||||
VerifyConnection: recordServeTLSConnection,
|
||||
}
|
||||
base.GetConfigForClient = func(hi *tls.ClientHelloInfo) (*tls.Config, error) {
|
||||
var nextProtos []string
|
||||
@@ -1690,7 +1693,26 @@ func handleC2NVIPServicesGet(b *LocalBackend, w http.ResponseWriter, r *http.Req
|
||||
json.NewEncoder(w).Encode(res)
|
||||
}
|
||||
|
||||
var metricIngressCalls = clientmetric.NewCounter("peerapi_ingress")
|
||||
var (
|
||||
metricIngressCalls = clientmetric.NewCounter("peerapi_ingress")
|
||||
metricServeTLSPQ = clientmetric.NewCounter("serve_tls_pq")
|
||||
metricServeTLSClassic = clientmetric.NewCounter("serve_tls_classic")
|
||||
)
|
||||
|
||||
// recordServeTLSConnection is a [tls.Config.VerifyConnection] callback that
|
||||
// records post-quantum vs classic TLS key exchange usage for Serve and Funnel
|
||||
// connections, ignoring ACME tls-alpn-01 challenges.
|
||||
func recordServeTLSConnection(cs tls.ConnectionState) error {
|
||||
if cs.NegotiatedProtocol == "acme-tls/1" {
|
||||
return nil
|
||||
}
|
||||
if tlsdial.IsPQCurve(cs.CurveID) {
|
||||
metricServeTLSPQ.Add(1)
|
||||
} else {
|
||||
metricServeTLSClassic.Add(1)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
RegisterPeerAPIHandler("/v0/ingress", handleServeIngress)
|
||||
|
||||
@@ -34,6 +34,7 @@ import (
|
||||
"github.com/pires/go-proxyproto"
|
||||
"tailscale.com/control/controlclient"
|
||||
"tailscale.com/envknob"
|
||||
"tailscale.com/feature/buildfeatures"
|
||||
"tailscale.com/health"
|
||||
"tailscale.com/ipn"
|
||||
"tailscale.com/ipn/store/mem"
|
||||
@@ -3070,3 +3071,82 @@ func TestTCPForwardWhoIs(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestServeTLSMetrics(t *testing.T) {
|
||||
if !buildfeatures.HasClientMetrics {
|
||||
t.Skip("client metrics disabled")
|
||||
}
|
||||
|
||||
b := newTestBackend(t)
|
||||
cert, err := tls.X509KeyPair(tlstest.Derper.CertPEM(), tlstest.Derper.KeyPEM())
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
getCert := func(*tls.ClientHelloInfo) (*tls.Certificate, error) {
|
||||
return &cert, nil
|
||||
}
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
serverProtos []string
|
||||
clientProtos []string
|
||||
clientCurves []tls.CurveID
|
||||
wantPQ int64
|
||||
wantClassic int64
|
||||
}{
|
||||
{
|
||||
name: "pq",
|
||||
serverProtos: serveTLSNextProtos(),
|
||||
clientCurves: []tls.CurveID{tls.X25519MLKEM768},
|
||||
wantPQ: 1,
|
||||
},
|
||||
{
|
||||
name: "classic",
|
||||
serverProtos: serveTLSNextProtos(),
|
||||
clientCurves: []tls.CurveID{tls.X25519},
|
||||
wantClassic: 1,
|
||||
},
|
||||
{
|
||||
name: "acme_alpn_skipped",
|
||||
serverProtos: []string{"acme-tls/1"},
|
||||
clientProtos: []string{"acme-tls/1"},
|
||||
clientCurves: []tls.CurveID{tls.X25519MLKEM768},
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
pqBefore := metricServeTLSPQ.Value()
|
||||
classicBefore := metricServeTLSClassic.Value()
|
||||
|
||||
clientConn, serverConn := net.Pipe()
|
||||
defer clientConn.Close()
|
||||
defer serverConn.Close()
|
||||
|
||||
srvTLS := tls.Server(serverConn, b.serveTLSConfig(getCert, tt.serverProtos))
|
||||
srvErr := make(chan error, 1)
|
||||
go func() {
|
||||
srvErr <- srvTLS.Handshake()
|
||||
}()
|
||||
|
||||
cliTLS := tls.Client(clientConn, &tls.Config{
|
||||
InsecureSkipVerify: true,
|
||||
NextProtos: tt.clientProtos,
|
||||
CurvePreferences: tt.clientCurves,
|
||||
})
|
||||
if err := cliTLS.Handshake(); err != nil {
|
||||
t.Fatalf("client Handshake: %v", err)
|
||||
}
|
||||
if err := <-srvErr; err != nil {
|
||||
t.Fatalf("server Handshake: %v", err)
|
||||
}
|
||||
|
||||
if got := metricServeTLSPQ.Value() - pqBefore; got != tt.wantPQ {
|
||||
t.Errorf("serve_tls_pq delta = %d; want %d", got, tt.wantPQ)
|
||||
}
|
||||
if got := metricServeTLSClassic.Value() - classicBefore; got != tt.wantClassic {
|
||||
t.Errorf("serve_tls_classic delta = %d; want %d", got, tt.wantClassic)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user