Merge pull request #2519 from hashicorp/b-sticky-tmp

Add sticky bit to temp directory
This commit is contained in:
Alex Dadgar 2017-04-12 14:59:14 -07:00 committed by GitHub
commit 67d29f684d
4 changed files with 12 additions and 12 deletions

View File

@ -40,7 +40,7 @@ var (
TaskSecrets = "secrets" TaskSecrets = "secrets"
// TaskDirs is the set of directories created in each tasks directory. // TaskDirs is the set of directories created in each tasks directory.
TaskDirs = []string{"tmp"} TaskDirs = map[string]os.FileMode{"tmp": os.ModeSticky | 0777}
) )
type AllocDir struct { type AllocDir struct {
@ -250,7 +250,7 @@ func (d *AllocDir) Build() error {
} }
// Make the shared directory have non-root permissions. // Make the shared directory have non-root permissions.
if err := dropDirPermissions(d.SharedDir); err != nil { if err := dropDirPermissions(d.SharedDir, os.ModePerm); err != nil {
return err return err
} }
@ -260,7 +260,7 @@ func (d *AllocDir) Build() error {
if err := os.MkdirAll(p, 0777); err != nil { if err := os.MkdirAll(p, 0777); err != nil {
return err return err
} }
if err := dropDirPermissions(p); err != nil { if err := dropDirPermissions(p, os.ModePerm); err != nil {
return err return err
} }
} }

View File

@ -28,8 +28,8 @@ var (
// dropDirPermissions gives full access to a directory to all users and sets // dropDirPermissions gives full access to a directory to all users and sets
// the owner to nobody. // the owner to nobody.
func dropDirPermissions(path string) error { func dropDirPermissions(path string, desired os.FileMode) error {
if err := os.Chmod(path, 0777); err != nil { if err := os.Chmod(path, desired|0777); err != nil {
return fmt.Errorf("Chmod(%v) failed: %v", path, err) return fmt.Errorf("Chmod(%v) failed: %v", path, err)
} }

View File

@ -51,7 +51,7 @@ func removeSecretDir(dir string) error {
} }
// The windows version does nothing currently. // The windows version does nothing currently.
func dropDirPermissions(path string) error { func dropDirPermissions(path string, desired os.FileMode) error {
return nil return nil
} }

View File

@ -66,7 +66,7 @@ func (t *TaskDir) Build(chrootCreated bool, chroot map[string]string, fsi cstruc
} }
// Make the task directory have non-root permissions. // Make the task directory have non-root permissions.
if err := dropDirPermissions(t.Dir); err != nil { if err := dropDirPermissions(t.Dir, os.ModePerm); err != nil {
return err return err
} }
@ -75,18 +75,18 @@ func (t *TaskDir) Build(chrootCreated bool, chroot map[string]string, fsi cstruc
return err return err
} }
if err := dropDirPermissions(t.LocalDir); err != nil { if err := dropDirPermissions(t.LocalDir, os.ModePerm); err != nil {
return err return err
} }
// Create the directories that should be in every task. // Create the directories that should be in every task.
for _, dir := range TaskDirs { for dir, perms := range TaskDirs {
absdir := filepath.Join(t.Dir, dir) absdir := filepath.Join(t.Dir, dir)
if err := os.MkdirAll(absdir, 0777); err != nil { if err := os.MkdirAll(absdir, perms); err != nil {
return err return err
} }
if err := dropDirPermissions(absdir); err != nil { if err := dropDirPermissions(absdir, perms); err != nil {
return err return err
} }
} }
@ -110,7 +110,7 @@ func (t *TaskDir) Build(chrootCreated bool, chroot map[string]string, fsi cstruc
return err return err
} }
if err := dropDirPermissions(t.SecretsDir); err != nil { if err := dropDirPermissions(t.SecretsDir, os.ModePerm); err != nil {
return err return err
} }