From 449d010a728aae7d47abf03bc98508774feb93d1 Mon Sep 17 00:00:00 2001 From: Claudiu Belu Date: Tue, 13 Jul 2021 07:09:52 +0000 Subject: [PATCH] Skips getting UID/GUID if passwd/group file is not found When running a WORKDIR instruction, buildkit will create that folder and chown it to the currently set user. For this, it will try to read the /etc/passwd file to get the proper UID, and if that user is not found in the file, the root user will be considered as the owner. However, Windows image do not have that file, which will result in an error while building the image. We can consider not finding the /etc/passwd file as the same as not finding the user in the file, which would solve this issue. Signed-off-by: Claudiu Belu --- solver/llbsolver/file/user_linux.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/solver/llbsolver/file/user_linux.go b/solver/llbsolver/file/user_linux.go index 8e4848cc5..1f17431f5 100644 --- a/solver/llbsolver/file/user_linux.go +++ b/solver/llbsolver/file/user_linux.go @@ -2,6 +2,7 @@ package file import ( "os" + "syscall" "github.com/containerd/continuity/fs" "github.com/moby/buildkit/snapshot" @@ -45,6 +46,10 @@ func readUser(chopt *pb.ChownOpt, mu, mg fileoptypes.Mount) (*copy.User, error) } ufile, err := os.Open(passwdPath) + if errors.Is(err, os.ErrNotExist) || errors.Is(err, syscall.ENOTDIR) { + // Couldn't open the file. Considering this case as not finding the user in the file. + break + } if err != nil { return nil, err } @@ -95,6 +100,10 @@ func readUser(chopt *pb.ChownOpt, mu, mg fileoptypes.Mount) (*copy.User, error) } gfile, err := os.Open(groupPath) + if errors.Is(err, os.ErrNotExist) || errors.Is(err, syscall.ENOTDIR) { + // Couldn't open the file. Considering this case as not finding the group in the file. + break + } if err != nil { return nil, err }