-
Notifications
You must be signed in to change notification settings - Fork 50
Add builtin functions for OCI artifacts discovery #3169
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
Open
st3penta
wants to merge
2
commits into
conforma:main
Choose a base branch
from
st3penta:EC-1655
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.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,79 @@ | ||
| package referrers | ||
|
|
||
| import rego.v1 | ||
|
|
||
| # METADATA | ||
| # custom: | ||
| # short_name: count | ||
| deny contains result if { | ||
| refs := ec.oci.image_referrers(input.image.ref) | ||
| count(refs) != 2 | ||
| result := { | ||
| "code": "referrers.count", | ||
| "msg": sprintf("Expected 2 referrers, got %d: %v", [count(refs), refs]), | ||
| } | ||
| } | ||
|
|
||
| # METADATA | ||
| # custom: | ||
| # short_name: format | ||
| deny contains result if { | ||
| descriptors := ec.oci.image_referrers(input.image.ref) | ||
| not all_descriptors_valid_format(descriptors) | ||
| result := { | ||
| "code": "referrers.format", | ||
| "msg": sprintf("Invalid referrer descriptor format in: %v", [descriptors]), | ||
| } | ||
| } | ||
|
|
||
| # METADATA | ||
| # custom: | ||
| # short_name: content_types | ||
| deny contains result if { | ||
| descriptors := ec.oci.image_referrers(input.image.ref) | ||
| not has_expected_artifact_types(descriptors) | ||
| result := { | ||
| "code": "referrers.content_types", | ||
| "msg": sprintf("Expected one signature and one attestation artifact type in referrers: %v", [descriptors]), | ||
| } | ||
| } | ||
|
|
||
| all_descriptors_valid_format(descriptors) if { | ||
| every descriptor in descriptors { | ||
| # Each descriptor should have required fields | ||
| descriptor.digest != "" | ||
| descriptor.mediaType != "" | ||
| descriptor.size >= 0 | ||
| descriptor.artifactType != "" | ||
| descriptor.ref != "" | ||
|
|
||
| # Digest should be a digest-only format: sha256:<hex> | ||
| startswith(descriptor.digest, "sha256:") | ||
| not contains(descriptor.digest, "@") | ||
|
|
||
| # Ref should be a full OCI reference with digest format: registry/repo@sha256:<hex> | ||
| contains(descriptor.ref, "@") | ||
| contains(descriptor.ref, "sha256:") | ||
| # Split by @ and verify format | ||
| parts := split(descriptor.ref, "@") | ||
| count(parts) == 2 | ||
| # Verify digest format matches | ||
| parts[1] == descriptor.digest | ||
| } | ||
| } | ||
|
|
||
| has_expected_artifact_types(descriptors) if { | ||
| # Check that we have one signature artifact directly from descriptors | ||
| signature_artifacts := [d | | ||
| some d in descriptors | ||
| d.artifactType == "application/vnd.dev.cosign.simplesigning.v1+json" | ||
| ] | ||
| count(signature_artifacts) == 1 | ||
|
|
||
| # Check that we have one attestation artifact directly from descriptors | ||
| attestation_artifacts := [d | | ||
| some d in descriptors | ||
| d.artifactType == "application/vnd.dsse.envelope.v1+json" | ||
| ] | ||
| count(attestation_artifacts) == 1 | ||
| } | ||
This file contains hidden or 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,75 @@ | ||
| package tag_refs | ||
|
|
||
| import rego.v1 | ||
|
|
||
| # METADATA | ||
| # custom: | ||
| # short_name: count | ||
| deny contains result if { | ||
| refs := ec.oci.image_tag_refs(input.image.ref) | ||
| count(refs) != 2 | ||
| result := { | ||
| "code": "tag_refs.count", | ||
| "msg": sprintf("Expected 2 tag-based artifact references, got %d: %v", [count(refs), refs]), | ||
| } | ||
| } | ||
|
|
||
| # METADATA | ||
| # custom: | ||
| # short_name: format | ||
| deny contains result if { | ||
| refs := ec.oci.image_tag_refs(input.image.ref) | ||
| not all_refs_valid_format(refs) | ||
| result := { | ||
| "code": "tag_refs.format", | ||
| "msg": sprintf("Invalid tag reference format in: %v", [refs]), | ||
st3penta marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
|
|
||
| # METADATA | ||
| # custom: | ||
| # short_name: sig_count | ||
| deny contains result if { | ||
| refs := ec.oci.image_tag_refs(input.image.ref) | ||
| sig_count := count([ref | some ref in refs; contains(ref, ".sig")]) | ||
| sig_count != 1 | ||
| result := { | ||
| "code": "tag_refs.sig_count", | ||
| "msg": sprintf("Expected 1 .sig reference, got %d", [sig_count]), | ||
| } | ||
| } | ||
|
|
||
| # METADATA | ||
| # custom: | ||
| # short_name: att_count | ||
| deny contains result if { | ||
| refs := ec.oci.image_tag_refs(input.image.ref) | ||
| att_count := count([ref | some ref in refs; contains(ref, ".att")]) | ||
| att_count != 1 | ||
| result := { | ||
| "code": "tag_refs.att_count", | ||
| "msg": sprintf("Expected 1 .att reference, got %d", [att_count]), | ||
| } | ||
| } | ||
|
|
||
| all_refs_valid_format(refs) if { | ||
| every ref in refs { | ||
| # Each ref should be a valid OCI reference with tag format: registry/repo:sha256-<hex>.<suffix> | ||
| contains(ref, ":") | ||
| contains(ref, "sha256-") | ||
| # Split by : and get the last part (the tag) | ||
| parts := split(ref, ":") | ||
| tag_part := parts[count(parts) - 1] | ||
| # Tag should start with sha256- and end with .sig or .att | ||
| startswith(tag_part, "sha256-") | ||
| valid_suffix(tag_part) | ||
| } | ||
| } | ||
|
|
||
| valid_suffix(tag) if { | ||
| endswith(tag, ".sig") | ||
| } | ||
|
|
||
| valid_suffix(tag) if { | ||
| endswith(tag, ".att") | ||
| } | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.