Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Stop cancelled Proxmox first-use certificate probes

pulse-triage[bot]768065b0db92
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index 929d04952f..494c94fc30 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -292,6 +292,13 @@ probe was in flight, and cancelled work cannot initiate or commit new trust.
Runtime captures belong to the client, not the caller's saved fingerprint map.
This does not add a certificate-management surface or persist new runtime trust.
+The credential-free first-use TLS probe shares the polling caller's context:
+cancellation or deadline ends a stalled handshake and releases its socket without
+waiting for the peer. The existing five-second capture ceiling remains; it never
+extends the caller's budget. Cancellation is checked again under the trust mutex
+before a runtime pin is committed. A later ordinary caller may still establish
+the declared member's first-use pin and make the existing pin-verified API read.
+
`TestClusterClientFingerprintTrustContract` checks changed and restored real TLS
leaves through startup/recovery, token containment, known/equivalent pins,
provider-text/undeclared/cancelled exclusions, concurrent first-use capture and
@@ -299,6 +306,11 @@ ordinary first-use authenticated acceptance. The existing #1664 new-member
control remains. These are secret-free loopback source proofs, not live cluster
or installed acceptance, exploitation evidence or native guest recovery.
+`TestClusterClientFirstUseCaptureCancellation` holds an actual first-use TLS
+handshake behind a local barrier. Cancellation and deadline must return before
+that barrier is released, without a new pin or authenticated request; a fresh
+caller subsequently establishes the owned leaf and makes one pinned API read.
+
### Known Windows guests do not receive Linux-only memory reads
An accepted guest OS reply identifying Windows suppresses the optional
diff --git a/docs/release-control/v6/internal/subsystems/security-privacy.md b/docs/release-control/v6/internal/subsystems/security-privacy.md
index 983efc60fe..c114f61a7b 100644
--- a/docs/release-control/v6/internal/subsystems/security-privacy.md
+++ b/docs/release-control/v6/internal/subsystems/security-privacy.md
@@ -134,6 +134,18 @@ leaves over IPv4/IPv6 and unchanged bare-host defaults, without HTTP. Existing
cluster trust and provisioning controls remain required. This is source proof,
not installed connection recovery or completion of #2140.
+`FetchFingerprintContext` additionally binds TCP dialing and the TLS handshake
+to the caller's context under the same five-second ceiling. A cancelled or
+expired caller receives no fingerprint, and a stalled capture closes its own
+socket. The existing `FetchFingerprint` helper retains its background-context
+interface and ordinary leaf/authority semantics. Proxmox first-use recovery
+uses the context-bound helper and checks cancellation under the trust mutex
+before committing a runtime pin; established pins and first-use eligibility
+are unchanged. `TestFetchFingerprintCancellationContract` covers pre-cancelled
+no-dial, stalled-handshake cancellation/deadline with peer-observed EOF, and
+ordinary owned-leaf capture through both interfaces without HTTP. These are
+local source/connection-lifecycle proofs, not installed trust recovery.
+
### TLS pin failures remain local typed trust evidence
`tlsutil.FingerprintVerifier` preserves its existing certificate digest checks,
diff --git a/pkg/proxmox/cluster_client.go b/pkg/proxmox/cluster_client.go
index c72eab250a..937cee4e05 100644
--- a/pkg/proxmox/cluster_client.go
+++ b/pkg/proxmox/cluster_client.go
@@ -297,7 +297,7 @@ func (cc *ClusterClient) refreshTOFUFingerprintAndRetry(ctx context.Context, end
return nil, lastErr, false
}
- newFingerprint, err := tlsutil.FetchFingerprint(endpoint)
+ newFingerprint, err := tlsutil.FetchFingerprintContext(ctx, endpoint)
if err != nil {
log.Warn().
Str("cluster", cc.name).
@@ -311,6 +311,12 @@ func (cc *ClusterClient) refreshTOFUFingerprintAndRetry(ctx context.Context, end
}
cc.mu.Lock()
+ // Cancellation may have arrived while waiting for the trust mutex too.
+ // Ending that caller cannot establish a new runtime pin.
+ if ctx.Err() != nil {
+ cc.mu.Unlock()
+ return nil, lastErr, false
+ }
captured := false
// A concurrent first-use capture may have established trust while the TLS
// probe was in flight. Use that winner's pin, not our later certificate.
diff --git a/pkg/proxmox/cluster_client_api_test.go b/pkg/proxmox/cluster_client_api_test.go
index 31c6a24a33..e8d9477cac 100644
--- a/pkg/proxmox/cluster_client_api_test.go
+++ b/pkg/proxmox/cluster_client_api_test.go
@@ -669,3 +669,78 @@ func TestGuestAgentIPv4MappedTrustScope(t *testing.T) {
}
}
}
+
+// A local TLS barrier holds only the unauthenticated first-use capture. A
+// caller cancellation must release the probe without waiting for that peer;
+// returning later without a pin is not enough to bound polling shutdown.
+func TestClusterClientFirstUseCaptureCancellation(t *testing.T) {
+ for _, mode := range []string{"cancel", "deadline"} {
+ t.Run(mode, func(t *testing.T) {
+ f := newClusterTrustFixture(t)
+ primaryPin := clusterTrustPin(clusterTrustCertificate(t))
+ cc := NewClusterClient("cancelled-capture", clusterTrustConfig("https://primary.trust.invalid", primaryPin), []string{f.server.URL}, nil)
+ lastErr := clusterTrustMismatch(t, f, primaryPin)
+ ctx, cancel := context.WithCancel(context.Background())
+ if mode == "deadline" {
+ cancel()
+ ctx, cancel = context.WithTimeout(context.Background(), 2*time.Second)
+ }
+ defer cancel()
+ type result struct {
+ client *Client
+ err error
+ retried bool
+ }
+ done := make(chan result, 1)
+ f.capture.Store(true)
+ released := false
+ release := func() {
+ if !released {
+ close(f.resume)
+ released = true
+ }
+ }
+ defer release()
+ go func() {
+ client, err, retried := cc.refreshTOFUFingerprintAndRetry(ctx, f.server.URL, time.Second, lastErr)
+ done <- result{client, err, retried}
+ }()
+ select {
+ case <-f.entered:
+ case got := <-done:
+ t.Fatalf("probe did not reach the owned TLS barrier: %v", got.err)
+ case <-time.After(10 * time.Second):
+ t.Fatal("probe did not reach the owned TLS barrier")
+ }
+ if mode == "cancel" {
+ cancel()
+ }
+ <-ctx.Done()
+ var got result
+ select {
+ case got = <-done:
+ case <-time.After(time.Second):
+ t.Error("cancelled capture still waits for the peer's TLS handshake")
+ release() // Join even the adverse parent without leaving a blocked peer.
+ got = <-done
+ }
+ if got.client != nil {
+ got.client.httpClient.CloseIdleConnections()
+ }
+ if got.client != nil || got.retried || !errors.Is(got.err, lastErr) || len(cc.endpointFingerprints) != 0 || f.requests.Load() != 0 {
+ t.Errorf("cancelled capture changed trust or sent authentication: retried=%t pins=%d requests=%d err=%v", got.retried, len(cc.endpointFingerprints), f.requests.Load(), got.err)
+ }
+ release()
+ // Ending this caller is not a revocation of ordinary declared-member
+ // first use. A fresh caller must still establish the same owned leaf
+ // and make exactly one pin-verified authenticated request.
+ client, err, retried := cc.refreshTOFUFingerprintAndRetry(context.Background(), f.server.URL, time.Second, lastErr)
+ if client != nil {
+ defer client.httpClient.CloseIdleConnections()
+ }
+ if err != nil || !retried || client == nil || cc.getEndpointFingerprint(f.server.URL) != clusterTrustPin(f.active.Load()) || f.requests.Load() != 1 {
+ t.Errorf("ordinary first use after cancelled probe failed: retried=%t requests=%d err=%v", retried, f.requests.Load(), err)
+ }
+ })
+ }
+}
diff --git a/pkg/tlsutil/fingerprint.go b/pkg/tlsutil/fingerprint.go
index 8f7a602939..68b7e037f0 100644
--- a/pkg/tlsutil/fingerprint.go
+++ b/pkg/tlsutil/fingerprint.go
@@ -61,6 +61,16 @@ func UnverifiedPeerCertificateCaptureTLSConfig() *tls.Config {
// port. A bare hostname or IP retains the legacy Proxmox default port, 8006.
// Capture is always a TLS handshake, not an HTTP request or a grant of trust.
func FetchFingerprint(host string) (string, error) {
+ return FetchFingerprintContext(context.Background(), host)
+}
+
+// FetchFingerprintContext captures the same credential-free TLS leaf while
+// respecting the caller's cancellation and deadline. The existing five-second
+// capture limit remains an upper bound, not an extension of the caller's budget.
+func FetchFingerprintContext(ctx context.Context, host string) (string, error) {
+ if err := ctx.Err(); err != nil {
+ return "", err
+ }
targetHost, err := fingerprintTarget(host)
if err != nil {
return "", fmt.Errorf("failed to parse host URL: %w", err)
@@ -68,11 +78,14 @@ func FetchFingerprint(host string) (string, error) {
// Create a TLS connection that explicitly accepts parseable peer certificates
// for fingerprint capture without relying on blanket skip-verify alone.
- ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
+ ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
- dialer := &net.Dialer{Timeout: 5 * time.Second}
- conn, err := tls.DialWithDialer(dialer, "tcp", targetHost, UnverifiedPeerCertificateCaptureTLSConfig())
+ dialer := &tls.Dialer{
+ NetDialer: &net.Dialer{Timeout: 5 * time.Second},
+ Config: UnverifiedPeerCertificateCaptureTLSConfig(),
+ }
+ conn, err := dialer.DialContext(ctx, "tcp", targetHost)
if err != nil {
return "", fmt.Errorf("failed to connect to %s: %w", targetHost, err)
}
@@ -86,7 +99,8 @@ func FetchFingerprint(host string) (string, error) {
}
// Get the peer certificates
- certs := conn.ConnectionState().PeerCertificates
+ // tls.Dialer.DialContext always returns a *tls.Conn on success.
+ certs := conn.(*tls.Conn).ConnectionState().PeerCertificates
if len(certs) == 0 {
return "", fmt.Errorf("no certificates presented by %s", targetHost)
}
diff --git a/pkg/tlsutil/fingerprint_cancellation_test.go b/pkg/tlsutil/fingerprint_cancellation_test.go
new file mode 100644
index 0000000000..dbf7c71dcd
--- /dev/null
+++ b/pkg/tlsutil/fingerprint_cancellation_test.go
@@ -0,0 +1,131 @@
+package tlsutil
+
+import (
+ "context"
+ "errors"
+ "io"
+ "net"
+ "testing"
+ "time"
+)
+
+func testFetchFingerprintCancellation(t *testing.T) {
+ t.Run("already-cancelled-does-not-dial", func(t *testing.T) {
+ listener, err := net.Listen("tcp4", "127.0.0.1:0")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer listener.Close()
+ ctx, cancel := context.WithCancel(context.Background())
+ cancel()
+ fingerprint, err := FetchFingerprintContext(ctx, "https://"+listener.Addr().String())
+ if fingerprint != "" || !errors.Is(err, context.Canceled) {
+ t.Fatalf("cancelled capture = %q, %v", fingerprint, err)
+ }
+ if err := listener.(*net.TCPListener).SetDeadline(time.Now().Add(250 * time.Millisecond)); err != nil {
+ t.Fatal(err)
+ }
+ connection, err := listener.Accept()
+ if connection != nil {
+ connection.Close()
+ t.Fatal("already-cancelled capture connected to the peer")
+ }
+ var timeout net.Error
+ if !errors.As(err, &timeout) || !timeout.Timeout() {
+ t.Fatalf("listener did not establish an empty accept queue: %v", err)
+ }
+ })
+ for _, mode := range []string{"cancel", "deadline"} {
+ t.Run(mode+"-closes-stalled-handshake", func(t *testing.T) {
+ listener, err := net.Listen("tcp4", "127.0.0.1:0")
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer listener.Close()
+ entered := make(chan net.Conn, 1)
+ peerDone := make(chan error, 1)
+ go func() {
+ connection, err := listener.Accept()
+ if err != nil {
+ peerDone <- err
+ return
+ }
+ defer connection.Close()
+ var first [1]byte
+ if _, err := io.ReadFull(connection, first[:]); err != nil {
+ peerDone <- err
+ return
+ }
+ if first[0] != 0x16 {
+ peerDone <- errors.New("probe did not start with a TLS handshake record")
+ return
+ }
+ entered <- connection
+ // Never send a ServerHello. EOF must come from the cancelled
+ // client, not a fixture timeout or the listener being closed.
+ _, err = io.Copy(io.Discard, connection)
+ peerDone <- err
+ }()
+ ctx, cancel := context.WithCancel(context.Background())
+ if mode == "deadline" {
+ cancel()
+ ctx, cancel = context.WithTimeout(context.Background(), 2*time.Second)
+ }
+ defer cancel()
+ type result struct {
+ fingerprint string
+ err error
+ }
+ done := make(chan result, 1)
+ go func() {
+ fingerprint, err := FetchFingerprintContext(ctx, "https://"+listener.Addr().String())
+ done <- result{fingerprint, err}
+ }()
+ var connection net.Conn
+ select {
+ case connection = <-entered:
+ defer connection.Close()
+ case err := <-peerDone:
+ t.Fatalf("peer did not reach the stalled TLS handshake: %v", err)
+ case <-time.After(10 * time.Second):
+ t.Fatal("peer did not reach the stalled TLS handshake")
+ }
+ if mode == "cancel" {
+ cancel()
+ }
+ <-ctx.Done()
+ select {
+ case got := <-done:
+ if got.fingerprint != "" || !errors.Is(got.err, ctx.Err()) {
+ t.Errorf("cancelled capture = %q, %v; want no certificate and %v", got.fingerprint, got.err, ctx.Err())
+ }
+ case <-time.After(time.Second):
+ t.Error("cancelled capture did not return while the peer remained stalled")
+ connection.Close()
+ <-done
+ }
+ select {
+ case err := <-peerDone:
+ if err != nil {
+ t.Errorf("cancelled client did not cleanly close its owned socket: %v", err)
+ }
+ case <-time.After(time.Second):
+ connection.Close()
+ <-peerDone
+ t.Error("cancelled capture returned without releasing its socket")
+ }
+ })
+ }
+ t.Run("ordinary-capture-keeps-owned-leaf-and-legacy-helper", func(t *testing.T) {
+ server, expected, requests := fingerprintAuthorityFixture(t, "tcp4", "127.0.0.1:0")
+ for _, capture := range []func(string) (string, error){
+ FetchFingerprint,
+ func(host string) (string, error) { return FetchFingerprintContext(context.Background(), host) },
+ } {
+ fingerprint, err := capture(server.URL + "/proxy/base/")
+ if err != nil || fingerprint != expected || requests.Load() != 0 {
+ t.Fatalf("ordinary capture = %q, %v; HTTP requests=%d", fingerprint, err, requests.Load())
+ }
+ }
+ })
+}
diff --git a/pkg/tlsutil/tlsutil_test.go b/pkg/tlsutil/tlsutil_test.go
index 3109fa1ea1..8877ec018a 100644
--- a/pkg/tlsutil/tlsutil_test.go
+++ b/pkg/tlsutil/tlsutil_test.go
@@ -13,6 +13,10 @@ import (
"time"
)
+func TestFetchFingerprintCancellationContract(t *testing.T) {
+ testFetchFingerprintCancellation(t)
+}
+
func TestCreateHTTPClientRedirectAuthorityValidation(t *testing.T) {
for _, mode := range []struct {
name string