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

Provide all components as additional input to policy check #1737

Merged

Conversation

yashvardhannanavati
Copy link
Contributor

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

Copy link

codecov bot commented Jul 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.92%. Comparing base (de191f2) to head (a6c123e).
Report is 5 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            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     
Flag Coverage Δ
acceptance 71.84% <100.00%> (?)
generative 80.68% <100.00%> (+0.40%) ⬆️
integration 80.68% <100.00%> (+0.40%) ⬆️
unit 80.68% <100.00%> (+0.40%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
cmd/validate/image.go 95.23% <100.00%> (+0.31%) ⬆️
...ation_snapshot_image/application_snapshot_image.go 77.96% <100.00%> (+20.82%) ⬆️
internal/image/validate.go 73.58% <100.00%> (+0.94%) ⬆️

... and 38 files with indirect coverage changes

@@ -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)
Copy link
Member

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:

Suggested change
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)

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)
Copy link
Member

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) {
Copy link
Member

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

@@ -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{})
Copy link
Member

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"`
Copy link
Member

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:

Suggested change
AllComponents []app.SnapshotComponent `json:"allcomponents"`
AllComponents []app.SnapshotComponent `json:"allComponents"`

@simonbaird
Copy link
Member

Looks pretty good so far.

@simonbaird
Copy link
Member

The acceptance test failures looks like some missing allcomponents field in input.json specified in features/__snapshots__/validate_image.snap

@yashvardhannanavati
Copy link
Contributor Author

@simonbaird @zregvart Thank you for the review! I addressed the suggestions. Can I please request you to take another look?

@zregvart
Copy link
Member

zregvart commented Jul 4, 2024

/ok-to-test

Copy link
Member

@zregvart zregvart left a 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
Copy link
Member

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

Suggested change
snap app.SnapshotSpec
snapshot app.SnapshotSpec

Copy link
Contributor Author

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"`
Copy link
Member

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

Suggested change
AppSnapshot app.SnapshotSpec `json:"appSnapshot"`
AppSnapshot app.SnapshotSpec `json:"snapshot"`

Copy link
Contributor Author

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]>
@zregvart zregvart merged commit 1554775 into enterprise-contract:main Jul 4, 2024
13 checks passed
@zregvart
Copy link
Member

zregvart commented Jul 4, 2024

Thanks!

robnester-rh added a commit to robnester-rh/ec-cli that referenced this pull request Oct 24, 2024
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]>
robnester-rh added a commit to robnester-rh/ec-cli that referenced this pull request Oct 24, 2024
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants