Skip to content

Commit

Permalink
Merge pull request opencontainers#39 from haircommander/reorder-chdir…
Browse files Browse the repository at this point in the history
…-4.5

[4.5] libctr/init_linux: reorder chdir
  • Loading branch information
Mrunal Patel authored Jan 5, 2021
2 parents 5101761 + b6bbbeb commit eadfc6b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions libcontainer/init_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,6 @@ func finalizeNamespace(config *initConfig) error {
return errors.Wrap(err, "close exec fds")
}

if config.Cwd != "" {
if err := unix.Chdir(config.Cwd); err != nil {
return fmt.Errorf("chdir to cwd (%q) set in config.json failed: %v", config.Cwd, err)
}
}

capabilities := &configs.Capabilities{}
if config.Capabilities != nil {
capabilities = config.Capabilities
Expand All @@ -153,6 +147,14 @@ func finalizeNamespace(config *initConfig) error {
if err := setupUser(config); err != nil {
return errors.Wrap(err, "setup user")
}
// Change working directory AFTER the user has been set up.
// Otherwise, if the cwd is also a volume that's been chowned to the container user (and not the user running runc),
// this command will EPERM.
if config.Cwd != "" {
if err := unix.Chdir(config.Cwd); err != nil {
return fmt.Errorf("chdir to cwd (%q) set in config.json failed: %v", config.Cwd, err)
}
}
if err := system.ClearKeepCaps(); err != nil {
return errors.Wrap(err, "clear keep caps")
}
Expand Down

0 comments on commit eadfc6b

Please sign in to comment.