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

Add ec.oci.image_manifest rego function #1357

Merged
merged 1 commit into from
Feb 22, 2024

Conversation

lcarva
Copy link
Member

@lcarva lcarva commented Feb 21, 2024

This commit adds a new custom rego function, ec.oci.image_manifest. This function retrieves the Image Manifest from an OCI registry. (It does not download the image, just its manifest.)

The main use case this is trying to achieve is validating image references that may occur in the SLSA Provenance attestation of an image being validated. For example, the SLSA Provenance may contain a link to the corresponding source container image. This function allows policy rules to be created to verify that such references actually exists.

Ref: EC-235

Copy link

codecov bot commented Feb 21, 2024

Codecov Report

Attention: 27 lines in your changes are missing coverage. Please review.

Comparison is base (379e101) 79.01% compared to head (9641116) 72.07%.
Report is 6 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1357      +/-   ##
==========================================
- Coverage   79.01%   72.07%   -6.95%     
==========================================
  Files          62       69       +7     
  Lines        4217     4612     +395     
==========================================
- Hits         3332     3324       -8     
- Misses        885     1288     +403     
Flag Coverage Δ
acceptance 72.07% <79.23%> (?)
generative ?
integration ?
unit ?

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

Files Coverage Δ
internal/evaluator/rego.go 73.52% <79.23%> (-23.66%) ⬇️

... and 64 files with indirect coverage changes

Copy link
Member

@simonbaird simonbaird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

remote.WithAuthFromKeychain(authn.DefaultKeychain),
}

image, err := oci.NewClient(bctx.Context).Image(ref, opts...)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reviewers: Took me a minute to find where it gets the image. Here ^

acceptance/examples/oci_image_manifest.rego Outdated Show resolved Hide resolved
# short_name: match
deny contains result if {
manifest := ec.oci.image_manifest(input.image.ref)
not manifest_matches(manifest)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could take the approach of failing, and then since the manifest is in the result message, match it in the snapshot, with a bit of creativity on the digest matching regex bit if we already don't have that

Copy link
Member Author

@lcarva lcarva Feb 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna leave this as is for now. I don't want to blindly replace any digest with a token, and plumbing through the different digests seems non-trivial.

internal/evaluator/rego.go Outdated Show resolved Hide resolved
internal/evaluator/rego.go Outdated Show resolved Hide resolved
This commit adds a new custom rego function, `ec.oci.image_manifest`.
This function retrieves the Image Manifest from an OCI registry. (It
does not download the image, just its manifest.)

The main use case this is trying to achieve is validating image
references that may occur in the SLSA Provenance attestation of an image
being validated. For example, the SLSA Provenance may contain a link to
the corresponding source container image. This function allows policy
rules to be created to verify that such references actually exists.

Ref: EC-235

Signed-off-by: Luiz Carvalho <[email protected]>
@lcarva lcarva merged commit bef41df into enterprise-contract:main Feb 22, 2024
14 of 15 checks passed
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