@@ -306,10 +306,7 @@ func (h *FFDX) beforeConnect(ctx context.Context, w wsclient.WSClient) error {
306306 }
307307
308308 for _ , cb := range h .callbacks .handlers {
309- err := cb .DXConnect (h )
310- if err != nil {
311- log .L (ctx ).Errorf ("error handling DX connect event: %v" , err )
312- }
309+ cb .DXConnect (h )
313310 }
314311
315312 h .initialized = true
@@ -479,51 +476,56 @@ func (h *FFDX) CheckNodeIdentityStatus(ctx context.Context, node *core.Identity)
479476 if h .metrics != nil && h .metrics .IsMetricsEnabled () {
480477 h .metrics .NodeIdentityDXCertMismatch (node .Namespace , mismatchState )
481478 }
479+ log .L (ctx ).Debugf ("Identity status checked against DX node='%s' mismatch_state='%s'" , node .Name , mismatchState )
482480 }()
483481
484482 dxPeer , err := h .GetEndpointInfo (ctx , node .Name ) // should be the same as the local node
485483 if err != nil {
486484 return err
487485 }
488486
487+ dxPeerCert := dxPeer .GetString ("cert" )
489488 // if this occurs, it is either a misconfigured / broken DX or likely a DX that is compatible from an API perspective
490489 // but does not have the same peer info as the HTTPS mTLS DX
491- if dxPeer . GetString ( "cert" ) == "" {
492- log .L (ctx ).Warnf ("DX peer does not have a 'cert', DX plugin may be unsupported" )
490+ if dxPeerCert == "" {
491+ log .L (ctx ).Debugf ("DX peer does not have a 'cert', DX plugin may be unsupported" )
493492 return nil
494493 }
495494
496- if h .metrics != nil && h .metrics .IsMetricsEnabled () {
497- expiry , err := extractSoonestExpiryFromCertBundle (strings .ReplaceAll (dxPeer .GetString ("cert" ), `\n` , "\n " ))
498- if err == nil {
499- if expiry .Before (time .Now ()) {
500- log .L (ctx ).Warnf ("Certificate for node '%s' has expired" , node .Name )
501- }
495+ expiry , err := extractSoonestExpiryFromCertBundle (strings .ReplaceAll (dxPeerCert , `\n` , "\n " ))
496+ if err == nil {
497+ if expiry .Before (time .Now ()) {
498+ log .L (ctx ).Warnf ("DX certificate for node '%s' has expired" , node .Name )
499+ }
502500
501+ if h .metrics != nil && h .metrics .IsMetricsEnabled () {
503502 h .metrics .NodeIdentityDXCertExpiry (node .Namespace , expiry )
504- } else {
505- log .L (ctx ).Errorf ("Failed to find x509 cert within DX cert bundle node='%s' namespace='%s'" , node .Name , node .Namespace )
506503 }
504+ } else {
505+ log .L (ctx ).Errorf ("Failed to find x509 cert within DX cert bundle node='%s' namespace='%s'" , node .Name , node .Namespace )
507506 }
508507
509508 if node .Profile == nil {
510509 return i18n .NewError (ctx , coremsgs .MsgNodeNotProvidedForCheck )
511510 }
512511
513- if node .Profile .GetString ("cert" ) != "" {
512+ nodeCert := node .Profile .GetString ("cert" )
513+ if nodeCert != "" {
514514 mismatchState = metrics .NodeIdentityDXCertMismatchStatusHealthy
515- if dxPeer .GetString ("cert" ) != node .Profile .GetString ("cert" ) {
515+ if dxPeerCert != nodeCert {
516+ log .L (ctx ).Warnf ("DX certificate for node '%s' is out-of-sync with on-chain identity" , node .Name )
516517 mismatchState = metrics .NodeIdentityDXCertMismatchStatusMismatched
517518 }
518519 }
519520
520521 return nil
521522}
522523
523- // we assume the cert with the soonest expiry is the leaf cert, but even if its the CA,
524- // thats what will invalidate the leaf anyways, so really we only care about the soonest expiry
524+ // We assume the cert with the soonest expiry is the leaf cert, but even if its the CA,
525+ // that's what will invalidate the leaf anyways, so really we only care about the soonest expiry.
526+ // So we loop through the bundle finding the soonest expiry, not necessarily the leaf.
525527func extractSoonestExpiryFromCertBundle (certBundle string ) (time.Time , error ) {
526- var leafCert * x509.Certificate
528+ var expiringCert * x509.Certificate
527529 var block * pem.Block
528530 var rest = []byte (certBundle )
529531
@@ -537,16 +539,16 @@ func extractSoonestExpiryFromCertBundle(certBundle string) (time.Time, error) {
537539 if err != nil {
538540 return time.Time {}, fmt .Errorf ("failed to parse non-certificate within bundle: %v" , err )
539541 }
540- if leafCert == nil || cert .NotAfter .Before (leafCert .NotAfter ) {
541- leafCert = cert
542+ if expiringCert == nil || cert .NotAfter .Before (expiringCert .NotAfter ) {
543+ expiringCert = cert
542544 }
543545 }
544546
545- if leafCert == nil {
547+ if expiringCert == nil {
546548 return time.Time {}, errors .New ("no valid certificate found" )
547549 }
548550
549- return leafCert .NotAfter .UTC (), nil
551+ return expiringCert .NotAfter .UTC (), nil
550552}
551553
552554func (h * FFDX ) ackLoop () {
0 commit comments