[APIv3] /build endpoint wrongly assumes the labels parameter is a list #9517
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.
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:
tar cf test.tar Dockerfile
URL encode a (flat) JSON object (e.g. with https://www.urlencoder.org/) and use it for the
labels
parameter: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: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
The text was updated successfully, but these errors were encountered: