Skip to content
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

Handle filters reference more like Docker does #826

Closed
wants to merge 1 commit into from

Conversation

rhatdan
Copy link
Member

@rhatdan rhatdan commented Nov 10, 2021

Currently we match reference, which is incorrect.
Docker hard codes the current registry and matches the reference
exactly, allowing users to pass in globs.

This fix will truncate the registry name and localhost/ as well has
the constant library/ off of images and then attempt to match.

Helps Fix: containers/podman#11905

Signed-off-by: Daniel J Walsh [email protected]

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Nov 10, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rhatdan

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

The pull request process is described here

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

"foo.bar",
"registry.access.redhat.com",
}
names := []string{

Choose a reason for hiding this comment

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

no test for bar not matching localhost/foobar (as in containers/podman#11905)? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Added a match for *box to match busybox

Choose a reason for hiding this comment

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

I was rather thinking about ensuring that with "localhost/foo:latest" and "localhost/foobar:latest" in names a test for {"bar:*", 1} succeeds.

@rhatdan
Copy link
Member Author

rhatdan commented Nov 11, 2021

@vrothberg @giuseppe @flouthoc PTAL

for _, reg := range registries {
newName = strings.TrimPrefix(name, reg+"/")
newName = strings.TrimPrefix(newName, "library/")
fmt.Println("DAN", filter, newName)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is left here by mistake. Could we remove this Println

Copy link
Collaborator

@flouthoc flouthoc left a comment

Choose a reason for hiding this comment

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

Should we test this against a PR with podman. Couple of nits.

if err != nil {
return nil, err
}
return filterImages(images, filters, append([]string{"localhost"}, registries...))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure but i think filterImages has a signature func filterImages(images []*Image, filters []filterFunc, registries []string) . I think this should fail with too many arguments in call to filterImages but haven't tried running with podman.

Copy link
Collaborator

Choose a reason for hiding this comment

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

no my bad this is correct i missed closing )

@flouthoc
Copy link
Collaborator

LGTM just one nit #826 (comment)

@vrothberg
Copy link
Member

vrothberg commented Nov 12, 2021

Please don't merge. I want to have a look at the exact behavior of Docker.

@@ -16,11 +16,11 @@ import (

// filterFunc is a prototype for a positive image filter. Returning `true`
// indicates that the image matches the criteria.
type filterFunc func(*Image) (bool, error)
type filterFunc func(*Image, []string) (bool, error)
Copy link
Member

Choose a reason for hiding this comment

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

Can you turn []string to []interface{} to make it generic?

@@ -158,33 +158,54 @@ func (r *Runtime) compileImageFilters(ctx context.Context, options *ListImagesOp
return filterFuncs, nil
}

func filterNames(filter string, names, registries []string) (bool, error) {
Copy link
Member

Choose a reason for hiding this comment

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

The entire function should be replaced with https://github.com/containers/image/blob/main/docker/reference/helpers.go#L36. That will match the exact behavior of Docker (I tracked it down in the moby code).

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't believe that is true. We need to remove the registry just like docker remove docker.io to be our own flavor. But if you have other ideas, I say take this PR over and make it the way you believe it should be.

Copy link
Member

Choose a reason for hiding this comment

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


// filterImages returns a slice of images which are passing all specified
// filters.
func filterImages(images []*Image, filters []filterFunc) ([]*Image, error) {
func filterImages(images []*Image, filters []filterFunc, registries []string) ([]*Image, error) {
Copy link
Member

Choose a reason for hiding this comment

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

registries should be of type []c/image/docker/reference.Reference.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why? registries, err := sysregistriesv2.UnqualifiedSearchRegistries(r.systemContextCopy())
Returns a []string

Seems like we would need to convert this to string to a reference only later to be converted back to a string.

Copy link
Member

Choose a reason for hiding this comment

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

Currently we match *reference*, which is incorrect.
Docker hard codes the current registry and matches the reference
exactly, allowing users to pass in globs.

This fix will truncate the registry name and localhost/ as well has
the constant library/ off of images and then attempt to match.

Helps Fix: containers/podman#11905

Signed-off-by: Daniel J Walsh <[email protected]>
@rhatdan
Copy link
Member Author

rhatdan commented Nov 15, 2021

@vrothberg PTAL

@rhatdan
Copy link
Member Author

rhatdan commented Nov 23, 2021

@vrothberg I would like to move forward on this.

@rhatdan
Copy link
Member Author

rhatdan commented Dec 2, 2021

@vrothberg Friendly ping.

@vrothberg
Copy link
Member

@vrothberg Friendly ping.

Thanks! I was buried in the docker.io enforcement work but have some cycles today.

@vrothberg vrothberg closed this Dec 3, 2021
@vrothberg
Copy link
Member

-> #847

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

unbound reference filter pattern
4 participants