Skip to content

Commit

Permalink
Fix permissions issues with sandbox mounts
Browse files Browse the repository at this point in the history
Signed-off-by: Kathryn Baldauf <kabaldau@microsoft.com>
  • Loading branch information
katiewasnothere committed Nov 3, 2021
1 parent 5f5e3ea commit aea3b96
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions internal/guest/runtime/hcsv2/workload_container.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ func updateSandboxMounts(sbid string, spec *oci.Spec) error {

_, err := os.Stat(sandboxSource)
if os.IsNotExist(err) {
if err := os.MkdirAll(sandboxSource, 0755); err != nil {
// os.MkdirAll combines the given permissions with the running process's
// umask. By default this causes 0777 to become 0755.
// Temporarily set the umask of this process to 0 so that we can actually
// make all dirs with os.ModePerm permissions.
savedUmask := unix.Umask(0)
defer unix.Umask(savedUmask)
if err := os.MkdirAll(sandboxSource, os.ModePerm); err != nil {
return err
}
}
Expand Down Expand Up @@ -68,7 +74,13 @@ func updateHugePageMounts(sbid string, spec *oci.Spec) error {

_, err := os.Stat(hugePageMountSource)
if os.IsNotExist(err) {
if err := os.MkdirAll(hugePageMountSource, 0755); err != nil {
// os.MkdirAll combines the given permissions with the running process's
// umask. By default this causes 0777 to become 0755.
// Temporarily set the umask of this process to 0 so that we can actually
// make all dirs with os.ModePerm permissions.
savedUmask := unix.Umask(0)
defer unix.Umask(savedUmask)
if err := os.MkdirAll(hugePageMountSource, os.ModePerm); err != nil {
return err
}

Expand Down

0 comments on commit aea3b96

Please sign in to comment.