Skip to content

Commit

Permalink
Add Timestamp validation in Provenance build metadata
Browse files Browse the repository at this point in the history
Signed-off-by: Marcela Melara <[email protected]>
  • Loading branch information
marcelamelara committed Sep 25, 2023
1 parent 43f3d9b commit 5e5cbba
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions go/predicates/provenance/v1/provenance.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ var (
ErrRunDetailsRequired = errors.New("RunDetails required")
)

func (m *BuildMetadata) Validate() error {
// check valid timestamps
s := m.GetStartedOn()
if s != nil {
if err := s.CheckValid(); err != nil {
return err
}
}

f := m.GetFinishedOn()
if f != nil {
if err := f.CheckValid(); err != nil {
return err
}
}

return nil
}

func (b *Builder) Validate() error {
// the id field is required for SLSA Build L1
if b.GetId() == "" {
Expand Down Expand Up @@ -73,6 +92,14 @@ func (r *RunDetails) Validate() error {
return err
}

// check the Metadata, if present
metadata := r.GetMetadata()
if metadata != nil {
if err := metadata.Validate(); err != nil {
return fmt.Errorf("Invalid RunDetails.Metadata: %w", err)
}
}

// check that all byproducts are valid RDs
byproducts := r.GetByproducts()
if len(byproducts) > 0 {
Expand Down

0 comments on commit 5e5cbba

Please sign in to comment.