From db2baee9fa0199a3abe4cd29b951fd2cd23898da Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Mon, 21 Jul 2025 19:56:54 -0400 Subject: [PATCH] API handler: don't force the IdentityLabel flag Don't force the IdentityLabel option one way or another when the client doesn't specifically request one or the other, so that the server can choose to use its default behavior. Fixes #26669 Signed-off-by: Nalin Dahyabhai --- pkg/api/handlers/compat/images_build.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go index c1c5081bae..737b7ad293 100644 --- a/pkg/api/handlers/compat/images_build.go +++ b/pkg/api/handlers/compat/images_build.go @@ -179,7 +179,6 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { Volumes []string `schema:"volume"` }{ Dockerfile: "Dockerfile", - IdentityLabel: true, Registry: "docker.io", Rm: true, ShmSize: 64 * 1024 * 1024, @@ -195,6 +194,11 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { return } + var identityLabel types.OptionalBool + if _, found := r.URL.Query()["identitylabel"]; found { + identityLabel = types.NewOptionalBool(query.IdentityLabel) + } + // if layers field not set assume its not from a valid podman-client // could be a docker client, set `layers=true` since that is the default // expected behaviour @@ -699,6 +703,9 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { } } + // Note: avoid using types.NewOptionaBool() to initialize optional bool fields of this + // struct without checking if the client supplied a value. Skipping that step prevents + // the builder from choosing/using its defaults. buildOptions := buildahDefine.BuildOptions{ AddCapabilities: addCaps, AdditionalBuildContexts: additionalBuildContexts, @@ -723,7 +730,7 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { DNSSearch: dnssearch, DNSServers: dnsservers, HTTPProxy: query.HTTPProxy, - IdentityLabel: types.NewOptionalBool(query.IdentityLabel), + IdentityLabel: identityLabel, LabelOpts: labelOpts, Memory: query.Memory, MemorySwap: query.MemSwap,