Skip to content
This repository was archived by the owner on Sep 23, 2025. It is now read-only.

Commit c927fd6

Browse files
authored
Merge pull request #1725 from codysoyland/bundle-support-rebased
Add support for Sigstore Bundle Spec
2 parents 414bf18 + 27c8ab4 commit c927fd6

File tree

16 files changed

+306
-51
lines changed

16 files changed

+306
-51
lines changed

cmd/webhook/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import (
5656
"github.com/sigstore/sigstore/pkg/tuf"
5757

5858
"github.com/sigstore/policy-controller/pkg/apis/config"
59+
pctuf "github.com/sigstore/policy-controller/pkg/tuf"
5960
cwebhook "github.com/sigstore/policy-controller/pkg/webhook"
6061
)
6162

@@ -136,7 +137,7 @@ func main() {
136137

137138
// Set the policy and trust root resync periods
138139
ctx = clusterimagepolicy.ToContext(ctx, *policyResyncPeriod)
139-
ctx = trustroot.ToContext(ctx, *trustrootResyncPeriod)
140+
ctx = pctuf.ToContext(ctx, *trustrootResyncPeriod)
140141

141142
// This must match the set of resources we configure in
142143
// cmd/webhook/main.go in the "types" map.

config/300-clusterimagepolicy.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ spec:
209209
trustRootRef:
210210
description: Use the Certificate Chain from the referred TrustRoot.TimeStampAuthorities
211211
type: string
212+
signatureFormat:
213+
description: SignatureFormat specifies the format the authority expects. Supported formats are "legacy" and "bundle". If not specified, the default is "legacy" (cosign's default).
214+
type: string
212215
source:
213216
description: Sources sets the configuration to specify the sources from where to consume the signatures.
214217
type: array
@@ -545,6 +548,9 @@ spec:
545548
trustRootRef:
546549
description: Use the Certificate Chain from the referred TrustRoot.TimeStampAuthorities
547550
type: string
551+
signatureFormat:
552+
description: SignatureFormat specifies the format the authority expects. Supported formats are "legacy" and "bundle". If not specified, the default is "legacy" (cosign's default).
553+
type: string
548554
source:
549555
description: Sources sets the configuration to specify the sources from where to consume the signatures.
550556
type: array

docs/api-types/index-v1alpha1.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ Attestation defines the type of attestation to validate and optionally apply a p
172172
| ctlog | CTLog sets the configuration to verify the authority against a Rekor instance. | [TLog](#tlog) | false |
173173
| attestations | Attestations is a list of individual attestations for this authority, once the signature for this authority has been verified. | [][Attestation](#attestation) | false |
174174
| rfc3161timestamp | RFC3161Timestamp sets the configuration to verify the signature timestamp against a RFC3161 time-stamping instance. | [RFC3161Timestamp](#rfc3161timestamp) | false |
175+
| signatureFormat | SignatureFormat specifies the format the authority expects. Supported formats are \"legacy\" and \"bundle\". If not specified, the default is \"legacy\" (cosign's default). | string | false |
175176

176177
[Back to TOC](#table-of-contents)
177178

docs/api-types/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ The authorities block defines the rules for discovering and validating signature
4949
| ctlog | CTLog sets the configuration to verify the authority against a Rekor instance. | [TLog](#tlog) | false |
5050
| attestations | Attestations is a list of individual attestations for this authority, once the signature for this authority has been verified. | [][Attestation](#attestation) | false |
5151
| rfc3161timestamp | RFC3161Timestamp sets the configuration to verify the signature timestamp against a RFC3161 time-stamping instance. | [RFC3161Timestamp](#rfc3161timestamp) | false |
52+
| signatureFormat | SignatureFormat specifies the format the authority expects. Supported formats are \"legacy\" and \"bundle\". If not specified, the default is \"legacy\" (cosign's default). | string | false |
5253

5354
[Back to TOC](#table-of-contents)
5455

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ require (
6464
github.com/go-jose/go-jose/v4 v4.1.0
6565
github.com/sigstore/protobuf-specs v0.4.1
6666
github.com/sigstore/scaffolding v0.7.22
67+
github.com/sigstore/sigstore-go v0.7.1
6768
github.com/sigstore/sigstore/pkg/signature/kms/aws v1.9.3
6869
github.com/sigstore/sigstore/pkg/signature/kms/azure v1.9.3
6970
github.com/sigstore/sigstore/pkg/signature/kms/gcp v1.9.3
@@ -229,7 +230,6 @@ require (
229230
github.com/sassoftware/relic v7.2.1+incompatible // indirect
230231
github.com/secure-systems-lab/go-securesystemslib v0.9.0 // indirect
231232
github.com/shibumi/go-pathspec v1.3.0 // indirect
232-
github.com/sigstore/sigstore-go v0.7.1 // indirect
233233
github.com/sigstore/timestamp-authority v1.2.5 // indirect
234234
github.com/sirupsen/logrus v1.9.3 // indirect
235235
github.com/sourcegraph/conc v0.3.0 // indirect

pkg/apis/policy/v1alpha1/clusterimagepolicy_conversion.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ func (matchResource *MatchResource) ConvertTo(_ context.Context, sink *v1beta1.M
8989

9090
func (authority *Authority) ConvertTo(ctx context.Context, sink *v1beta1.Authority) error {
9191
sink.Name = authority.Name
92+
sink.SignatureFormat = authority.SignatureFormat
9293
if authority.CTLog != nil && authority.CTLog.URL != nil {
9394
sink.CTLog = &v1beta1.TLog{
9495
URL: authority.CTLog.URL.DeepCopy(),
@@ -244,6 +245,7 @@ func (spec *ClusterImagePolicySpec) ConvertFrom(ctx context.Context, source *v1b
244245

245246
func (authority *Authority) ConvertFrom(ctx context.Context, source *v1beta1.Authority) error {
246247
authority.Name = source.Name
248+
authority.SignatureFormat = source.SignatureFormat
247249
if source.CTLog != nil && source.CTLog.URL != nil {
248250
authority.CTLog = &TLog{
249251
URL: source.CTLog.URL.DeepCopy(),

pkg/apis/policy/v1alpha1/clusterimagepolicy_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,10 @@ type Authority struct {
144144
// RFC3161Timestamp sets the configuration to verify the signature timestamp against a RFC3161 time-stamping instance.
145145
// +optional
146146
RFC3161Timestamp *RFC3161Timestamp `json:"rfc3161timestamp,omitempty"`
147+
// SignatureFormat specifies the format the authority expects. Supported
148+
// formats are "legacy" and "bundle". If not specified, the default
149+
// is "legacy" (cosign's default).
150+
SignatureFormat string `json:"signatureFormat,omitempty"`
147151
}
148152

149153
// This references a public verification key stored in

pkg/apis/policy/v1beta1/clusterimagepolicy_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,10 @@ type Authority struct {
143143
// RFC3161Timestamp sets the configuration to verify the signature timestamp against a RFC3161 time-stamping instance.
144144
// +optional
145145
RFC3161Timestamp *RFC3161Timestamp `json:"rfc3161timestamp,omitempty"`
146+
// SignatureFormat specifies the format the authority expects. Supported
147+
// formats are "legacy" and "bundle". If not specified, the default
148+
// is "legacy" (cosign's default).
149+
SignatureFormat string `json:"signatureFormat,omitempty"`
146150
}
147151

148152
// This references a public verification key stored in

pkg/reconciler/trustroot/controller.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ package trustroot
1616

1717
import (
1818
"context"
19-
"time"
2019

2120
"k8s.io/client-go/tools/cache"
2221
kubeclient "knative.dev/pkg/client/injection/kube/client"
@@ -30,15 +29,14 @@ import (
3029
"github.com/sigstore/policy-controller/pkg/apis/config"
3130
trustrootinformer "github.com/sigstore/policy-controller/pkg/client/injection/informers/policy/v1alpha1/trustroot"
3231
trustrootreconciler "github.com/sigstore/policy-controller/pkg/client/injection/reconciler/policy/v1alpha1/trustroot"
32+
"github.com/sigstore/policy-controller/pkg/tuf"
3333
cminformer "knative.dev/pkg/injection/clients/namespacedkube/informers/core/v1/configmap"
3434
)
3535

3636
// This is what the default finalizer name is, but make it explicit so we can
3737
// use it in tests as well.
3838
const FinalizerName = "trustroots.policy.sigstore.dev"
3939

40-
type trustrootResyncPeriodKey struct{}
41-
4240
// NewController creates a Reconciler and returns the result of NewImpl.
4341
func NewController(
4442
ctx context.Context,
@@ -78,22 +76,8 @@ func NewController(
7876
pkgreconciler.NamespaceFilterFunc(system.Namespace()),
7977
pkgreconciler.NameFilterFunc(config.SigstoreKeysConfigName)),
8078
Handler: controller.HandleAll(grCb),
81-
}, FromContextOrDefaults(ctx)); err != nil {
79+
}, tuf.FromContextOrDefaults(ctx)); err != nil {
8280
logging.FromContext(ctx).Warnf("Failed configMapInformer AddEventHandlerWithResyncPeriod() %v", err)
8381
}
8482
return impl
8583
}
86-
87-
func ToContext(ctx context.Context, duration time.Duration) context.Context {
88-
return context.WithValue(ctx, trustrootResyncPeriodKey{}, duration)
89-
}
90-
91-
// FromContextOrDefaults returns a stored trustrootResyncPeriod if attached.
92-
// If not found, it returns a default duration
93-
func FromContextOrDefaults(ctx context.Context) time.Duration {
94-
x, ok := ctx.Value(trustrootResyncPeriodKey{}).(time.Duration)
95-
if ok {
96-
return x
97-
}
98-
return controller.DefaultResyncPeriod
99-
}

pkg/reconciler/trustroot/controller_test.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ package trustroot
1616

1717
import (
1818
"testing"
19-
"time"
2019

2120
"knative.dev/pkg/configmap"
22-
"knative.dev/pkg/controller"
2321
rtesting "knative.dev/pkg/reconciler/testing"
2422

2523
// Fake injection informers
@@ -39,21 +37,3 @@ func TestNew(t *testing.T) {
3937
t.Fatal("Expected NewController to return a non-nil value")
4038
}
4139
}
42-
43-
func TestContextDuration(t *testing.T) {
44-
ctx, _ := rtesting.SetupFakeContext(t)
45-
46-
expected := controller.DefaultResyncPeriod
47-
actual := FromContextOrDefaults(ctx)
48-
if expected != actual {
49-
t.Fatal("Expected the context to store the value and be retrievable")
50-
}
51-
52-
expected = time.Hour
53-
ctx = ToContext(ctx, expected)
54-
actual = FromContextOrDefaults(ctx)
55-
56-
if expected != actual {
57-
t.Fatal("Expected the context to store the value and be retrievable")
58-
}
59-
}

0 commit comments

Comments
 (0)