@@ -3,12 +3,13 @@ package actions
33import (
44 "context"
55 "fmt"
6+ "maps"
7+ "slices"
68
79 rhtasv1 "github.com/securesign/operator/api/v1"
810 "github.com/securesign/operator/internal/action"
911 fipsAction "github.com/securesign/operator/internal/action/fips"
1012 tufConstants "github.com/securesign/operator/internal/controller/tuf/constants"
11- "github.com/securesign/operator/internal/controller/tuf/trustroot"
1213 fipsutil "github.com/securesign/operator/internal/utils/fips"
1314 "sigs.k8s.io/controller-runtime/pkg/client"
1415)
@@ -25,22 +26,40 @@ func NewFIPSValidationAction() action.Action[*rhtasv1.Tuf] {
2526
2627func tufCryptoMaterial (ctx context.Context , i * rhtasv1.Tuf , c client.Client ) ([]fipsAction.CryptoRef , error ) {
2728 var refs []fipsAction.CryptoRef
28-
29- specHasRef := make (map [string ]bool )
30- for _ , key := range trustroot .ActiveKeys (i ) {
31- secretRef := trustroot .Binding (i , key ).SecretRef
32- if secretRef == nil {
33- continue
29+ asTrustRootBindings := func (bindings []rhtasv1.TrustRootBindingWithOIDC ) []rhtasv1.TrustRootBinding {
30+ b := make ([]rhtasv1.TrustRootBinding , len (bindings ))
31+ for i , binding := range bindings {
32+ b [i ] = binding .TrustRootBinding
3433 }
35- specHasRef [key .String ()] = true
36- if err := fipsAction .AppendSecretRef (ctx , c , i .Namespace , secretRef ,
37- fmt .Sprintf ("spec.%s[0].secretRef" , key ), fipsutil .ValidateCryptoMaterialPEM , & refs ); err != nil {
38- return nil , err
34+ return b
35+ }
36+
37+ components := map [string ][]rhtasv1.TrustRootBinding {
38+ "ctlog" : i .Spec .Ctlog ,
39+ "fulcio" : asTrustRootBindings (i .Spec .Fulcio ),
40+ "rekor" : i .Spec .Rekor ,
41+ "tsa" : i .Spec .Tsa ,
42+ }
43+ for component , array := range components {
44+ for _ , key := range array {
45+
46+ if key .SecretRef == nil {
47+ continue
48+ }
49+ if err := fipsAction .AppendSecretRef (ctx , c , i .Namespace , key .SecretRef ,
50+ fmt .Sprintf ("spec.%s[0].secretRef" , component ), fipsutil .ValidateCryptoMaterialPEM , & refs ); err != nil {
51+ return nil , err
52+ }
3953 }
4054 }
4155
4256 for _ , ks := range i .Status .Keys {
43- if ks .SecretRef == nil || specHasRef [ks .Name ] {
57+ if ks .SecretRef == nil {
58+ continue
59+ }
60+ if slices .ContainsFunc (slices .Concat (slices .Collect (maps .Values (components ))... ), func (key rhtasv1.TrustRootBinding ) bool {
61+ return key .SecretRef != nil && key .SecretRef .Name == ks .SecretRef .Name
62+ }) {
4463 continue
4564 }
4665 if err := fipsAction .AppendSecretRef (ctx , c , i .Namespace , ks .SecretRef ,
0 commit comments