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

Add support for fetching images across all projects #14260

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

kadinsayani
Copy link
Contributor

Resolves #14126.

This PR adds support for fetching images across all projects by adding a query parameter all-projects and doGetImagesAllProjects(). I've also added a client function to lxd_images.go if we ever want to use this feature in the LXD CLI.

Signed-off-by: Kadin Sayani <kadin.sayani@canonical.com>
Signed-off-by: Kadin Sayani <kadin.sayani@canonical.com>
@github-actions github-actions bot added Documentation Documentation needs updating API Changes to the REST API labels Oct 10, 2024
Copy link

Heads up @mionaalex - the "Documentation" label was applied to this issue.

…all projects

Signed-off-by: Kadin Sayani <kadin.sayani@canonical.com>
Signed-off-by: Kadin Sayani <kadin.sayani@canonical.com>
@kadinsayani kadinsayani force-pushed the 14126-add-all-projects-support-to-fetch-images branch from 80348bf to 9c8ceab Compare October 11, 2024 00:07
}

for _, projectName := range projects {
images, err := doImagesGet(ctx, tx, true, projectName, public, clauses, hasPermission)
Copy link
Member

Choose a reason for hiding this comment

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

Why is the recursion parameter hardcoded to true? And yet in imagesGet it is passed to doImagesGet via the util.IsRecursionRequest(r) call?

Copy link
Contributor Author

@kadinsayani kadinsayani Oct 14, 2024

Choose a reason for hiding this comment

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

For the images endpoint there is an option to fetch image fingerprints or image structs (based on the recursion parameter). For this new feature, I've hardcoded recursion to true to match the spec of fetching all image structs across all projects. I'm assuming image structs are required since the GH issue requirements specify a need for image.Name. We don't want to change the behaviour of doImagesGet() with this change, so when the all-projects parameter is set to false, util.IsRecursionRequest(r) is passed into doImagesGet().

Copy link
Member

Choose a reason for hiding this comment

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

It is expected that this API endpoint behaves in the same way as other endpoints in LXD, namely that all-projects influences which resources are returned, and recursion controls whether or not they are returned as a URL list or as a struct. The all-projects parameter should not change the format that the resources are returned in, so hardcoding true here seems wrong to me.

Also ive assigned you some Incus imports related to all-projects to consider whilst you're working on this.

Finally we should ask @markylaing to advise on what authz checks we should be making to ensure we dont list access to the wrong images.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good 👍 I’ll take a look at those Incus imports tomorrow - thanks for pointing them out!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reviewed the Incus imports. Their implementation also includes support for a --all-projects flag in the CLI. It appears that they’ve extended this feature to other client interactions, such as networks and profiles. I think it's a good idea to adjust this PR to incorporate Incus cherry-picks relating to fetching images across all projects, along with the appropriate LXD authentication checks, to guarantee trusted client access. After that, I'll take a look at the other PR's which expand the --all-projects feature to other endpoints.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good thanks!

Copy link
Member

@tomponline tomponline left a comment

Choose a reason for hiding this comment

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

The all-projects parameter should only change which resources are returned, it should not change the output format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Changes to the REST API Documentation Documentation needs updating
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add all projects support to fetch images
2 participants