From 7776511d0054a59a8546595622d84d93b7bfaa60 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sun, 30 Apr 2023 11:08:58 +0800 Subject: [PATCH] fix rootless --- modules/setting/setting.go | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 87b1e2797fe7d..dfe8dcfa1ce95 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -282,6 +282,9 @@ func loadCommonSettingsFrom(cfg ConfigProvider) { loadLogFrom(cfg) loadServerFrom(cfg) loadSSHFrom(cfg) + + mustCurrentRunUserMatch(cfg) // it depends on the SSH config, only non-builtin SSH server requires this check + loadOAuth2From(cfg) loadSecurityFrom(cfg) loadAttachmentFrom(cfg) @@ -314,14 +317,6 @@ func loadRunModeFrom(rootCfg ConfigProvider) { RunMode = rootSec.Key("RUN_MODE").MustString("prod") } IsProd = strings.EqualFold(RunMode, "prod") - // Does not check run user when the install lock is off. - installLock := rootCfg.Section("security").Key("INSTALL_LOCK").MustBool(false) - if installLock { - currentUser, match := IsRunUserMatchCurrentUser(RunUser) - if !match { - log.Fatal("Expect user '%s' but current user is: %s", RunUser, currentUser) - } - } // check if we run as root if os.Getuid() == 0 { @@ -333,6 +328,17 @@ func loadRunModeFrom(rootCfg ConfigProvider) { } } +func mustCurrentRunUserMatch(rootCfg ConfigProvider) { + // Does not check run user when the "InstallLock" is off. + installLock := rootCfg.Section("security").Key("INSTALL_LOCK").MustBool(false) + if installLock { + currentUser, match := IsRunUserMatchCurrentUser(RunUser) + if !match { + log.Fatal("Expect user '%s' but current user is: %s", RunUser, currentUser) + } + } +} + // CreateOrAppendToCustomConf creates or updates the custom config. // Use the callback to set individual values. func CreateOrAppendToCustomConf(purpose string, callback func(cfg *ini.File)) {