From 89818f72b740195215520c7765a686ca843e46a7 Mon Sep 17 00:00:00 2001 From: Jhon Honce Date: Mon, 9 Aug 2021 09:19:21 -0700 Subject: For compatibility, ignore Content-Type Endpoint /build logs an info entry when a client uses the wrong Content-Type for build payload. Given Content-Type is ignored and assumed to be "application/x-tar". Endpoint /libpod/build will fail unless "application/x-tar" or "application/tar" is given for Content-Type. "application/tar" will be logged as an info entry. Fixes #11012 Signed-off-by: Jhon Honce --- pkg/api/handlers/compat/images_build.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'pkg') diff --git a/pkg/api/handlers/compat/images_build.go b/pkg/api/handlers/compat/images_build.go index 08d1df4b8..0fcca1821 100644 --- a/pkg/api/handlers/compat/images_build.go +++ b/pkg/api/handlers/compat/images_build.go @@ -34,13 +34,16 @@ func BuildImage(w http.ResponseWriter, r *http.Request) { contentType := hdr[0] switch contentType { case "application/tar": - logrus.Warnf("tar file content type is %s, should use \"application/x-tar\" content type", contentType) + logrus.Infof("tar file content type is %s, should use \"application/x-tar\" content type", contentType) case "application/x-tar": break default: - utils.BadRequest(w, "Content-Type", hdr[0], - fmt.Errorf("Content-Type: %s is not supported. Should be \"application/x-tar\"", hdr[0])) - return + if utils.IsLibpodRequest(r) { + utils.BadRequest(w, "Content-Type", hdr[0], + fmt.Errorf("Content-Type: %s is not supported. Should be \"application/x-tar\"", hdr[0])) + return + } + logrus.Infof("tar file content type is %s, should use \"application/x-tar\" content type", contentType) } } -- cgit v1.2.3-54-g00ecf From b71ef443a4f5539ccdda7a1f635e41f9a5818eb2 Mon Sep 17 00:00:00 2001 From: Nalin Dahyabhai Date: Wed, 18 Aug 2021 09:52:56 -0400 Subject: pkg/bindings/images.nTar(): slashify hdr.Name values When setting path names in the build context archive, convert path names to use forward slashes, as is normal for those archives, so that directory hierarchies archived on Windows hosts extract correctly everywhere. Not really sure how to run the remote client in CI on a system that uses `\` as a path separator, which is where this error crops up, so [NO TESTS NEEDED] Signed-off-by: Nalin Dahyabhai --- pkg/bindings/images/build.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'pkg') diff --git a/pkg/bindings/images/build.go b/pkg/bindings/images/build.go index e1aeae244..39e0fc5df 100644 --- a/pkg/bindings/images/build.go +++ b/pkg/bindings/images/build.go @@ -481,9 +481,9 @@ func nTar(excludes []string, sources ...string) (io.ReadCloser, error) { return nil // skip root dir } - name := strings.TrimPrefix(path, s+string(filepath.Separator)) + name := filepath.ToSlash(strings.TrimPrefix(path, s+string(filepath.Separator))) - excluded, err := pm.Matches(filepath.ToSlash(name)) // nolint:staticcheck + excluded, err := pm.Matches(name) // nolint:staticcheck if err != nil { return errors.Wrapf(err, "error checking if %q is excluded", name) } -- cgit v1.2.3-54-g00ecf From a52b6bf23864073c39fda753b8c88a391bfe3555 Mon Sep 17 00:00:00 2001 From: Guillaume Rose Date: Thu, 19 Aug 2021 16:14:06 +0200 Subject: machine: check for file exists instead of listing directory [NO TESTS NEEDED] Signed-off-by: Guillaume Rose --- pkg/machine/fcos.go | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'pkg') diff --git a/pkg/machine/fcos.go b/pkg/machine/fcos.go index 11936aee7..943b9fd3c 100644 --- a/pkg/machine/fcos.go +++ b/pkg/machine/fcos.go @@ -6,6 +6,7 @@ import ( "crypto/sha256" "io/ioutil" url2 "net/url" + "os" "path/filepath" "runtime" "strings" @@ -91,24 +92,16 @@ func UpdateAvailable(d *Download) (bool, error) { // check the sha of the local image if it exists // get the sha of the remote image // == dont bother to pull - files, err := ioutil.ReadDir(filepath.Dir(d.LocalPath)) + if _, err := os.Stat(d.LocalPath); os.IsNotExist(err) { + return false, nil + } + b, err := ioutil.ReadFile(d.LocalPath) if err != nil { return false, err } - for _, file := range files { - if filepath.Base(d.LocalPath) == file.Name() { - b, err := ioutil.ReadFile(d.LocalPath) - if err != nil { - return false, err - } - s := sha256.Sum256(b) - sum := digest.NewDigestFromBytes(digest.SHA256, s[:]) - if sum.Encoded() == d.Sha256sum { - return true, nil - } - } - } - return false, nil + s := sha256.Sum256(b) + sum := digest.NewDigestFromBytes(digest.SHA256, s[:]) + return sum.Encoded() == d.Sha256sum, nil } func getFcosArch() string { -- cgit v1.2.3-54-g00ecf From b5e04ae115e0ed6a337d33a98ef70c8f45504040 Mon Sep 17 00:00:00 2001 From: Guillaume Rose Date: Thu, 19 Aug 2021 16:17:23 +0200 Subject: machine: compute sha256 as we read the image file It avoids to have the full file in memory. [NO TESTS NEEDED] Signed-off-by: Guillaume Rose --- pkg/machine/fcos.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'pkg') diff --git a/pkg/machine/fcos.go b/pkg/machine/fcos.go index 943b9fd3c..49ec01e67 100644 --- a/pkg/machine/fcos.go +++ b/pkg/machine/fcos.go @@ -3,8 +3,6 @@ package machine import ( - "crypto/sha256" - "io/ioutil" url2 "net/url" "os" "path/filepath" @@ -12,6 +10,7 @@ import ( "strings" digest "github.com/opencontainers/go-digest" + "github.com/sirupsen/logrus" ) // These should eventually be moved into machine/qemu as @@ -95,12 +94,19 @@ func UpdateAvailable(d *Download) (bool, error) { if _, err := os.Stat(d.LocalPath); os.IsNotExist(err) { return false, nil } - b, err := ioutil.ReadFile(d.LocalPath) + fd, err := os.Open(d.LocalPath) + if err != nil { + return false, err + } + defer func() { + if err := fd.Close(); err != nil { + logrus.Error(err) + } + }() + sum, err := digest.SHA256.FromReader(fd) if err != nil { return false, err } - s := sha256.Sum256(b) - sum := digest.NewDigestFromBytes(digest.SHA256, s[:]) return sum.Encoded() == d.Sha256sum, nil } -- cgit v1.2.3-54-g00ecf