Skip to content

Commit

Permalink
Fix ownership of the working dir
Browse files Browse the repository at this point in the history
The working dir should be owned by the owner of the container.

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Apr 28, 2020
1 parent bea8692 commit 9dba09d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
10 changes: 7 additions & 3 deletions imagebuildah/stage_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1325,7 +1325,7 @@ func (s *StageExecutor) commit(ctx context.Context, createdBy string, emptyLayer
return imgID, ref, nil
}

func (s *StageExecutor) EnsureContainerPath(path string) error {
func (s *StageExecutor) EnsureContainerPath(path, user string) error {
targetPath, err := securejoin.SecureJoin(s.mountPoint, path)
if err != nil {
return errors.Wrapf(err, "error ensuring container path %q", path)
Expand All @@ -1339,11 +1339,15 @@ func (s *StageExecutor) EnsureContainerPath(path string) error {
}
// get the uid and gid so that we can set the correct permissions on the
// working directory
uid, gid, _, err := chrootuser.GetUser(s.mountPoint, s.builder.User())
uid, gid, _, err := chrootuser.GetUser(s.mountPoint, user)
if err != nil {
return errors.Wrapf(err, "error getting uid and gid for user %q", s.builder.User())
}
if err = os.Chown(targetPath, int(uid), int(gid)); err != nil {
hostUID, hostGID, err := util.GetHostIDs(s.builder.IDMappingOptions.UIDMap, s.builder.IDMappingOptions.GIDMap, uid, gid)
if err != nil {
return err
}
if err = os.Chown(targetPath, int(hostUID), int(hostGID)); err != nil {
return errors.Wrapf(err, "error setting ownership on %q", targetPath)
}
}
Expand Down
6 changes: 6 additions & 0 deletions tests/bud/user/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
FROM alpine
USER bin
WORKDIR /home/workdir
RUN ls -ld /home/workdir
RUN touch file
RUN ls -l /home/workdir/file
10 changes: 5 additions & 5 deletions vendor/github.com/openshift/imagebuilder/builder.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 9dba09d

Please sign in to comment.