[management] optimize posture cache (#8366)

This commit is contained in:
Pascal Fischer
2026-10-26 16:03:33 +01:00
committed by GitHub
parent afa6eec6a7
commit 2c68a84a97
11 changed files with 690 additions and 182 deletions
@@ -1,6 +1,8 @@
package nmdata
import (
"crypto/x509"
"sync"
"time"
"github.com/netbirdio/netbird/shared/management/certposture"
@@ -9,8 +11,21 @@ import (
// CertificateCheck is the slim twin of posture.CertificateCheck.
type CertificateCheck struct {
CACertificates []string
rootsOnce sync.Once
roots *x509.CertPool
rootsErr error
}
func (c *CertificateCheck) check(peer *Peer) (bool, error) {
return certposture.AnyChainMatchesCAs(peer.Meta.Certificates, c.CACertificates, time.Now()), nil
if len(peer.Meta.Certificates) == 0 {
return false, nil
}
c.rootsOnce.Do(func() {
c.roots, c.rootsErr = certposture.ParseCAs(c.CACertificates)
})
if c.rootsErr != nil {
return false, c.rootsErr
}
return certposture.AnyChainMatchesPool(peer.Meta.Certificates, c.roots, time.Now()), nil
}