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

[APIv3] /build endpoint wrongly assumes the labels parameter is a list #9517

Closed
riyad opened this issue Feb 25, 2021 · 3 comments · Fixed by #9550
Closed

[APIv3] /build endpoint wrongly assumes the labels parameter is a list #9517

riyad opened this issue Feb 25, 2021 · 3 comments · Fixed by #9550
Assignees
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@riyad
Copy link
Contributor

riyad commented Feb 25, 2021

Is this a BUG REPORT or FEATURE REQUEST? (leave only one on its own line)

/kind bug

Description

Trying to find regressions by exercising the APIv2 trough docker-py's test suite (see #5386) I came across a bug via the BuildTest::test_build_labels test.

The /build endpoint allows to specify a set of labels with corresponding values. Podman (and by extension Buildah) wrongly assume labels are a list of strings where it should be a mapping string -> string.

In the words of the Docker API docs the labels parameter should be an "arbitrary key/value labels to set on the image, as a JSON map of string pairs".

Steps to reproduce the issue:

cat > Dockerfile <<EOF
FROM scratch
CMD sh -c "echo \'something\'
EOF
  1. tar cf test.tar Dockerfile

  2. URL encode a (flat) JSON object (e.g. with https://www.urlencoder.org/) and use it for the labels parameter:

{
  "test 1": "OK",
  "test 2": "also"
}
  1. curl -sS --unix-socket /var/run/user/1000/podman/podman.sock -XPOST 'http://localhost/v1.40/build?labels=%7B%0A%20%20%22test%201%22%3A%20%22OK%22%2C%0A%20%20%22test%202%22%3A%20%22also%22%0A%7D' -H "Content-Type: application/tar" --data-binary '@test.tar'

Describe the results you received:

Using a JSON object for labels fails with:

400 Bad Request
{"cause":"json: cannot unmarshal object into Go value of type []string","message":"failed to parse query parameter 'labels': \"{\\n  \\\"test 1\\\": \\\"OK\\\",\\n  \\\"test 2\\\": \\\"also\\\"\\n}\": json: cannot unmarshal object into Go value of type []string","response":400}

Describe the results you expected:

The image should build and the assigned labels should be visible via podman image inspect aa74af768cd | jq '.[] | .Config.Labels'

Additional information you deem important (e.g. issue happens only occasionally):

The error starts by failing to correctly parse the URL parameter as a JSON object:

https://github.com/containers/podman/blob/master/pkg/api/handlers/compat/images_build.go#L222

Changing the line to var labels = map[string]string{} fails to compile because Buildah expects this to be a list as well:

https://github.com/containers/buildah/blob/master/imagebuildah/build.go#L147

@openshift-ci-robot openshift-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Feb 25, 2021
@mheon
Copy link
Member

mheon commented Feb 25, 2021

@rhatdan @baude @jwhonce This is another tricky case - I think we need to retain the []string to not cause an API change, but we also need to accept maps for Docker-compat

@baude
Copy link
Member

baude commented Feb 25, 2021

i dont, it's a bug ...

@baude baude self-assigned this Feb 25, 2021
@rhatdan
Copy link
Member

rhatdan commented Feb 25, 2021

I agree it's a bug.

baude added a commit to baude/podman that referenced this issue Mar 2, 2021
The compatibility endpoint for build labels should be of type dict (not
list).  For backwards compatibility, we support both.

Fixes: containers#9517

Signed-off-by: baude <[email protected]>
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 22, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants