Skip to content

Commit

Permalink
Remove assumptions about temp file locations
Browse files Browse the repository at this point in the history
Many configuration files live in a parent directory that is only writeable by root or another user.  Despite this, current code assumes the parent directory is writable by the consul-template process.

In addition, the assumption is made that the temporary file is created on the same filesystem.

We can still retain an atomic copy+delete using the existing `copyFile(...)` and deferred `os.Remove(...)`.

This patch allows for more granular security and more variation in the host filesystem.  In my case, I run consul-template as a dedicated user, so that I can explicitly give it permission to writeable locations.
  • Loading branch information
doublerebel committed Jan 12, 2016
1 parent 451cd20 commit 6523b07
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ func atomicWrite(path string, contents []byte, perms os.FileMode, backup bool) e
}
}

f, err := ioutil.TempFile(parent, "")
f, err := ioutil.TempFile(os.TempDir(), "")
if err != nil {
return err
}
Expand Down Expand Up @@ -845,7 +845,7 @@ func atomicWrite(path string, contents []byte, perms os.FileMode, backup bool) e
}
}

if err := os.Rename(f.Name(), path); err != nil {
if err := copyFile(f.Name(), path); err != nil {
return err
}

Expand Down

0 comments on commit 6523b07

Please sign in to comment.