Skip to content

Commit d9d3f52

Browse files
authored
Fix incorrect CurrentUser check for docker rootless (#24435)
Many users report that 1.19 has a regression bug: the rootless image can't start if the UID is not 1000. #23632 (comment) https://discourse.gitea.io/t/gitea-doesnt-start-after-update-to-1-19/6920/9 The problem is that the IsRunUserMatchCurrentUser logic is fragile, the "SSH" config is not ready when it executes. This PR is just a quick fix for 1.19. For 1.20, we need a clear and stable solution.
1 parent 7d7ba76 commit d9d3f52

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
@@ -282,6 +282,9 @@ func loadCommonSettingsFrom(cfg ConfigProvider) {
282282
loadLogFrom(cfg)
283283
loadServerFrom(cfg)
284284
loadSSHFrom(cfg)
285+
286+
mustCurrentRunUserMatch(cfg) // it depends on the SSH config, only non-builtin SSH server requires this check
287+
285288
loadOAuth2From(cfg)
286289
loadSecurityFrom(cfg)
287290
loadAttachmentFrom(cfg)
@@ -314,14 +317,6 @@ func loadRunModeFrom(rootCfg ConfigProvider) {
314317
RunMode = rootSec.Key("RUN_MODE").MustString("prod")
315318
}
316319
IsProd = strings.EqualFold(RunMode, "prod")
317-
// Does not check run user when the install lock is off.
318-
installLock := rootCfg.Section("security").Key("INSTALL_LOCK").MustBool(false)
319-
if installLock {
320-
currentUser, match := IsRunUserMatchCurrentUser(RunUser)
321-
if !match {
322-
log.Fatal("Expect user '%s' but current user is: %s", RunUser, currentUser)
323-
}
324-
}
325320

326321
// check if we run as root
327322
if os.Getuid() == 0 {
@@ -333,6 +328,17 @@ func loadRunModeFrom(rootCfg ConfigProvider) {
333328
}
334329
}
335330

331+
func mustCurrentRunUserMatch(rootCfg ConfigProvider) {
332+
// Does not check run user when the "InstallLock" is off.
333+
installLock := rootCfg.Section("security").Key("INSTALL_LOCK").MustBool(false)
334+
if installLock {
335+
currentUser, match := IsRunUserMatchCurrentUser(RunUser)
336+
if !match {
337+
log.Fatal("Expect user '%s' but current user is: %s", RunUser, currentUser)
338+
}
339+
}
340+
}
341+
336342
// CreateOrAppendToCustomConf creates or updates the custom config.
337343
// Use the callback to set individual values.
338344
func CreateOrAppendToCustomConf(purpose string, callback func(cfg *ini.File)) {

0 commit comments

Comments
 (0)