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 27, 2020
1 parent 0b9a534 commit 3319344
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
13 changes: 12 additions & 1 deletion run_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,18 @@ func (b *Builder) Run(command []string, options RunOptions) error {
g = nil

logrus.Debugf("ensuring working directory %q exists", filepath.Join(mountPoint, spec.Process.Cwd))
if err = os.MkdirAll(filepath.Join(mountPoint, spec.Process.Cwd), 0755); err != nil && !os.IsExist(err) {
// Find out which user (and group) the destination should belong to.

user, _, err := b.user(mountPoint, options.User)
if err != nil {
return err
}
hostUID, hostGID, err := util.GetHostIDs(b.IDMappingOptions.UIDMap, b.IDMappingOptions.GIDMap, user.UID, user.GID)
if err != nil {
return err
}
hostOwner := idtools.IDPair{UID: int(hostUID), GID: int(hostGID)}
if err = idtools.MkdirAllAndChown(filepath.Join(mountPoint, spec.Process.Cwd), 0755, hostOwner); err != nil {
return errors.Wrapf(err, "error ensuring working directory %q exists", spec.Process.Cwd)
}

Expand Down
8 changes: 8 additions & 0 deletions tests/bud.bats
Original file line number Diff line number Diff line change
Expand Up @@ -2065,3 +2065,11 @@ EOM
run grep "secretthings" <<< "$output"
expect_output ""
}

@test "bud with user flags" {
_prefetch alpine
run_buildah bud --signature-policy ${TESTSDIR}/policy.json ${TESTSDIR}/bud/user
expect_output --substring "bin"
expect_output --substring "/home/work"
run_buildah rmi -a -f
}
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/work
RUN ls -ld /home/work
RUN touch file
RUN ls -l /home/work/file

0 comments on commit 3319344

Please sign in to comment.