From 9dc70841c789521cb13f6719753c0f8eb1da3a35 Mon Sep 17 00:00:00 2001 From: Jan Bouska Date: Wed, 2 Dec 2026 16:23:31 +0100 Subject: [PATCH] feat: update API --- api/v1/securesign_defaults.go | 22 +- api/v1/tuf_defaults.go | 57 +++ api/v1/tuf_types.go | 108 +++- api/v1/tuf_types_test.go | 12 +- api/v1/zz_generated.deepcopy.go | 110 +++- api/v1alpha1/conversion_roundtrip_test.go | 78 ++- api/v1alpha1/conversion_unit_test.go | 287 ++++++++++- api/v1alpha1/conversion_webhook_test.go | 34 +- api/v1alpha1/securesign_conversion.go | 38 +- api/v1alpha1/tuf_conversion.go | 168 ++++--- api/v1alpha1/zz_generated.conversion.go | 5 +- .../bases/rhtas.redhat.com_securesigns.yaml | 118 ++++- config/crd/bases/rhtas.redhat.com_tufs.yaml | 470 +++++++++++++++++- .../securesign/actions/ensure_tuf.go | 59 ++- .../securesign/actions/ensure_tuf_test.go | 52 ++ .../tuf/actions/resolve_keys_test.go | 111 +++-- internal/controller/tuf/trustroot/resolver.go | 18 +- .../controller/tuf/tuf_controller_test.go | 56 +-- test/e2e/install/namespaced_test.go | 4 +- test/e2e/install/provided_certs_test.go | 2 +- test/e2e/lifecycle/securesign_1855_test.go | 2 +- test/e2e/support/tas/tuf/tuf.go | 6 +- test/e2e/update/tsa_test.go | 2 +- 23 files changed, 1492 insertions(+), 327 deletions(-) create mode 100644 internal/controller/securesign/actions/ensure_tuf_test.go diff --git a/api/v1/securesign_defaults.go b/api/v1/securesign_defaults.go index 9a365a16a..feff02238 100644 --- a/api/v1/securesign_defaults.go +++ b/api/v1/securesign_defaults.go @@ -44,10 +44,22 @@ func (s *Securesign) SetDefaults() { if len(s.Spec.Tuf.Ctlog) == 0 { s.Spec.Tuf.Ctlog = []TrustRootBinding{{ServiceReference: ServiceReference{Ref: siblingRef}}} } - // Tsa is a tri-state pointer, with nil meaning TSA is excluded from the trust root - // entirely. Only populate a sibling ref when TimestampAuthority is actually - // configured, and only if the user hasn't already set an explicit override. - if s.Spec.TimestampAuthority != nil && (s.Spec.Tuf.Tsa == nil || len(*s.Spec.Tuf.Tsa) == 0) { - s.Spec.Tuf.Tsa = &[]TrustRootBinding{{ServiceReference: ServiceReference{Ref: siblingRef}}} + + if s.Spec.TimestampAuthority != nil && len(s.Spec.Tuf.Tsa) == 0 { + s.Spec.Tuf.Tsa = []TrustRootBinding{{ServiceReference: ServiceReference{Ref: siblingRef}}} + } + + // set defaults on tuf bindings - the TargetName compute date so it have to be defaulted right away + for i := range s.Spec.Tuf.Rekor { + s.Spec.Tuf.Rekor[i].SetDefaults(TufKeyRekor) + } + for i := range s.Spec.Tuf.Fulcio { + s.Spec.Tuf.Fulcio[i].SetDefaults(TufKeyFulcio) + } + for i := range s.Spec.Tuf.Ctlog { + s.Spec.Tuf.Ctlog[i].SetDefaults(TufKeyCTFE) + } + for i := range s.Spec.Tuf.Tsa { + s.Spec.Tuf.Tsa[i].SetDefaults(TufKeyTSA) } } diff --git a/api/v1/tuf_defaults.go b/api/v1/tuf_defaults.go index 92c78086e..427b5f9e7 100644 --- a/api/v1/tuf_defaults.go +++ b/api/v1/tuf_defaults.go @@ -1,6 +1,9 @@ package v1 import ( + "strings" + "time" + k8sresource "k8s.io/apimachinery/pkg/api/resource" "k8s.io/utils/ptr" ) @@ -17,4 +20,58 @@ func (s *TufSpec) SetDefaults() { s.Pvc.Size = ptr.To(k8sresource.MustParse("100Mi")) } s.Pvc.SetDefaults() + + for i := range s.Ctlog { + s.Ctlog[i].SetDefaults(TufKeyCTFE) + } + for i := range s.Fulcio { + s.Fulcio[i].SetDefaults(TufKeyFulcio) + } + for i := range s.Rekor { + s.Rekor[i].SetDefaults(TufKeyRekor) + } + + for i := range s.Tsa { + s.Tsa[i].SetDefaults(TufKeyTSA) + } +} + +func (s *TrustRootBinding) SetDefaults(componentKey string) { + injectSuffix := func(name, suffix string) string { + i := strings.LastIndex(name, ".") + if i == -1 { + return name + "-" + suffix + } + return name[:i] + "-" + suffix + name[i:] + } + switch { + case s.TargetName != "": + return + case s.Ref != nil && s.Ref.Name != "": + s.TargetName = injectSuffix(componentKey, s.Ref.Name) + if s.ValidFor != nil && s.ValidFor.Start != nil { + s.TargetName = injectSuffix(s.TargetName, s.ValidFor.Start.Format(time.DateOnly)) + } + default: + if s.ValidFor != nil && s.ValidFor.Start != nil { + s.TargetName = injectSuffix(componentKey, s.ValidFor.Start.Format(time.DateOnly)) + } else { + s.TargetName = componentKey + } + } +} + +func (c *Components) SetDefaults() { + for i := range c.Ctlog { + c.Ctlog[i].SetDefaults(TufKeyCTFE) + } + for i := range c.Fulcio { + c.Fulcio[i].SetDefaults(TufKeyFulcio) + } + for i := range c.Rekor { + c.Rekor[i].SetDefaults(TufKeyRekor) + } + for i := range c.Tsa { + c.Tsa[i].SetDefaults(TufKeyTSA) + } } diff --git a/api/v1/tuf_types.go b/api/v1/tuf_types.go index ded06584e..88c8377f0 100644 --- a/api/v1/tuf_types.go +++ b/api/v1/tuf_types.go @@ -48,38 +48,28 @@ type TufSpec struct { Pvc Pvc `json:"pvc,omitempty"` // Ctlog service and trust material binding. // +optional - // At most one entry is allowed today; this ceiling is deliberate and temporary, - // pending future multi-instance support. - // +kubebuilder:validation:MaxItems:=1 + // +kubebuilder:validation:MaxItems:=64 // +listType=atomic // +kubebuilder:validation:XValidation:rule="self.all(x, !has(x.url) || size(x.url) == 0 || x.url.matches('^([a-zA-Z][a-zA-Z0-9+.-]*://[^/]+/.+|//[^/]*/.+)$'))",message="url must follow the pattern scheme://host[:port]/path or //[:port]/path" - Ctlog []TrustRootBinding `json:"ctlog,omitempty"` //nolint:kubeapilinter // arrayofstruct: empty struct means autoload + Ctlog []TrustRootBinding `json:"ctlog,omitempty"` //nolint:kubeapilinter // arrayofstruct is API hygiene; targetName cannot be required yet (crdify) // Fulcio service and trust material binding. // +optional - // At most one entry is allowed today; this ceiling is deliberate and temporary, - // pending future multi-instance support. - // +kubebuilder:validation:MaxItems:=1 + // +kubebuilder:validation:MaxItems:=64 // +listType=atomic // +kubebuilder:validation:XValidation:rule="self.all(x, !has(x.url) || size(x.url) == 0 || x.url.matches('^([a-zA-Z][a-zA-Z0-9+.-]*://[^/].*|//.+)$'))",message="url must follow the pattern scheme://host[:port][/path] or //[:port][/path]" - Fulcio []TrustRootBindingWithOIDC `json:"fulcio,omitempty"` //nolint:kubeapilinter // arrayofstruct: empty struct means autoload + Fulcio []TrustRootBindingWithOIDC `json:"fulcio,omitempty"` //nolint:kubeapilinter // arrayofstruct is API hygiene; targetName cannot be required yet (crdify) // Rekor service and trust material binding. // +optional - // At most one entry is allowed today; this ceiling is deliberate and temporary, - // pending future multi-instance support. - // +kubebuilder:validation:MaxItems:=1 + // +kubebuilder:validation:MaxItems:=64 // +listType=atomic // +kubebuilder:validation:XValidation:rule="self.all(x, !has(x.url) || size(x.url) == 0 || x.url.matches('^([a-zA-Z][a-zA-Z0-9+.-]*://[^/].*|//.+)$'))",message="url must follow the pattern scheme://host[:port][/path] or //[:port][/path]" - Rekor []TrustRootBinding `json:"rekor,omitempty"` //nolint:kubeapilinter // arrayofstruct: empty struct means autoload - // TSA service and trust material binding. A nil value excludes TSA from the - // trust root entirely; a non-nil value (even an empty list, meaning - // autodiscover) includes it. - // +optional - // At most one entry is allowed today; this ceiling is deliberate and temporary, - // pending future multi-instance support. - // +kubebuilder:validation:MaxItems:=1 + Rekor []TrustRootBinding `json:"rekor,omitempty"` //nolint:kubeapilinter // arrayofstruct is API hygiene; targetName cannot be required yet (crdify) + // TSA service and trust material binding. + // +optional + // +kubebuilder:validation:MaxItems:=64 // +listType=atomic // +kubebuilder:validation:XValidation:rule="self.all(x, !has(x.url) || size(x.url) == 0 || x.url.matches('^([a-zA-Z][a-zA-Z0-9+.-]*://[^/].*|//.+)$'))",message="url must follow the pattern scheme://host[:port][/path] or //[:port][/path]" - Tsa *[]TrustRootBinding `json:"tsa,omitempty"` + Tsa []TrustRootBinding `json:"tsa,omitempty"` //nolint:kubeapilinter // Keep targetName optional for existing TSA bindings. // ConfigMap with additional bundle of trusted CA // +optional @@ -97,6 +87,23 @@ type TrustRootBinding struct { ServiceReference `json:",inline"` // +optional SecretRef *SecretKeySelector `json:"secretRef,omitempty"` + // ValidFor is the validity interval of this binding's trust material. + // +optional + ValidFor *ValidFor `json:"validFor,omitempty"` + // TargetName is the name of this binding's TUF target. + // Optional for compatibility with pre-existing bindings; the defaulting + // webhook fills the component default when unset. + // +optional + TargetName string `json:"targetName,omitempty"` +} + +type ValidFor struct { + // RFC3339 timestamp when this binding's trust material becomes valid. Defaults to the time when the binding is added to the trust root. + // +optional + Start *metav1.Time `json:"start,omitempty"` + // RFC3339 timestamp when this binding's trust material expires. + // +optional + End *metav1.Time `json:"end,omitempty"` } // TrustRootBindingWithOIDC is a TrustRootBinding for Fulcio, which additionally @@ -111,6 +118,42 @@ type TrustRootBindingWithOIDC struct { OIDCIssuers []string `json:"oidcIssuers,omitempty"` } +// Components holds a snapshot of the component bindings used for publication. +type Components struct { + // +optional + // +kubebuilder:validation:MaxItems:=64 + // +listType=atomic + Ctlog []TrustRootBinding `json:"ctlog,omitempty"` //nolint:kubeapilinter // arrayofstruct is API hygiene; targetName cannot be required yet (crdify) + // +optional + // +kubebuilder:validation:MaxItems:=64 + // +listType=atomic + Fulcio []TrustRootBindingWithOIDC `json:"fulcio,omitempty"` //nolint:kubeapilinter // arrayofstruct is API hygiene; targetName cannot be required yet (crdify) + // +optional + // +kubebuilder:validation:MaxItems:=64 + // +listType=atomic + Rekor []TrustRootBinding `json:"rekor,omitempty"` //nolint:kubeapilinter // arrayofstruct is API hygiene; targetName cannot be required yet (crdify) + // +optional + // +kubebuilder:validation:MaxItems:=64 + // +listType=atomic + Tsa []TrustRootBinding `json:"tsa,omitempty"` //nolint:kubeapilinter // arrayofstruct is API hygiene; targetName cannot be required yet (crdify) +} + +// TrustRootStatus records the last successful trust root publication. +type TrustRootStatus struct { + // PublishedTargetsVersion is the targets.json version recorded by the + // last successful publication. Older results are ignored. + // +optional + PublishedTargetsVersion int64 `json:"publishedTargetsVersion,omitempty"` + + // Published is a deep copy of the component bindings included in the last successful publication. + // +optional + Published *Components `json:"published,omitempty"` + + // LastPublishTime is the time of the last successful trust-material update. + // +optional + LastPublishTime *metav1.Time `json:"lastPublishTime,omitempty"` +} + type TufKeyStatus struct { // +required Name string `json:"name"` @@ -126,6 +169,11 @@ type TufStatus struct { // +patchMergeKey=type // +optional Conditions []metav1.Condition `json:"conditions,omitempty" patchStrategy:"merge" patchMergeKey:"type" protobuf:"bytes,1,rep,name=conditions"` + // TrustRoot records the last successful trust root publication. + // +optional + TrustRoot *TrustRootStatus `json:"trustRoot,omitempty"` + // +deprecated: use TrustRoot instead + // Keys holds the Secret references mounted by the repository init job. // +listType=map // +listMapKey=name Keys []TufKeyStatus `json:"keys,omitempty"` //nolint:kubeapilinter // arrayofstruct: status fields are operator-managed @@ -189,3 +237,23 @@ func (i *Tuf) GetTrustedCA() *LocalObjectReference { func (i *Tuf) GetServiceURL() string { return i.Status.URL } + +func (b TrustRootBinding) GetTrustRootBinding() TrustRootBinding { + return b +} + +func (b TrustRootBinding) GetSecretRef() *SecretKeySelector { + return b.SecretRef +} + +func (b TrustRootBinding) GetValidFor() *ValidFor { + return b.ValidFor +} + +func (b TrustRootBinding) GetName() string { + return b.TargetName +} + +func (b TrustRootBindingWithOIDC) GetOIDCIssuers() []string { + return b.OIDCIssuers +} diff --git a/api/v1/tuf_types_test.go b/api/v1/tuf_types_test.go index bfbcfa20f..09279aa62 100644 --- a/api/v1/tuf_types_test.go +++ b/api/v1/tuf_types_test.go @@ -109,14 +109,6 @@ var _ = Describe("TUF", func() { To(MatchError(ContainSubstring("should be less than or equal to 65535"))) }) - It("more than one ctlog binding is rejected", func() { - invalidObject := generateMinimalTuf("too-many-ctlog") - invalidObject.Spec.Ctlog = []TrustRootBinding{{}, {}} - Expect(apierrors.IsInvalid(k8sClient.Create(context.Background(), invalidObject))).To(BeTrue()) - Expect(k8sClient.Create(context.Background(), invalidObject)). - To(MatchError(ContainSubstring("Too many"))) - }) - When("service URL validation", func() { It("rejects ctlog without scheme", func() { obj := generateMinimalTuf("ctlog-no-scheme") @@ -170,7 +162,7 @@ var _ = Describe("TUF", func() { It("rejects tsa without scheme", func() { obj := generateMinimalTuf("tsa-no-scheme") - obj.Spec.Tsa = &[]TrustRootBinding{{ServiceReference: ServiceReference{URL: "tsa:3000"}}} + obj.Spec.Tsa = []TrustRootBinding{{ServiceReference: ServiceReference{URL: "tsa:3000"}}} Expect(apierrors.IsInvalid(k8sClient.Create(context.Background(), obj))).To(BeTrue()) Expect(k8sClient.Create(context.Background(), obj)). To(MatchError(ContainSubstring("url must follow the pattern scheme://host[:port]"))) @@ -178,7 +170,7 @@ var _ = Describe("TUF", func() { It("accepts tsa with scheme", func() { obj := generateMinimalTuf("tsa-valid") - obj.Spec.Tsa = &[]TrustRootBinding{{ServiceReference: ServiceReference{URL: "http://tsa:3000"}}} + obj.Spec.Tsa = []TrustRootBinding{{ServiceReference: ServiceReference{URL: "http://tsa:3000"}}} Expect(k8sClient.Create(context.Background(), obj)).To(Succeed()) }) diff --git a/api/v1/zz_generated.deepcopy.go b/api/v1/zz_generated.deepcopy.go index 4e7f71b1c..09003998b 100644 --- a/api/v1/zz_generated.deepcopy.go +++ b/api/v1/zz_generated.deepcopy.go @@ -551,6 +551,49 @@ func (in *CertificateChain) DeepCopy() *CertificateChain { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Components) DeepCopyInto(out *Components) { + *out = *in + if in.Ctlog != nil { + in, out := &in.Ctlog, &out.Ctlog + *out = make([]TrustRootBinding, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Fulcio != nil { + in, out := &in.Fulcio, &out.Fulcio + *out = make([]TrustRootBindingWithOIDC, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Rekor != nil { + in, out := &in.Rekor, &out.Rekor + *out = make([]TrustRootBinding, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Tsa != nil { + in, out := &in.Tsa, &out.Tsa + *out = make([]TrustRootBinding, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Components. +func (in *Components) DeepCopy() *Components { + if in == nil { + return nil + } + out := new(Components) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Console) DeepCopyInto(out *Console) { *out = *in @@ -2505,6 +2548,11 @@ func (in *TrustRootBinding) DeepCopyInto(out *TrustRootBinding) { *out = new(SecretKeySelector) **out = **in } + if in.ValidFor != nil { + in, out := &in.ValidFor, &out.ValidFor + *out = new(ValidFor) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TrustRootBinding. @@ -2538,6 +2586,30 @@ func (in *TrustRootBindingWithOIDC) DeepCopy() *TrustRootBindingWithOIDC { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *TrustRootStatus) DeepCopyInto(out *TrustRootStatus) { + *out = *in + if in.Published != nil { + in, out := &in.Published, &out.Published + *out = new(Components) + (*in).DeepCopyInto(*out) + } + if in.LastPublishTime != nil { + in, out := &in.LastPublishTime, &out.LastPublishTime + *out = (*in).DeepCopy() + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TrustRootStatus. +func (in *TrustRootStatus) DeepCopy() *TrustRootStatus { + if in == nil { + return nil + } + out := new(TrustRootStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TsaCertificateAuthority) DeepCopyInto(out *TsaCertificateAuthority) { *out = *in @@ -2682,13 +2754,9 @@ func (in *TufSpec) DeepCopyInto(out *TufSpec) { } if in.Tsa != nil { in, out := &in.Tsa, &out.Tsa - *out = new([]TrustRootBinding) - if **in != nil { - in, out := *in, *out - *out = make([]TrustRootBinding, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } + *out = make([]TrustRootBinding, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) } } if in.TrustedCA != nil { @@ -2719,6 +2787,11 @@ func (in *TufStatus) DeepCopyInto(out *TufStatus) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.TrustRoot != nil { + in, out := &in.TrustRoot, &out.TrustRoot + *out = new(TrustRootStatus) + (*in).DeepCopyInto(*out) + } if in.Keys != nil { in, out := &in.Keys, &out.Keys *out = make([]TufKeyStatus, len(*in)) @@ -2737,3 +2810,26 @@ func (in *TufStatus) DeepCopy() *TufStatus { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ValidFor) DeepCopyInto(out *ValidFor) { + *out = *in + if in.Start != nil { + in, out := &in.Start, &out.Start + *out = (*in).DeepCopy() + } + if in.End != nil { + in, out := &in.End, &out.End + *out = (*in).DeepCopy() + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ValidFor. +func (in *ValidFor) DeepCopy() *ValidFor { + if in == nil { + return nil + } + out := new(ValidFor) + in.DeepCopyInto(out) + return out +} diff --git a/api/v1alpha1/conversion_roundtrip_test.go b/api/v1alpha1/conversion_roundtrip_test.go index f05a9cf17..97a30b36e 100644 --- a/api/v1alpha1/conversion_roundtrip_test.go +++ b/api/v1alpha1/conversion_roundtrip_test.go @@ -20,6 +20,7 @@ package v1alpha1 import ( "testing" + "time" rhtasv1 "github.com/securesign/operator/api/v1" utilconversion "github.com/securesign/operator/internal/conversion" @@ -27,6 +28,7 @@ import ( tfuzzer "github.com/securesign/operator/internal/testing/fuzzer" core "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/apitesting/fuzzer" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" runtimeserializer "k8s.io/apimachinery/pkg/runtime/serializer" "k8s.io/utils/ptr" @@ -97,16 +99,39 @@ func randServiceReference(c randfill.Continue, urlFunc func(c randfill.Continue, } } -// randTrustRootBinding wraps randServiceReference, adding a random optional SecretRef. -func randTrustRootBinding(c randfill.Continue, urlFunc func(c randfill.Continue, withPort bool) string) rhtasv1.TrustRootBinding { - b := rhtasv1.TrustRootBinding{ServiceReference: randServiceReference(c, urlFunc)} - if c.Bool() { +// randTrustRootBinding wraps randServiceReference with optional SecretRef/ValidFor. +// SecretRef is mutually exclusive with Ref (TrustRootBinding XValidation). +func randTrustRootBinding(c randfill.Continue, urlFunc func(c randfill.Continue, withPort bool) string, targetName string) rhtasv1.TrustRootBinding { + b := rhtasv1.TrustRootBinding{ + ServiceReference: randServiceReference(c, urlFunc), + TargetName: targetName, + } + if b.Ref == nil { b.SecretRef = &rhtasv1.SecretKeySelector{} c.FillNoCustom(b.SecretRef) } + if c.Bool() { + start := metav1.NewTime(time.Date(2025, time.January, 1+c.Intn(28), 0, 0, 0, 0, time.UTC)) + b.ValidFor = &rhtasv1.ValidFor{Start: &start} + if c.Bool() { + end := metav1.NewTime(start.Add(24 * time.Hour)) + b.ValidFor.End = &end + } + } return b } +// randTrustRootBindings returns a legacy-named binding plus, optionally, a second +// custom-named binding. Convert serializes only [0] into v1alpha1; extras round-trip +// via annotation and are restored by TargetName match / append. +func randTrustRootBindings(c randfill.Continue, urlFunc func(c randfill.Continue, withPort bool) string, defaultTarget string) []rhtasv1.TrustRootBinding { + bindings := []rhtasv1.TrustRootBinding{randTrustRootBinding(c, urlFunc, defaultTarget)} + if c.Bool() { + bindings = append(bindings, randTrustRootBinding(c, urlFunc, "custom-"+defaultTarget)) + } + return bindings +} + func trillianServiceFuzzerFuncs(_ runtimeserializer.CodecFactory) []interface{} { return []interface{}{ func(s *TrillianSpec, c randfill.Continue) { @@ -249,14 +274,18 @@ func securesignFuzzerFuncs(_ runtimeserializer.CodecFactory) []interface{} { s.Spec.Rekor.Trillian = randServiceReference(c, tfuzzer.GRPCURL) s.Spec.Fulcio.Ctlog = randServiceReference(c, httpURLWithPath) - s.Spec.Tuf.Ctlog = []rhtasv1.TrustRootBinding{randTrustRootBinding(c, httpURLWithPath)} - s.Spec.Tuf.Rekor = []rhtasv1.TrustRootBinding{randTrustRootBinding(c, httpURLWithPath)} - s.Spec.Tuf.Fulcio = []rhtasv1.TrustRootBindingWithOIDC{{ - TrustRootBinding: randTrustRootBinding(c, httpURLWithPath), - OIDCIssuers: []string{tfuzzer.HTTPURL(c, c.Bool(), c.Bool())}, - }} + s.Spec.Tuf.Ctlog = randTrustRootBindings(c, httpURLWithPath, rhtasv1.TufKeyCTFE) + s.Spec.Tuf.Rekor = randTrustRootBindings(c, httpURLWithPath, rhtasv1.TufKeyRekor) + fulcioBindings := randTrustRootBindings(c, httpURLWithPath, rhtasv1.TufKeyFulcio) + s.Spec.Tuf.Fulcio = make([]rhtasv1.TrustRootBindingWithOIDC, len(fulcioBindings)) + for i, b := range fulcioBindings { + s.Spec.Tuf.Fulcio[i] = rhtasv1.TrustRootBindingWithOIDC{ + TrustRootBinding: b, + OIDCIssuers: []string{tfuzzer.HTTPURL(c, c.Bool(), c.Bool())}, + } + } if c.Bool() { - s.Spec.Tuf.Tsa = &[]rhtasv1.TrustRootBinding{randTrustRootBinding(c, httpURLWithPath)} + s.Spec.Tuf.Tsa = randTrustRootBindings(c, httpURLWithPath, rhtasv1.TufKeyTSA) } else { s.Spec.Tuf.Tsa = nil } @@ -267,6 +296,15 @@ func securesignFuzzerFuncs(_ runtimeserializer.CodecFactory) []interface{} { s.Spec.Ctlog.PrivateKeyPasswordRef = nil // ServerConfigRef is deprecated in favor of spec.sharding; it has no roundtrip path. s.Spec.Ctlog.ServerConfigRef = nil + // Generated TUF endpoints round-trip when paired with explicit trust material. + // TestLegacySecuresignTufBindings covers conversion to sibling refs. + for i := range s.Spec.Tuf.Keys { + key := &s.Spec.Tuf.Keys[i] + if key.SecretRef == nil { + key.SecretRef = &SecretKeySelector{} + c.FillNoCustom(key.SecretRef) + } + } }, } } @@ -358,14 +396,18 @@ func tufFuzzerFuncs(_ runtimeserializer.CodecFactory) []interface{} { }, func(s *rhtasv1.Tuf, c randfill.Continue) { c.FillNoCustom(s) - s.Spec.Ctlog = []rhtasv1.TrustRootBinding{randTrustRootBinding(c, httpURLWithPath)} - s.Spec.Rekor = []rhtasv1.TrustRootBinding{randTrustRootBinding(c, httpURLWithPath)} - s.Spec.Fulcio = []rhtasv1.TrustRootBindingWithOIDC{{ - TrustRootBinding: randTrustRootBinding(c, httpURLWithPath), - OIDCIssuers: []string{tfuzzer.HTTPURL(c, c.Bool(), c.Bool())}, - }} + s.Spec.Ctlog = randTrustRootBindings(c, httpURLWithPath, rhtasv1.TufKeyCTFE) + s.Spec.Rekor = randTrustRootBindings(c, httpURLWithPath, rhtasv1.TufKeyRekor) + fulcioBindings := randTrustRootBindings(c, httpURLWithPath, rhtasv1.TufKeyFulcio) + s.Spec.Fulcio = make([]rhtasv1.TrustRootBindingWithOIDC, len(fulcioBindings)) + for i, b := range fulcioBindings { + s.Spec.Fulcio[i] = rhtasv1.TrustRootBindingWithOIDC{ + TrustRootBinding: b, + OIDCIssuers: []string{tfuzzer.HTTPURL(c, c.Bool(), c.Bool())}, + } + } if c.Bool() { - s.Spec.Tsa = &[]rhtasv1.TrustRootBinding{randTrustRootBinding(c, httpURLWithPath)} + s.Spec.Tsa = randTrustRootBindings(c, httpURLWithPath, rhtasv1.TufKeyTSA) } else { s.Spec.Tsa = nil } diff --git a/api/v1alpha1/conversion_unit_test.go b/api/v1alpha1/conversion_unit_test.go index 40916c9d5..9744de2a2 100644 --- a/api/v1alpha1/conversion_unit_test.go +++ b/api/v1alpha1/conversion_unit_test.go @@ -17,7 +17,9 @@ limitations under the License. package v1alpha1 import ( + "slices" "testing" + "time" "github.com/google/go-cmp/cmp" rhtasv1 "github.com/securesign/operator/api/v1" @@ -53,6 +55,7 @@ func TestSecuresignConversionUnit(t *testing.T) { { name: "empty spec round-trips", hub: func() *rhtasv1.Securesign { + tufService := rhtasv1.ServiceReference{Ref: &rhtasv1.ServiceReferenceRef{Name: "test", Namespace: "default"}} // Enabled fields must be explicitly set: v1alpha1 uses bare bool, so // nil *bool → false → &false after roundtrip. In production the CRD // defaulter guarantees these are never nil. @@ -82,9 +85,9 @@ func TestSecuresignConversionUnit(t *testing.T) { }, Tuf: rhtasv1.TufSpec{ Ingress: rhtasv1.Ingress{Enabled: ptr.To(false)}, - Ctlog: []rhtasv1.TrustRootBinding{{}}, - Rekor: []rhtasv1.TrustRootBinding{{}}, - Fulcio: []rhtasv1.TrustRootBindingWithOIDC{{}}, + Ctlog: []rhtasv1.TrustRootBinding{{ServiceReference: tufService, TargetName: rhtasv1.TufKeyCTFE}}, + Rekor: []rhtasv1.TrustRootBinding{{ServiceReference: tufService, TargetName: rhtasv1.TufKeyRekor}}, + Fulcio: []rhtasv1.TrustRootBindingWithOIDC{{TrustRootBinding: rhtasv1.TrustRootBinding{ServiceReference: tufService, TargetName: rhtasv1.TufKeyFulcio}}}, }, }, } @@ -107,6 +110,7 @@ func TestSecuresignConversionUnit(t *testing.T) { { name: "full spec with all components", hub: func() *rhtasv1.Securesign { + tufService := rhtasv1.ServiceReference{Ref: &rhtasv1.ServiceReferenceRef{Name: "test", Namespace: "ns"}} return &rhtasv1.Securesign{ ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "ns"}, Spec: rhtasv1.SecuresignSpec{ @@ -150,9 +154,10 @@ func TestSecuresignConversionUnit(t *testing.T) { }, Tuf: rhtasv1.TufSpec{ Ingress: rhtasv1.Ingress{Enabled: ptr.To(false)}, - Ctlog: []rhtasv1.TrustRootBinding{{ServiceReference: rhtasv1.ServiceReference{URL: "///trusted-artifact-signer"}}}, - Rekor: []rhtasv1.TrustRootBinding{{}}, - Fulcio: []rhtasv1.TrustRootBindingWithOIDC{{}}, + Ctlog: []rhtasv1.TrustRootBinding{{ServiceReference: tufService, TargetName: rhtasv1.TufKeyCTFE}}, + Rekor: []rhtasv1.TrustRootBinding{{ServiceReference: tufService, TargetName: rhtasv1.TufKeyRekor}}, + Fulcio: []rhtasv1.TrustRootBindingWithOIDC{{TrustRootBinding: rhtasv1.TrustRootBinding{ServiceReference: tufService, TargetName: rhtasv1.TufKeyFulcio}}}, + Tsa: []rhtasv1.TrustRootBinding{{ServiceReference: tufService, TargetName: rhtasv1.TufKeyTSA}}, }, TimestampAuthority: &rhtasv1.TimestampAuthoritySpec{ Signer: rhtasv1.TimestampAuthoritySigner{ @@ -194,11 +199,11 @@ func TestSecuresignConversionUnit(t *testing.T) { TreeID: ptr.To[int64](67890), }, Tuf: TufSpec{ - Ctlog: CtlogService{Prefix: "trusted-artifact-signer"}, Keys: []TufKey{ {Name: "rekor.pub"}, {Name: "ctfe.pub"}, {Name: "fulcio_v1.crt.pem"}, + {Name: rhtasv1.TufKeyTSA}, }, }, TimestampAuthority: &TimestampAuthoritySpec{ @@ -249,6 +254,159 @@ func TestSecuresignConversionUnit(t *testing.T) { } } +func TestLegacySecuresignTufBindings(t *testing.T) { + legacy := &Securesign{ + ObjectMeta: metav1.ObjectMeta{Name: "test", Namespace: "upgrade"}, + Spec: SecuresignSpec{ + Tuf: TufSpec{ + Ctlog: CtlogService{Prefix: "trusted-artifact-signer"}, + Keys: []TufKey{ + {Name: rhtasv1.TufKeyRekor}, + {Name: rhtasv1.TufKeyCTFE}, + {Name: rhtasv1.TufKeyFulcio}, + {Name: rhtasv1.TufKeyTSA}, + }, + }, + TimestampAuthority: &TimestampAuthoritySpec{}, + }, + } + sibling := rhtasv1.ServiceReference{Ref: &rhtasv1.ServiceReferenceRef{Name: legacy.Name, Namespace: legacy.Namespace}} + want := rhtasv1.Components{ + Rekor: []rhtasv1.TrustRootBinding{{ServiceReference: sibling, TargetName: rhtasv1.TufKeyRekor}}, + Ctlog: []rhtasv1.TrustRootBinding{{ServiceReference: sibling, TargetName: rhtasv1.TufKeyCTFE}}, + Fulcio: []rhtasv1.TrustRootBindingWithOIDC{{TrustRootBinding: rhtasv1.TrustRootBinding{ + ServiceReference: sibling, TargetName: rhtasv1.TufKeyFulcio, + }}}, + Tsa: []rhtasv1.TrustRootBinding{{ServiceReference: sibling, TargetName: rhtasv1.TufKeyTSA}}, + } + + hub := &rhtasv1.Securesign{} + if err := legacy.ConvertTo(hub); err != nil { + t.Fatalf("ConvertTo failed: %v", err) + } + spec := hub.Spec.Tuf + got := rhtasv1.Components{Rekor: spec.Rekor, Ctlog: spec.Ctlog, Fulcio: spec.Fulcio, Tsa: spec.Tsa} + if diff := cmp.Diff(want, got); diff != "" { + t.Errorf("legacy TUF bindings mismatch (-want +got):\n%s", diff) + } + + legacy.Spec.Tuf.Rekor.Address = "https://rekor.example.com" + legacy.Spec.Tuf.Keys = []TufKey{ + { + Name: rhtasv1.TufKeyRekor, + SecretRef: &SecretKeySelector{LocalObjectReference: LocalObjectReference{Name: "custom-keys"}, Key: "public"}, + }, + {Name: rhtasv1.TufKeyCTFE}, + {Name: rhtasv1.TufKeyFulcio}, + } + legacy.Spec.Tuf.Ctlog.Prefix = "custom-entry" + legacy.Spec.Tuf.Fulcio.Address = "https://fulcio.example.com" + hub = &rhtasv1.Securesign{} + if err := legacy.ConvertTo(hub); err != nil { + t.Fatalf("ConvertTo failed: %v", err) + } + want.Rekor[0] = rhtasv1.TrustRootBinding{ + ServiceReference: rhtasv1.ServiceReference{URL: "https://rekor.example.com"}, + SecretRef: &rhtasv1.SecretKeySelector{LocalObjectReference: rhtasv1.LocalObjectReference{Name: "custom-keys"}, Key: "public"}, + TargetName: rhtasv1.TufKeyRekor, + } + want.Tsa = nil + spec = hub.Spec.Tuf + got = rhtasv1.Components{Rekor: spec.Rekor, Ctlog: spec.Ctlog, Fulcio: spec.Fulcio, Tsa: spec.Tsa} + if diff := cmp.Diff(want, got); diff != "" { + t.Errorf("legacy TUF endpoint overrides mismatch (-want +got):\n%s", diff) + } + + roundTripped := &Securesign{} + if err := roundTripped.ConvertFrom(hub); err != nil { + t.Fatalf("ConvertFrom failed: %v", err) + } + if diff := cmp.Diff(legacy.Spec.Tuf.Keys, roundTripped.Spec.Tuf.Keys); diff != "" { + t.Errorf("legacy TUF key selection changed on round-trip (-want +got):\n%s", diff) + } +} + +func TestLegacyTufKeyRemoval(t *testing.T) { + binding := func(target, service string) rhtasv1.TrustRootBinding { + return rhtasv1.TrustRootBinding{ + TargetName: target, + ServiceReference: rhtasv1.ServiceReference{ + Ref: &rhtasv1.ServiceReferenceRef{Name: service, Namespace: "default"}, + }, + } + } + spec := rhtasv1.TufSpec{ + Rekor: []rhtasv1.TrustRootBinding{binding(rhtasv1.TufKeyRekor, "rekor"), binding("custom-rekor.pub", "custom-rekor")}, + Ctlog: []rhtasv1.TrustRootBinding{binding(rhtasv1.TufKeyCTFE, "ctlog"), binding("custom-ctfe.pub", "custom-ctlog")}, + Fulcio: []rhtasv1.TrustRootBindingWithOIDC{ + {TrustRootBinding: binding(rhtasv1.TufKeyFulcio, "fulcio")}, + {TrustRootBinding: binding("custom-fulcio.pem", "custom-fulcio"), OIDCIssuers: []string{"https://issuer.example.com"}}, + }, + Tsa: []rhtasv1.TrustRootBinding{binding(rhtasv1.TufKeyTSA, "tsa"), binding("custom-tsa.pem", "custom-tsa")}, + } + bindings := func(spec rhtasv1.TufSpec) rhtasv1.Components { + return rhtasv1.Components{Rekor: spec.Rekor, Ctlog: spec.Ctlog, Fulcio: spec.Fulcio, Tsa: spec.Tsa} + } + tests := []struct { + key string + remove func(*rhtasv1.Components) + }{ + {key: rhtasv1.TufKeyRekor, remove: func(c *rhtasv1.Components) { c.Rekor = c.Rekor[1:] }}, + {key: rhtasv1.TufKeyCTFE, remove: func(c *rhtasv1.Components) { c.Ctlog = c.Ctlog[1:] }}, + {key: rhtasv1.TufKeyFulcio, remove: func(c *rhtasv1.Components) { c.Fulcio = c.Fulcio[1:] }}, + {key: rhtasv1.TufKeyTSA, remove: func(c *rhtasv1.Components) { c.Tsa = c.Tsa[1:] }}, + } + for _, tt := range tests { + t.Run(tt.key, func(t *testing.T) { + want := bindings(spec) + tt.remove(&want) + removeKey := func(t *testing.T, spec *TufSpec) { + t.Helper() + index := slices.IndexFunc(spec.Keys, func(k TufKey) bool { return k.Name == tt.key }) + if index < 0 { + t.Fatalf("expected legacy key %q before deletion", tt.key) + } + spec.Keys = slices.Delete(spec.Keys, index, index+1) + } + checkBindings := func(t *testing.T, got rhtasv1.TufSpec) { + t.Helper() + if diff := cmp.Diff(want, bindings(got)); diff != "" { + t.Errorf("TUF bindings mismatch (-want +got):\n%s", diff) + } + } + + t.Run("Tuf", func(t *testing.T) { + spoke := &Tuf{} + if err := spoke.ConvertFrom(&rhtasv1.Tuf{Spec: spec}); err != nil { + t.Fatalf("ConvertFrom failed: %v", err) + } + removeKey(t, &spoke.Spec) + got := &rhtasv1.Tuf{} + if err := spoke.ConvertTo(got); err != nil { + t.Fatalf("ConvertTo failed: %v", err) + } + checkBindings(t, got.Spec) + }) + + t.Run("Securesign", func(t *testing.T) { + spoke := &Securesign{} + if err := spoke.ConvertFrom(&rhtasv1.Securesign{Spec: rhtasv1.SecuresignSpec{ + Tuf: spec, + TimestampAuthority: &rhtasv1.TimestampAuthoritySpec{}, + }}); err != nil { + t.Fatalf("ConvertFrom failed: %v", err) + } + removeKey(t, &spoke.Spec.Tuf) + got := &rhtasv1.Securesign{} + if err := spoke.ConvertTo(got); err != nil { + t.Fatalf("ConvertTo failed: %v", err) + } + checkBindings(t, got.Spec.Tuf) + }) + }) + } +} + func TestCTlogConversionUnit(t *testing.T) { tests := []struct { name string @@ -966,10 +1124,21 @@ func TestTufConversionUnit(t *testing.T) { hub: &rhtasv1.Tuf{ ObjectMeta: metav1.ObjectMeta{Name: "tuf", Namespace: "default"}, Spec: rhtasv1.TufSpec{ - Port: 80, - Ctlog: []rhtasv1.TrustRootBinding{{ServiceReference: rhtasv1.ServiceReference{URL: "http://ctlog:6963/trusted-artifact-signer"}}}, - Fulcio: []rhtasv1.TrustRootBindingWithOIDC{{TrustRootBinding: rhtasv1.TrustRootBinding{ServiceReference: rhtasv1.ServiceReference{URL: "http://fulcio:5554"}}}}, - Rekor: []rhtasv1.TrustRootBinding{{ServiceReference: rhtasv1.ServiceReference{URL: "http://rekor:3000"}}}, + Port: 80, + Ctlog: []rhtasv1.TrustRootBinding{{ + ServiceReference: rhtasv1.ServiceReference{URL: "http://ctlog:6963/trusted-artifact-signer"}, + TargetName: rhtasv1.TufKeyCTFE, + }}, + Fulcio: []rhtasv1.TrustRootBindingWithOIDC{{ + TrustRootBinding: rhtasv1.TrustRootBinding{ + ServiceReference: rhtasv1.ServiceReference{URL: "http://fulcio:5554"}, + TargetName: rhtasv1.TufKeyFulcio, + }, + }}, + Rekor: []rhtasv1.TrustRootBinding{{ + ServiceReference: rhtasv1.ServiceReference{URL: "http://rekor:3000"}, + TargetName: rhtasv1.TufKeyRekor, + }}, Ingress: rhtasv1.Ingress{Enabled: ptr.To(false)}, }, }, @@ -1013,6 +1182,102 @@ func TestTufConversionUnit(t *testing.T) { } } +// TestTufCustomTargetNameRoundTrip ensures both directions match by TargetName: +// hub→spoke populates the alpha slot from the legacy-named binding (not index 0), +// and spoke→hub merges annotation fields only onto the same-named binding. +func TestTufCustomTargetNameRoundTrip(t *testing.T) { + start := metav1.NewTime(time.Date(2025, time.January, 1, 0, 0, 0, 0, time.UTC)) + end := metav1.NewTime(time.Date(2026, time.January, 1, 0, 0, 0, 0, time.UTC)) + hub := &rhtasv1.Tuf{ + ObjectMeta: metav1.ObjectMeta{Name: "tuf", Namespace: "default"}, + Spec: rhtasv1.TufSpec{ + Port: 80, + // Custom bindings first so index-[0] conversion would pick the wrong + // key; hub→spoke must select the legacy TargetName by name. + Ctlog: []rhtasv1.TrustRootBinding{ + { + ServiceReference: rhtasv1.ServiceReference{URL: "http://ctlog-extra:6963/extra"}, + TargetName: "custom-ctfe.pub", + ValidFor: &rhtasv1.ValidFor{Start: &start}, + }, + { + ServiceReference: rhtasv1.ServiceReference{ + Ref: &rhtasv1.ServiceReferenceRef{Name: "ctlog", Namespace: "default"}, + }, + TargetName: rhtasv1.TufKeyCTFE, + ValidFor: &rhtasv1.ValidFor{Start: &start, End: &end}, + }, + }, + Fulcio: []rhtasv1.TrustRootBindingWithOIDC{ + { + TrustRootBinding: rhtasv1.TrustRootBinding{ + ServiceReference: rhtasv1.ServiceReference{URL: "http://fulcio-extra:5554"}, + TargetName: "custom-fulcio.crt.pem", + }, + OIDCIssuers: []string{"https://extra-oidc.example.com"}, + }, + { + TrustRootBinding: rhtasv1.TrustRootBinding{ + ServiceReference: rhtasv1.ServiceReference{ + Ref: &rhtasv1.ServiceReferenceRef{Name: "fulcio", Namespace: "default"}, + }, + TargetName: rhtasv1.TufKeyFulcio, + ValidFor: &rhtasv1.ValidFor{Start: &start}, + }, + OIDCIssuers: []string{"https://oidc.example.com"}, + }, + }, + Rekor: []rhtasv1.TrustRootBinding{ + { + ServiceReference: rhtasv1.ServiceReference{URL: "http://rekor-extra:3000"}, + TargetName: "custom-rekor.pub", + }, + { + ServiceReference: rhtasv1.ServiceReference{ + Ref: &rhtasv1.ServiceReferenceRef{Name: "rekor", Namespace: "default"}, + }, + TargetName: rhtasv1.TufKeyRekor, + ValidFor: &rhtasv1.ValidFor{End: &end}, + }, + }, + Tsa: []rhtasv1.TrustRootBinding{ + { + ServiceReference: rhtasv1.ServiceReference{URL: "http://tsa-extra:3000"}, + TargetName: "custom-tsa.pem", + }, + { + ServiceReference: rhtasv1.ServiceReference{ + Ref: &rhtasv1.ServiceReferenceRef{Name: "tsa", Namespace: "default"}, + }, + TargetName: rhtasv1.TufKeyTSA, + }, + }, + Ingress: rhtasv1.Ingress{Enabled: ptr.To(false)}, + }, + } + + spoke := &Tuf{} + if err := spoke.ConvertFrom(hub); err != nil { + t.Fatalf("ConvertFrom failed: %v", err) + } + got := &rhtasv1.Tuf{} + if err := spoke.ConvertTo(got); err != nil { + t.Fatalf("ConvertTo failed: %v", err) + } + if !equality.Semantic.DeepEqual(hub.Spec.Ctlog, got.Spec.Ctlog) { + t.Errorf("Ctlog mismatch (-want +got):\n%s", cmp.Diff(hub.Spec.Ctlog, got.Spec.Ctlog)) + } + if !equality.Semantic.DeepEqual(hub.Spec.Rekor, got.Spec.Rekor) { + t.Errorf("Rekor mismatch (-want +got):\n%s", cmp.Diff(hub.Spec.Rekor, got.Spec.Rekor)) + } + if !equality.Semantic.DeepEqual(hub.Spec.Fulcio, got.Spec.Fulcio) { + t.Errorf("Fulcio mismatch (-want +got):\n%s", cmp.Diff(hub.Spec.Fulcio, got.Spec.Fulcio)) + } + if !equality.Semantic.DeepEqual(hub.Spec.Tsa, got.Spec.Tsa) { + t.Errorf("Tsa mismatch (-want +got):\n%s", cmp.Diff(hub.Spec.Tsa, got.Spec.Tsa)) + } +} + func TestTimestampAuthorityConversionUnit(t *testing.T) { tests := []struct { name string diff --git a/api/v1alpha1/conversion_webhook_test.go b/api/v1alpha1/conversion_webhook_test.go index 11e6214fa..fb13fc135 100644 --- a/api/v1alpha1/conversion_webhook_test.go +++ b/api/v1alpha1/conversion_webhook_test.go @@ -164,7 +164,7 @@ var _ = Describe("Conversion webhook", func() { }) Context("Tuf", func() { - It("should preserve trust root bindings across versions, and TSA inclusion via Keys presence", func() { + It("should expose only configured trust root bindings in v1alpha1", func() { v1obj := &rhtasv1.Tuf{ ObjectMeta: metav1.ObjectMeta{ Name: "tuf-keys-test", @@ -172,12 +172,15 @@ var _ = Describe("Conversion webhook", func() { }, Spec: rhtasv1.TufSpec{ Port: 80, - Rekor: []rhtasv1.TrustRootBinding{{ - SecretRef: &rhtasv1.SecretKeySelector{ - LocalObjectReference: rhtasv1.LocalObjectReference{Name: "rekor-key"}, - Key: "public", + Rekor: []rhtasv1.TrustRootBinding{ + { + TargetName: rhtasv1.TufKeyRekor, + SecretRef: &rhtasv1.SecretKeySelector{ + LocalObjectReference: rhtasv1.LocalObjectReference{Name: "rekor-key"}, + Key: "public", + }, }, - }}, + }, // Tsa left nil: excluded from the trust root. }, } @@ -187,18 +190,13 @@ var _ = Describe("Conversion webhook", func() { Expect(k8sClient.Get(ctx, types.NamespacedName{Name: "tuf-keys-test", Namespace: testNs}, v1alpha1obj)).To(Succeed()) Expect(v1alpha1obj.Spec.Port).To(Equal(int32(80))) - byName := map[string]TufKey{} - for _, k := range v1alpha1obj.Spec.Keys { - byName[k.Name] = k - } - Expect(byName).To(HaveKey("rekor.pub")) - Expect(byName["rekor.pub"].SecretRef).To(Equal(&SecretKeySelector{ - LocalObjectReference: LocalObjectReference{Name: "rekor-key"}, - Key: "public", - })) - Expect(byName).To(HaveKey("ctfe.pub")) - Expect(byName).To(HaveKey("fulcio_v1.crt.pem")) - Expect(byName).ToNot(HaveKey("tsa.certchain.pem")) + Expect(v1alpha1obj.Spec.Keys).To(Equal([]TufKey{{ + Name: rhtasv1.TufKeyRekor, + SecretRef: &SecretKeySelector{ + LocalObjectReference: LocalObjectReference{Name: "rekor-key"}, + Key: "public", + }, + }})) }) }) diff --git a/api/v1alpha1/securesign_conversion.go b/api/v1alpha1/securesign_conversion.go index 6fd3e2390..592f324f6 100644 --- a/api/v1alpha1/securesign_conversion.go +++ b/api/v1alpha1/securesign_conversion.go @@ -97,8 +97,23 @@ func (src *Securesign) ConvertTo(dstRaw conversion.Hub) error { //nolint:gocyclo } restored := &rhtasv1.Securesign{} - if ok, err := utilconversion.UnmarshalData(src, restored); err != nil || !ok { + if ok, err := utilconversion.UnmarshalData(src, restored); err != nil { return err + } else if !ok { + // set explicit bindings and bypass the autoloading + if len(dst.Spec.Tuf.Ctlog) == 1 && dst.Spec.Tuf.Ctlog[0].SecretRef == nil { + dst.Spec.Tuf.Ctlog[0].ServiceReference = rhtasv1.ServiceReference{Ref: &rhtasv1.ServiceReferenceRef{Name: dst.Name, Namespace: dst.Namespace}, URL: ""} + } + if len(dst.Spec.Tuf.Rekor) == 1 && dst.Spec.Tuf.Rekor[0].SecretRef == nil { + dst.Spec.Tuf.Rekor[0].ServiceReference = rhtasv1.ServiceReference{Ref: &rhtasv1.ServiceReferenceRef{Name: dst.Name, Namespace: dst.Namespace}, URL: ""} + } + if len(dst.Spec.Tuf.Fulcio) == 1 && dst.Spec.Tuf.Fulcio[0].SecretRef == nil { + dst.Spec.Tuf.Fulcio[0].ServiceReference = rhtasv1.ServiceReference{Ref: &rhtasv1.ServiceReferenceRef{Name: dst.Name, Namespace: dst.Namespace}, URL: ""} + } + if len(dst.Spec.Tuf.Tsa) == 1 && dst.Spec.Tuf.Tsa[0].SecretRef == nil && dst.Spec.TimestampAuthority != nil { + dst.Spec.Tuf.Tsa[0].ServiceReference = rhtasv1.ServiceReference{Ref: &rhtasv1.ServiceReferenceRef{Name: dst.Name, Namespace: dst.Namespace}, URL: ""} + } + return nil } dst.Spec.Fulcio.ImagePullSecrets = restored.Spec.Fulcio.ImagePullSecrets dst.Spec.Fulcio.Ingress.Annotations = restored.Spec.Fulcio.Ingress.Annotations @@ -155,22 +170,11 @@ func (src *Securesign) ConvertTo(dstRaw conversion.Hub) error { //nolint:gocyclo dst.Spec.Tuf.Ingress.Annotations = restored.Spec.Tuf.Ingress.Annotations dst.Spec.Tuf.TrustedCA = restored.Spec.Tuf.TrustedCA dst.Spec.Tuf.PodExtensions = restored.Spec.Tuf.PodExtensions - restoreBindingRef(dst.Spec.Tuf.Rekor, restored.Spec.Tuf.Rekor) - if len(dst.Spec.Tuf.Fulcio) > 0 && len(restored.Spec.Tuf.Fulcio) > 0 { - if dst.Spec.Tuf.Fulcio[0].URL == "" { - dst.Spec.Tuf.Fulcio[0].Ref = restored.Spec.Tuf.Fulcio[0].Ref - } - dst.Spec.Tuf.Fulcio[0].OIDCIssuers = restored.Spec.Tuf.Fulcio[0].OIDCIssuers - } - // v1alpha1 inject prefix into URL - we need to restore empty URL to allow ref resolution - if len(dst.Spec.Tuf.Ctlog) > 0 && len(restored.Spec.Tuf.Ctlog) > 0 && - restored.Spec.Tuf.Ctlog[0].URL == "" && dst.Spec.Tuf.Ctlog[0].URL == "///trusted-artifact-signer" { //nolint:goconst - dst.Spec.Tuf.Ctlog[0].URL = "" - } - restoreBindingRef(dst.Spec.Tuf.Ctlog, restored.Spec.Tuf.Ctlog) - if dst.Spec.Tuf.Tsa != nil && restored.Spec.Tuf.Tsa != nil { - restoreBindingRef(*dst.Spec.Tuf.Tsa, *restored.Spec.Tuf.Tsa) - } + dst.Spec.Tuf.Rekor = restoreBindings(dst.Spec.Tuf.Rekor, restored.Spec.Tuf.Rekor, rhtasv1.TufKeyRekor, restoreBinding) + dst.Spec.Tuf.Fulcio = restoreBindings(dst.Spec.Tuf.Fulcio, restored.Spec.Tuf.Fulcio, rhtasv1.TufKeyFulcio, restoreBindingWithOIDC) + dst.Spec.Tuf.Ctlog = restoreBindings(dst.Spec.Tuf.Ctlog, restored.Spec.Tuf.Ctlog, rhtasv1.TufKeyCTFE, restoreBinding) + dst.Spec.Tuf.Tsa = restoreBindings(dst.Spec.Tuf.Tsa, restored.Spec.Tuf.Tsa, rhtasv1.TufKeyTSA, restoreBinding) + if dst.Spec.TimestampAuthority != nil && restored.Spec.TimestampAuthority != nil { dst.Spec.TimestampAuthority.ImagePullSecrets = restored.Spec.TimestampAuthority.ImagePullSecrets dst.Spec.TimestampAuthority.Ingress.Annotations = restored.Spec.TimestampAuthority.Ingress.Annotations diff --git a/api/v1alpha1/tuf_conversion.go b/api/v1alpha1/tuf_conversion.go index aecfa9ec2..d1f1fbc4b 100644 --- a/api/v1alpha1/tuf_conversion.go +++ b/api/v1alpha1/tuf_conversion.go @@ -1,6 +1,8 @@ package v1alpha1 import ( + "slices" + rhtasv1 "github.com/securesign/operator/api/v1" utilconversion "github.com/securesign/operator/internal/conversion" apiconversion "k8s.io/apimachinery/pkg/conversion" @@ -36,40 +38,69 @@ func (src *Tuf) ConvertTo(dstRaw conversion.Hub) error { dst.Spec.TrustedCA = restored.Spec.TrustedCA dst.Spec.Ingress.Annotations = restored.Spec.Ingress.Annotations - restoreBindingRef(dst.Spec.Rekor, restored.Spec.Rekor) + dst.Spec.Rekor = restoreBindings(dst.Spec.Rekor, restored.Spec.Rekor, rhtasv1.TufKeyRekor, restoreBinding) // v1alpha1 inject prefix into URL - we need to restore empty URL to allow ref resolution - if len(dst.Spec.Ctlog) > 0 && len(restored.Spec.Ctlog) > 0 && - restored.Spec.Ctlog[0].URL == "" && dst.Spec.Ctlog[0].URL == "///trusted-artifact-signer" { //nolint:goconst - dst.Spec.Ctlog[0].URL = "" + if i := slices.IndexFunc(dst.Spec.Ctlog, func(b rhtasv1.TrustRootBinding) bool { return b.TargetName == rhtasv1.TufKeyCTFE }); i >= 0 { + if j := slices.IndexFunc(restored.Spec.Ctlog, func(b rhtasv1.TrustRootBinding) bool { return b.TargetName == rhtasv1.TufKeyCTFE }); j >= 0 && + restored.Spec.Ctlog[j].URL == "" && dst.Spec.Ctlog[i].URL == "///trusted-artifact-signer" { //nolint:goconst + dst.Spec.Ctlog[i].URL = "" + } } // Note: v1alpha1 has static prefix binding (https://github.com/securesign/operator/blob/main/api/v1alpha1/common.go#L91) // Users don't expect autoloading in v1alpha1, so we preserve the static prefix-based URL. // CTlog instance can have a different name than the Tuf resource, so we don't auto-set Ref here. - restoreBindingRef(dst.Spec.Ctlog, restored.Spec.Ctlog) - if len(dst.Spec.Fulcio) > 0 && len(restored.Spec.Fulcio) > 0 { - if dst.Spec.Fulcio[0].URL == "" { - dst.Spec.Fulcio[0].Ref = restored.Spec.Fulcio[0].Ref - } - dst.Spec.Fulcio[0].OIDCIssuers = restored.Spec.Fulcio[0].OIDCIssuers - } - if dst.Spec.Tsa != nil && restored.Spec.Tsa != nil { - restoreBindingRef(*dst.Spec.Tsa, *restored.Spec.Tsa) - } + dst.Spec.Ctlog = restoreBindings(dst.Spec.Ctlog, restored.Spec.Ctlog, rhtasv1.TufKeyCTFE, restoreBinding) + dst.Spec.Fulcio = restoreBindings(dst.Spec.Fulcio, restored.Spec.Fulcio, rhtasv1.TufKeyFulcio, restoreBindingWithOIDC) + dst.Spec.Tsa = restoreBindings(dst.Spec.Tsa, restored.Spec.Tsa, rhtasv1.TufKeyTSA, restoreBinding) dst.Spec.PodExtensions = restored.Spec.PodExtensions + dst.Status.TrustRoot = restored.Status.TrustRoot return nil } -// restoreBindingRef restores bindings[0].Ref from restored[0].Ref when bindings[0] -// has no explicit URL. v1alpha1 has no ref concept at all, so Ref information only -// survives via the conversion-data annotation. -func restoreBindingRef(bindings, restored []rhtasv1.TrustRootBinding) { - if len(bindings) == 0 || len(restored) == 0 { - return +// restoreBindings merges annotation bindings into spoke-derived bindings by TargetName. +// An omitted legacy key removes its binding. Custom-named bindings exist only in +// the annotation and keep their original fields and order. +func restoreBindings[B interface{ GetName() string }](bindings, restored []B, legacyName string, restore func(B, B) B) []B { + if len(restored) == 0 { + return bindings + } + + spokeByName := make(map[string]B, len(bindings)) + for _, b := range bindings { + spokeByName[b.GetName()] = b } - if bindings[0].URL == "" { - bindings[0].Ref = restored[0].Ref + var out []B + for _, r := range restored { + name := r.GetName() + if spoke, ok := spokeByName[name]; ok { + out = append(out, restore(spoke, r)) + } else if name != legacyName { + out = append(out, r) + } + } + return out +} + +func restoreBinding(spoke, restored rhtasv1.TrustRootBinding) rhtasv1.TrustRootBinding { + if spoke.SecretRef == nil && restored.Ref != nil { + spoke.Ref = restored.Ref + spoke.URL = "" } + spoke.ValidFor = restored.ValidFor.DeepCopy() + return spoke +} + +func restoreBindingWithOIDC(spoke, restored rhtasv1.TrustRootBindingWithOIDC) rhtasv1.TrustRootBindingWithOIDC { + if spoke.SecretRef == nil && restored.Ref != nil { + spoke.URL = "" + spoke.Ref = restored.Ref + } + spoke.ValidFor = restored.ValidFor.DeepCopy() + if len(spoke.OIDCIssuers) == 0 { + spoke.OIDCIssuers = restored.OIDCIssuers + } + return spoke } func (dst *Tuf) ConvertFrom(srcRaw conversion.Hub) error { @@ -96,35 +127,54 @@ func Convert_v1alpha1_TufSpec_To_v1_TufSpec(in *TufSpec, out *rhtasv1.TufSpec, s secretRefs[key.Name] = convertSecretKeySelectorTo(key.SecretRef) } - rekorURL, err := buildURL(in.Rekor.Address, in.Rekor.Port, "") - if err != nil { - return err + if ref, ok := secretRefs[rhtasv1.TufKeyRekor]; ok { + rekorURL, err := buildURL(in.Rekor.Address, in.Rekor.Port, "") + if err != nil { + return err + } + out.Rekor = []rhtasv1.TrustRootBinding{{ + ServiceReference: rhtasv1.ServiceReference{URL: rekorURL}, + SecretRef: ref, + TargetName: rhtasv1.TufKeyRekor, + }} } - out.Rekor = []rhtasv1.TrustRootBinding{{ServiceReference: rhtasv1.ServiceReference{URL: rekorURL}, SecretRef: secretRefs[rhtasv1.TufKeyRekor]}} - ctlogURL, err := buildURL(in.Ctlog.Address, in.Ctlog.Port, in.Ctlog.Prefix) - if err != nil { - return err + if ref, ok := secretRefs[rhtasv1.TufKeyCTFE]; ok { + ctlogURL, err := buildURL(in.Ctlog.Address, in.Ctlog.Port, in.Ctlog.Prefix) + if err != nil { + return err + } + out.Ctlog = []rhtasv1.TrustRootBinding{{ + ServiceReference: rhtasv1.ServiceReference{URL: ctlogURL}, + SecretRef: ref, + TargetName: rhtasv1.TufKeyCTFE, + }} } - out.Ctlog = []rhtasv1.TrustRootBinding{{ServiceReference: rhtasv1.ServiceReference{URL: ctlogURL}, SecretRef: secretRefs[rhtasv1.TufKeyCTFE]}} - fulcioURL, err := buildURL(in.Fulcio.Address, in.Fulcio.Port, "") - if err != nil { - return err + if ref, ok := secretRefs[rhtasv1.TufKeyFulcio]; ok { + fulcioURL, err := buildURL(in.Fulcio.Address, in.Fulcio.Port, "") + if err != nil { + return err + } + out.Fulcio = []rhtasv1.TrustRootBindingWithOIDC{{ + TrustRootBinding: rhtasv1.TrustRootBinding{ + ServiceReference: rhtasv1.ServiceReference{URL: fulcioURL}, + SecretRef: ref, + TargetName: rhtasv1.TufKeyFulcio, + }, + }} } - out.Fulcio = []rhtasv1.TrustRootBindingWithOIDC{{TrustRootBinding: rhtasv1.TrustRootBinding{ServiceReference: rhtasv1.ServiceReference{URL: fulcioURL}, SecretRef: secretRefs[rhtasv1.TufKeyFulcio]}}} - // TSA is only included in the trust root if tsa.certchain.pem appears in Keys at - // all. A hand-authored v1alpha1 Tuf CR that dropped it from Keys is how - // "excluded" is expressed in v1alpha1 terms. - if tsaSecretRef, tsaConfigured := secretRefs[rhtasv1.TufKeyTSA]; tsaConfigured { + if ref, ok := secretRefs[rhtasv1.TufKeyTSA]; ok { tsaURL, err := buildURL(in.Tsa.Address, in.Tsa.Port, "") if err != nil { return err } - out.Tsa = &[]rhtasv1.TrustRootBinding{{ServiceReference: rhtasv1.ServiceReference{URL: tsaURL}, SecretRef: tsaSecretRef}} - } else { - out.Tsa = nil + out.Tsa = []rhtasv1.TrustRootBinding{{ + ServiceReference: rhtasv1.ServiceReference{URL: tsaURL}, + SecretRef: ref, + TargetName: rhtasv1.TufKeyTSA, + }} } return nil @@ -140,18 +190,18 @@ func Convert_v1_TufSpec_To_v1alpha1_TufSpec(in *rhtasv1.TufSpec, out *TufSpec, s keys := make([]TufKey, 0, 4) - if len(in.Rekor) > 0 { - if err := serviceReferenceToAddressPort(&in.Rekor[0].ServiceReference, &out.Rekor.Address, &out.Rekor.Port); err != nil { + // v1alpha1 has a single slot per component. Populate it only from the + // legacy-named binding; differently named keys stay annotation-only. + if i := slices.IndexFunc(in.Rekor, func(b rhtasv1.TrustRootBinding) bool { return b.TargetName == rhtasv1.TufKeyRekor }); i >= 0 { + if err := serviceReferenceToAddressPort(&in.Rekor[i].ServiceReference, &out.Rekor.Address, &out.Rekor.Port); err != nil { return err } - keys = append(keys, TufKey{Name: rhtasv1.TufKeyRekor, SecretRef: convertSecretKeySelectorFrom(in.Rekor[0].SecretRef)}) - } else { - keys = append(keys, TufKey{Name: rhtasv1.TufKeyRekor}) + keys = append(keys, TufKey{Name: rhtasv1.TufKeyRekor, SecretRef: convertSecretKeySelectorFrom(in.Rekor[i].SecretRef)}) } - if len(in.Ctlog) > 0 { - if in.Ctlog[0].URL != "" { - base, prefix, err := splitURLPath(in.Ctlog[0].URL) + if i := slices.IndexFunc(in.Ctlog, func(b rhtasv1.TrustRootBinding) bool { return b.TargetName == rhtasv1.TufKeyCTFE }); i >= 0 { + if in.Ctlog[i].URL != "" { + base, prefix, err := splitURLPath(in.Ctlog[i].URL) if err != nil { return err } @@ -163,28 +213,22 @@ func Convert_v1_TufSpec_To_v1alpha1_TufSpec(in *rhtasv1.TufSpec, out *TufSpec, s return err } } - keys = append(keys, TufKey{Name: rhtasv1.TufKeyCTFE, SecretRef: convertSecretKeySelectorFrom(in.Ctlog[0].SecretRef)}) - } else { - keys = append(keys, TufKey{Name: rhtasv1.TufKeyCTFE}) + keys = append(keys, TufKey{Name: rhtasv1.TufKeyCTFE, SecretRef: convertSecretKeySelectorFrom(in.Ctlog[i].SecretRef)}) } - if len(in.Fulcio) > 0 { - if err := serviceReferenceToAddressPort(&in.Fulcio[0].ServiceReference, &out.Fulcio.Address, &out.Fulcio.Port); err != nil { + if i := slices.IndexFunc(in.Fulcio, func(b rhtasv1.TrustRootBindingWithOIDC) bool { return b.TargetName == rhtasv1.TufKeyFulcio }); i >= 0 { + if err := serviceReferenceToAddressPort(&in.Fulcio[i].ServiceReference, &out.Fulcio.Address, &out.Fulcio.Port); err != nil { return err } - keys = append(keys, TufKey{Name: rhtasv1.TufKeyFulcio, SecretRef: convertSecretKeySelectorFrom(in.Fulcio[0].SecretRef)}) - } else { - keys = append(keys, TufKey{Name: rhtasv1.TufKeyFulcio}) + keys = append(keys, TufKey{Name: rhtasv1.TufKeyFulcio, SecretRef: convertSecretKeySelectorFrom(in.Fulcio[i].SecretRef)}) } - if in.Tsa != nil && len(*in.Tsa) > 0 { - tsa := (*in.Tsa)[0] - if err := serviceReferenceToAddressPort(&tsa.ServiceReference, &out.Tsa.Address, &out.Tsa.Port); err != nil { + if i := slices.IndexFunc(in.Tsa, func(b rhtasv1.TrustRootBinding) bool { return b.TargetName == rhtasv1.TufKeyTSA }); i >= 0 { + if err := serviceReferenceToAddressPort(&in.Tsa[i].ServiceReference, &out.Tsa.Address, &out.Tsa.Port); err != nil { return err } - keys = append(keys, TufKey{Name: rhtasv1.TufKeyTSA, SecretRef: convertSecretKeySelectorFrom(tsa.SecretRef)}) + keys = append(keys, TufKey{Name: rhtasv1.TufKeyTSA, SecretRef: convertSecretKeySelectorFrom(in.Tsa[i].SecretRef)}) } - // else: TSA excluded out.Keys = keys return nil diff --git a/api/v1alpha1/zz_generated.conversion.go b/api/v1alpha1/zz_generated.conversion.go index c85fadf4d..f27a3ad86 100644 --- a/api/v1alpha1/zz_generated.conversion.go +++ b/api/v1alpha1/zz_generated.conversion.go @@ -2715,7 +2715,7 @@ func autoConvert_v1alpha1_TufSpec_To_v1_TufSpec(in *TufSpec, out *v1.TufSpec, s // WARNING: in.Ctlog requires manual conversion: inconvertible types (github.com/securesign/operator/api/v1alpha1.CtlogService vs []github.com/securesign/operator/api/v1.TrustRootBinding) // WARNING: in.Fulcio requires manual conversion: inconvertible types (github.com/securesign/operator/api/v1alpha1.FulcioService vs []github.com/securesign/operator/api/v1.TrustRootBindingWithOIDC) // WARNING: in.Rekor requires manual conversion: inconvertible types (github.com/securesign/operator/api/v1alpha1.RekorService vs []github.com/securesign/operator/api/v1.TrustRootBinding) - // WARNING: in.Tsa requires manual conversion: inconvertible types (github.com/securesign/operator/api/v1alpha1.TsaService vs *[]github.com/securesign/operator/api/v1.TrustRootBinding) + // WARNING: in.Tsa requires manual conversion: inconvertible types (github.com/securesign/operator/api/v1alpha1.TsaService vs []github.com/securesign/operator/api/v1.TrustRootBinding) return nil } @@ -2733,7 +2733,7 @@ func autoConvert_v1_TufSpec_To_v1alpha1_TufSpec(in *v1.TufSpec, out *TufSpec, s // WARNING: in.Ctlog requires manual conversion: inconvertible types ([]github.com/securesign/operator/api/v1.TrustRootBinding vs github.com/securesign/operator/api/v1alpha1.CtlogService) // WARNING: in.Fulcio requires manual conversion: inconvertible types ([]github.com/securesign/operator/api/v1.TrustRootBindingWithOIDC vs github.com/securesign/operator/api/v1alpha1.FulcioService) // WARNING: in.Rekor requires manual conversion: inconvertible types ([]github.com/securesign/operator/api/v1.TrustRootBinding vs github.com/securesign/operator/api/v1alpha1.RekorService) - // WARNING: in.Tsa requires manual conversion: inconvertible types (*[]github.com/securesign/operator/api/v1.TrustRootBinding vs github.com/securesign/operator/api/v1alpha1.TsaService) + // WARNING: in.Tsa requires manual conversion: inconvertible types ([]github.com/securesign/operator/api/v1.TrustRootBinding vs github.com/securesign/operator/api/v1alpha1.TsaService) // WARNING: in.TrustedCA requires manual conversion: does not exist in peer-type // WARNING: in.PodExtensions requires manual conversion: does not exist in peer-type return nil @@ -2749,6 +2749,7 @@ func autoConvert_v1alpha1_TufStatus_To_v1_TufStatus(in *TufStatus, out *v1.TufSt func autoConvert_v1_TufStatus_To_v1alpha1_TufStatus(in *v1.TufStatus, out *TufStatus, s conversion.Scope) error { out.Conditions = *(*[]metav1.Condition)(unsafe.Pointer(&in.Conditions)) + // WARNING: in.TrustRoot requires manual conversion: does not exist in peer-type out.Keys = *(*[]TufKey)(unsafe.Pointer(&in.Keys)) out.PvcName = in.PvcName // WARNING: in.URL requires manual conversion: does not exist in peer-type diff --git a/config/crd/bases/rhtas.redhat.com_securesigns.yaml b/config/crd/bases/rhtas.redhat.com_securesigns.yaml index 9ec579543..4944a5f80 100644 --- a/config/crd/bases/rhtas.redhat.com_securesigns.yaml +++ b/config/crd/bases/rhtas.redhat.com_securesigns.yaml @@ -17685,10 +17685,7 @@ spec: type: object type: object ctlog: - description: |- - Ctlog service and trust material binding. - At most one entry is allowed today; this ceiling is deliberate and temporary, - pending future multi-instance support. + description: Ctlog service and trust material binding. items: description: |- TrustRootBinding identifies a component's service binding and, optionally, a @@ -17730,6 +17727,12 @@ spec: - name type: object x-kubernetes-map-type: atomic + targetName: + description: |- + TargetName is the name of this binding's TUF target. + Optional for compatibility with pre-existing bindings; the defaulting + webhook fills the component default when unset. + type: string url: description: |- Direct URL for an external or cross-namespace service. @@ -17737,6 +17740,22 @@ spec: maxLength: 2048 minLength: 1 type: string + validFor: + description: ValidFor is the validity interval of this binding's + trust material. + properties: + end: + description: RFC3339 timestamp when this binding's trust + material expires. + format: date-time + type: string + start: + description: RFC3339 timestamp when this binding's trust + material becomes valid. Defaults to the time when + the binding is added to the trust root. + format: date-time + type: string + type: object type: object x-kubernetes-validations: - message: ref and secretRef are mutually exclusive @@ -17744,7 +17763,7 @@ spec: - message: ref and url are mutually exclusive rule: '!(has(self.ref) && has(self.url) && size(self.url) > 0)' - maxItems: 1 + maxItems: 64 type: array x-kubernetes-list-type: atomic x-kubernetes-validations: @@ -17752,10 +17771,7 @@ spec: or //[:port]/path rule: self.all(x, !has(x.url) || size(x.url) == 0 || x.url.matches('^([a-zA-Z][a-zA-Z0-9+.-]*://[^/]+/.+|//[^/]*/.+)$')) fulcio: - description: |- - Fulcio service and trust material binding. - At most one entry is allowed today; this ceiling is deliberate and temporary, - pending future multi-instance support. + description: Fulcio service and trust material binding. items: description: |- TrustRootBindingWithOIDC is a TrustRootBinding for Fulcio, which additionally @@ -17803,6 +17819,12 @@ spec: - name type: object x-kubernetes-map-type: atomic + targetName: + description: |- + TargetName is the name of this binding's TUF target. + Optional for compatibility with pre-existing bindings; the defaulting + webhook fills the component default when unset. + type: string url: description: |- Direct URL for an external or cross-namespace service. @@ -17810,6 +17832,22 @@ spec: maxLength: 2048 minLength: 1 type: string + validFor: + description: ValidFor is the validity interval of this binding's + trust material. + properties: + end: + description: RFC3339 timestamp when this binding's trust + material expires. + format: date-time + type: string + start: + description: RFC3339 timestamp when this binding's trust + material becomes valid. Defaults to the time when + the binding is added to the trust root. + format: date-time + type: string + type: object type: object x-kubernetes-validations: - message: ref and secretRef are mutually exclusive @@ -17817,7 +17855,7 @@ spec: - message: ref and url are mutually exclusive rule: '!(has(self.ref) && has(self.url) && size(self.url) > 0)' - maxItems: 1 + maxItems: 64 type: array x-kubernetes-list-type: atomic x-kubernetes-validations: @@ -18528,10 +18566,7 @@ spec: rule: oldSelf == null || has(self.name) || (!has(oldSelf.accessModes) || has(self.accessModes) && oldSelf.accessModes == self.accessModes) rekor: - description: |- - Rekor service and trust material binding. - At most one entry is allowed today; this ceiling is deliberate and temporary, - pending future multi-instance support. + description: Rekor service and trust material binding. items: description: |- TrustRootBinding identifies a component's service binding and, optionally, a @@ -18573,6 +18608,12 @@ spec: - name type: object x-kubernetes-map-type: atomic + targetName: + description: |- + TargetName is the name of this binding's TUF target. + Optional for compatibility with pre-existing bindings; the defaulting + webhook fills the component default when unset. + type: string url: description: |- Direct URL for an external or cross-namespace service. @@ -18580,6 +18621,22 @@ spec: maxLength: 2048 minLength: 1 type: string + validFor: + description: ValidFor is the validity interval of this binding's + trust material. + properties: + end: + description: RFC3339 timestamp when this binding's trust + material expires. + format: date-time + type: string + start: + description: RFC3339 timestamp when this binding's trust + material becomes valid. Defaults to the time when + the binding is added to the trust root. + format: date-time + type: string + type: object type: object x-kubernetes-validations: - message: ref and secretRef are mutually exclusive @@ -18587,7 +18644,7 @@ spec: - message: ref and url are mutually exclusive rule: '!(has(self.ref) && has(self.url) && size(self.url) > 0)' - maxItems: 1 + maxItems: 64 type: array x-kubernetes-list-type: atomic x-kubernetes-validations: @@ -18726,12 +18783,7 @@ spec: type: object x-kubernetes-map-type: atomic tsa: - description: |- - TSA service and trust material binding. A nil value excludes TSA from the - trust root entirely; a non-nil value (even an empty list, meaning - autodiscover) includes it. - At most one entry is allowed today; this ceiling is deliberate and temporary, - pending future multi-instance support. + description: TSA service and trust material binding. items: description: |- TrustRootBinding identifies a component's service binding and, optionally, a @@ -18773,6 +18825,12 @@ spec: - name type: object x-kubernetes-map-type: atomic + targetName: + description: |- + TargetName is the name of this binding's TUF target. + Optional for compatibility with pre-existing bindings; the defaulting + webhook fills the component default when unset. + type: string url: description: |- Direct URL for an external or cross-namespace service. @@ -18780,6 +18838,22 @@ spec: maxLength: 2048 minLength: 1 type: string + validFor: + description: ValidFor is the validity interval of this binding's + trust material. + properties: + end: + description: RFC3339 timestamp when this binding's trust + material expires. + format: date-time + type: string + start: + description: RFC3339 timestamp when this binding's trust + material becomes valid. Defaults to the time when + the binding is added to the trust root. + format: date-time + type: string + type: object type: object x-kubernetes-validations: - message: ref and secretRef are mutually exclusive @@ -18787,7 +18861,7 @@ spec: - message: ref and url are mutually exclusive rule: '!(has(self.ref) && has(self.url) && size(self.url) > 0)' - maxItems: 1 + maxItems: 64 type: array x-kubernetes-list-type: atomic x-kubernetes-validations: diff --git a/config/crd/bases/rhtas.redhat.com_tufs.yaml b/config/crd/bases/rhtas.redhat.com_tufs.yaml index cf61514d6..10f9b79d6 100644 --- a/config/crd/bases/rhtas.redhat.com_tufs.yaml +++ b/config/crd/bases/rhtas.redhat.com_tufs.yaml @@ -961,10 +961,7 @@ spec: type: object type: object ctlog: - description: |- - Ctlog service and trust material binding. - At most one entry is allowed today; this ceiling is deliberate and temporary, - pending future multi-instance support. + description: Ctlog service and trust material binding. items: description: |- TrustRootBinding identifies a component's service binding and, optionally, a @@ -1006,6 +1003,12 @@ spec: - name type: object x-kubernetes-map-type: atomic + targetName: + description: |- + TargetName is the name of this binding's TUF target. + Optional for compatibility with pre-existing bindings; the defaulting + webhook fills the component default when unset. + type: string url: description: |- Direct URL for an external or cross-namespace service. @@ -1013,13 +1016,29 @@ spec: maxLength: 2048 minLength: 1 type: string + validFor: + description: ValidFor is the validity interval of this binding's + trust material. + properties: + end: + description: RFC3339 timestamp when this binding's trust + material expires. + format: date-time + type: string + start: + description: RFC3339 timestamp when this binding's trust + material becomes valid. Defaults to the time when the + binding is added to the trust root. + format: date-time + type: string + type: object type: object x-kubernetes-validations: - message: ref and secretRef are mutually exclusive rule: '!(has(self.ref) && has(self.secretRef))' - message: ref and url are mutually exclusive rule: '!(has(self.ref) && has(self.url) && size(self.url) > 0)' - maxItems: 1 + maxItems: 64 type: array x-kubernetes-list-type: atomic x-kubernetes-validations: @@ -1027,10 +1046,7 @@ spec: //[:port]/path rule: self.all(x, !has(x.url) || size(x.url) == 0 || x.url.matches('^([a-zA-Z][a-zA-Z0-9+.-]*://[^/]+/.+|//[^/]*/.+)$')) fulcio: - description: |- - Fulcio service and trust material binding. - At most one entry is allowed today; this ceiling is deliberate and temporary, - pending future multi-instance support. + description: Fulcio service and trust material binding. items: description: |- TrustRootBindingWithOIDC is a TrustRootBinding for Fulcio, which additionally @@ -1078,6 +1094,12 @@ spec: - name type: object x-kubernetes-map-type: atomic + targetName: + description: |- + TargetName is the name of this binding's TUF target. + Optional for compatibility with pre-existing bindings; the defaulting + webhook fills the component default when unset. + type: string url: description: |- Direct URL for an external or cross-namespace service. @@ -1085,13 +1107,29 @@ spec: maxLength: 2048 minLength: 1 type: string + validFor: + description: ValidFor is the validity interval of this binding's + trust material. + properties: + end: + description: RFC3339 timestamp when this binding's trust + material expires. + format: date-time + type: string + start: + description: RFC3339 timestamp when this binding's trust + material becomes valid. Defaults to the time when the + binding is added to the trust root. + format: date-time + type: string + type: object type: object x-kubernetes-validations: - message: ref and secretRef are mutually exclusive rule: '!(has(self.ref) && has(self.secretRef))' - message: ref and url are mutually exclusive rule: '!(has(self.ref) && has(self.url) && size(self.url) > 0)' - maxItems: 1 + maxItems: 64 type: array x-kubernetes-list-type: atomic x-kubernetes-validations: @@ -1798,10 +1836,7 @@ spec: rule: oldSelf == null || has(self.name) || (!has(oldSelf.accessModes) || has(self.accessModes) && oldSelf.accessModes == self.accessModes) rekor: - description: |- - Rekor service and trust material binding. - At most one entry is allowed today; this ceiling is deliberate and temporary, - pending future multi-instance support. + description: Rekor service and trust material binding. items: description: |- TrustRootBinding identifies a component's service binding and, optionally, a @@ -1843,6 +1878,12 @@ spec: - name type: object x-kubernetes-map-type: atomic + targetName: + description: |- + TargetName is the name of this binding's TUF target. + Optional for compatibility with pre-existing bindings; the defaulting + webhook fills the component default when unset. + type: string url: description: |- Direct URL for an external or cross-namespace service. @@ -1850,13 +1891,29 @@ spec: maxLength: 2048 minLength: 1 type: string + validFor: + description: ValidFor is the validity interval of this binding's + trust material. + properties: + end: + description: RFC3339 timestamp when this binding's trust + material expires. + format: date-time + type: string + start: + description: RFC3339 timestamp when this binding's trust + material becomes valid. Defaults to the time when the + binding is added to the trust root. + format: date-time + type: string + type: object type: object x-kubernetes-validations: - message: ref and secretRef are mutually exclusive rule: '!(has(self.ref) && has(self.secretRef))' - message: ref and url are mutually exclusive rule: '!(has(self.ref) && has(self.url) && size(self.url) > 0)' - maxItems: 1 + maxItems: 64 type: array x-kubernetes-list-type: atomic x-kubernetes-validations: @@ -1994,12 +2051,7 @@ spec: type: object x-kubernetes-map-type: atomic tsa: - description: |- - TSA service and trust material binding. A nil value excludes TSA from the - trust root entirely; a non-nil value (even an empty list, meaning - autodiscover) includes it. - At most one entry is allowed today; this ceiling is deliberate and temporary, - pending future multi-instance support. + description: TSA service and trust material binding. items: description: |- TrustRootBinding identifies a component's service binding and, optionally, a @@ -2041,6 +2093,12 @@ spec: - name type: object x-kubernetes-map-type: atomic + targetName: + description: |- + TargetName is the name of this binding's TUF target. + Optional for compatibility with pre-existing bindings; the defaulting + webhook fills the component default when unset. + type: string url: description: |- Direct URL for an external or cross-namespace service. @@ -2048,13 +2106,29 @@ spec: maxLength: 2048 minLength: 1 type: string + validFor: + description: ValidFor is the validity interval of this binding's + trust material. + properties: + end: + description: RFC3339 timestamp when this binding's trust + material expires. + format: date-time + type: string + start: + description: RFC3339 timestamp when this binding's trust + material becomes valid. Defaults to the time when the + binding is added to the trust root. + format: date-time + type: string + type: object type: object x-kubernetes-validations: - message: ref and secretRef are mutually exclusive rule: '!(has(self.ref) && has(self.secretRef))' - message: ref and url are mutually exclusive rule: '!(has(self.ref) && has(self.url) && size(self.url) > 0)' - maxItems: 1 + maxItems: 64 type: array x-kubernetes-list-type: atomic x-kubernetes-validations: @@ -3007,6 +3081,8 @@ spec: - type x-kubernetes-list-type: map keys: + description: Keys holds the Secret references mounted by the repository + init job. items: properties: name: @@ -3038,6 +3114,356 @@ spec: x-kubernetes-list-type: map pvcName: type: string + trustRoot: + description: TrustRoot records the last successful trust root publication. + properties: + lastPublishTime: + description: LastPublishTime is the time of the last successful + trust-material update. + format: date-time + type: string + published: + description: Published is a deep copy of the component bindings + included in the last successful publication. + properties: + ctlog: + items: + description: |- + TrustRootBinding identifies a component's service binding and, optionally, a + reference to the Secret holding its trust material (public key for + Rekor/CTlog, cert chain for Fulcio/TSA). If SecretRef is unset, the operator + resolves material from the referenced or autodiscovered component CR's + status. + properties: + ref: + description: In-cluster reference to a component CR. + properties: + name: + description: Name of the referenced CR. + minLength: 1 + type: string + namespace: + description: Namespace of the referenced CR. + minLength: 1 + type: string + required: + - name + - namespace + type: object + secretRef: + description: SecretKeySelector selects a key of a Secret. + properties: + key: + description: The key of the secret to select from. + Must be a valid secret key. + pattern: ^[-._a-zA-Z0-9]+$ + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + required: + - key + - name + type: object + x-kubernetes-map-type: atomic + targetName: + description: |- + TargetName is the name of this binding's TUF target. + Optional for compatibility with pre-existing bindings; the defaulting + webhook fills the component default when unset. + type: string + url: + description: |- + Direct URL for an external or cross-namespace service. + Accepts: host:port, dns:///host:port, http(s)://host/path + maxLength: 2048 + minLength: 1 + type: string + validFor: + description: ValidFor is the validity interval of this + binding's trust material. + properties: + end: + description: RFC3339 timestamp when this binding's + trust material expires. + format: date-time + type: string + start: + description: RFC3339 timestamp when this binding's + trust material becomes valid. Defaults to the + time when the binding is added to the trust root. + format: date-time + type: string + type: object + type: object + x-kubernetes-validations: + - message: ref and secretRef are mutually exclusive + rule: '!(has(self.ref) && has(self.secretRef))' + - message: ref and url are mutually exclusive + rule: '!(has(self.ref) && has(self.url) && size(self.url) + > 0)' + maxItems: 64 + type: array + x-kubernetes-list-type: atomic + fulcio: + items: + description: |- + TrustRootBindingWithOIDC is a TrustRootBinding for Fulcio, which additionally + carries the OIDC issuers accepted for code-signing certificate requests. + properties: + oidcIssuers: + description: |- + OIDCIssuers is a list of OIDC issuer URLs to include in the Fulcio signing configuration. + Use for manual configuration; when specified, these values take precedence over auto-loaded OIDC configuration from the Fulcio service reference. + items: + pattern: ^[a-zA-Z][a-zA-Z0-9+.-]*://.+$ + type: string + type: array + x-kubernetes-list-type: set + ref: + description: In-cluster reference to a component CR. + properties: + name: + description: Name of the referenced CR. + minLength: 1 + type: string + namespace: + description: Namespace of the referenced CR. + minLength: 1 + type: string + required: + - name + - namespace + type: object + secretRef: + description: SecretKeySelector selects a key of a Secret. + properties: + key: + description: The key of the secret to select from. + Must be a valid secret key. + pattern: ^[-._a-zA-Z0-9]+$ + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + required: + - key + - name + type: object + x-kubernetes-map-type: atomic + targetName: + description: |- + TargetName is the name of this binding's TUF target. + Optional for compatibility with pre-existing bindings; the defaulting + webhook fills the component default when unset. + type: string + url: + description: |- + Direct URL for an external or cross-namespace service. + Accepts: host:port, dns:///host:port, http(s)://host/path + maxLength: 2048 + minLength: 1 + type: string + validFor: + description: ValidFor is the validity interval of this + binding's trust material. + properties: + end: + description: RFC3339 timestamp when this binding's + trust material expires. + format: date-time + type: string + start: + description: RFC3339 timestamp when this binding's + trust material becomes valid. Defaults to the + time when the binding is added to the trust root. + format: date-time + type: string + type: object + type: object + x-kubernetes-validations: + - message: ref and secretRef are mutually exclusive + rule: '!(has(self.ref) && has(self.secretRef))' + - message: ref and url are mutually exclusive + rule: '!(has(self.ref) && has(self.url) && size(self.url) + > 0)' + maxItems: 64 + type: array + x-kubernetes-list-type: atomic + rekor: + items: + description: |- + TrustRootBinding identifies a component's service binding and, optionally, a + reference to the Secret holding its trust material (public key for + Rekor/CTlog, cert chain for Fulcio/TSA). If SecretRef is unset, the operator + resolves material from the referenced or autodiscovered component CR's + status. + properties: + ref: + description: In-cluster reference to a component CR. + properties: + name: + description: Name of the referenced CR. + minLength: 1 + type: string + namespace: + description: Namespace of the referenced CR. + minLength: 1 + type: string + required: + - name + - namespace + type: object + secretRef: + description: SecretKeySelector selects a key of a Secret. + properties: + key: + description: The key of the secret to select from. + Must be a valid secret key. + pattern: ^[-._a-zA-Z0-9]+$ + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + required: + - key + - name + type: object + x-kubernetes-map-type: atomic + targetName: + description: |- + TargetName is the name of this binding's TUF target. + Optional for compatibility with pre-existing bindings; the defaulting + webhook fills the component default when unset. + type: string + url: + description: |- + Direct URL for an external or cross-namespace service. + Accepts: host:port, dns:///host:port, http(s)://host/path + maxLength: 2048 + minLength: 1 + type: string + validFor: + description: ValidFor is the validity interval of this + binding's trust material. + properties: + end: + description: RFC3339 timestamp when this binding's + trust material expires. + format: date-time + type: string + start: + description: RFC3339 timestamp when this binding's + trust material becomes valid. Defaults to the + time when the binding is added to the trust root. + format: date-time + type: string + type: object + type: object + x-kubernetes-validations: + - message: ref and secretRef are mutually exclusive + rule: '!(has(self.ref) && has(self.secretRef))' + - message: ref and url are mutually exclusive + rule: '!(has(self.ref) && has(self.url) && size(self.url) + > 0)' + maxItems: 64 + type: array + x-kubernetes-list-type: atomic + tsa: + items: + description: |- + TrustRootBinding identifies a component's service binding and, optionally, a + reference to the Secret holding its trust material (public key for + Rekor/CTlog, cert chain for Fulcio/TSA). If SecretRef is unset, the operator + resolves material from the referenced or autodiscovered component CR's + status. + properties: + ref: + description: In-cluster reference to a component CR. + properties: + name: + description: Name of the referenced CR. + minLength: 1 + type: string + namespace: + description: Namespace of the referenced CR. + minLength: 1 + type: string + required: + - name + - namespace + type: object + secretRef: + description: SecretKeySelector selects a key of a Secret. + properties: + key: + description: The key of the secret to select from. + Must be a valid secret key. + pattern: ^[-._a-zA-Z0-9]+$ + type: string + name: + description: |- + Name of the referent. + More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names + type: string + required: + - key + - name + type: object + x-kubernetes-map-type: atomic + targetName: + description: |- + TargetName is the name of this binding's TUF target. + Optional for compatibility with pre-existing bindings; the defaulting + webhook fills the component default when unset. + type: string + url: + description: |- + Direct URL for an external or cross-namespace service. + Accepts: host:port, dns:///host:port, http(s)://host/path + maxLength: 2048 + minLength: 1 + type: string + validFor: + description: ValidFor is the validity interval of this + binding's trust material. + properties: + end: + description: RFC3339 timestamp when this binding's + trust material expires. + format: date-time + type: string + start: + description: RFC3339 timestamp when this binding's + trust material becomes valid. Defaults to the + time when the binding is added to the trust root. + format: date-time + type: string + type: object + type: object + x-kubernetes-validations: + - message: ref and secretRef are mutually exclusive + rule: '!(has(self.ref) && has(self.secretRef))' + - message: ref and url are mutually exclusive + rule: '!(has(self.ref) && has(self.url) && size(self.url) + > 0)' + maxItems: 64 + type: array + x-kubernetes-list-type: atomic + type: object + publishedTargetsVersion: + description: |- + PublishedTargetsVersion is the targets.json version recorded by the + last successful publication. Older results are ignored. + format: int64 + type: integer + type: object url: type: string type: object diff --git a/internal/controller/securesign/actions/ensure_tuf.go b/internal/controller/securesign/actions/ensure_tuf.go index 403b8e835..38d8fa2a1 100644 --- a/internal/controller/securesign/actions/ensure_tuf.go +++ b/internal/controller/securesign/actions/ensure_tuf.go @@ -56,20 +56,16 @@ func (i tufAction) Handle(ctx context.Context, instance *rhtasv1.Securesign) *ac ensure.Labels[*rhtasv1.Tuf](slices.Collect(maps.Keys(l)), l), ensure.Annotations[*rhtasv1.Tuf](annotations.InheritableAnnotations, instance.Annotations), func(object *rhtasv1.Tuf) error { - defaulted := instance.Spec.Tuf.DeepCopy() - defaulted.SetDefaults() - object.Spec = *defaulted - // Auto-wire CTlog binding if not explicitly set. - // CTlog is always required; the Ref must point to the CTlog resource - // so TUF's watch can trigger reconciliation when CTlog status changes. - // ref and url are mutually exclusive, so clear URL when setting Ref. - if len(object.Spec.Ctlog) > 0 && object.Spec.Ctlog[0].Ref == nil && object.Spec.Ctlog[0].URL != "" { - object.Spec.Ctlog[0].Ref = &rhtasv1.ServiceReferenceRef{ - Name: instance.Name, - Namespace: instance.Namespace, - } - object.Spec.Ctlog[0].URL = "" + spec := instance.Spec.Tuf.DeepCopy() + siblingRef := rhtasv1.ServiceReference{Ref: &rhtasv1.ServiceReferenceRef{Name: instance.Name, Namespace: instance.Namespace}, URL: ""} + spec.Rekor = defaultLegacyBinding(spec.Rekor, rhtasv1.TufKeyRekor, siblingRef) + spec.Fulcio = defaultLegacyBindingWithOIDC(spec.Fulcio, rhtasv1.TufKeyFulcio, siblingRef) + spec.Ctlog = defaultLegacyBinding(spec.Ctlog, rhtasv1.TufKeyCTFE, siblingRef) + if instance.Spec.TimestampAuthority != nil { + spec.Tsa = defaultLegacyBinding(spec.Tsa, rhtasv1.TufKeyTSA, siblingRef) } + spec.SetDefaults() + object.Spec = *spec return nil }, ); err != nil { @@ -117,3 +113,40 @@ func (i tufAction) CopyStatus(ctx context.Context, object *rhtasv1.Tuf, instance return i.ReturnOnChange(i.PersistStatus)(ctx, instance) } + +// [backwards compatibility] set explicit bindings and bypass the autoloading. This is called only on objects created on 1.5.x release (targetName is defaulted on create otherwise) +func defaultLegacyBinding(bindings []rhtasv1.TrustRootBinding, name string, siblingRef rhtasv1.ServiceReference) []rhtasv1.TrustRootBinding { + if len(bindings) != 1 || bindings[0].TargetName != "" { + // this is not case of 1.5.x release, return as is + // - never 0 (defaulted on create) + // - never > 1 (multiple bindings are not supported) + // - targetName is set on create on newer releases + return bindings + } + + b := &bindings[0] + b.TargetName = name + if b.SecretRef == nil && b.Ref == nil { + // prompt to autoload -> set explicit binding + b.ServiceReference = *siblingRef.DeepCopy() + } + return bindings +} + +func defaultLegacyBindingWithOIDC(bindings []rhtasv1.TrustRootBindingWithOIDC, name string, siblingRef rhtasv1.ServiceReference) []rhtasv1.TrustRootBindingWithOIDC { + if len(bindings) != 1 || bindings[0].TargetName != "" { + // this is not case of 1.5.x release, return as is + // - never 0 (defaulted on create) + // - never > 1 (multiple bindings are not supported) + // - targetName is set on create on newer releases + return bindings + } + + b := &bindings[0] + b.TargetName = name + if b.SecretRef == nil && b.Ref == nil { + // prompt to autoload -> set explicit binding + b.ServiceReference = *siblingRef.DeepCopy() + } + return bindings +} diff --git a/internal/controller/securesign/actions/ensure_tuf_test.go b/internal/controller/securesign/actions/ensure_tuf_test.go new file mode 100644 index 000000000..6df1be354 --- /dev/null +++ b/internal/controller/securesign/actions/ensure_tuf_test.go @@ -0,0 +1,52 @@ +package actions + +import ( + "testing" + + . "github.com/onsi/gomega" + rhtasv1 "github.com/securesign/operator/api/v1" + testAction "github.com/securesign/operator/internal/testing/action" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +func TestTufActionDefaultsMissingBindings(t *testing.T) { + g := NewWithT(t) + parent := &rhtasv1.Securesign{ + ObjectMeta: metav1.ObjectMeta{Name: "stack", Namespace: "default"}, + Spec: rhtasv1.SecuresignSpec{ + Tuf: rhtasv1.TufSpec{ + Ctlog: []rhtasv1.TrustRootBinding{{}}, + Rekor: []rhtasv1.TrustRootBinding{{}}, + Fulcio: []rhtasv1.TrustRootBindingWithOIDC{{}}, + Tsa: []rhtasv1.TrustRootBinding{{}}, + }, + TimestampAuthority: &rhtasv1.TimestampAuthoritySpec{}, + }, + } + c := testAction.FakeClientBuilder().WithObjects(parent.DeepCopy()).WithStatusSubresource(parent).Build() + a := testAction.PrepareAction(c, NewTufAction()) + a.Handle(t.Context(), parent) + + child := &rhtasv1.Tuf{} + key := client.ObjectKeyFromObject(parent) + g.Expect(c.Get(t.Context(), key, child)).To(Succeed()) + sibling := rhtasv1.ServiceReference{Ref: &rhtasv1.ServiceReferenceRef{Name: parent.Name, Namespace: parent.Namespace}} + g.Expect(child.Spec.Rekor).To(Equal([]rhtasv1.TrustRootBinding{ + {ServiceReference: sibling, TargetName: "rekor.pub"}, + })) + g.Expect(child.Spec.Fulcio).To(Equal([]rhtasv1.TrustRootBindingWithOIDC{ + {TrustRootBinding: rhtasv1.TrustRootBinding{ServiceReference: sibling, TargetName: "fulcio_v1.crt.pem"}}, + })) + g.Expect(child.Spec.Tsa).To(Equal([]rhtasv1.TrustRootBinding{ + {ServiceReference: sibling, TargetName: "tsa.certchain.pem"}, + })) + g.Expect(child.Spec.Ctlog).To(Equal([]rhtasv1.TrustRootBinding{ + {ServiceReference: sibling, TargetName: "ctfe.pub"}, + })) + + version := child.ResourceVersion + a.Handle(t.Context(), parent) + g.Expect(c.Get(t.Context(), key, child)).To(Succeed()) + g.Expect(child.ResourceVersion).To(Equal(version)) +} diff --git a/internal/controller/tuf/actions/resolve_keys_test.go b/internal/controller/tuf/actions/resolve_keys_test.go index 42db6feda..c892645d6 100644 --- a/internal/controller/tuf/actions/resolve_keys_test.go +++ b/internal/controller/tuf/actions/resolve_keys_test.go @@ -23,27 +23,30 @@ import ( //go:embed testdata/public_key.pem var testPEM string -// tufInstance builds a "tuf"/"default" Tuf instance with explicit trust root -// bindings. Ctlog always autodiscovers (no test needs an explicit Ctlog -// binding); a nil tsa excludes TSA from the trust root entirely. -func tufInstance(rekor []rhtasv1.TrustRootBinding, fulcio []rhtasv1.TrustRootBindingWithOIDC, tsa *[]rhtasv1.TrustRootBinding) *rhtasv1.Tuf { +func tufInstance(spec rhtasv1.TufSpec) *rhtasv1.Tuf { return &rhtasv1.Tuf{ ObjectMeta: metav1.ObjectMeta{Name: "tuf", Namespace: "default"}, - Spec: rhtasv1.TufSpec{ - Rekor: rekor, - Fulcio: fulcio, - Tsa: tsa, - }, + Spec: spec, Status: rhtasv1.TufStatus{Conditions: []metav1.Condition{ {Type: constants.ReadyCondition, Reason: state.Pending.String(), Status: metav1.ConditionFalse}, }}, } } -// noTSA builds a "tuf" instance with TSA excluded, and rekor/ctlog/fulcio all -// zero-value bindings (autodiscover) unless overridden by the caller. -func noTSA() *rhtasv1.Tuf { - return tufInstance(nil, nil, nil) +func referencedTuf() *rhtasv1.Tuf { + return tufInstance(rhtasv1.TufSpec{ + Rekor: []rhtasv1.TrustRootBinding{referenceBinding("rekor")}, + Ctlog: []rhtasv1.TrustRootBinding{referenceBinding("ctlog")}, + Fulcio: []rhtasv1.TrustRootBindingWithOIDC{{TrustRootBinding: referenceBinding("fulcio")}}, + }) +} + +func referenceBinding(name string) rhtasv1.TrustRootBinding { + return rhtasv1.TrustRootBinding{ + ServiceReference: rhtasv1.ServiceReference{ + Ref: &rhtasv1.ServiceReferenceRef{Name: name, Namespace: "default"}, + }, + } } func readyRekor() *rhtasv1.Rekor { @@ -105,8 +108,7 @@ func userRef(name, key string) *rhtasv1.SecretKeySelector { } } -// explicitSecret builds the Secret a SecretRef-carrying binding points at, so -// material resolution for that binding succeeds without needing autodiscovery. +// explicitSecret builds the Secret referenced by a binding. func explicitSecret(ns, name, key string) *v1.Secret { return &v1.Secret{ ObjectMeta: metav1.ObjectMeta{Name: name, Namespace: ns}, @@ -143,8 +145,8 @@ func TestResolveKeys_Handle(t *testing.T) { want want }{ { - name: "all autodiscovered, no TSA", - instance: func() *rhtasv1.Tuf { return noTSA() }, + name: "referenced components without TSA", + instance: referencedTuf, objects: []client.Object{readyRekor(), readyCTlog(), readyFulcio()}, want: want{ result: testAction.Return(), @@ -164,9 +166,11 @@ func TestResolveKeys_Handle(t *testing.T) { }, }, { - name: "all four components including TSA", + name: "referenced components including TSA", instance: func() *rhtasv1.Tuf { - return tufInstance(nil, nil, &[]rhtasv1.TrustRootBinding{}) + instance := referencedTuf() + instance.Spec.Tsa = []rhtasv1.TrustRootBinding{referenceBinding("tsa")} + return instance }, objects: []client.Object{readyRekor(), readyCTlog(), readyFulcio(), readyTSA(ns)}, want: want{ @@ -182,28 +186,31 @@ func TestResolveKeys_Handle(t *testing.T) { { name: "user-provided secretRef passes through untouched", instance: func() *rhtasv1.Tuf { - return tufInstance( - []rhtasv1.TrustRootBinding{explicitBinding("my-secret", "pub")}, nil, nil) + return tufInstance(rhtasv1.TufSpec{ + Rekor: []rhtasv1.TrustRootBinding{explicitBinding("my-secret", "pub")}, + }) }, - objects: []client.Object{readyCTlog(), readyFulcio(), explicitSecret(ns, "my-secret", "pub")}, + objects: []client.Object{explicitSecret(ns, "my-secret", "pub")}, want: want{ result: testAction.Return(), verify: func(g Gomega, instance *rhtasv1.Tuf, c client.Client) { - g.Expect(instance.Status.Keys[0].SecretRef).To(Equal(userRef("my-secret", "pub"))) + g.Expect(instance.Status.Keys).To(ConsistOf(rhtasv1.TufKeyStatus{ + Name: trustroot.Rekor.String(), SecretRef: userRef("my-secret", "pub"), + })) g.Expect(meta.IsStatusConditionTrue(instance.Status.Conditions, trustroot.Rekor.String())).To(BeTrue()) }, }, }, { - name: "mixed — provided and autodiscovery", + name: "mixed service and Secret references", instance: func() *rhtasv1.Tuf { - return tufInstance( - []rhtasv1.TrustRootBinding{explicitBinding("user-rekor", "key")}, - []rhtasv1.TrustRootBindingWithOIDC{{ - TrustRootBinding: explicitBinding("user-fulcio", "cert"), - OIDCIssuers: []string{"https://oidc.fakeserver.com"}, - }}, - nil) + instance := referencedTuf() + instance.Spec.Rekor[0] = explicitBinding("user-rekor", "key") + instance.Spec.Fulcio[0] = rhtasv1.TrustRootBindingWithOIDC{ + TrustRootBinding: explicitBinding("user-fulcio", "cert"), + OIDCIssuers: []string{"https://oidc.fakeserver.com"}, + } + return instance }, objects: []client.Object{readyCTlog(), explicitSecret(ns, "user-rekor", "key"), explicitSecret(ns, "user-fulcio", "cert")}, want: want{ @@ -228,7 +235,7 @@ func TestResolveKeys_Handle(t *testing.T) { { name: "TSA excluded, stale status and condition are dropped", instance: func() *rhtasv1.Tuf { - instance := noTSA() + instance := referencedTuf() instance.Status.Keys = []rhtasv1.TufKeyStatus{ {Name: trustroot.TSA.String(), SecretRef: userRef("stale-tsa", "key")}, } @@ -237,10 +244,11 @@ func TestResolveKeys_Handle(t *testing.T) { }) return instance }, - objects: []client.Object{readyRekor(), readyCTlog(), readyFulcio()}, + objects: []client.Object{readyRekor(), readyCTlog(), readyFulcio(), readyTSA(ns)}, want: want{ result: testAction.Return(), verify: func(g Gomega, instance *rhtasv1.Tuf, c client.Client) { + g.Expect(instance.Status.Keys).To(HaveLen(3)) for _, k := range instance.Status.Keys { g.Expect(k.Name).ToNot(Equal(trustroot.TSA.String())) } @@ -251,15 +259,16 @@ func TestResolveKeys_Handle(t *testing.T) { { name: "no changes needed, continues without persisting", instance: func() *rhtasv1.Tuf { - instance := noTSA() - instance.Status.Keys = []rhtasv1.TufKeyStatus{ - {Name: trustroot.Rekor.String(), SecretRef: &rhtasv1.SecretKeySelector{LocalObjectReference: rhtasv1.LocalObjectReference{Name: tufSecretName()}, Key: trustroot.Rekor.String()}}, - {Name: trustroot.CTFE.String(), SecretRef: &rhtasv1.SecretKeySelector{LocalObjectReference: rhtasv1.LocalObjectReference{Name: tufSecretName()}, Key: trustroot.CTFE.String()}}, - {Name: trustroot.Fulcio.String(), SecretRef: &rhtasv1.SecretKeySelector{LocalObjectReference: rhtasv1.LocalObjectReference{Name: tufSecretName()}, Key: trustroot.Fulcio.String()}}, + instance := referencedTuf() + for _, key := range trustroot.ActiveKeys(instance) { + name := key.String() + instance.Status.Keys = append(instance.Status.Keys, rhtasv1.TufKeyStatus{ + Name: name, SecretRef: userRef(tufSecretName(), name), + }) + meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{ + Type: name, Status: metav1.ConditionTrue, Reason: state.Ready.String(), + }) } - meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{Type: trustroot.Rekor.String(), Status: metav1.ConditionTrue, Reason: state.Ready.String()}) - meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{Type: trustroot.CTFE.String(), Status: metav1.ConditionTrue, Reason: state.Ready.String()}) - meta.SetStatusCondition(&instance.Status.Conditions, metav1.Condition{Type: trustroot.Fulcio.String(), Status: metav1.ConditionTrue, Reason: state.Ready.String()}) return instance }, objects: []client.Object{readyRekor(), readyCTlog(), readyFulcio()}, @@ -271,8 +280,8 @@ func TestResolveKeys_Handle(t *testing.T) { }, }, { - name: "component not ready — requeue", - instance: func() *rhtasv1.Tuf { return noTSA() }, + name: "referenced component not ready, requeues", + instance: referencedTuf, objects: []client.Object{ &rhtasv1.Rekor{ ObjectMeta: metav1.ObjectMeta{Name: "rekor", Namespace: ns}, @@ -290,9 +299,13 @@ func TestResolveKeys_Handle(t *testing.T) { }, }, { - name: "no component instance — requeue", - instance: func() *rhtasv1.Tuf { return noTSA() }, - objects: []client.Object{readyCTlog(), readyFulcio()}, + name: "referenced component missing, requeues", + instance: func() *rhtasv1.Tuf { + instance := referencedTuf() + instance.Spec.Rekor[0] = referenceBinding("missing-rekor") + return instance + }, + objects: []client.Object{readyRekor(), readyCTlog(), readyFulcio()}, want: want{ result: testAction.RequeueAfter(5 * time.Second), verify: func(g Gomega, instance *rhtasv1.Tuf, c client.Client) { @@ -301,8 +314,8 @@ func TestResolveKeys_Handle(t *testing.T) { }, }, { - name: "component ready but trust material empty — requeue", - instance: func() *rhtasv1.Tuf { return noTSA() }, + name: "referenced component has no trust material, requeues", + instance: referencedTuf, objects: []client.Object{ &rhtasv1.Rekor{ ObjectMeta: metav1.ObjectMeta{Name: "rekor", Namespace: ns}, @@ -359,7 +372,7 @@ func TestResolveKeys_CanHandle(t *testing.T) { }{ { name: "pending state", - instance: noTSA(), + instance: referencedTuf(), canHandle: true, }, { diff --git a/internal/controller/tuf/trustroot/resolver.go b/internal/controller/tuf/trustroot/resolver.go index 6f8714d30..ae4aa40f9 100644 --- a/internal/controller/tuf/trustroot/resolver.go +++ b/internal/controller/tuf/trustroot/resolver.go @@ -40,10 +40,19 @@ func (k ComponentKey) String() string { return string(k) } // always, TSA only when instance.Spec.Tsa is non-nil (nil excludes TSA from the trust // root entirely). func ActiveKeys(instance *rhtasv1.Tuf) []ComponentKey { - keys := []ComponentKey{Rekor, CTFE, Fulcio} - if instance.Spec.Tsa != nil { + keys := make([]ComponentKey, 0, 4) + if len(instance.Spec.Tsa) > 0 { keys = append(keys, TSA) } + if len(instance.Spec.Fulcio) > 0 { + keys = append(keys, Fulcio) + } + if len(instance.Spec.Rekor) > 0 { + keys = append(keys, Rekor) + } + if len(instance.Spec.Ctlog) > 0 { + keys = append(keys, CTFE) + } return keys } @@ -59,10 +68,7 @@ func Binding(instance *rhtasv1.Tuf, key ComponentKey) rhtasv1.TrustRootBinding { case Fulcio: return FulcioBinding(instance).TrustRootBinding case TSA: - if instance.Spec.Tsa == nil { - return rhtasv1.TrustRootBinding{} - } - return firstBinding(*instance.Spec.Tsa) + return firstBinding(instance.Spec.Tsa) default: return rhtasv1.TrustRootBinding{} } diff --git a/internal/controller/tuf/tuf_controller_test.go b/internal/controller/tuf/tuf_controller_test.go index 6c61cbf6f..4eadc48f5 100644 --- a/internal/controller/tuf/tuf_controller_test.go +++ b/internal/controller/tuf/tuf_controller_test.go @@ -107,10 +107,11 @@ var _ = Describe("TUF controller", func() { Enabled: ptr.To(true), }, Port: 8181, - // Fulcio via secretRef, Rekor via an explicit ref, and CTlog via autodiscovery + // Fulcio uses an explicit URL, issuer, and Secret. Rekor and CTlog use named refs. Fulcio: []rhtasv1.TrustRootBindingWithOIDC{ { TrustRootBinding: rhtasv1.TrustRootBinding{ + ServiceReference: rhtasv1.ServiceReference{URL: "https://fulcio.example.com"}, SecretRef: &rhtasv1.SecretKeySelector{ LocalObjectReference: rhtasv1.LocalObjectReference{ Name: "fulcio-pub-key", @@ -118,6 +119,7 @@ var _ = Describe("TUF controller", func() { Key: "cert", }, }, + OIDCIssuers: []string{"https://oidc.example.com"}, }, }, Rekor: []rhtasv1.TrustRootBinding{ @@ -127,6 +129,13 @@ var _ = Describe("TUF controller", func() { }, }, }, + Ctlog: []rhtasv1.TrustRootBinding{ + { + ServiceReference: rhtasv1.ServiceReference{ + Ref: &rhtasv1.ServiceReferenceRef{Name: "ctlog-test", Namespace: TufNamespace}, + }, + }, + }, }, } Expect(suite.Client().Create(ctx, &corev1.Secret{ @@ -160,7 +169,7 @@ var _ = Describe("TUF controller", func() { return cond.Reason }).WithContext(ctx).Should(Equal(state.Pending.String())) - By("Creating component CRs for autodiscovery and ref resolution, not yet ready") + By("Creating the referenced CTlog and Rekor resources") componentObjects := []apis.AddressableConditionAware{ &rhtasv1.CTlog{ ObjectMeta: metav1.ObjectMeta{ @@ -177,31 +186,6 @@ var _ = Describe("TUF controller", func() { }, }, }, - &rhtasv1.Fulcio{ - ObjectMeta: metav1.ObjectMeta{ - Name: "fulcio-test", - Namespace: typeNamespaceName.Namespace, - }, - Spec: rhtasv1.FulcioSpec{ - Config: rhtasv1.FulcioConfig{ - OIDCIssuers: []rhtasv1.OIDCIssuer{ - { - ClientID: "test", - Issuer: "test", - Type: "email", - }, - }, - }, - Signer: rhtasv1.FulcioSigner{ - Type: "file", - CertificateChain: rhtasv1.FulcioCertificateChain{ - CommonName: "test", - OrganizationName: "test", - OrganizationEmail: "test@test.com", - }, - }, - }, - }, &rhtasv1.Rekor{ ObjectMeta: metav1.ObjectMeta{ Name: "rekor-test", @@ -221,7 +205,7 @@ var _ = Describe("TUF controller", func() { return cond.Reason }).WithContext(ctx).Should(Equal(state.Pending.String())) - By("Marking Ctlog and the referenced Fulcio/Rekor instances Ready") + By("Marking the referenced CTlog and Rekor resources Ready") for i, component := range componentObjects { Expect(setStatusURL(component, "https://example.com/"+strconv.Itoa(i))).To(BeTrue()) switch c := component.(type) { @@ -321,18 +305,16 @@ var _ = Describe("TUF controller", func() { Expect(ingress.Spec.Rules[0].IngressRuleValue.HTTP.Paths[0].Backend.Service.Name).Should(Equal(service.Name)) Expect(ingress.Spec.Rules[0].IngressRuleValue.HTTP.Paths[0].Backend.Service.Port.Name).Should(Equal(tufConstants.PortName)) - By("Checking the latest Status Condition added to the Tuf instance") + By("Checking the readiness conditions for all configured bindings") Eventually(func(g Gomega, ctx context.Context) error { found := &rhtasv1.Tuf{} g.Expect(suite.Client().Get(ctx, typeNamespaceName, found)).Should(Succeed()) - rekorCondition := meta.FindStatusCondition(found.Status.Conditions, "rekor.pub") - g.Expect(rekorCondition).Should(Not(BeNil())) - g.Expect(rekorCondition.Status).Should(Equal(metav1.ConditionTrue)) - g.Expect(rekorCondition.Reason).Should(Equal(state.Ready.String())) - ctlogCondition := meta.FindStatusCondition(found.Status.Conditions, "ctfe.pub") - g.Expect(ctlogCondition).Should(Not(BeNil())) - g.Expect(ctlogCondition.Status).Should(Equal(metav1.ConditionTrue)) - g.Expect(ctlogCondition.Reason).Should(Equal(state.Ready.String())) + for _, name := range []string{rhtasv1.TufKeyRekor, rhtasv1.TufKeyCTFE, rhtasv1.TufKeyFulcio} { + condition := meta.FindStatusCondition(found.Status.Conditions, name) + g.Expect(condition).ShouldNot(BeNil(), name) + g.Expect(condition.Status).Should(Equal(metav1.ConditionTrue), name) + g.Expect(condition.Reason).Should(Equal(state.Ready.String()), name) + } return nil }).WithContext(ctx).Should(Succeed()) diff --git a/test/e2e/install/namespaced_test.go b/test/e2e/install/namespaced_test.go index 5ad6cfd00..1720df1e5 100644 --- a/test/e2e/install/namespaced_test.go +++ b/test/e2e/install/namespaced_test.go @@ -290,7 +290,7 @@ var _ = Describe("Install components to separate namespaces", Ordered, func() { }, }, }, - Tsa: &[]rhtasv1.TrustRootBinding{ + Tsa: []rhtasv1.TrustRootBinding{ { SecretRef: &rhtasv1.SecretKeySelector{ LocalObjectReference: rhtasv1.LocalObjectReference{ @@ -372,7 +372,7 @@ var _ = Describe("Install components to separate namespaces", Ordered, func() { tufObject.Spec.Fulcio[0].URL = fulcio.Get(ctx, cli, namespaces["fulcio"].Name, fulcioObject.Name).Status.URL tufObject.Spec.Fulcio[0].OIDCIssuers = []string{support.OidcIssuerUrl()} tufObject.Spec.Rekor[0].URL = rekor.Get(ctx, cli, namespaces["rekor"].Name, rekorObject.Name).Status.URL - (*tufObject.Spec.Tsa)[0].URL = tsa.Get(ctx, cli, namespaces["tsa"].Name, tsaObject.Name).Status.URL + tufObject.Spec.Tsa[0].URL = tsa.Get(ctx, cli, namespaces["tsa"].Name, tsaObject.Name).Status.URL tufObject.Spec.Ctlog[0].URL = ctlog.Get(ctx, cli, namespaces["ctlog"].Name, ctlogObject.Name).Status.URL Expect(cli.Create(ctx, tufObject)).To(Succeed()) tuf.Verify(ctx, cli, namespaces["tuf"].Name, tufObject.Name) diff --git a/test/e2e/install/provided_certs_test.go b/test/e2e/install/provided_certs_test.go index 8632d4578..b6d2a44fd 100644 --- a/test/e2e/install/provided_certs_test.go +++ b/test/e2e/install/provided_certs_test.go @@ -80,7 +80,7 @@ var _ = Describe("Securesign install with provided certs", Ordered, func() { }, }, } - v.Spec.Tuf.Tsa = &[]rhtasv1.TrustRootBinding{ + v.Spec.Tuf.Tsa = []rhtasv1.TrustRootBinding{ { SecretRef: &rhtasv1.SecretKeySelector{ LocalObjectReference: rhtasv1.LocalObjectReference{ diff --git a/test/e2e/lifecycle/securesign_1855_test.go b/test/e2e/lifecycle/securesign_1855_test.go index d5c1a6ee2..953e7d9ff 100644 --- a/test/e2e/lifecycle/securesign_1855_test.go +++ b/test/e2e/lifecycle/securesign_1855_test.go @@ -150,7 +150,7 @@ func createInstance(name, ns string) *rhtasv1.Tuf { }, }, }, - Tsa: &[]rhtasv1.TrustRootBinding{ + Tsa: []rhtasv1.TrustRootBinding{ { ServiceReference: rhtasv1.ServiceReference{URL: "http://tsa.fakeserver.com"}, SecretRef: &rhtasv1.SecretKeySelector{ diff --git a/test/e2e/support/tas/tuf/tuf.go b/test/e2e/support/tas/tuf/tuf.go index 5b10a28fb..6c3082514 100644 --- a/test/e2e/support/tas/tuf/tuf.go +++ b/test/e2e/support/tas/tuf/tuf.go @@ -105,10 +105,10 @@ func RefreshTufRepository(ctx context.Context, cli client.Client, ns string, nam } t.Spec.Rekor[0].URL = rekor.Get(ctx, cli, ns, name).Status.URL - if t.Spec.Tsa == nil || len(*t.Spec.Tsa) == 0 { - t.Spec.Tsa = &[]rhtasv1.TrustRootBinding{{}} + if len(t.Spec.Tsa) == 0 { + t.Spec.Tsa = []rhtasv1.TrustRootBinding{{}} } - (*t.Spec.Tsa)[0].URL = tsa.Get(ctx, cli, ns, name).Status.URL + t.Spec.Tsa[0].URL = tsa.Get(ctx, cli, ns, name).Status.URL refreshJob, err := kubernetes.Create(ctx, cli, refreshTufJob(ctx, cli, t)) Expect(err).To(Succeed()) diff --git a/test/e2e/update/tsa_test.go b/test/e2e/update/tsa_test.go index ebe51cd58..47a3d25ee 100644 --- a/test/e2e/update/tsa_test.go +++ b/test/e2e/update/tsa_test.go @@ -162,7 +162,7 @@ var _ = Describe("TSA update", Ordered, func() { It("update TUF deployment", func(ctx SpecContext) { Eventually(func(g Gomega) error { g.Expect(cli.Get(ctx, runtimeCli.ObjectKeyFromObject(s), s)).To(Succeed()) - s.Spec.Tuf.Tsa = &[]rhtasv1.TrustRootBinding{ + s.Spec.Tuf.Tsa = []rhtasv1.TrustRootBinding{ { SecretRef: &rhtasv1.SecretKeySelector{ LocalObjectReference: rhtasv1.LocalObjectReference{