Skip to content

api: implement compat distribution inspect endpoint#28358

Open
aaron-ang wants to merge 1 commit into
containers:mainfrom
aaron-ang:issue-17726-distribution-api
Open

api: implement compat distribution inspect endpoint#28358
aaron-ang wants to merge 1 commit into
containers:mainfrom
aaron-ang:issue-17726-distribution-api

Conversation

@aaron-ang
Copy link
Copy Markdown
Contributor

@aaron-ang aaron-ang commented Mar 25, 2026

Fixes #17726.

Checklist

Ensure you have completed the following checklist for your pull request to be reviewed:

  • Certify you wrote the patch or otherwise have the right to pass it on as an open-source patch by signing all
    commits. (git commit -s). (If needed, use git commit -s --amend). The author email must match
    the sign-off email address. See CONTRIBUTING.md
    for more information.
  • Referenced issues using Fixes: #00000 in commit message (if applicable)
  • Tests have been added/updated (or no tests are needed)
  • Documentation has been updated (or no documentation changes are needed)
  • All commits pass make validatepr (format/lint checks)
  • Release note entered in the section below (or None if no user-facing changes)

Does this PR introduce a user-facing change?

Added Docker-compatible support for the `/distribution/{name}/json` API endpoint.

@github-actions github-actions Bot added the kind/api-change Change to remote API; merits scrutiny label Mar 25, 2026
@aaron-ang aaron-ang force-pushed the issue-17726-distribution-api branch 3 times, most recently from df2ff09 to 12e4664 Compare March 30, 2026 01:52
@aaron-ang aaron-ang marked this pull request as ready for review March 30, 2026 01:52
@aaron-ang aaron-ang force-pushed the issue-17726-distribution-api branch from 12e4664 to 8dd8fed Compare March 30, 2026 03:03
Comment thread pkg/api/handlers/compat/distribution.go Outdated
func DistributionInspect(w http.ResponseWriter, r *http.Request) {
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
imageName := utils.GetName(r)
if _, err := reference.ParseNormalizedNamed(imageName); err != nil {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I believe this check is redundant with the check on row 42.

Comment thread pkg/api/handlers/compat/distribution.go Outdated
}

var latestErr error
appendErr := func(e error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please use multierror

Comment thread pkg/api/server/register_distribution.go
Comment thread test/apiv2/10-images.at Outdated
t GET "/distribution/quay.io/idonotexist/idonotexist:dummy/json" 401

# Exercise the single-manifest path using a digest from the multi-arch test image.
single_manifest_digest=sha256:6953980e46925f8ac2c09fc7ecf9f353c2cac49f87e7e60ed78287d55a14c296
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I am not sure about hardcoding the manifest digest.

Comment thread pkg/api/handlers/compat/distribution.go Outdated
utils.InternalServerError(w, latestErr)
}

func distributionInspectFromManifest(ctx context.Context, src types.ImageSource, named reference.Named, manifestBytes []byte, manifestType string) (dockerRegistry.DistributionInspect, error) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this function can be simplified with things from container-libs. Please check that repository; there are definitely things that can help simplify it.

@aaron-ang
Copy link
Copy Markdown
Contributor Author

thanks for the comments @Honny1, will review and implement the changes.

@aaron-ang aaron-ang force-pushed the issue-17726-distribution-api branch 2 times, most recently from da4dd25 to d2d374f Compare April 6, 2026 05:40
@packit-as-a-service
Copy link
Copy Markdown

[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore.

3 similar comments
@packit-as-a-service
Copy link
Copy Markdown

[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore.

@packit-as-a-service
Copy link
Copy Markdown

[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore.

@packit-as-a-service
Copy link
Copy Markdown

[NON-BLOCKING] Packit jobs failed. @containers/packit-build please check. Everyone else, feel free to ignore.

@baude
Copy link
Copy Markdown
Member

baude commented Apr 6, 2026

@mtrmac mind adding this to your list of things to review at your convience ?

@aaron-ang aaron-ang force-pushed the issue-17726-distribution-api branch 2 times, most recently from 56bd7e5 to 9454b2a Compare April 7, 2026 01:29
Copy link
Copy Markdown
Contributor

@mtrmac mtrmac left a comment

Choose a reason for hiding this comment

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

(I didn’t study the Podman API integration in detail, looking mostly at the c/image parts.)

Comment thread test/apiv2/10-images.at
runtime := r.Context().Value(api.RuntimeKey).(*libpod.Runtime)
imageName := utils.GetName(r)

normalizedImageName, err := utils.NormalizeToDockerHub(r, imageName)
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.

This looks up images in local storage, and changes the results based on that. Do we want that?!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed.

Comment thread pkg/api/handlers/compat/distribution.go Outdated
sys := runtime.SystemContext()
sys.AuthFilePath = authfile
sys.DockerAuthConfig = authConf
if err := utils.PossiblyEnforceDockerHub(r, sys); err != nil {
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.

Does this do anything after NormalizeToDockerHub?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

no effect, removed.

Comment thread pkg/api/handlers/compat/distribution.go Outdated
Comment thread pkg/api/handlers/compat/distribution.go Outdated
Comment thread pkg/api/handlers/compat/distribution.go Outdated
}

var registryErrCode errcode.ErrorCoder
if errors.As(combinedErr, &registryErrCode) {
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.

(This is pretty inaccurate but I also don’t have any better ideas.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

It’s not exactly the same situation — Moby collects errors per mirror (where the last one is the primary registry), we collect errors per short name candidate (where the first one is the one we prefer).

By “pretty inaccurate” I meant that we have no good way to report “authentication error or not” when we resolve to multiple short name candidates, and the answers may differ for different candidates.

[Maybe we don’t want the short name resolution and all this goes away? I don’t know.]


I think it makes more sense to report errors for all of the short name candidates (regardless of what HTTP status we use, the text is more useful if it contains everything).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

changed back to reporting all candidate errors

Comment thread pkg/api/handlers/compat/distribution.go Outdated
Comment thread pkg/api/handlers/compat/distribution.go Outdated
@aaron-ang aaron-ang force-pushed the issue-17726-distribution-api branch 2 times, most recently from f9c45c1 to 03b2ea2 Compare April 8, 2026 04:16
Comment thread pkg/api/handlers/compat/distribution.go Outdated
sys.AuthFilePath = authfile
sys.DockerAuthConfig = authConf

resolved, err := shortnames.Resolve(sys, named.String())
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.

ParseNormalizedNamed().String() is never a short name.

I don’t know what we want to do here (compare earlier use of utils.NormalizeToDockerHub), but this specific combination doesn’t make sense.

(I think being consistent with the rest of the handlers/compat’s handling would be preferable, but I’ll leave that to experts.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(I think being consistent with the rest of the handlers/compat’s handling would be preferable, but I’ll leave that to experts.)

I think we should match other compat handlers Docker Hub normalization behavior. Becuase this API is for compatibility with Docker.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

ok, I've changed it back to use utils.NormalizeToDockerHub and corresponding reference.ParseNormalizedNamed

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.

I think we should match other compat handlers Docker Hub normalization behavior. Becuase this API is for compatibility with Docker.

Then we are back to #28358 (comment) . Is that desirable? OTOH, looking now, pulls using the compat API also do this, and that might be a pretty strong reason to have that behavior for remote inspect as well. I’ll leave that to Podman maintainers.

}

var registryErrCode errcode.ErrorCoder
if errors.As(combinedErr, &registryErrCode) {
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.

It’s not exactly the same situation — Moby collects errors per mirror (where the last one is the primary registry), we collect errors per short name candidate (where the first one is the one we prefer).

By “pretty inaccurate” I meant that we have no good way to report “authentication error or not” when we resolve to multiple short name candidates, and the answers may differ for different candidates.

[Maybe we don’t want the short name resolution and all this goes away? I don’t know.]


I think it makes more sense to report errors for all of the short name candidates (regardless of what HTTP status we use, the text is more useful if it contains everything).

Comment thread pkg/api/handlers/compat/distribution.go Outdated
sys.AuthFilePath = authfile
sys.DockerAuthConfig = authConf

resolved, err := shortnames.Resolve(sys, named.String())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(I think being consistent with the rest of the handlers/compat’s handling would be preferable, but I’ll leave that to experts.)

I think we should match other compat handlers Docker Hub normalization behavior. Becuase this API is for compatibility with Docker.

Comment thread test/apiv2/10-images.at
@aaron-ang aaron-ang force-pushed the issue-17726-distribution-api branch 2 times, most recently from 6c3c566 to dfdbc40 Compare April 16, 2026 00:53
Copy link
Copy Markdown
Member

@Honny1 Honny1 left a comment

Choose a reason for hiding this comment

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

LGTM

@Honny1
Copy link
Copy Markdown
Member

Honny1 commented Apr 17, 2026

PTAL @containers/podman-maintainers

Comment thread pkg/api/handlers/compat/distribution.go Outdated
for _, candidate := range resolved.PullCandidates {
inspect, err := inspectCandidate(r.Context(), sys, candidate.Value)
if err != nil {
merr = multierror.Append(merr, err)
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.

If we report all errors, the individual ones must be annotated with candidate.Value.String(), otherwise users would have no idea how the failures and the registries correspond.

Copy link
Copy Markdown
Contributor Author

@aaron-ang aaron-ang Apr 17, 2026

Choose a reason for hiding this comment

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

thanks, i've added the annotation using the format candidate.Value.String(): error

@aaron-ang aaron-ang force-pushed the issue-17726-distribution-api branch from dfdbc40 to 1018613 Compare April 17, 2026 23:47
@Honny1
Copy link
Copy Markdown
Member

Honny1 commented Apr 29, 2026

@aaron-ang, can you please rebase on main? Thanks

Signed-off-by: Aaron Ang <aaron.angyd@gmail.com>
@aaron-ang aaron-ang force-pushed the issue-17726-distribution-api branch from 1018613 to 0a72f99 Compare May 1, 2026 18:39
@packit-as-a-service
Copy link
Copy Markdown

Cockpit tests failed for commit 0a72f99. @martinpitt, @jelly, @mvollmer please check.

@aaron-ang
Copy link
Copy Markdown
Contributor Author

aaron-ang commented May 10, 2026

Hi there, could you let me know if I need to rebase or fix my tests? I can't tell if the CI failures are due to my changes. Thanks!

@mheon
Copy link
Copy Markdown
Member

mheon commented May 10, 2026

The remaining two are allowed failures, this is actually merge ready now

Copy link
Copy Markdown
Member

@mheon mheon left a comment

Choose a reason for hiding this comment

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

LGTM
@containers/podman-maintainers PTAL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/api-change Change to remote API; merits scrutiny

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Distribution API seems missing

5 participants