Skip to content

ContainerRegistry: Reject invalid image tags and digests #142

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
Jul 1, 2025

Conversation

euanh
Copy link
Collaborator

@euanh euanh commented Jul 1, 2025

Motivation

Cherry pick of #140.

ImageReference does not check for illegal characters in parsed image digests and tags. This means that containertool will send illegal image
names to the registry. The registry will reject them, but the error message might not explain why, so a generic error message will be printed. Runtimes reject illegal image references immediately, without sending them to the registry.

Some desktop runtimes accept local image names which the registry will reject; other runtimes reject these names even for local names. containertool
now also rejects them.

Modifications

  • Check validity of tags and digests when parsing image names
  • Change the low-level API functions to accept Digest or Reference instead of String.

Result

It is impossible to create a Repository object containing a malformed tag or digest, because the constructor checks the string value. It is impossible
to send a malformed name to the registry because the API wrappers only accept Digest or Reference (Digest | Tag) objects.

Fixes #139

Test Plan

Existing tests continue to pass.
New tests exercise additional checks which were previously missing. Removed tests which checked tags which seemed to be accepted by some desktop runtimes, but which were not accepted by registries.

Motivation
----------

`ImageReference` does not check for illegal characters in parsed image
digests and tags. This means that `containertool` will send illegal
image
names to the registry. The registry will reject them, but the error
message might not explain why, so a generic error message will be
printed. Runtimes reject illegal image references immediately, without
sending them to the registry.

Some desktop runtimes accept local image names which the registry will 
reject; other runtimes reject these names even for local names.
`containertool`
now also rejects them.

Modifications
-------------

* Check validity of tags and digests when parsing image names
* Change the low-level API functions to accept `Digest` or `Reference`
instead of `String`.

Result
------

It is impossible to create a `Repository` object containing a malformed
tag or digest, because the constructor checks the string value. It is
impossible
to send a malformed name to the registry because the API wrappers only
accept `Digest` or `Reference (Digest | Tag)` objects.

Fixes apple#139 

Test Plan
---------

Existing tests continue to pass.
New tests exercise additional checks which were previously missing.
Removed tests which checked tags which seemed to be accepted by some
desktop runtimes, but which were not accepted by registries.
@euanh euanh added kind/bug Something isn't working semver/patch No public API change. kind/cherry-pick Back-port changes from one release or branch to another labels Jul 1, 2025
@euanh euanh merged commit 4ffc546 into apple:release/1.0 Jul 1, 2025
23 checks passed
@euanh euanh deleted the cherry-pick-validate-tags branch July 1, 2025 13:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working kind/cherry-pick Back-port changes from one release or branch to another semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant