Merge pull request #5193 from dokku/5190-env-perms

Force-set correct permissions on env files
This commit is contained in:
Jose Diaz-Gonzalez authored and GitHub committed 2022-05-21 13:37:03 -04:00
commit f6cd3f5c89
2 files changed
+8

No files matched your search

+3
View File
@@ -52,6 +52,7 @@ func SetMany(appName string, entries map[string]string, restart bool) (err error
fmt.Println(prettyPrintEnvEntries(" ", entries)) fmt.Println(prettyPrintEnvEntries(" ", entries))
} }
env.Write() env.Write()
common.SetPermissions(env.Filename(), 0600)
triggerUpdate(appName, "set", keys) triggerUpdate(appName, "set", keys)
} }
if !global && restart && env.GetBoolDefault("DOKKU_APP_RESTORE", true) { if !global && restart && env.GetBoolDefault("DOKKU_APP_RESTORE", true) {
@@ -84,6 +85,7 @@ func UnsetMany(appName string, keys []string, restart bool) (err error) {
} }
if changed { if changed {
env.Write() env.Write()
common.SetPermissions(env.Filename(), 0600)
triggerUpdate(appName, "unset", keys) triggerUpdate(appName, "unset", keys)
} }
if !global && restart && env.GetBoolDefault("DOKKU_APP_RESTORE", true) { if !global && restart && env.GetBoolDefault("DOKKU_APP_RESTORE", true) {
@@ -107,6 +109,7 @@ func UnsetAll(appName string, restart bool) (err error) {
} }
if changed { if changed {
env.Write() env.Write()
common.SetPermissions(env.Filename(), 0600)
triggerUpdate(appName, "clear", []string{}) triggerUpdate(appName, "clear", []string{})
} }
if !global && restart && env.GetBoolDefault("DOKKU_APP_RESTORE", true) { if !global && restart && env.GetBoolDefault("DOKKU_APP_RESTORE", true) {
+5
View File
@@ -92,6 +92,11 @@ func LoadGlobalEnv() (*Env, error) {
return loadFromFile("<global>", getGlobalFile()) return loadFromFile("<global>", getGlobalFile())
} }
// Filename returns the full path on disk to the file holding the env vars
func (e *Env) Filename() string {
return e.filename
}
//Get an environment variable //Get an environment variable
func (e *Env) Get(key string) (value string, ok bool) { func (e *Env) Get(key string) (value string, ok bool) {
value, ok = e.env[key] value, ok = e.env[key]