Skip to content

Add OCI functions for signing #79

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

Merged
merged 1 commit into from
Oct 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions oci.jq
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,53 @@ def sort_manifests:
sort_by(.platform | sort_split_platform)
| sort_attestations
;

# https://github.com/opencontainers/image-spec/blob/v1.1.0/image-index.md

def validate_oci_index_media_type:
if . != "application/vnd.oci.image.index.v1+json" then
error("unsupported index mediaType: \(.)")
else . end
;

def validate_oci_index:
if .schemaVersion != 2 then
error("unsupported index schemaVersion: \(.schemaVersion)")
else . end
| .mediaType |= if . then # TODO drop this conditional (BuildKit 0.14+): https://github.com/moby/buildkit/issues/4595
validate_oci_index_media_type
else . end
;

# https://github.com/opencontainers/image-spec/blob/v1.1.0/image-layout.md#oci-layout-file
def validate_oci_layout_file:
if .imageLayoutVersion != "1.0.0" then
error("unsupported imageLayoutVersion: \(.imageLayoutVersion)")
else . end
;

# https://github.com/opencontainers/image-spec/blob/v1.1.0/image-layout.md#indexjson-file
def validate_oci_layout_index:
validate_oci_index
| .manifests |= (
if length != 1 then
error("expected only one manifests entry, not \(length)")
else . end
| .[0] |= (
if .size < 0 then
error("invalid descriptor size: \(.size)")
else . end
# TODO validate .digest somehow (`crane validate`?) - would also be good to validate all descriptors recursively
| .mediaType |= validate_oci_index_media_type
)
)
;

# input: array of 'oci-layout' file contents followed by 'index.json' file contents (`jq -s 'validate_oci_layout' dir/oci-layout dir/index.json`)
def validate_oci_layout:
if length != 2 then
error("unexpected input: expecting single-document 'oci-layout' and 'index.json'")
else . end
| .[0] |= validate_oci_layout_file
| .[1] |= validate_oci_layout_index
;