@@ -86,6 +86,7 @@ type NFDConfig struct {
86
86
LeaderElection LeaderElectionConfig
87
87
NfdApiParallelism int
88
88
Klog klogutils.KlogConfigOpts
89
+ EnableSpiffe bool
89
90
}
90
91
91
92
// LeaderElectionConfig contains the configuration for leader election
@@ -105,6 +106,7 @@ type ConfigOverrideArgs struct {
105
106
NoPublish * bool
106
107
ResyncPeriod * utils.DurationVal
107
108
NfdApiParallelism * int
109
+ EnableSpiffe * bool
108
110
}
109
111
110
112
// Args holds command line arguments
@@ -211,6 +213,7 @@ func newDefaultConfig() *NFDConfig {
211
213
NfdApiParallelism : 10 ,
212
214
ResourceLabels : utils.StringSetVal {},
213
215
EnableTaints : false ,
216
+ EnableSpiffe : false ,
214
217
ResyncPeriod : utils.DurationVal {Duration : time .Duration (1 ) * time .Hour },
215
218
LeaderElection : LeaderElectionConfig {
216
219
LeaseDuration : utils.DurationVal {Duration : time .Duration (15 ) * time .Second },
@@ -764,19 +767,11 @@ func (m *nfdMaster) nfdAPIUpdateOneNode(nodeName string) error {
764
767
return objs [i ].Namespace < objs [j ].Namespace
765
768
})
766
769
767
- verifiedObjects := []* v1alpha1.NodeFeature {}
768
- // Verify nfd objects signature
769
- for _ , obj := range objs {
770
- isSignatureVerified , err := m .spiffeClient .VerifyDataSignature (obj .Spec , spiffe .GetSpiffeId (utils .NodeName ()), obj .Annotations ["signature" ])
770
+ // If spiffe is enabled, we should filter out the non verified NFD objects
771
+ if m .config .EnableSpiffe {
772
+ objs , err = m .getVerifiedNFDObjects (objs )
771
773
if err != nil {
772
- klog .ErrorS (err , "error while getting data signature" )
773
- return fmt .Errorf ("failed to sign CRD data using Spiffe: %w" , err )
774
- }
775
- if isSignatureVerified {
776
- klog .InfoS ("data verified" , "nfd name" , obj .Name )
777
- verifiedObjects = append (verifiedObjects , obj )
778
- } else {
779
- klog .InfoS ("data not verified" , "nfd name" , obj .Name )
774
+ return err
780
775
}
781
776
}
782
777
@@ -790,13 +785,13 @@ func (m *nfdMaster) nfdAPIUpdateOneNode(nodeName string) error {
790
785
791
786
annotations := Annotations {}
792
787
793
- if len (verifiedObjects ) > 0 {
788
+ if len (objs ) > 0 {
794
789
// Merge in features
795
790
//
796
791
// NOTE: changing the rule api to support handle multiple objects instead
797
792
// of merging would probably perform better with lot less data to copy.
798
- features = verifiedObjects [0 ].Spec .DeepCopy ()
799
- for _ , o := range verifiedObjects [1 :] {
793
+ features = objs [0 ].Spec .DeepCopy ()
794
+ for _ , o := range objs [1 :] {
800
795
o .Spec .MergeInto (features )
801
796
}
802
797
@@ -1261,6 +1256,9 @@ func (m *nfdMaster) configure(filepath string, overrides string) error {
1261
1256
if m .args .Overrides .NfdApiParallelism != nil {
1262
1257
c .NfdApiParallelism = * m .args .Overrides .NfdApiParallelism
1263
1258
}
1259
+ if m .args .Overrides .EnableSpiffe != nil {
1260
+ c .EnableSpiffe = * m .args .Overrides .EnableSpiffe
1261
+ }
1264
1262
1265
1263
if c .NfdApiParallelism <= 0 {
1266
1264
return fmt .Errorf ("the maximum number of concurrent labelers should be a non-zero positive number" )
@@ -1407,3 +1405,22 @@ func (m *nfdMaster) nfdAPIUpdateHandlerWithLeaderElection() {
1407
1405
1408
1406
leaderElector .Run (ctx )
1409
1407
}
1408
+
1409
+ func (m * nfdMaster ) getVerifiedNFDObjects (objs []* v1alpha1.NodeFeature ) ([]* v1alpha1.NodeFeature , error ) {
1410
+ verifiedObjects := []* v1alpha1.NodeFeature {}
1411
+
1412
+ for _ , obj := range objs {
1413
+ isSignatureVerified , err := m .spiffeClient .VerifyDataSignature (obj .Spec , spiffe .GetSpiffeId (utils .NodeName ()), obj .Annotations ["signature" ])
1414
+ if err != nil {
1415
+ return nil , fmt .Errorf ("failed to verify NodeFeature signature: %w" , err )
1416
+ }
1417
+
1418
+ if isSignatureVerified {
1419
+ klog .InfoS ("NodeFeature verified" , "NodeFeature name" , obj .Name )
1420
+ verifiedObjects = append (verifiedObjects , obj )
1421
+ } else {
1422
+ klog .InfoS ("NodeFeature not verified, skipping..." , "NodeFeature name" , obj .Name )
1423
+ }
1424
+ }
1425
+ return verifiedObjects , nil
1426
+ }
0 commit comments