The Open Container Initiative (OCI) is inching closer to a v1.1 release which provides official guidance on how to connect things in a registry. In our blog post from last year Intro to OCI Reference Types, we walkthrough the current state of OCI and why these changes are becoming increasingly necessary in the realm of supply chain security.
Latest developments in OCI land
The OCI Reference Types Working Group has completed its mission in proposing how to describe and query relationships between objects stored in an OCI registry. The group is no longer meeting, and the project has been archived. Proposal E (“cherry pick”) was introduced, which combined various ideas from other proposals. The changes defined in Proposal E were then organized and submitted as pull requests which were subsequently approved by OCI spec maintainers:
All that is left to do is to cut v1.1 releases for both distribution-spec and image-spec for these new features to be considered OCI-supported.
Since the PRs above have been merged, there have been small updates made to the specs to solidify some of the proposed behavior. There has also been some ongoing debate regarding some of the more controversial changes. Despite the delay, members of the OCI community appear determined to resolve these issues and release v1.1 specs as soon as possible.
What OCI v1.1 means for cosign
As we described in Intro to OCI Reference Types, cosign has already “solved” the problem of relationships between objects in registries. It does so using a method that the OCI community has come to refer to as “polluting the tag space”.
As a recap, cosign takes the SHA256 checksum of an image, and pushes a tag to the registry in the following format:
This approach works just fine, but presents a couple downsides:
In OCI v1.1, a variation of this approach has been introduced called the “Referrers Tag Schema”. Instead of publishing a new tag for each attachment, the following tag is updated by the client each time a new reference is added:
The manifest published to this tag should be a valid OCI Image Index. In the manifests array should be a list of all references to this image. Here is an example of what this might look like:
Notice in the JSON above the new artifactType field. This is how arbitrary types in the registry can be distinguished instead of appending “.sig” or “.sbom” to the tag. The artifactType is derived from the config.mediaType field on the manifest of the attachment. For example, here is what the beginning of an SBOM manifest might look like:
Keep in mind that this is the same method that Helm, OPA, and other tools have already started storing arbitrary content. If you’ve ever come across the opaque term “OCI Artifacts”, this is what we are talking about. Even though this method and terminology have been around for a long time now, OCI never officially codified this into a specification.
In OCI v1.1, the config.mediaType field is considered important, as it maps to the artifactType field when we are dealing with references. The underlying behavior of “OCI Artifacts” will finally be considered a supported mechanism for storing arbitrary content in a registry! You can learn more about the term "OCI Artifacts" on Chainguard Academy.
So I still need to use tags?
The Referrers Tag Schema described above is considered in OCI v1.1 to be simply a fallback mechanism. This means that this behavior should work in existing v1.0 registries without any changes needed.
One of the biggest additions in OCI v1.1 is the new “Referrers API”. This defines a brand new endpoint on the registry which allows fetching a dynamic list of references:
The response of this call should be identical to OCI Image Index described above using the Referrers Tag Schema. This means clients can first check this endpoint for references, and if a 404 is returned, then the client can try to fetch the fallback tag. This response from either request should be able to be processed in the exact same way.
The Referrers API has additional features such as pagination and the ability to filter by artifactType (e.g., “give me only SBOMs”).
In addition, if a registry supports the Referrers API, no additional tags are needed! This is enabled by another feature coming in OCI v1.1 - a new field on the OCI Image Manifest called subject.
When publishing an “OCI Artifact”, you can include an optional subject section which points to an image which this artifact references:
When uploading a manifest to the registry containing a subject section, a registry supporting the Referrers API is required to respond with the following HTTP header to indicating that the subject was processed:
OCI-Subject: <subject digest>
If this header is detected, then the client knows that it does not need to upload a fallback tag using the Referrers Tag Schema.
Putting the pieces together
Even though OCI v1.1 has not yet been officially released, we decided to put together a prototype of cosign using some of these new features. You can find a working version of this prototype on cosign main.
This prototype is powered by an unreleased version of google/go-containerregistry (“GGCR”), which is the library that cosign leverages under the hood to work with OCI registries.
Here we will walk through the new behavior found in the prototype.
Note: if you are trying these steps against a different registry, it must accept the new subject field. Most OCI v1.0 registries should allow this. If they do not, they are technically out of compliance.
First clone the repo and build cosign:
Next, set the COSIGN_EXPERIMENTAL environment variable to enable the new behavior:
We will need a registry to work with. First, let's try using an OCI v1.0 registry (one that does not support the new Referrers API). We can run a local instance of CNCF Distribution on port 5001 in the background:
Next, let’s copy an existing image into the registry using crane:
Create a dummy SBOM:
Now, using our locally-built version of cosign, attach this SBOM to the image:
Note the new --registry-referrers-mode flag which must be set to “oci-1-1”.
Using crane, check the list of tags on the repository:
You should notice 2 tags: a “latest” tag, as well as a tag using the Referrers Tag Schema (actual digest will vary depending on wolfi-base image):
Notice the digest tag does not have a “.sbom” suffix. Using crane and jq, take a look at the manifest for this tag:
This should look something like the following:
We can also inspect the manifest of the SBOM itself:
This should look something like the following:
Notice the config.mediaType on this manifest indicating the artifactType, as well as the subject section pointing to the digest of the image.
So that’s neat and all, but what would happen if we were using an OCI v.1.1 registry?
We can use zot, an open-source registry which has been closely tracking the progress of OCI v1.1 and has support for the Referrers API.
Let’s start a local zot registry in the background on another port (5002):
Once again, copy an image and attach an SBOM:
Now list the tags:
This time we should only see just one tag: “latest”:
So where is the SBOM?
Since zot supports the Referrers API, cosign does not have to create the digest tag, but should still be able to retrieve SBOM since it was uploaded with a subject section.
To prove it, we can try downloading the SBOM:
That should return us the contents of the dummy SBOM:
If you rerun the previous command with the --verbose flag and inspect the logs, you can see all of the HTTP requests made to the registry. Here you will find evidence of cosign making calls to the Referrers API (ctrl+f “referrers”):
When you’re done playing around, make sure to shutdown your local registry instances:
We will continue to work with the OCI community in making the v1.1 release a reality. Once this is finalized, you can expect to see some form of stable support land in an upcoming cosign release. Learn more about the OCI project on Chainguard Academy.