From 50236f7fa17063873e6eb31ca6590801f832c2f5 Mon Sep 17 00:00:00 2001 From: Michael Schurter Date: Fri, 5 Jan 2018 15:45:41 -0800 Subject: [PATCH] chown dirs when migrating ephemeral_disk data Fixes #3702 Added missing chown call and made it conditional on running as root and not on Windows as we do with files. --- CHANGELOG.md | 1 + client/alloc_watcher.go | 13 ++++++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e23e1d43de98..4de56632a602 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ BUG FIXES: * core: Fix search endpoint forwarding for multi-region clusters [[GH-3680](https://github.com/hashicorp/nomad/issues/3680)] * core: Fix an issue in which batch jobs with queued placements and lost allocations could result in improper placement counts [[GH-3717](https://github.com/hashicorp/nomad/issues/3717)] + * client: chown directories for migrated `ephemeral_disk`s [GH-3723] * config: Revert minimum CPU limit back to 20 from 100. ## 0.7.1 (December 19, 2017) diff --git a/client/alloc_watcher.go b/client/alloc_watcher.go index e54e7184d135..ecac7190f487 100644 --- a/client/alloc_watcher.go +++ b/client/alloc_watcher.go @@ -499,7 +499,15 @@ func (p *remotePrevAlloc) streamAllocDir(ctx context.Context, resp io.ReadCloser // If the header is for a directory we create the directory if hdr.Typeflag == tar.TypeDir { - os.MkdirAll(filepath.Join(dest, hdr.Name), os.FileMode(hdr.Mode)) + name := filepath.Join(dest, hdr.Name) + os.MkdirAll(name, os.FileMode(hdr.Mode)) + + // Can't change owner if not root or on Windows. + if euid == 0 { + if err := os.Chown(name, hdr.Uid, hdr.Gid); err != nil { + return fmt.Errorf("error chowning directory %v", err) + } + } continue } // If the header is for a symlink we create the symlink @@ -522,8 +530,7 @@ func (p *remotePrevAlloc) streamAllocDir(ctx context.Context, resp io.ReadCloser return fmt.Errorf("error chmoding file %v", err) } - // Can't change owner if not root. Returns false on - // Windows as Chown always errors there. + // Can't change owner if not root or on Windows. if euid == 0 { if err := f.Chown(hdr.Uid, hdr.Gid); err != nil { f.Close()