Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable blocking specific pluggable type versions from being inserted into the log #1004

Merged
merged 1 commit into from Aug 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/rekor-cli/app/get.go
Expand Up @@ -159,7 +159,7 @@ func parseEntry(uuid string, e models.LogEntryAnon) (interface{}, error) {
if err != nil {
return nil, err
}
eimpl, err := types.NewEntry(pe)
eimpl, err := types.UnmarshalEntry(pe)
if err != nil {
return nil, err
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/entries.go
Expand Up @@ -101,7 +101,7 @@ func logEntryFromLeaf(ctx context.Context, signer signature.Signer, tc TrillianC
if err != nil {
return nil, err
}
eimpl, err := types.NewEntry(pe)
eimpl, err := types.UnmarshalEntry(pe)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -161,7 +161,7 @@ func GetLogEntryByIndexHandler(params entries.GetLogEntryByIndexParams) middlewa

func createLogEntry(params entries.CreateLogEntryParams) (models.LogEntry, middleware.Responder) {
ctx := params.HTTPRequest.Context()
entry, err := types.NewEntry(params.ProposedEntry)
entry, err := types.CreateVersionedEntry(params.ProposedEntry)
if err != nil {
return nil, handleRekorAPIError(params, http.StatusBadRequest, err, fmt.Sprintf(validationError, err))
}
Expand Down Expand Up @@ -341,7 +341,7 @@ func SearchLogQueryHandler(params entries.SearchLogQueryParams) middleware.Respo
for _, e := range params.Entry.Entries() {
e := e // https://golang.org/doc/faq#closures_and_goroutines
g.Go(func() error {
entry, err := types.NewEntry(e)
entry, err := types.UnmarshalEntry(e)
if err != nil {
return err
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/types/README.md
Expand Up @@ -8,6 +8,10 @@ Rekor supports pluggable types (aka different schemas) for entries stored in the

- Alpine Packages [schema](alpine/alpine_schema.json)
- Versions: 0.0.1
- COSE Envelopes [schema](cose/cose_schema.json)
- Versions: 0.0.1
- HashedRekord [schema](hashedrekord/hashedrekord_schema.json)
- Versions: 0.0.1
- Helm Provenance Files [schema](helm/helm_schema.json)
- Versions: 0.0.1
- In-Toto Attestations [schema](intoto/intoto_schema.json)
Expand All @@ -20,7 +24,7 @@ Rekor supports pluggable types (aka different schemas) for entries stored in the
- Versions: 0.0.1
- RPM Packages [schema](rpm/rpm_schema.json)
- Versions: 0.0.1
- COSE Envelopes [schema](cose/cose_schema.json)
- TUF Metadata [schema](tuf/tuf_schema.json)
- Versions: 0.0.1

Refer to [Rekor docs](https://docs.sigstore.dev/rekor/pluggable-types) for adding support for new types.
2 changes: 1 addition & 1 deletion pkg/types/alpine/v0.0.1/entry_test.go
Expand Up @@ -157,7 +157,7 @@ func TestCrossFieldValidation(t *testing.T) {
if err != nil {
t.Errorf("unexpected err from Unmarshalling canonicalized entry for '%v': %v", tc.caseDesc, err)
}
if _, err := types.NewEntry(pe); err != nil {
if _, err := types.UnmarshalEntry(pe); err != nil {
t.Errorf("unexpected err from type-specific unmarshalling for '%v': %v", tc.caseDesc, err)
}
}
Expand Down
26 changes: 23 additions & 3 deletions pkg/types/entries.go
Expand Up @@ -59,8 +59,28 @@ func NewProposedEntry(ctx context.Context, kind, version string, props ArtifactP
return nil, fmt.Errorf("could not create entry for kind '%v'", kind)
}

// NewEntry returns the specific instance for the type and version specified in the doc
func NewEntry(pe models.ProposedEntry) (EntryImpl, error) {
// CreateVersionedEntry returns the specific instance for the type and version specified in the doc
// This method should be used on the insertion flow, which validates that the specific version proposed
// is permitted to be entered into the log.
func CreateVersionedEntry(pe models.ProposedEntry) (EntryImpl, error) {
ei, err := UnmarshalEntry(pe)
if err != nil {
return nil, err
}
kind := pe.Kind()
if tf, found := TypeMap.Load(kind); found {
if !tf.(func() TypeImpl)().IsSupportedVersion(ei.APIVersion()) {
return nil, fmt.Errorf("entry kind '%v' does not support inserting entries of version '%v'", kind, ei.APIVersion())
}
}

return ei, nil
}

// UnmarshalEntry returns the specific instance for the type and version specified in the doc
// This method does not check for whether the version of the entry could be currently inserted into the log,
// and is useful when dealing with entries that have been persisted to the log.
func UnmarshalEntry(pe models.ProposedEntry) (EntryImpl, error) {
if pe == nil {
return nil, errors.New("proposed entry cannot be nil")
}
Expand All @@ -73,7 +93,7 @@ func NewEntry(pe models.ProposedEntry) (EntryImpl, error) {
}
return t.UnmarshalEntry(pe)
}
return nil, fmt.Errorf("could not create entry for kind '%v'", kind)
return nil, fmt.Errorf("could not unmarshal entry for kind '%v'", kind)
}

// DecodeEntry maps the (abstract) input structure into the specific entry implementation class;
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/hashedrekord/v0.0.1/entry_test.go
Expand Up @@ -285,7 +285,7 @@ func TestCrossFieldValidation(t *testing.T) {
if err != nil {
t.Errorf("unexpected err from Unmarshalling canonicalized entry for '%v': %v", tc.caseDesc, err)
}
if _, err := types.NewEntry(pe); err != nil {
if _, err := types.UnmarshalEntry(pe); err != nil {
t.Errorf("unexpected err from type-specific unmarshalling for '%v': %v", tc.caseDesc, err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/helm/v0.0.1/entry_test.go
Expand Up @@ -188,7 +188,7 @@ func TestCrossFieldValidation(t *testing.T) {
if err != nil {
t.Errorf("unexpected err from Unmarshalling canonicalized entry for '%v': %v", tc.caseDesc, err)
}
if _, err := types.NewEntry(pe); err != nil {
if _, err := types.UnmarshalEntry(pe); err != nil {
t.Errorf("unexpected err from type-specific unmarshalling for '%v': %v", tc.caseDesc, err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/intoto/v0.0.1/entry_test.go
Expand Up @@ -270,7 +270,7 @@ func TestV001Entry_Unmarshal(t *testing.T) {
if err != nil {
t.Errorf("unexpected err from Unmarshalling canonicalized entry for '%v': %v", tt.name, err)
}
canonicalEntry, err := types.NewEntry(pe)
canonicalEntry, err := types.UnmarshalEntry(pe)
if err != nil {
t.Errorf("unexpected err from type-specific unmarshalling for '%v': %v", tt.name, err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/jar/v0.0.1/entry_test.go
Expand Up @@ -108,7 +108,7 @@ func TestCrossFieldValidation(t *testing.T) {
if err != nil {
t.Errorf("unexpected err from Unmarshalling canonicalized entry for '%v': %v", tc.caseDesc, err)
}
if _, err := types.NewEntry(pe); err != nil {
if _, err := types.UnmarshalEntry(pe); err != nil {
t.Errorf("unexpected err from type-specific unmarshalling for '%v': %v", tc.caseDesc, err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/rekord/v0.0.1/entry_test.go
Expand Up @@ -233,7 +233,7 @@ func TestCrossFieldValidation(t *testing.T) {
if err != nil {
t.Errorf("unexpected err from Unmarshalling canonicalized entry for '%v': %v", tc.caseDesc, err)
}
if _, err := types.NewEntry(pe); err != nil {
if _, err := types.UnmarshalEntry(pe); err != nil {
t.Errorf("unexpected err from type-specific unmarshalling for '%v': %v", tc.caseDesc, err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/rfc3161/v0.0.1/entry_test.go
Expand Up @@ -182,7 +182,7 @@ func TestCrossFieldValidation(t *testing.T) {
if err != nil {
t.Errorf("unexpected err from Unmarshalling canonicalized entry for '%v': %v", tc.caseDesc, err)
}
if _, err := types.NewEntry(pe); err != nil {
if _, err := types.UnmarshalEntry(pe); err != nil {
t.Errorf("unexpected err from type-specific unmarshalling for '%v': %v", tc.caseDesc, err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/rpm/v0.0.1/entry_test.go
Expand Up @@ -173,7 +173,7 @@ func TestCrossFieldValidation(t *testing.T) {
if err != nil {
t.Errorf("unexpected err from Unmarshalling canonicalized entry for '%v': %v", tc.caseDesc, err)
}
if _, err := types.NewEntry(pe); err != nil {
if _, err := types.UnmarshalEntry(pe); err != nil {
t.Errorf("unexpected err from type-specific unmarshalling for '%v': %v", tc.caseDesc, err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/types/tuf/v0.0.1/entry_test.go
Expand Up @@ -208,7 +208,7 @@ func TestCrossFieldValidation(t *testing.T) {
if err != nil {
t.Errorf("unexpected err from Unmarshalling canonicalized entry for '%v': %v", tc.caseDesc, err)
}
if _, err := types.NewEntry(pe); err != nil {
if _, err := types.UnmarshalEntry(pe); err != nil {
t.Errorf("unexpected err from type-specific unmarshalling for '%v': %v", tc.caseDesc, err)
}
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/types_test.go
Expand Up @@ -65,7 +65,7 @@ func (e UnmarshalErrorValidEntry) ContextValidate(context context.Context, forma
return nil
}

func TestNewEntry(t *testing.T) {
func TestUnmarshalEntry(t *testing.T) {
type TestCase struct {
entry models.ProposedEntry
expectSuccess bool
Expand All @@ -83,7 +83,7 @@ func TestNewEntry(t *testing.T) {
}

for _, tc := range testCases {
if _, err := NewEntry(tc.entry); (err == nil) != tc.expectSuccess {
if _, err := UnmarshalEntry(tc.entry); (err == nil) != tc.expectSuccess {
t.Errorf("unexpected error creating entry of type '%v': %v", tc.entry.Kind(), err)
}
}
Expand Down