Skip to content

Commit 4b867e9

Browse files
committed
Added option to disable 2FA
This mod introduces DISABLE_2FA parameter in [security] section of app.ini (by default set to false). If set to true it disables access to 2FA feature in user preferences (not required in some environments i.e. when reverse proxy auth is used). Authentication code using 2FA and any existing 2FA configuration are left untouched. This mod hides also security tab in user preferences when openid is also disabled; for this reason this mod is not separate PR but exiting PR enhancement. Author-Change-Id: IB#1105071
1 parent 03c07c2 commit 4b867e9

File tree

6 files changed

+12
-0
lines changed

6 files changed

+12
-0
lines changed

custom/conf/app.example.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,8 @@ IMPORT_LOCAL_PATHS = false
541541
; It also enables them to access other resources available to the user on the operating system that is running the Gitea instance and perform arbitrary actions in the name of the Gitea OS user.
542542
; WARNING: This maybe harmful to you website or your operating system.
543543
DISABLE_GIT_HOOKS = true
544+
; Set to false to disable 2FA feature.
545+
DISABLE_2FA = false
544546
; Set to false to allow pushes to gitea repositories despite having an incomplete environment - NOT RECOMMENDED
545547
ONLY_ALLOW_PUSH_IF_GITEA_ENVIRONMENT_SET = true
546548
;Comma separated list of character classes required to pass minimum complexity.

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ relation to port exhaustion.
400400
It also enables them to access other resources available to the user on the operating system that is running the
401401
Gitea instance and perform arbitrary actions in the name of the Gitea OS user.
402402
This maybe harmful to you website or your operating system.
403+
- `DISABLE_2FA`: **false**: Set to `true` to disable 2FA feature.
403404
- `ONLY_ALLOW_PUSH_IF_GITEA_ENVIRONMENT_SET`: **true**: Set to `false` to allow local users to push to gitea-repositories without setting up the Gitea environment. This is not recommended and if you want local users to push to gitea repositories you should set the environment appropriately.
404405
- `IMPORT_LOCAL_PATHS`: **false**: Set to `false` to prevent all users (including admin) from importing local path on server.
405406
- `INTERNAL_TOKEN`: **\<random at every install if no uri set\>**: Secret used to validate communication within Gitea binary.

modules/setting/setting.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ var (
152152
MinPasswordLength int
153153
ImportLocalPaths bool
154154
DisableGitHooks bool
155+
Disable2FA bool
155156
OnlyAllowPushIfGiteaEnvironmentSet bool
156157
PasswordComplexity []string
157158
PasswordHashAlgo string
@@ -770,6 +771,7 @@ func NewContext() {
770771
MinPasswordLength = sec.Key("MIN_PASSWORD_LENGTH").MustInt(6)
771772
ImportLocalPaths = sec.Key("IMPORT_LOCAL_PATHS").MustBool(false)
772773
DisableGitHooks = sec.Key("DISABLE_GIT_HOOKS").MustBool(true)
774+
Disable2FA = sec.Key("DISABLE_2FA").MustBool(false)
773775
OnlyAllowPushIfGiteaEnvironmentSet = sec.Key("ONLY_ALLOW_PUSH_IF_GITEA_ENVIRONMENT_SET").MustBool(true)
774776
PasswordHashAlgo = sec.Key("PASSWORD_HASH_ALGO").MustString("argon2")
775777
CSRFCookieHTTPOnly = sec.Key("CSRF_COOKIE_HTTP_ONLY").MustBool(true)

modules/templates/helper.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,9 @@ func NewFuncMap() []template.FuncMap {
234234
"DisableOAuth2": func() bool {
235235
return !setting.OAuth2.Enable
236236
},
237+
"Disable2FA": func() bool {
238+
return setting.Disable2FA
239+
},
237240
"TrN": TrN,
238241
"Dict": func(values ...interface{}) (map[string]interface{}, error) {
239242
if len(values)%2 != 0 {

templates/user/settings/navbar.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
<a class="{{if .PageIsSettingsAccount}}active{{end}} item" href="{{AppSubUrl}}/user/settings/account">
66
{{.i18n.Tr "settings.account"}}
77
</a>
8+
{{if or (not Disable2FA) .EnableOpenIDSignIn}}
89
<a class="{{if .PageIsSettingsSecurity}}active{{end}} item" href="{{AppSubUrl}}/user/settings/security">
910
{{.i18n.Tr "settings.security"}}
1011
</a>
12+
{{end}}
1113
{{if or .EnableSwagger (not DisableOAuth2)}}
1214
<a class="{{if .PageIsSettingsApplications}}active{{end}} item" href="{{AppSubUrl}}/user/settings/applications">
1315
{{.i18n.Tr "settings.applications"}}

templates/user/settings/security.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
{{template "user/settings/navbar" .}}
44
<div class="ui container">
55
{{template "base/alert" .}}
6+
{{if not Disable2FA}}
67
{{template "user/settings/security_twofa" .}}
78
{{template "user/settings/security_u2f" .}}
9+
{{end}}
810
{{if .EnableOpenIDSignIn}}
911
{{template "user/settings/security_accountlinks" .}}
1012
{{template "user/settings/security_openid" .}}

0 commit comments

Comments
 (0)