Permalink
Browse files

set permissions on /tmp

[#64329392]

Signed-off-by: Nick Wade <nwade@pivotallabs.com>
  • Loading branch information...
1 parent 9657e1d commit a98c30c5b280ec1331778cc6cc162f03baf99aae @benjaminleesmith benjaminleesmith committed with nwade Jan 23, 2014
@@ -82,6 +82,12 @@ func (boot bootstrap) Run() (settingsService boshsettings.Service, err error) {
return
}
+ err = boot.platform.SetupTmpDir()
+ if err != nil {
+ err = bosherr.WrapError(err, "Changing ownership of /tmp")
+ return
+ }
+
for _, devicePath := range settings.Disks.Persistent {
err = boot.platform.MountPersistentDisk(devicePath, boot.dirProvider.StoreDir())
if err != nil {
@@ -117,6 +117,15 @@ func TestRunSetsUpEphemeralDisk(t *testing.T) {
assert.Equal(t, fakePlatform.SetupEphemeralDiskWithPathDevicePath, "/dev/sda")
}
+func TestRunSetsUpTmpDir(t *testing.T) {
+ fakeInfrastructure, fakePlatform, dirProvider := getBootstrapDependencies()
+
+ boot := New(fakeInfrastructure, fakePlatform, dirProvider)
+ boot.Run()
+
+ assert.True(t, fakePlatform.SetupTmpDirCalled)
+}
+
func TestRunMountsPersistentDisk(t *testing.T) {
settings := boshsettings.Settings{
Disks: boshsettings.Disks{
@@ -413,6 +413,21 @@ func (p centos) SetupEphemeralDiskWithPath(devicePath string) (err error) {
return
}
+func (p centos) SetupTmpDir() (err error) {
+ _, _, err = p.cmdRunner.RunCommand("chown", "root:vcap", "/tmp")
+ if err != nil {
+ err = bosherr.WrapError(err, "chown /tmp")
+ return
+ }
+ _, _, err = p.cmdRunner.RunCommand("chmod", "0770", "/tmp")
+ if err != nil {
+ err = bosherr.WrapError(err, "chmod /tmp")
+ return
+ }
+
+ return
+}
+
func (p centos) MountPersistentDisk(devicePath, mountPoint string) (err error) {
p.fs.MkdirAll(mountPoint, os.FileMode(0700))
@@ -310,6 +310,18 @@ func TestCentosSetupEphemeralDiskWithPath(t *testing.T) {
assert.Equal(t, os.FileMode(0750), sysRunStats.FileMode)
}
+func TestCentosSetupTmpDir(t *testing.T) {
+ deps, centos := buildCentos()
+
+ err := centos.SetupTmpDir()
+ assert.NoError(t, err)
+
+ assert.Equal(t, 2, len(deps.cmdRunner.RunCommands))
+
+ assert.Equal(t, []string{"chown", "root:vcap", "/tmp"}, deps.cmdRunner.RunCommands[0])
+ assert.Equal(t, []string{"chmod", "0770", "/tmp"}, deps.cmdRunner.RunCommands[1])
+}
+
func TestCentosMountPersistentDisk(t *testing.T) {
deps, centos := buildCentos()
fakeFormatter := deps.diskManager.FakeFormatter
@@ -109,6 +109,10 @@ func (p dummyPlatform) SetupEphemeralDiskWithPath(devicePath string) (err error)
return
}
+func (p dummyPlatform) SetupTmpDir() (err error) {
+ return
+}
+
func (p dummyPlatform) MountPersistentDisk(devicePath, mountPoint string) (err error) {
return
}
@@ -37,6 +37,8 @@ type FakePlatform struct {
SetupEphemeralDiskWithPathDevicePath string
+ SetupTmpDirCalled bool
+
MountPersistentDiskDevicePath string
MountPersistentDiskMountPoint string
@@ -155,6 +157,11 @@ func (p *FakePlatform) SetupEphemeralDiskWithPath(devicePath string) (err error)
return
}
+func (p *FakePlatform) SetupTmpDir() (err error) {
+ p.SetupTmpDirCalled = true
+ return
+}
+
func (p *FakePlatform) MountPersistentDisk(devicePath, mountPoint string) (err error) {
p.MountPersistentDiskDevicePath = devicePath
p.MountPersistentDiskMountPoint = mountPoint
@@ -29,6 +29,7 @@ type Platform interface {
SetupLogrotate(groupName, basePath, size string) (err error)
SetTimeWithNtpServers(servers []string) (err error)
SetupEphemeralDiskWithPath(devicePath string) (err error)
+ SetupTmpDir() (err error)
MountPersistentDisk(devicePath, mountPoint string) (err error)
UnmountPersistentDisk(devicePath string) (didUnmount bool, err error)
MigratePersistentDisk(fromMountPoint, toMountPoint string) (err error)
@@ -414,6 +414,21 @@ func (p ubuntu) SetupEphemeralDiskWithPath(devicePath string) (err error) {
return
}
+func (p ubuntu) SetupTmpDir() (err error) {
+ _, _, err = p.cmdRunner.RunCommand("chown", "root:vcap", "/tmp")
+ if err != nil {
+ err = bosherr.WrapError(err, "chown /tmp")
+ return
+ }
+ _, _, err = p.cmdRunner.RunCommand("chmod", "0770", "/tmp")
+ if err != nil {
+ err = bosherr.WrapError(err, "chmod /tmp")
+ return
+ }
+
+ return
+}
+
func (p ubuntu) MountPersistentDisk(devicePath, mountPoint string) (err error) {
p.fs.MkdirAll(mountPoint, os.FileMode(0700))
@@ -311,6 +311,18 @@ func TestUbuntuSetupEphemeralDiskWithPath(t *testing.T) {
assert.Equal(t, os.FileMode(0750), sysRunStats.FileMode)
}
+func TestSetupTmpDir(t *testing.T) {
+ deps, ubuntu := buildUbuntu()
+
+ err := ubuntu.SetupTmpDir()
+ assert.NoError(t, err)
+
+ assert.Equal(t, 2, len(deps.cmdRunner.RunCommands))
+
+ assert.Equal(t, []string{"chown", "root:vcap", "/tmp"}, deps.cmdRunner.RunCommands[0])
+ assert.Equal(t, []string{"chmod", "0770", "/tmp"}, deps.cmdRunner.RunCommands[1])
+}
+
func TestUbuntuMountPersistentDisk(t *testing.T) {
deps, ubuntu := buildUbuntu()
fakeFormatter := deps.diskManager.FakeFormatter

0 comments on commit a98c30c

Please sign in to comment.