Skip to content

Commit 3ddaba1

Browse files
committed
DISABLE_2FA parameter for disabling 2FA added
Gitea does not use 2FA when reverse proxy auth is enabled. 2FA is hardcoded and cannot be disabled (i.e. when stronger authentication scheme is implemented on reverse proxy). Leaving unused elements like 2FA in UI should be avoided to make UI clean and to avoid unnecessarry maintanance (questions/problems from users). This mod introduces new `DISABLE_2FA` parameter in app.ini section `[security]`. When disabled (default when parameter is not present) gitea behaves as without this mod (2FA is available). When enabled, 2FA feature and its UI elements are not avaiable. This mod also hides those areas on Settings/Security page that are disabled in config and hides menu link to Security page if all its areas are disabled in config. Related: go-gitea#13129 Author-Change-Id: IB#1115243
1 parent b7c6457 commit 3ddaba1

File tree

9 files changed

+22
-0
lines changed

9 files changed

+22
-0
lines changed

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,9 @@ INTERNAL_TOKEN=
372372
;; Set to true to disable webhooks feature.
373373
;DISABLE_WEBHOOKS = false
374374
;;
375+
;; Set to false to disable 2FA feature.
376+
;DISABLE_2FA = false
377+
;;
375378
;; Set to false to allow pushes to gitea repositories despite having an incomplete environment - NOT RECOMMENDED
376379
;ONLY_ALLOW_PUSH_IF_GITEA_ENVIRONMENT_SET = true
377380
;;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,6 +498,7 @@ Certain queues have defaults that override the defaults set in `[queue]` (this o
498498
Gitea instance and perform arbitrary actions in the name of the Gitea OS user.
499499
This maybe harmful to you website or your operating system.
500500
- `DISABLE_WEBHOOKS`: **false**: Set to `true` to disable webhooks feature.
501+
- `DISABLE_2FA`: **false**: Set to `true` to disable 2FA feature.
501502
- `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.
502503
- `IMPORT_LOCAL_PATHS`: **false**: Set to `false` to prevent all users (including admin) from importing local path on server.
503504
- `INTERNAL_TOKEN`: **\<random at every install if no uri set\>**: Secret used to validate communication within Gitea binary.

modules/context/context.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,7 @@ func Contexter() func(next http.Handler) http.Handler {
706706

707707
ctx.Data["EnableSwagger"] = setting.API.EnableSwagger
708708
ctx.Data["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn
709+
ctx.Data["EnableOpenIDSignUp"] = setting.Service.EnableOpenIDSignUp
709710
ctx.Data["DisableMigrations"] = setting.Repository.DisableMigrations
710711
ctx.Data["DisableStars"] = setting.Repository.DisableStars
711712

modules/setting/setting.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ var (
187187
ImportLocalPaths bool
188188
DisableGitHooks bool
189189
DisableWebhooks bool
190+
Disable2FA bool
190191
OnlyAllowPushIfGiteaEnvironmentSet bool
191192
PasswordComplexity []string
192193
PasswordHashAlgo string
@@ -868,6 +869,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
868869
ImportLocalPaths = sec.Key("IMPORT_LOCAL_PATHS").MustBool(false)
869870
DisableGitHooks = sec.Key("DISABLE_GIT_HOOKS").MustBool(true)
870871
DisableWebhooks = sec.Key("DISABLE_WEBHOOKS").MustBool(false)
872+
Disable2FA = sec.Key("DISABLE_2FA").MustBool(false)
871873
OnlyAllowPushIfGiteaEnvironmentSet = sec.Key("ONLY_ALLOW_PUSH_IF_GITEA_ENVIRONMENT_SET").MustBool(true)
872874
PasswordHashAlgo = sec.Key("PASSWORD_HASH_ALGO").MustString("pbkdf2")
873875
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
@@ -236,6 +236,9 @@ func NewFuncMap() []template.FuncMap {
236236
"DisableWebhooks": func() bool {
237237
return setting.DisableWebhooks
238238
},
239+
"Disable2FA": func() bool {
240+
return setting.Disable2FA
241+
},
239242
"DisableImportLocal": func() bool {
240243
return !setting.ImportLocalPaths
241244
},

templates/admin/user/list.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@
7373
<th>{{.i18n.Tr "admin.users.activated"}}</th>
7474
<th>{{.i18n.Tr "admin.users.admin"}}</th>
7575
<th>{{.i18n.Tr "admin.users.restricted"}}</th>
76+
{{if not Disable2FA}}
7677
<th>{{.i18n.Tr "admin.users.2fa"}}</th>
78+
{{end}}
7779
<th>{{.i18n.Tr "admin.users.repos"}}</th>
7880
<th>{{.i18n.Tr "admin.users.created"}}</th>
7981
<th data-sortt-asc="leastupdate" data-sortt-desc="recentupdate">
@@ -92,7 +94,9 @@
9294
<td>{{if .IsActive}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}</td>
9395
<td>{{if .IsAdmin}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}</td>
9496
<td>{{if .IsRestricted}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}</td>
97+
{{if not Disable2FA}}
9598
<td>{{if index $.UsersTwoFaStatus .ID}}{{svg "octicon-check"}}{{else}}{{svg "octicon-x"}}{{end}}</td>
99+
{{end}}
96100
<td>{{.NumRepos}}</td>
97101
<td><span title="{{.CreatedUnix.FormatLong}}">{{.CreatedUnix.FormatShort}}</span></td>
98102
{{if .LastLoginUnix}}

templates/org/member/members.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
<strong>{{if index $.MembersIsUserOrgOwner .ID}}{{svg "octicon-shield-lock"}} {{$.i18n.Tr "org.members.owner"}}{{else}}{{$.i18n.Tr "org.members.member"}}{{end}}</strong>
3838
</div>
3939
</div>
40+
{{if not Disable2FA}}
4041
<div class="ui two wide column center">
4142
<div class="meta">
4243
{{$.i18n.Tr "admin.users.2fa"}}
@@ -51,6 +52,7 @@
5152
</strong>
5253
</div>
5354
</div>
55+
{{end}}
5456
<div class="ui three wide column">
5557
<div class="text right">
5658
{{if eq $.SignedUser.ID .ID}}

templates/user/settings/navbar.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@
99
<a class="{{if .PageIsSettingsAppearance}}active{{end}} item" href="{{AppSubUrl}}/user/settings/appearance">
1010
{{.i18n.Tr "settings.appearance"}}
1111
</a>
12+
{{if or (not Disable2FA) .EnableOpenIDSignIn .EnableOpenIDSignUp}}
1213
<a class="{{if .PageIsSettingsSecurity}}active{{end}} item" href="{{AppSubUrl}}/user/settings/security">
1314
{{.i18n.Tr "settings.security"}}
1415
</a>
16+
{{end}}
1517
<a class="{{if .PageIsSettingsApplications}}active{{end}} item" href="{{AppSubUrl}}/user/settings/applications">
1618
{{.i18n.Tr "settings.applications"}}
1719
</a>

templates/user/settings/security/security.tmpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@
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/webauthn" .}}
9+
{{end}}
10+
{{if .EnableOpenIDSignUp}}
811
{{template "user/settings/security/accountlinks" .}}
12+
{{end}}
913
{{if .EnableOpenIDSignIn}}
1014
{{template "user/settings/security/openid" .}}
1115
{{end}}

0 commit comments

Comments
 (0)