Skip to content

Conversation

@akhilerm
Copy link
Member

@akhilerm akhilerm commented Aug 29, 2023

check if the target tag that is to be created using ctr image tag is valid and does not contain any forbidden characters.

A new flag --skip-reference-check has been added so that this check for forbidden characters can be skipped.

Fixes #8844

@akhilerm
Copy link
Member Author

/cc @dmcgowan

There is also an alternate solution for this that I can think of as described here #8844 (comment)

@k8s-ci-robot
Copy link

Hi @akhilerm. Thanks for your PR.

I'm waiting for a containerd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@akhilerm
Copy link
Member Author

/cc @samuelkarp

@samuelkarp
Copy link
Member

I think my preference is the alternate approach you outlined in #8844 (comment); validating in the service would prevent any client from creating an invalid tag rather than just ctr. But @dmcgowan might have a different opinion since that's arguably a breaking change.

@akhilerm
Copy link
Member Author

/ok-to-test

@k8s-ci-robot
Copy link

@akhilerm: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

Details

In response to this:

/ok-to-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@dmcgowan
Copy link
Member

dmcgowan commented Aug 30, 2023

We have intentionally not added any sort of image name validation in the image service, this should be done by clients or components interacting with the registry. The reason being that the definition of a valid tag is highly contextual. We don't need to block users from creating a tag with + and running a container with that. If a user tries to push such a tag, then the tag validation is based on what is supported by the registry. Adding a definition and validation in the transfer service could make sense though.

What is the use case trying to be prevented here though? ctr is not a tool we expect end users to use, we generally don't add extra guardrails around it since users are expected to interact with CRI/Docker/Nerdctl for their use cases.

@thaJeztah
Copy link
Member

Also related (have not looked at the code in this PR yet, but the PR description caught my eye);

@akhilerm
Copy link
Member Author

The reason being that the definition of a valid tag is highly contextual.

Isnt this defined as per the OCI spec?

Adding a definition and validation in the transfer service could make sense though.

for that we will have to do the tagging via transfer API right, which is not enabled by default.

What is the use case trying to be prevented here though?

The images tagged by ctr with invalid tags cannot be seen by CRI as those tags are omitted

@SergeyKanzhelev might be able to provide more use cases for it.

@dmcgowan
Copy link
Member

Isnt this defined as per the OCI spec?

It is defined for image distribution and for the layout annotations, maybe elsewhere as well. We always aim to support the super set for local image management though and our data model and API really has no limitation on what the image name could be. The expectation is that image name is enforced via build tooling, registry limitations, and what is supported via import. Tag was an operation we initially didn't allow in ctr because of the belief that images creation would be done elsewhere. With support for tagging and image creation, it is still the responsibility of the user or tool to pick the right format for how the image is intended to be used.

for that we will have to do the tagging via transfer API right, which is not enabled by default.

We could switch the default for tagging to use the transfer API

The images tagged by ctr with invalid tags cannot be seen by CRI as those tags are omitted

Maybe they don't even need to be omitted. CRI does not support push anyway. Any attempt to pull or refresh the image from a registry will not succeed though.

@dmcgowan
Copy link
Member

dmcgowan commented Sep 5, 2023

I am LGTM on this if we add support for --force or some other flag to get around the reference check. Also update the reference package import from #9034

@akhilerm
Copy link
Member Author

akhilerm commented Sep 6, 2023

Will update it. Better than --force, I think we can have a --skip-reference-check for the tag command or common for all commands which can then be used to ignore the check.

check if the target tag that is to be created using ctr image tag
is valid and does not contain any forbidden characters.

Signed-off-by: Akhil Mohan <makhil@vmware.com>
@akhilerm akhilerm force-pushed the fix-ctr-forbidden-characters branch from 58eeffd to 9311b38 Compare September 6, 2023 11:32

if !context.BoolT("local") {
for _, targetRef := range context.Args()[1:] {
if _, err := reference.ParseAnyReference(targetRef); !context.Bool("skip-reference-check") && err != nil {
Copy link
Member Author

Choose a reason for hiding this comment

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

@dmcgowan Added a new flag, to skip the strict reference name check.

But IMHO, doesn't it make the code less clean?

Also, should we have this as a global flag, so that other commands can also have the flag to skip the strict checks

@akhilerm
Copy link
Member Author

akhilerm commented Sep 6, 2023

Should we also add a proper release note as this is a breaking change for the ctr images tag command.?

@akhilerm
Copy link
Member Author

Can I get another round of review on the PR? Have addressed all the comments.

Signed-off-by: Akhil Mohan <makhil@vmware.com>
@akhilerm akhilerm force-pushed the fix-ctr-forbidden-characters branch from 9311b38 to 4b59d67 Compare October 6, 2023 12:27
@akhilerm
Copy link
Member Author

akhilerm commented Oct 6, 2023

@samuelkarp Can you take a look once again. I have made the changes as suggested.

@samuelkarp samuelkarp merged commit 4205030 into containerd:main Oct 12, 2023
@samuelkarp samuelkarp removed their assignment Oct 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ctr images tag allows to create tags with the forbidden characters

6 participants