Skip to content

Commit

Permalink
fix(install/script): config dir permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
Mikołaj Świątek committed Jan 27, 2023
1 parent 6a27647 commit c39f44e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 25 deletions.
28 changes: 18 additions & 10 deletions pkg/scripts_test/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,22 @@ func checkConfigFilesOwnershipAndPermissions(ownerName string, ownerGroup string
etcPathNestedGlob := filepath.Join(etcPath, "*", "*")

for _, glob := range []string{etcPathGlob, etcPathNestedGlob} {
configFiles, err := filepath.Glob(glob)
paths, err := filepath.Glob(glob)
require.NoError(c.test, err)
for _, configFile := range configFiles {
PathHasPermissions(c.test, configFile, configPathPermissions)
PathHasOwner(c.test, configFile, ownerName, ownerGroup)
for _, path := range paths {
var permissions uint32
info, err := os.Stat(path)
require.NoError(c.test, err)
if info.IsDir() {
permissions = configPathDirPermissions
} else {
permissions = configPathFilePermissions
}
PathHasPermissions(c.test, path, permissions)
PathHasOwner(c.test, configPath, ownerName, ownerGroup)
}
}
PathHasPermissions(c.test, configPath, configPathPermissions)
PathHasPermissions(c.test, configPath, configPathFilePermissions)
}
}

Expand Down Expand Up @@ -152,7 +160,7 @@ func checkHostmetricsConfigCreated(c check) {
func checkHostmetricsOwnershipAndPermissions(ownerName string, ownerGroup string) func(c check) {
return func(c check) {
PathHasOwner(c.test, hostmetricsConfigPath, ownerName, ownerGroup)
PathHasPermissions(c.test, hostmetricsConfigPath, configPathPermissions)
PathHasPermissions(c.test, hostmetricsConfigPath, configPathFilePermissions)
}
}

Expand All @@ -173,7 +181,7 @@ func checkSystemdEnvDirExists(c check) {
}

func checkSystemdEnvDirPermissions(c check) {
PathHasPermissions(c.test, etcPath+"/env", configPathPermissions)
PathHasPermissions(c.test, etcPath+"/env", configPathDirPermissions)
}

func checkTags(c check) {
Expand Down Expand Up @@ -214,18 +222,18 @@ func preActionMockConfig(c check) {
f, err := os.Create(configPath)
require.NoError(c.test, err)

err = f.Chmod(fs.FileMode(configPathPermissions))
err = f.Chmod(fs.FileMode(configPathFilePermissions))
require.NoError(c.test, err)
}

func preActionMockUserConfig(c check) {
err := os.MkdirAll(confDPath, fs.FileMode(configPathPermissions))
err := os.MkdirAll(confDPath, fs.FileMode(configPathDirPermissions))
require.NoError(c.test, err)

f, err := os.Create(userConfigPath)
require.NoError(c.test, err)

err = f.Chmod(fs.FileMode(configPathPermissions))
err = f.Chmod(fs.FileMode(configPathFilePermissions))
require.NoError(c.test, err)
}

Expand Down
25 changes: 13 additions & 12 deletions pkg/scripts_test/consts.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
package sumologic_scripts_tests

const (
binaryPath string = "/usr/local/bin/otelcol-sumo"
libPath string = "/var/lib/otelcol-sumo"
fileStoragePath string = libPath + "/file_storage"
etcPath string = "/etc/otelcol-sumo"
etcPathPermissions uint32 = 0444
systemdPath string = "/etc/systemd/system/otelcol-sumo.service"
scriptPath string = "../../scripts/install.sh"
configPath string = etcPath + "/sumologic.yaml"
configPathPermissions uint32 = 0440
confDPath string = etcPath + "/conf.d"
userConfigPath string = confDPath + "/common.yaml"
hostmetricsConfigPath string = confDPath + "/hostmetrics.yaml"
binaryPath string = "/usr/local/bin/otelcol-sumo"
libPath string = "/var/lib/otelcol-sumo"
fileStoragePath string = libPath + "/file_storage"
etcPath string = "/etc/otelcol-sumo"
etcPathPermissions uint32 = 0555
systemdPath string = "/etc/systemd/system/otelcol-sumo.service"
scriptPath string = "../../scripts/install.sh"
configPath string = etcPath + "/sumologic.yaml"
configPathFilePermissions uint32 = 0440
configPathDirPermissions uint32 = 0550
confDPath string = etcPath + "/conf.d"
userConfigPath string = confDPath + "/common.yaml"
hostmetricsConfigPath string = confDPath + "/hostmetrics.yaml"

systemdDirectoryPath string = "/run/systemd/system"

Expand Down
7 changes: 4 additions & 3 deletions scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -592,12 +592,13 @@ function setup_config() {
fi

echo 'Changing permissions for config files and storage'
chmod 444 "${CONFIG_DIRECTORY}"
chmod -R 440 "${CONFIG_DIRECTORY}"/*
chmod 555 "${CONFIG_DIRECTORY}"
chmod -R 440 "${CONFIG_DIRECTORY}"/* # all files only readable by the owner
find "${CONFIG_DIRECTORY}/" -type d -mindepth 1 -exec chmod 550 {} \; # directories also traversable
chmod -R 750 "${HOME_DIRECTORY}"

echo 'Changing permissions for user env directory'
chmod -R 440 "${USER_ENV_DIRECTORY}"
chmod 550 "${USER_ENV_DIRECTORY}"
chmod g+s "${USER_ENV_DIRECTORY}"
}

Expand Down

0 comments on commit c39f44e

Please sign in to comment.