Skip to content

fix: hex-encode OCI layout image name to avoid validation errors#1954

Merged
openshift-merge-bot[bot] merged 2 commits into
operator-framework:masterfrom
joelanford:fix/hex-encode-oci-layout-ref-name
Apr 15, 2026
Merged

fix: hex-encode OCI layout image name to avoid validation errors#1954
openshift-merge-bot[bot] merged 2 commits into
operator-framework:masterfrom
joelanford:fix/hex-encode-oci-layout-ref-name

Conversation

@joelanford

Copy link
Copy Markdown
Member

Description of the change:

Hex-encode the image reference string when using it as the OCI layout ref.name annotation in the containers/image registry cache. Docker tags allow characters (e.g. __) that are not valid in OCI layout ref.name annotations, causing opm render to fail with Invalid image errors for images with such tags.

The layoutKey() function hex-encodes the reference string, producing a value that is always valid per the OCI ref.name regex while remaining reversible for debugging.

Motivation for the change:

Running opm render on images with double underscores in their tags (e.g. quay.io/redhat-user-workloads/ocp-art-tenant/art-fbc:oadp-1.6__v4.22__oadp-rhel9-operator) fails because the containersimageregistry Pull method passes the raw docker reference as the OCI layout image name, and the OCI ref.name annotation format is stricter than docker tag rules.

Reviewer Checklist

  • Implementation matches the proposed design, or proposal is updated to match implementation
  • Sufficient unit test coverage
  • Sufficient end-to-end test coverage
  • Docs updated or added to /docs
  • Commit messages sensible and descriptive

Generated with Claude Code

Copilot AI review requested due to automatic review settings April 8, 2026 18:33

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the containersimageregistry OCI-layout cache keying to avoid OCI ref.name validation failures when Docker image tags contain characters that OCI layout does not permit (e.g. __). It does this by hex-encoding the full image reference string before passing it to layout.NewReference.

Changes:

  • Add layoutKey(ref string) which hex-encodes the reference into an OCI-ref-name-safe string.
  • Use layoutKey(ref.String()) when creating OCI layout references in Pull, Unpack, and Labels.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pkg/image/containersimageregistry/registry.go
Comment on lines +119 to +125
// layoutKey returns a deterministic, OCI-ref-name-safe key for the given
// image reference. Docker tags allow characters (e.g. "__") that are not
// valid in OCI layout ref.name annotations, so we hex-encode the reference
// instead of using it directly.
func layoutKey(ref string) string {
return hex.EncodeToString([]byte(ref))
}

Copilot AI Apr 8, 2026

Copy link

Choose a reason for hiding this comment

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

Changing the OCI layout key from the raw ref string to a hex-encoded value will effectively invalidate any existing on-disk cache entries when OLM_CACHE_DIR is set (preserve=true), forcing images to be re-pulled and making older cache entries unreachable by Unpack/Labels. If persistent cache reuse across runs is expected, consider a backward-compatible fallback (try the legacy raw ref.name when the new key is missing) and/or a one-time migration/cleanup strategy, or clearly document this cache-key change as a breaking cache behavior.

Copilot uses AI. Check for mistakes.

@joelanford joelanford Apr 8, 2026

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Image re-pulling is already optimized by containers/image internals and is not related to the use of the org.opencontainers.image.ref.name annotation.

That annotation is written by Pull and then read by Unpack and Labels. If someone pulls using the new Pull method, but then unpacks/gets labels with the old Unpack and Labels methods, that would be a problem. But it is not intended for different versions of the library to be used for different image interactions.

@codecov

codecov Bot commented Apr 8, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 57.71%. Comparing base (93adf40) to head (becb80f).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1954   +/-   ##
=======================================
  Coverage   57.70%   57.71%           
=======================================
  Files         139      139           
  Lines       13371    13373    +2     
=======================================
+ Hits         7716     7718    +2     
  Misses       4468     4468           
  Partials     1187     1187           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@joelanford joelanford force-pushed the fix/hex-encode-oci-layout-ref-name branch from eebc916 to 7332146 Compare April 8, 2026 20:34
joelanford and others added 2 commits April 8, 2026 16:45
Docker tags allow characters (e.g. "__") that are not valid in OCI
layout ref.name annotations. Instead of passing the raw image
reference as the OCI layout image name, hex-encode it to produce
a string that always satisfies the OCI ref.name regex.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@joelanford joelanford force-pushed the fix/hex-encode-oci-layout-ref-name branch from 7332146 to becb80f Compare April 8, 2026 20:45
@@ -0,0 +1 @@
sha256:a1bec450c104ceddbb25b252275eb59f1f1e6ca68e0ced76462042f72f7057d8 No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we care about empty new line at the end of the file?

@@ -0,0 +1 @@
sha256:a1bec450c104ceddbb25b252275eb59f1f1e6ca68e0ced76462042f72f7057d8 No newline at end of file

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same as above

@perdasilva

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci openshift-ci Bot added the lgtm Indicates that a PR is ready to be merged. label Apr 13, 2026
@grokspawn

Copy link
Copy Markdown
Contributor

/approve

@openshift-ci

openshift-ci Bot commented Apr 15, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: grokspawn

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@openshift-ci openshift-ci Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 15, 2026
@openshift-merge-bot openshift-merge-bot Bot merged commit 2c26996 into operator-framework:master Apr 15, 2026
13 checks passed
@joelanford joelanford deleted the fix/hex-encode-oci-layout-ref-name branch April 16, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants