@@ -22,6 +22,7 @@ import (
22
22
"time"
23
23
24
24
"code.gitea.io/gitea/modules/container"
25
+ "code.gitea.io/gitea/modules/generate"
25
26
"code.gitea.io/gitea/modules/json"
26
27
"code.gitea.io/gitea/modules/log"
27
28
"code.gitea.io/gitea/modules/user"
@@ -962,6 +963,11 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
962
963
SuccessfulTokensCacheSize = sec .Key ("SUCCESSFUL_TOKENS_CACHE_SIZE" ).MustInt (20 )
963
964
964
965
InternalToken = loadSecret (sec , "INTERNAL_TOKEN_URI" , "INTERNAL_TOKEN" )
966
+ if InstallLock && InternalToken == "" {
967
+ // if Gitea has been installed but the InternalToken hasn't been generated (upgrade from an old release), we should generate
968
+ // some users do cluster deployment, they still depend on this auto-generating behavior.
969
+ generateSaveInternalToken ()
970
+ }
965
971
966
972
cfgdata := sec .Key ("PASSWORD_COMPLEXITY" ).Strings ("," )
967
973
if len (cfgdata ) == 0 {
@@ -1182,6 +1188,19 @@ func loadSecret(sec *ini.Section, uriKey, verbatimKey string) string {
1182
1188
}
1183
1189
}
1184
1190
1191
+ // generateSaveInternalToken generates and saves the internal token to app.ini
1192
+ func generateSaveInternalToken () {
1193
+ token , err := generate .NewInternalToken ()
1194
+ if err != nil {
1195
+ log .Fatal ("Error generate internal token: %v" , err )
1196
+ }
1197
+
1198
+ InternalToken = token
1199
+ CreateOrAppendToCustomConf ("security.INTERNAL_TOKEN" , func (cfg * ini.File ) {
1200
+ cfg .Section ("security" ).Key ("INTERNAL_TOKEN" ).SetValue (token )
1201
+ })
1202
+ }
1203
+
1185
1204
// MakeAbsoluteAssetURL returns the absolute asset url prefix without a trailing slash
1186
1205
func MakeAbsoluteAssetURL (appURL , staticURLPrefix string ) string {
1187
1206
parsedPrefix , err := url .Parse (strings .TrimSuffix (staticURLPrefix , "/" ))
0 commit comments