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.

Keep established Proxmox certificate pins during recovery

pulse-triage[bot]7100938fb366
diff --git a/docs/release-control/v6/internal/subsystems/monitoring.md b/docs/release-control/v6/internal/subsystems/monitoring.md
index c70dd6a886..c53a8c63d7 100644
--- a/docs/release-control/v6/internal/subsystems/monitoring.md
+++ b/docs/release-control/v6/internal/subsystems/monitoring.md
@@ -17,6 +17,32 @@
## Purpose
+### Cluster recovery preserves established certificate pins
+
+Startup and unhealthy-endpoint recovery must not replace the configured primary
+fingerprint or a saved/previously captured member fingerprint after a TLS
+mismatch. No authenticated retry or unverified certificate capture is admitted
+for those known endpoints; their failure remains visible until the trusted
+certificate returns or the operator independently verifies and saves new trust.
+Equivalent URL spellings preserve the same pin without merging distinct scheme,
+port or base-path authorities.
+
+First-use trust remains available for a declared, previously untrusted member
+that fails the primary fingerprint check. Only the typed local TLS verifier
+failure admits this bootstrap, not a provider message quoting a mismatch.
+Capture itself sends no API credential. The subsequent API request verifies the
+captured pin. A competing capture cannot replace a pin established while its
+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.
+
+`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
+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.
+
### 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 ee10c187ff..7831ddf0d7 100644
--- a/docs/release-control/v6/internal/subsystems/security-privacy.md
+++ b/docs/release-control/v6/internal/subsystems/security-privacy.md
@@ -18,6 +18,19 @@
## Purpose
+### TLS pin failures remain local typed trust evidence
+
+`tlsutil.FingerprintVerifier` preserves its existing certificate digest checks,
+normalisation, minimum TLS version and mismatch diagnostic, while returning a
+`FingerprintMismatchError` from the local verifier. Error wrapping retains the
+type; provider text repeating that diagnostic does not acquire it. Proxmox
+cluster first-use admission uses this distinction and never automatically
+replaces a known primary or member pin. `TestFingerprintVerifier_MismatchedFingerprint`
+in `pkg/tlsutil/tlsutil_test.go` checks digest identity, wrapping and rejection
+of quoted text; `TestClusterClientFingerprintTrustContract` supplies connected
+startup/recovery/first-use proof. CA verification and the existing explicit
+unverified-discovery modes are unchanged. No live security acceptance is claimed.
+
### Existing PMG collection choices constrain provider reads
The owning PMG collector honours the saved mail, queue, quarantine and domain
diff --git a/pkg/proxmox/cluster_client.go b/pkg/proxmox/cluster_client.go
index 64338a616d..fde1cffbec 100644
--- a/pkg/proxmox/cluster_client.go
+++ b/pkg/proxmox/cluster_client.go
@@ -2,6 +2,7 @@ package proxmox
import (
"context"
+ "errors"
"fmt"
"math/rand"
"regexp"
@@ -10,6 +11,7 @@ import (
"sync"
"time"
+ "github.com/rcourtman/pulse-go-rewrite/internal/securityutil"
"github.com/rcourtman/pulse-go-rewrite/pkg/tlsutil"
"github.com/rs/zerolog/log"
)
@@ -150,6 +152,9 @@ func sanitizeEndpointError(errMsg string) string {
}
// TLS/certificate errors
+ if strings.Contains(lower, "fingerprint mismatch") {
+ return "TLS fingerprint changed - independently verify the certificate before updating the saved fingerprint"
+ }
if strings.Contains(lower, "certificate") || strings.Contains(lower, "x509") {
return "TLS certificate error - check SSL settings or add fingerprint"
}
@@ -173,14 +178,17 @@ func sanitizeEndpointError(errMsg string) string {
// This enables TOFU (Trust On First Use) for clusters with unique self-signed certs per node.
func NewClusterClient(name string, config ClientConfig, endpoints []string, endpointFingerprints map[string]string) *ClusterClient {
registerGuestAgentEndpoints(config.Host, endpoints)
- if endpointFingerprints == nil {
- endpointFingerprints = make(map[string]string)
+ // The client owns subsequent first-use captures. Do not mutate the caller's
+ // saved trust map or let another client overwrite it without our mutex.
+ ownedFingerprints := make(map[string]string, len(endpointFingerprints))
+ for endpoint, fingerprint := range endpointFingerprints {
+ ownedFingerprints[endpoint] = fingerprint
}
cc := &ClusterClient{
name: name,
clients: make(map[string]*Client),
endpoints: endpoints,
- endpointFingerprints: endpointFingerprints,
+ endpointFingerprints: ownedFingerprints,
nodeHealth: make(map[string]bool),
lastHealthCheck: make(map[string]time.Time),
lastError: make(map[string]string),
@@ -211,31 +219,76 @@ func (cc *ClusterClient) getEndpointFingerprint(endpoint string) string {
}
func (cc *ClusterClient) getEndpointFingerprintLocked(endpoint string) string {
- if fp, ok := cc.endpointFingerprints[endpoint]; ok && fp != "" {
+ if fp, ok := cc.knownEndpointFingerprintLocked(endpoint); ok {
return fp
}
return cc.config.Fingerprint
}
+func clusterEndpointKey(endpoint string) (string, bool) {
+ u, err := securityutil.NormalizeHTTPBaseURL(endpoint, "https")
+ if err != nil {
+ return "", false
+ }
+ // Reuse the origin/base-path identity used for guest coordination, without
+ // joining cluster aliases or changing the actual request/TLS authority.
+ return guestAgentEndpointKey(u.String())
+}
+
+func (cc *ClusterClient) knownEndpointFingerprintLocked(endpoint string) (string, bool) {
+ if fp := cc.endpointFingerprints[endpoint]; fp != "" {
+ return fp, true
+ }
+ key, valid := clusterEndpointKey(endpoint)
+ if !valid {
+ return "", false
+ }
+ for storedEndpoint, fp := range cc.endpointFingerprints {
+ if storedKey, ok := clusterEndpointKey(storedEndpoint); ok && storedKey == key && fp != "" {
+ return fp, true
+ }
+ }
+ return "", false
+}
+
+// Only a declared, previously untrusted member may use the primary pin as a
+// first-use bootstrap. A known member or the configured primary must keep its
+// established pin; recovery is never permission to replace it.
+func (cc *ClusterClient) canTrustMemberOnFirstUseLocked(endpoint string) bool {
+ key, valid := clusterEndpointKey(endpoint)
+ primary, primaryValid := clusterEndpointKey(cc.config.Host)
+ if !valid || !primaryValid || key == primary || cc.config.Fingerprint == "" {
+ return false
+ }
+ if _, known := cc.knownEndpointFingerprintLocked(endpoint); known {
+ return false
+ }
+ for _, member := range cc.endpoints {
+ if memberKey, ok := clusterEndpointKey(member); ok && memberKey == key {
+ return true
+ }
+ }
+ return false
+}
+
func isFingerprintMismatchError(err error) bool {
- return err != nil && strings.Contains(strings.ToLower(err.Error()), "fingerprint mismatch")
+ var mismatch *tlsutil.FingerprintMismatchError
+ return errors.As(err, &mismatch)
}
-// refreshTOFUFingerprintAndRetry refreshes a per-endpoint TOFU fingerprint after a mismatch and retries connectivity.
-// Returns (client, err, refreshed) where refreshed indicates whether TOFU refresh logic was applied.
+// refreshTOFUFingerprintAndRetry captures a new member's first-use pin, never
+// refreshes an established pin. Returns whether a pinned retry was attempted.
func (cc *ClusterClient) refreshTOFUFingerprintAndRetry(ctx context.Context, endpoint string, timeout time.Duration, lastErr error) (*Client, error, bool) {
- if !isFingerprintMismatchError(lastErr) {
+ if ctx.Err() != nil || !isFingerprintMismatchError(lastErr) {
return nil, lastErr, false
}
- // A member without a stored per-endpoint fingerprint fails against the
- // base config's pinned fingerprint (the primary's). Cluster members carry
- // their own certificates, so capture the member's fingerprint on first
- // use just like discovery does, instead of pinning it to the primary's
- // certificate forever.
cc.mu.RLock()
- _, hasTOFU := cc.endpointFingerprints[endpoint]
+ firstUse := cc.canTrustMemberOnFirstUseLocked(endpoint)
cc.mu.RUnlock()
+ if !firstUse {
+ return nil, lastErr, false
+ }
newFingerprint, err := tlsutil.FetchFingerprint(endpoint)
if err != nil {
@@ -246,17 +299,26 @@ func (cc *ClusterClient) refreshTOFUFingerprintAndRetry(ctx context.Context, end
Msg("Failed to refresh TOFU fingerprint after mismatch")
return nil, lastErr, false
}
+ if ctx.Err() != nil {
+ return nil, lastErr, false
+ }
cc.mu.Lock()
- cc.endpointFingerprints[endpoint] = newFingerprint
- cc.mu.Unlock()
-
- if hasTOFU {
- log.Warn().
- Str("cluster", cc.name).
- Str("endpoint", endpoint).
- Msg("Detected TLS certificate change; refreshed TOFU fingerprint")
+ 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.
+ if existing, known := cc.knownEndpointFingerprintLocked(endpoint); known {
+ newFingerprint = existing
} else {
+ if !cc.canTrustMemberOnFirstUseLocked(endpoint) {
+ cc.mu.Unlock()
+ return nil, lastErr, false
+ }
+ cc.endpointFingerprints[endpoint] = newFingerprint
+ captured = true
+ }
+ cc.mu.Unlock()
+ if captured {
log.Warn().
Str("cluster", cc.name).
Str("endpoint", endpoint).
diff --git a/pkg/proxmox/cluster_client_api_test.go b/pkg/proxmox/cluster_client_api_test.go
index bbf27e5310..e80cf7998e 100644
--- a/pkg/proxmox/cluster_client_api_test.go
+++ b/pkg/proxmox/cluster_client_api_test.go
@@ -560,8 +560,8 @@ func TestClusterClient_GetTaskLog(t *testing.T) {
}
// Issue #1664: refreshTOFUFingerprintAndRetry only refreshed endpoints that
-// already had a per-endpoint fingerprint entry, so it recovered certificate
-// rotation on known members but never first trust of a newly joined member.
+// already had a per-endpoint fingerprint entry, so a newly joined member could
+// never establish its first-use trust. Known-member rotation is not first use.
// A new member has no entry and fell back to the primary's pinned
// fingerprint forever.
func TestClusterClient_TOFUFirstUse_TrustsNewMemberCert(t *testing.T) {
@@ -576,7 +576,7 @@ func TestClusterClient_TOFUFirstUse_TrustsNewMemberCert(t *testing.T) {
defer server.Close()
cfg := ClientConfig{
- Host: server.URL,
+ Host: "https://primary.issue1664.invalid",
TokenName: "root@pam!pulse",
TokenValue: "secret",
Fingerprint: "DE:AD:BE:EF:DE:AD:BE:EF:DE:AD:BE:EF:DE:AD:BE:EF:DE:AD:BE:EF:DE:AD:BE:EF:DE:AD:BE:EF:DE:AD:BE:EF",
@@ -585,7 +585,17 @@ func TestClusterClient_TOFUFirstUse_TrustsNewMemberCert(t *testing.T) {
// no per-endpoint fingerprint entry, exactly like a freshly joined node.
cc := NewClusterClient("issue1664", cfg, []string{server.URL}, nil)
- mismatch := errors.New("certificate fingerprint mismatch: expected DE:AD, got EF:B5")
+ pinnedConfig := cfg
+ pinnedConfig.Host = server.URL
+ pinned, err := NewClient(pinnedConfig)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer pinned.httpClient.CloseIdleConnections()
+ _, mismatch := pinned.GetNodes(context.Background())
+ if !isFingerprintMismatchError(mismatch) {
+ t.Fatalf("expected a real TLS verifier mismatch, got %v", mismatch)
+ }
client, err, refreshed := cc.refreshTOFUFingerprintAndRetry(context.Background(), server.URL, 2*time.Second, mismatch)
if !refreshed {
t.Fatal("expected TOFU refresh to run for an endpoint with no stored fingerprint")
@@ -619,3 +629,8 @@ func TestClusterClient_TOFURefresh_IgnoresNonTLSMismatch(t *testing.T) {
t.Fatalf("expected original error back, got %v", err)
}
}
+
+// Keep the trust-boundary proof alongside cluster runtime qualification.
+func TestClusterClientFingerprintTrustContract(t *testing.T) {
+ testClusterClientFingerprintTrust(t)
+}
diff --git a/pkg/proxmox/cluster_client_fingerprint_trust_test.go b/pkg/proxmox/cluster_client_fingerprint_trust_test.go
new file mode 100644
index 0000000000..c9775de280
--- /dev/null
+++ b/pkg/proxmox/cluster_client_fingerprint_trust_test.go
@@ -0,0 +1,272 @@
+package proxmox
+
+import (
+ "context"
+ "crypto/ed25519"
+ "crypto/rand"
+ "crypto/sha256"
+ "crypto/tls"
+ "crypto/x509"
+ "encoding/hex"
+ "errors"
+ "fmt"
+ "io"
+ "log"
+ "math/big"
+ "net/http"
+ "net/http/httptest"
+ "strings"
+ "sync/atomic"
+ "testing"
+ "time"
+)
+
+// These certificates and authentication values belong only to secret-free,
+// guest-local fixtures. A changed certificate is not a production probe.
+func clusterTrustCertificate(t *testing.T) *tls.Certificate {
+ t.Helper()
+ pub, key, err := ed25519.GenerateKey(rand.Reader)
+ if err != nil {
+ t.Fatal(err)
+ }
+ template := &x509.Certificate{SerialNumber: big.NewInt(1), NotBefore: time.Now().Add(-time.Hour), NotAfter: time.Now().Add(time.Hour)}
+ der, err := x509.CreateCertificate(rand.Reader, template, template, pub, key)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return &tls.Certificate{Certificate: [][]byte{der}, PrivateKey: key}
+}
+
+func clusterTrustPin(cert *tls.Certificate) string {
+ sha := sha256.Sum256(cert.Certificate[0])
+ return hex.EncodeToString(sha[:])
+}
+
+type clusterTrustFixture struct {
+ server *httptest.Server
+ active atomic.Pointer[tls.Certificate]
+ requests atomic.Int32
+ handshakes atomic.Int32
+ capture atomic.Bool
+ entered chan struct{}
+ resume chan struct{}
+}
+
+func newClusterTrustFixture(t *testing.T) *clusterTrustFixture {
+ t.Helper()
+ f := &clusterTrustFixture{entered: make(chan struct{}), resume: make(chan struct{})}
+ f.active.Store(clusterTrustCertificate(t))
+ f.server = httptest.NewUnstartedServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ f.requests.Add(1)
+ if r.Header.Get("Authorization") != "PVEAPIToken=fixture@pve!pulse=fixture" {
+ t.Error("lost fixture authentication")
+ }
+ if r.URL.Path != "/api2/json/nodes" {
+ t.Errorf("unexpected fixture path %q", r.URL.Path)
+ }
+ fmt.Fprint(w, `{"data":[{"node":"member","status":"online"}]}`)
+ }))
+ f.server.Config.ErrorLog = log.New(io.Discard, "", 0)
+ f.server.TLS = &tls.Config{GetConfigForClient: func(*tls.ClientHelloInfo) (*tls.Config, error) {
+ f.handshakes.Add(1)
+ cert := f.active.Load()
+ if f.capture.CompareAndSwap(true, false) {
+ close(f.entered)
+ <-f.resume
+ }
+ return &tls.Config{MinVersion: tls.VersionTLS12, Certificates: []tls.Certificate{*cert}}, nil
+ }}
+ f.server.StartTLS()
+ t.Cleanup(f.server.Close)
+ return f
+}
+
+func clusterTrustConfig(host, pin string) ClientConfig {
+ return ClientConfig{Host: host, Fingerprint: pin, VerifySSL: true, TokenName: "fixture@pve!pulse", TokenValue: "fixture", Timeout: time.Second}
+}
+
+func clusterTrustMismatch(t *testing.T, f *clusterTrustFixture, pin string) error {
+ t.Helper()
+ client, err := NewClient(clusterTrustConfig(f.server.URL, pin))
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer client.httpClient.CloseIdleConnections()
+ _, err = client.GetNodes(context.Background())
+ if !isFingerprintMismatchError(err) {
+ t.Fatalf("expected real local pin failure, got %v", err)
+ }
+ return err
+}
+
+func testClusterClientFingerprintTrust(t *testing.T) {
+ for _, phase := range []string{"startup", "recovery"} {
+ for _, role := range []string{"primary", "member"} {
+ t.Run("known-pins/"+phase+"/"+role, func(t *testing.T) {
+ f := newClusterTrustFixture(t)
+ original := f.active.Load()
+ pin := clusterTrustPin(original)
+ cfg := clusterTrustConfig(f.server.URL, pin)
+ pins := map[string]string{}
+ if role == "member" {
+ cfg.Host = "https://primary.trust.invalid"
+ pins[f.server.URL] = pin
+ }
+ cc := NewClusterClient("trust", cfg, []string{f.server.URL}, pins)
+ // Change the actual leaf while retaining the configured/saved pin.
+ f.active.Store(clusterTrustCertificate(t))
+ if phase == "startup" {
+ // A real second, independently pinned endpoint keeps ordinary
+ // cluster reads usable while the changed leaf stays rejected.
+ safe := newClusterTrustFixture(t)
+ pins[safe.server.URL] = clusterTrustPin(safe.active.Load())
+ cc = NewClusterClient("trust", cfg, []string{f.server.URL, safe.server.URL}, pins)
+ if _, err := cc.GetNodes(context.Background()); err != nil || safe.requests.Load() != 2 {
+ t.Errorf("trusted sibling lost ordinary monitoring: %v", err)
+ }
+ } else {
+ cc.mu.Lock()
+ cc.nodeHealth[f.server.URL] = false
+ cc.mu.Unlock()
+ cc.recoverUnhealthyNodes(context.Background())
+ }
+ cc.mu.RLock()
+ stored := cc.getEndpointFingerprintLocked(f.server.URL)
+ healthy, diagnostic := cc.nodeHealth[f.server.URL], cc.lastError[f.server.URL]
+ cc.mu.RUnlock()
+ if f.requests.Load() != 0 || stored != pin || healthy || !strings.Contains(diagnostic, "independently verify") {
+ t.Errorf("changed certificate gained trust: authenticated=%d retained-pin=%t healthy=%t diagnostic=%q", f.requests.Load(), stored == pin, healthy, diagnostic)
+ }
+ // Re-presenting the trusted leaf restores ordinary monitoring.
+ f.active.Store(original)
+ f.server.CloseClientConnections()
+ cc.mu.Lock()
+ cc.nodeHealth[f.server.URL] = false
+ delete(cc.lastHealthCheck, f.server.URL)
+ cc.mu.Unlock()
+ before := f.requests.Load()
+ cc.recoverUnhealthyNodes(context.Background())
+ if !cc.GetHealthStatus()[f.server.URL] || f.requests.Load() != before+1 || cc.getEndpointFingerprint(f.server.URL) != pin {
+ t.Error("restored original certificate did not resume ordinary monitoring under the same pin")
+ }
+ t.Logf("changed leaf: no authenticated requests; original leaf: one authenticated recovery, retained %s pin", role)
+ })
+ }
+ }
+
+ for _, reason := range []string{"provider-text", "undeclared-endpoint", "cancelled-first-use", "primary-spelling"} {
+ t.Run(reason, func(t *testing.T) {
+ f := newClusterTrustFixture(t)
+ pin := clusterTrustPin(clusterTrustCertificate(t))
+ cc := NewClusterClient("trust", clusterTrustConfig("https://primary.trust.invalid", pin), []string{f.server.URL}, nil)
+ var lastErr error
+ if reason == "provider-text" {
+ lastErr = fmt.Errorf("API response: %w", errors.New("certificate fingerprint mismatch: expected x, got y"))
+ } else {
+ lastErr = clusterTrustMismatch(t, f, pin)
+ if reason == "undeclared-endpoint" {
+ cc.endpoints = []string{"https://declared.trust.invalid"}
+ } else if reason == "primary-spelling" {
+ cc.config.Host = strings.TrimPrefix(f.server.URL, "https://") + "/./"
+ }
+ }
+ ctx, cancel := context.WithCancel(context.Background())
+ defer cancel()
+ if reason == "cancelled-first-use" {
+ cancel()
+ }
+ before := f.handshakes.Load()
+ client, err, retried := cc.refreshTOFUFingerprintAndRetry(ctx, f.server.URL, time.Second, lastErr)
+ if client != nil || retried || !errors.Is(err, lastErr) || f.handshakes.Load() != before || f.requests.Load() != 0 || len(cc.endpointFingerprints) != 0 {
+ t.Error("untrusted refresh evidence started capture, authenticated retry or pin mutation")
+ }
+ })
+ }
+
+ t.Run("concurrent-first-use", func(t *testing.T) {
+ f := newClusterTrustFixture(t)
+ primaryPin := clusterTrustPin(clusterTrustCertificate(t))
+ cc := NewClusterClient("trust", clusterTrustConfig("https://primary.trust.invalid", primaryPin), []string{f.server.URL}, nil)
+ lastErr := clusterTrustMismatch(t, f, primaryPin)
+ f.capture.Store(true)
+ done := make(chan error, 1)
+ go func() {
+ client, err, retried := cc.refreshTOFUFingerprintAndRetry(context.Background(), f.server.URL, time.Second, lastErr)
+ if client != nil {
+ defer client.httpClient.CloseIdleConnections()
+ }
+ if !retried && err == nil {
+ err = errors.New("missing pinned retry")
+ }
+ done <- err
+ }()
+ select {
+ case <-f.entered:
+ case <-time.After(10 * time.Second):
+ close(f.resume)
+ t.Fatal("capture did not reach bounded fixture handshake")
+ }
+ // A competing first-use capture establishes its pin while this older
+ // probe is still in flight. The older probe must not replace that winner.
+ winner := clusterTrustCertificate(t)
+ winnerPin := clusterTrustPin(winner)
+ cc.mu.Lock()
+ cc.endpointFingerprints[f.server.URL] = winnerPin
+ cc.mu.Unlock()
+ f.active.Store(winner)
+ close(f.resume)
+ if err := <-done; err != nil {
+ t.Errorf("retry did not use concurrently established trust: %v", err)
+ }
+ if cc.getEndpointFingerprint(f.server.URL) != winnerPin || f.requests.Load() != 1 {
+ t.Error("older first-use capture replaced the winner or failed its authenticated acceptance")
+ }
+ })
+
+ t.Run("first-use-and-input-ownership", func(t *testing.T) {
+ f := newClusterTrustFixture(t)
+ primaryPin := clusterTrustPin(clusterTrustCertificate(t))
+ input := map[string]string{}
+ cc := NewClusterClient("trust", clusterTrustConfig("https://primary.trust.invalid", primaryPin), []string{f.server.URL}, input)
+ lastErr := clusterTrustMismatch(t, f, primaryPin)
+ before := f.handshakes.Load()
+ 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 || f.requests.Load() != 1 || cc.getEndpointFingerprint(f.server.URL) != clusterTrustPin(f.active.Load()) {
+ t.Fatalf("declared new member cannot establish first-use trust: %v", err)
+ }
+ if len(input) != 0 {
+ t.Error("runtime trust capture mutated caller-owned saved pins")
+ }
+ // Exactly one unauthenticated capture handshake and one pinned API
+ // handshake follow the initial mismatch. No password or API token is
+ // sent by the capture itself.
+ if f.handshakes.Load() != before+2 {
+ t.Error("first use performed unexpected TLS work")
+ }
+ f.active.Store(clusterTrustCertificate(t))
+ f.server.CloseClientConnections()
+ cc.mu.Lock()
+ cc.nodeHealth[f.server.URL] = false
+ cc.mu.Unlock()
+ cc.recoverUnhealthyNodes(context.Background())
+ if f.requests.Load() != 1 || cc.GetHealthStatus()[f.server.URL] {
+ t.Error("first-use pin was silently replaced on later recovery")
+ }
+ })
+
+ t.Run("equivalent-known-endpoint", func(t *testing.T) {
+ cc := NewClusterClient("trust", clusterTrustConfig("https://primary.trust.invalid", "primary-pin"), nil,
+ map[string]string{"https://MEMBER.trust.invalid:443/tenant/": "member-pin"})
+ if cc.getEndpointFingerprint("https://member.trust.invalid/tenant") != "member-pin" {
+ t.Error("equivalent URL spelling forgot established member trust")
+ }
+ for _, endpoint := range []string{"http://member.trust.invalid/tenant", "https://member.trust.invalid:8006/tenant", "https://member.trust.invalid/Tenant"} {
+ if cc.getEndpointFingerprint(endpoint) != "primary-pin" {
+ t.Errorf("independent authority/path inherited another endpoint's pin: %s", endpoint)
+ }
+ }
+ })
+}
diff --git a/pkg/tlsutil/fingerprint.go b/pkg/tlsutil/fingerprint.go
index 98a50abe29..2667b89156 100644
--- a/pkg/tlsutil/fingerprint.go
+++ b/pkg/tlsutil/fingerprint.go
@@ -16,6 +16,17 @@ import (
const minimumTLSVersion = tls.VersionTLS12
+// FingerprintMismatchError identifies a failed local certificate-pin check.
+// Provider response text mentioning a mismatch is not TLS trust evidence.
+type FingerprintMismatchError struct {
+ Expected string
+ Actual string
+}
+
+func (e *FingerprintMismatchError) Error() string {
+ return fmt.Sprintf("certificate fingerprint mismatch: expected %s, got %s", e.Expected, e.Actual)
+}
+
func verifyPresentedPeerCertificates(rawCerts [][]byte, _ [][]*x509.Certificate) error {
if len(rawCerts) == 0 {
return fmt.Errorf("no certificates presented by server")
@@ -107,8 +118,7 @@ func FingerprintVerifier(fingerprint string) *tls.Config {
actualFingerprint := hex.EncodeToString(fingerprint[:])
if actualFingerprint != expectedFingerprint {
- return fmt.Errorf("certificate fingerprint mismatch: expected %s, got %s",
- expectedFingerprint, actualFingerprint)
+ return &FingerprintMismatchError{Expected: expectedFingerprint, Actual: actualFingerprint}
}
return nil
diff --git a/pkg/tlsutil/tlsutil_test.go b/pkg/tlsutil/tlsutil_test.go
index 3f5d52c785..f5248f0edd 100644
--- a/pkg/tlsutil/tlsutil_test.go
+++ b/pkg/tlsutil/tlsutil_test.go
@@ -4,6 +4,8 @@ import (
"crypto/sha256"
"crypto/x509"
"encoding/hex"
+ "errors"
+ "fmt"
"net/http"
"net/url"
"strings"
@@ -107,6 +109,17 @@ func TestFingerprintVerifier_MismatchedFingerprint(t *testing.T) {
if !strings.Contains(err.Error(), "mismatch") {
t.Errorf("Error message should mention mismatch, got: %v", err)
}
+ var mismatch *FingerprintMismatchError
+ if !errors.As(fmt.Errorf("request failed: %w", err), &mismatch) || mismatch.Expected != wrongFP {
+ t.Fatal("local pin failure lost its typed trust evidence through wrapping")
+ }
+ actual := sha256.Sum256(mockCert)
+ if mismatch.Actual != hex.EncodeToString(actual[:]) {
+ t.Fatal("typed mismatch changed the observed certificate identity")
+ }
+ if errors.As(errors.New(err.Error()), &mismatch) {
+ t.Fatal("quoted error text created verifier evidence")
+ }
}
func TestCreateHTTPClient_InsecureMode(t *testing.T) {