Skip to content

Commit 3a3df56

Browse files
authored
enable blocking specific pluggable type versions from being inserted into the log (sigstore#1004)
Signed-off-by: Bob Callaway <bcallaway@google.com> Signed-off-by: Bob Callaway <bcallaway@google.com>
1 parent e9d59c8 commit 3a3df56

File tree

14 files changed

+43
-19
lines changed

14 files changed

+43
-19
lines changed

cmd/rekor-cli/app/get.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func parseEntry(uuid string, e models.LogEntryAnon) (interface{}, error) {
159159
if err != nil {
160160
return nil, err
161161
}
162-
eimpl, err := types.NewEntry(pe)
162+
eimpl, err := types.UnmarshalEntry(pe)
163163
if err != nil {
164164
return nil, err
165165
}

pkg/api/entries.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ func logEntryFromLeaf(ctx context.Context, signer signature.Signer, tc TrillianC
101101
if err != nil {
102102
return nil, err
103103
}
104-
eimpl, err := types.NewEntry(pe)
104+
eimpl, err := types.UnmarshalEntry(pe)
105105
if err != nil {
106106
return nil, err
107107
}
@@ -161,7 +161,7 @@ func GetLogEntryByIndexHandler(params entries.GetLogEntryByIndexParams) middlewa
161161

162162
func createLogEntry(params entries.CreateLogEntryParams) (models.LogEntry, middleware.Responder) {
163163
ctx := params.HTTPRequest.Context()
164-
entry, err := types.NewEntry(params.ProposedEntry)
164+
entry, err := types.CreateVersionedEntry(params.ProposedEntry)
165165
if err != nil {
166166
return nil, handleRekorAPIError(params, http.StatusBadRequest, err, fmt.Sprintf(validationError, err))
167167
}
@@ -341,7 +341,7 @@ func SearchLogQueryHandler(params entries.SearchLogQueryParams) middleware.Respo
341341
for _, e := range params.Entry.Entries() {
342342
e := e // https://golang.org/doc/faq#closures_and_goroutines
343343
g.Go(func() error {
344-
entry, err := types.NewEntry(e)
344+
entry, err := types.UnmarshalEntry(e)
345345
if err != nil {
346346
return err
347347
}

pkg/types/README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ Rekor supports pluggable types (aka different schemas) for entries stored in the
88

99
- Alpine Packages [schema](alpine/alpine_schema.json)
1010
- Versions: 0.0.1
11+
- COSE Envelopes [schema](cose/cose_schema.json)
12+
- Versions: 0.0.1
13+
- HashedRekord [schema](hashedrekord/hashedrekord_schema.json)
14+
- Versions: 0.0.1
1115
- Helm Provenance Files [schema](helm/helm_schema.json)
1216
- Versions: 0.0.1
1317
- In-Toto Attestations [schema](intoto/intoto_schema.json)
@@ -20,7 +24,7 @@ Rekor supports pluggable types (aka different schemas) for entries stored in the
2024
- Versions: 0.0.1
2125
- RPM Packages [schema](rpm/rpm_schema.json)
2226
- Versions: 0.0.1
23-
- COSE Envelopes [schema](cose/cose_schema.json)
27+
- TUF Metadata [schema](tuf/tuf_schema.json)
2428
- Versions: 0.0.1
2529

2630
Refer to [Rekor docs](https://docs.sigstore.dev/rekor/pluggable-types) for adding support for new types.

pkg/types/alpine/v0.0.1/entry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func TestCrossFieldValidation(t *testing.T) {
157157
if err != nil {
158158
t.Errorf("unexpected err from Unmarshalling canonicalized entry for '%v': %v", tc.caseDesc, err)
159159
}
160-
if _, err := types.NewEntry(pe); err != nil {
160+
if _, err := types.UnmarshalEntry(pe); err != nil {
161161
t.Errorf("unexpected err from type-specific unmarshalling for '%v': %v", tc.caseDesc, err)
162162
}
163163
}

pkg/types/entries.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,28 @@ func NewProposedEntry(ctx context.Context, kind, version string, props ArtifactP
5959
return nil, fmt.Errorf("could not create entry for kind '%v'", kind)
6060
}
6161

62-
// NewEntry returns the specific instance for the type and version specified in the doc
63-
func NewEntry(pe models.ProposedEntry) (EntryImpl, error) {
62+
// CreateVersionedEntry returns the specific instance for the type and version specified in the doc
63+
// This method should be used on the insertion flow, which validates that the specific version proposed
64+
// is permitted to be entered into the log.
65+
func CreateVersionedEntry(pe models.ProposedEntry) (EntryImpl, error) {
66+
ei, err := UnmarshalEntry(pe)
67+
if err != nil {
68+
return nil, err
69+
}
70+
kind := pe.Kind()
71+
if tf, found := TypeMap.Load(kind); found {
72+
if !tf.(func() TypeImpl)().IsSupportedVersion(ei.APIVersion()) {
73+
return nil, fmt.Errorf("entry kind '%v' does not support inserting entries of version '%v'", kind, ei.APIVersion())
74+
}
75+
}
76+
77+
return ei, nil
78+
}
79+
80+
// UnmarshalEntry returns the specific instance for the type and version specified in the doc
81+
// This method does not check for whether the version of the entry could be currently inserted into the log,
82+
// and is useful when dealing with entries that have been persisted to the log.
83+
func UnmarshalEntry(pe models.ProposedEntry) (EntryImpl, error) {
6484
if pe == nil {
6585
return nil, errors.New("proposed entry cannot be nil")
6686
}
@@ -73,7 +93,7 @@ func NewEntry(pe models.ProposedEntry) (EntryImpl, error) {
7393
}
7494
return t.UnmarshalEntry(pe)
7595
}
76-
return nil, fmt.Errorf("could not create entry for kind '%v'", kind)
96+
return nil, fmt.Errorf("could not unmarshal entry for kind '%v'", kind)
7797
}
7898

7999
// DecodeEntry maps the (abstract) input structure into the specific entry implementation class;

pkg/types/hashedrekord/v0.0.1/entry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ func TestCrossFieldValidation(t *testing.T) {
285285
if err != nil {
286286
t.Errorf("unexpected err from Unmarshalling canonicalized entry for '%v': %v", tc.caseDesc, err)
287287
}
288-
if _, err := types.NewEntry(pe); err != nil {
288+
if _, err := types.UnmarshalEntry(pe); err != nil {
289289
t.Errorf("unexpected err from type-specific unmarshalling for '%v': %v", tc.caseDesc, err)
290290
}
291291
}

pkg/types/helm/v0.0.1/entry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func TestCrossFieldValidation(t *testing.T) {
188188
if err != nil {
189189
t.Errorf("unexpected err from Unmarshalling canonicalized entry for '%v': %v", tc.caseDesc, err)
190190
}
191-
if _, err := types.NewEntry(pe); err != nil {
191+
if _, err := types.UnmarshalEntry(pe); err != nil {
192192
t.Errorf("unexpected err from type-specific unmarshalling for '%v': %v", tc.caseDesc, err)
193193
}
194194
}

pkg/types/intoto/v0.0.1/entry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func TestV001Entry_Unmarshal(t *testing.T) {
270270
if err != nil {
271271
t.Errorf("unexpected err from Unmarshalling canonicalized entry for '%v': %v", tt.name, err)
272272
}
273-
canonicalEntry, err := types.NewEntry(pe)
273+
canonicalEntry, err := types.UnmarshalEntry(pe)
274274
if err != nil {
275275
t.Errorf("unexpected err from type-specific unmarshalling for '%v': %v", tt.name, err)
276276
}

pkg/types/jar/v0.0.1/entry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func TestCrossFieldValidation(t *testing.T) {
108108
if err != nil {
109109
t.Errorf("unexpected err from Unmarshalling canonicalized entry for '%v': %v", tc.caseDesc, err)
110110
}
111-
if _, err := types.NewEntry(pe); err != nil {
111+
if _, err := types.UnmarshalEntry(pe); err != nil {
112112
t.Errorf("unexpected err from type-specific unmarshalling for '%v': %v", tc.caseDesc, err)
113113
}
114114
}

pkg/types/rekord/v0.0.1/entry_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ func TestCrossFieldValidation(t *testing.T) {
233233
if err != nil {
234234
t.Errorf("unexpected err from Unmarshalling canonicalized entry for '%v': %v", tc.caseDesc, err)
235235
}
236-
if _, err := types.NewEntry(pe); err != nil {
236+
if _, err := types.UnmarshalEntry(pe); err != nil {
237237
t.Errorf("unexpected err from type-specific unmarshalling for '%v': %v", tc.caseDesc, err)
238238
}
239239
}

0 commit comments

Comments
 (0)