Skip to content

Commit 2a56666

Browse files
authored
Fix incorrect CurrentUser check for docker rootless (#24441)
The IsRunUserMatchCurrentUser logic is fragile, the "SSH" config is not ready when it executes.
1 parent f7cf7e6 commit 2a56666

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

modules/setting/setting.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ func loadCommonSettingsFrom(cfg ConfigProvider) {
250250
loadLogFrom(cfg)
251251
loadServerFrom(cfg)
252252
loadSSHFrom(cfg)
253+
254+
mustCurrentRunUserMatch(cfg) // it depends on the SSH config, only non-builtin SSH server requires this check
255+
253256
loadOAuth2From(cfg)
254257
loadSecurityFrom(cfg)
255258
loadAttachmentFrom(cfg)
@@ -282,14 +285,6 @@ func loadRunModeFrom(rootCfg ConfigProvider) {
282285
RunMode = rootSec.Key("RUN_MODE").MustString("prod")
283286
}
284287
IsProd = strings.EqualFold(RunMode, "prod")
285-
// Does not check run user when the install lock is off.
286-
installLock := rootCfg.Section("security").Key("INSTALL_LOCK").MustBool(false)
287-
if installLock {
288-
currentUser, match := IsRunUserMatchCurrentUser(RunUser)
289-
if !match {
290-
log.Fatal("Expect user '%s' but current user is: %s", RunUser, currentUser)
291-
}
292-
}
293288

294289
// check if we run as root
295290
if os.Getuid() == 0 {
@@ -301,6 +296,17 @@ func loadRunModeFrom(rootCfg ConfigProvider) {
301296
}
302297
}
303298

299+
func mustCurrentRunUserMatch(rootCfg ConfigProvider) {
300+
// Does not check run user when the "InstallLock" is off.
301+
installLock := rootCfg.Section("security").Key("INSTALL_LOCK").MustBool(false)
302+
if installLock {
303+
currentUser, match := IsRunUserMatchCurrentUser(RunUser)
304+
if !match {
305+
log.Fatal("Expect user '%s' but current user is: %s", RunUser, currentUser)
306+
}
307+
}
308+
}
309+
304310
// LoadSettings initializes the settings for normal start up
305311
func LoadSettings() {
306312
loadDBSetting(CfgProvider)

0 commit comments

Comments
 (0)