-
Notifications
You must be signed in to change notification settings - Fork 21
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
fix: Fix missing checks on product include/exclude glob for attestation. #66
Open
matglas
wants to merge
9
commits into
in-toto:main
Choose a base branch
from
matglas:fix-product-glob
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+203
−29
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7028400
fix: Fix missing checks on product include/exclude glob for attestation.
matglas 0e2edf5
fix: Fix issue with super match and exclude combined.
matglas 5ab78e6
fix: Adjust attestation output to include attestor configuration.
matglas eca3b8f
feat: Add material incl/excl glob
matglas 18b5e8b
Fix validation after failing unit tests.
matglas dfedf35
Run gofmt -s
jkjell dbd93f6
Update attestation/product/product.go
matglas 67bd420
chore: Add conditional configuration
matglas 762dc49
chore: Add changelog for attestors
matglas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Attestor Changelog | ||
|
||
## Product attestor | ||
|
||
### `v0.2` | ||
|
||
Type: https://witness.dev/attestations/product | ||
Version: `v0.2` | ||
|
||
- Attestor configuration has been added as `configuration`. | ||
- Products has been put into its own `products` field. | ||
|
||
|
||
## Material attestator | ||
|
||
### `v0.2` | ||
|
||
Type: https://witness.dev/attestations/product | ||
Version: `v0.2` | ||
|
||
- Attestor configuration has been added as `configuration`. | ||
- Material has been put into its own `materials` field. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,17 +16,23 @@ package material | |
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/gobwas/glob" | ||
"github.com/in-toto/go-witness/attestation" | ||
"github.com/in-toto/go-witness/attestation/file" | ||
"github.com/in-toto/go-witness/cryptoutil" | ||
"github.com/in-toto/go-witness/registry" | ||
"github.com/invopop/jsonschema" | ||
) | ||
|
||
const ( | ||
Name = "material" | ||
Type = "https://witness.dev/attestations/material/v0.1" | ||
Type = "https://witness.dev/attestations/material/v0.2" | ||
RunType = attestation.MaterialRunType | ||
|
||
defaultIncludeGlob = "*" | ||
defaultExcludeGlob = "" | ||
) | ||
|
||
// This is a hacky way to create a compile time error in case the attestor | ||
|
@@ -49,15 +55,68 @@ type MaterialAttestor interface { | |
} | ||
|
||
func init() { | ||
attestation.RegisterAttestation(Name, Type, RunType, func() attestation.Attestor { | ||
return New() | ||
}) | ||
attestation.RegisterAttestation(Name, Type, RunType, func() attestation.Attestor { return New() }, | ||
registry.StringConfigOption( | ||
"include-glob", | ||
"Pattern to use when recording materials. Files that match this pattern will be included as materials in the material attestation.", | ||
defaultIncludeGlob, | ||
func(a attestation.Attestor, includeGlob string) (attestation.Attestor, error) { | ||
prodAttestor, ok := a.(*Attestor) | ||
if !ok { | ||
return a, fmt.Errorf("unexpected attestor type: %T is not a material attestor", a) | ||
} | ||
|
||
WithIncludeGlob(includeGlob)(prodAttestor) | ||
return prodAttestor, nil | ||
}, | ||
), | ||
registry.StringConfigOption( | ||
"exclude-glob", | ||
"Pattern to use when recording materials. Files that match this pattern will be excluded as materials on the material attestation.", | ||
defaultExcludeGlob, | ||
func(a attestation.Attestor, excludeGlob string) (attestation.Attestor, error) { | ||
prodAttestor, ok := a.(*Attestor) | ||
if !ok { | ||
return a, fmt.Errorf("unexpected attestor type: %T is not a product attestor", a) | ||
} | ||
|
||
WithExcludeGlob(excludeGlob)(prodAttestor) | ||
return prodAttestor, nil | ||
}, | ||
), | ||
) | ||
} | ||
|
||
type Option func(*Attestor) | ||
|
||
func WithIncludeGlob(glob string) Option { | ||
return func(a *Attestor) { | ||
a.includeGlob = glob | ||
} | ||
} | ||
|
||
func WithExcludeGlob(glob string) Option { | ||
return func(a *Attestor) { | ||
a.excludeGlob = glob | ||
} | ||
} | ||
|
||
type Attestor struct { | ||
materials map[string]cryptoutil.DigestSet | ||
materials map[string]cryptoutil.DigestSet | ||
includeGlob string | ||
compiledIncludeGlob glob.Glob | ||
excludeGlob string | ||
compiledExcludeGlob glob.Glob | ||
} | ||
|
||
type attestorJson struct { | ||
Materials map[string]cryptoutil.DigestSet `json:"materials"` | ||
Configuration attestorConfiguration `json:"configuration"` | ||
matglas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
type attestorConfiguration struct { | ||
IncludeGlob string `json:"includeGlob"` | ||
ExcludeGlob string `json:"excludeGlob"` | ||
} | ||
|
||
func (a *Attestor) Name() string { | ||
|
@@ -90,7 +149,19 @@ func (a *Attestor) Schema() *jsonschema.Schema { | |
} | ||
|
||
func (a *Attestor) Attest(ctx *attestation.AttestationContext) error { | ||
materials, err := file.RecordArtifacts(ctx.WorkingDir(), nil, ctx.Hashes(), map[string]struct{}{}, false, map[string]bool{}) | ||
compiledIncludeGlob, err := glob.Compile(a.includeGlob) | ||
if err != nil { | ||
return err | ||
} | ||
a.compiledIncludeGlob = compiledIncludeGlob | ||
|
||
compiledExcludeGlob, err := glob.Compile(a.excludeGlob) | ||
if err != nil { | ||
return err | ||
} | ||
a.compiledExcludeGlob = compiledExcludeGlob | ||
|
||
materials, err := file.RecordArtifacts(ctx.WorkingDir(), nil, ctx.Hashes(), map[string]struct{}{}, false, map[string]bool{}, compiledIncludeGlob, compiledExcludeGlob) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -100,16 +171,36 @@ func (a *Attestor) Attest(ctx *attestation.AttestationContext) error { | |
} | ||
|
||
func (a *Attestor) MarshalJSON() ([]byte, error) { | ||
return json.Marshal(a.materials) | ||
output := attestorJson{ | ||
Materials: a.materials, | ||
} | ||
|
||
if a.includeGlob != "" || a.excludeGlob != "" { | ||
config := attestorConfiguration{} | ||
|
||
if a.includeGlob != "" { | ||
config.IncludeGlob = a.includeGlob | ||
} | ||
if a.excludeGlob != "" { | ||
config.ExcludeGlob = a.excludeGlob | ||
} | ||
} | ||
|
||
return json.Marshal(output) | ||
} | ||
|
||
func (a *Attestor) UnmarshalJSON(data []byte) error { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll need to make this backwards compatible. I think we can check |
||
mats := make(map[string]cryptoutil.DigestSet) | ||
if err := json.Unmarshal(data, &mats); err != nil { | ||
attestation := attestorJson{ | ||
Materials: make(map[string]cryptoutil.DigestSet), | ||
} | ||
|
||
if err := json.Unmarshal(data, &attestation); err != nil { | ||
return err | ||
} | ||
|
||
a.materials = mats | ||
a.materials = attestation.Materials | ||
a.includeGlob = attestation.Configuration.IncludeGlob | ||
a.excludeGlob = attestation.Configuration.ExcludeGlob | ||
return nil | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jkjell I was just thinking if we might need to mention somewhere that the version is bumped. Like a changelog of some sorts? This will break current policies that are in place. Same goes for the product.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added CHANGELOG-ATTESTORS.md.