-
Notifications
You must be signed in to change notification settings - Fork 30
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
Provide all components as additional input to policy check #1737
Provide all components as additional input to policy check #1737
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1737 +/- ##
==========================================
+ Coverage 80.28% 86.92% +6.64%
==========================================
Files 67 78 +11
Lines 4874 5231 +357
==========================================
+ Hits 3913 4547 +634
+ Misses 961 684 -277
Flags with carried forward coverage won't be shown. Click here to find out more.
|
317c90f
to
1270117
Compare
cmd/validate/image.go
Outdated
@@ -42,7 +42,7 @@ import ( | |||
validate_utils "github.com/enterprise-contract/ec-cli/internal/validate" | |||
) | |||
|
|||
type imageValidationFunc func(context.Context, app.SnapshotComponent, policy.Policy, []evaluator.Evaluator, bool) (*output.Output, error) | |||
type imageValidationFunc func(context.Context, app.SnapshotComponent, policy.Policy, []evaluator.Evaluator, bool, []app.SnapshotComponent) (*output.Output, error) |
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.
Could pass in the whole snapshot spec:
type imageValidationFunc func(context.Context, app.SnapshotComponent, policy.Policy, []evaluator.Evaluator, bool, []app.SnapshotComponent) (*output.Output, error) | |
type imageValidationFunc func(context.Context, app.SnapshotComponent, app.SnapshotSpec, policy.Policy, []evaluator.Evaluator, bool) (*output.Output, error) |
cmd/validate/image.go
Outdated
log.Debugf("Starting worker %d", id) | ||
for comp := range jobs { | ||
log.Debugf("Worker %d got a component %q", id, comp.ContainerImage) | ||
ctx := cmd.Context() | ||
out, err := validate(ctx, comp, data.policy, evaluators, data.info) | ||
log.Debugf("Worker %d got appComponents %v", id, appComponents) |
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.
This might be a bit too verbose, IIRC the whole app snapshot is logged before
} | ||
|
||
// WriteInputFile writes the JSON from the attestations to input.json in a random temp dir | ||
func (a *ApplicationSnapshotImage) WriteInputFile(ctx context.Context) (string, []byte, error) { | ||
func (a *ApplicationSnapshotImage) WriteInputFile(ctx context.Context, allcomp []app.SnapshotComponent) (string, []byte, error) { |
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.
Rather that doing this, hold the *app.SnapshotSpec
in the ApplicationSnapshotImage
struct
internal/image/validate_test.go
Outdated
@@ -146,7 +146,7 @@ func TestBuiltinChecks(t *testing.T) { | |||
client := ecoci.NewClient(ctx) | |||
c.setup(client.(*fake.FakeClient)) | |||
|
|||
actual, err := ValidateImage(ctx, c.component, p, evaluators, false) | |||
actual, err := ValidateImage(ctx, c.component, p, evaluators, false, []app.SnapshotComponent{}) |
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.
Could make the test a bit more realistic an include the component that is validated in the array
Image image `json:"image"` | ||
Attestations []attestationData `json:"attestations"` | ||
Image image `json:"image"` | ||
AllComponents []app.SnapshotComponent `json:"allcomponents"` |
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 think some camel case would be more conventional here:
AllComponents []app.SnapshotComponent `json:"allcomponents"` | |
AllComponents []app.SnapshotComponent `json:"allComponents"` |
Looks pretty good so far. |
The acceptance test failures looks like some missing |
4c37650
to
cf01797
Compare
@simonbaird @zregvart Thank you for the review! I addressed the suggestions. Can I please request you to take another look? |
/ok-to-test |
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.
Naming suggestions, otherwise looks good
@@ -59,21 +59,23 @@ type ApplicationSnapshotImage struct { | |||
Evaluators []evaluator.Evaluator | |||
files map[string]json.RawMessage | |||
component app.SnapshotComponent | |||
snap app.SnapshotSpec |
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.
Nit, I'd use the full name
snap app.SnapshotSpec | |
snapshot app.SnapshotSpec |
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.
Done
@@ -326,6 +328,7 @@ type image struct { | |||
type Input struct { | |||
Attestations []attestationData `json:"attestations"` | |||
Image image `json:"image"` | |||
AppSnapshot app.SnapshotSpec `json:"appSnapshot"` |
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.
Makes it more alike the other fields
AppSnapshot app.SnapshotSpec `json:"appSnapshot"` | |
AppSnapshot app.SnapshotSpec `json:"snapshot"` |
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.
Done
ec-cli spawns workers with individual components of the input to perform policy check. This commit adds all input components when performing the policy check as an additional parameter. So each worker has access to all input components during policy check resolves: CVP-4191 Signed-off-by: Yashvardhan Nanavati <[email protected]>
cf01797
to
a6c123e
Compare
Thanks! |
This commit documents the modification that was introduced to the policy input in enterprise-contract#1737 to include the provided snapshot. Signed-off-by: robnester-rh <[email protected]>
This commit documents the modification that was introduced to the policy input in enterprise-contract#1737 to include the provided snapshot. Signed-off-by: robnester-rh <[email protected]>
ec-cli spawns workers with individual components of the input to perform policy check. This commit adds all input components when performing the policy check as an additional parameter. So each worker has access to all input components during policy check