Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions api/v1/securesign_defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
57 changes: 57 additions & 0 deletions api/v1/tuf_defaults.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package v1

import (
"strings"
"time"

k8sresource "k8s.io/apimachinery/pkg/api/resource"
"k8s.io/utils/ptr"
)
Expand All @@ -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)
}
}
108 changes: 88 additions & 20 deletions api/v1/tuf_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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"`
Expand All @@ -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
Expand Down Expand Up @@ -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
}
12 changes: 2 additions & 10 deletions api/v1/tuf_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -170,15 +162,15 @@ 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]")))
})

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())
})

Expand Down
Loading
Loading