Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disabling application elements fixed #13129

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,8 @@ IMPORT_LOCAL_PATHS = false
; 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.
; WARNING: This maybe harmful to you website or your operating system.
DISABLE_GIT_HOOKS = true
; Set to false to disable 2FA feature.
DISABLE_2FA = false
; Set to false to allow pushes to gitea repositories despite having an incomplete environment - NOT RECOMMENDED
ONLY_ALLOW_PUSH_IF_GITEA_ENVIRONMENT_SET = true
;Comma separated list of character classes required to pass minimum complexity.
Expand Down
1 change: 1 addition & 0 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ relation to port exhaustion.
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.
This maybe harmful to you website or your operating system.
- `DISABLE_2FA`: **false**: Set to `true` to disable 2FA feature.
- `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.
- `IMPORT_LOCAL_PATHS`: **false**: Set to `false` to prevent all users (including admin) from importing local path on server.
- `INTERNAL_TOKEN`: **\<random at every install if no uri set\>**: Secret used to validate communication within Gitea binary.
Expand Down
12 changes: 9 additions & 3 deletions modules/cron/tasks_extended.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,15 @@ func initExtendedTasks() {
registerDeleteInactiveUsers()
registerDeleteRepositoryArchives()
registerGarbageCollectRepositories()
registerRewriteAllPublicKeys()
registerRewriteAllPrincipalKeys()
registerRepositoryUpdateHook()
if !setting.SSH.Disabled && !setting.SSH.StartBuiltinServer && setting.SSH.CreateAuthorizedKeysFile {
registerRewriteAllPublicKeys()
}
if !setting.SSH.Disabled && !setting.SSH.StartBuiltinServer && setting.SSH.CreateAuthorizedPrincipalsFile {
registerRewriteAllPrincipalKeys()
}
if !setting.DisableGitHooks {
registerRepositoryUpdateHook()
}
registerReinitMissingRepositories()
registerDeleteMissingRepositories()
registerRemoveRandomAvatars()
Expand Down
2 changes: 2 additions & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ var (
MinPasswordLength int
ImportLocalPaths bool
DisableGitHooks bool
Disable2FA bool
OnlyAllowPushIfGiteaEnvironmentSet bool
PasswordComplexity []string
PasswordHashAlgo string
Expand Down Expand Up @@ -770,6 +771,7 @@ func NewContext() {
MinPasswordLength = sec.Key("MIN_PASSWORD_LENGTH").MustInt(6)
ImportLocalPaths = sec.Key("IMPORT_LOCAL_PATHS").MustBool(false)
DisableGitHooks = sec.Key("DISABLE_GIT_HOOKS").MustBool(true)
Disable2FA = sec.Key("DISABLE_2FA").MustBool(false)
OnlyAllowPushIfGiteaEnvironmentSet = sec.Key("ONLY_ALLOW_PUSH_IF_GITEA_ENVIRONMENT_SET").MustBool(true)
PasswordHashAlgo = sec.Key("PASSWORD_HASH_ALGO").MustString("argon2")
CSRFCookieHTTPOnly = sec.Key("CSRF_COOKIE_HTTP_ONLY").MustBool(true)
Expand Down
9 changes: 9 additions & 0 deletions modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ func NewFuncMap() []template.FuncMap {
"DisableImportLocal": func() bool {
return !setting.ImportLocalPaths
},
"DisableSSH": func() bool {
return setting.SSH.Disabled
},
"DisableOAuth2": func() bool {
return !setting.OAuth2.Enable
},
"Disable2FA": func() bool {
return setting.Disable2FA
},
"TrN": TrN,
"Dict": func(values ...interface{}) (map[string]interface{}, error) {
if len(values)%2 != 0 {
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_bg-BG.ini
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,6 @@ account=Профил
password=Парола
security=Сигурност
avatar=Аватар
ssh_gpg_keys=SSH / GPG ключове
social=Социални профили
applications=Приложения
orgs=Управление на организации
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_cs-CZ.ini
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ account=Účet
password=Heslo
security=Zabezpečení
avatar=Avatar
ssh_gpg_keys=SSH / GPG klíče
social=Účty sociálních sítí
applications=Aplikace
orgs=Spravovat organizace
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_de-DE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ account=Account
password=Passwort
security=Sicherheit
avatar=Profilbild
ssh_gpg_keys=SSH- / GPG-Schlüssel
social=Soziale Konten
applications=Anwendungen
orgs=Organisationen verwalten
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ account = Account
password = Password
security = Security
avatar = Avatar
ssh_gpg_keys = SSH / GPG Keys
keys = Keys
social = Social Accounts
applications = Applications
orgs = Manage Organizations
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_es-ES.ini
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ account=Cuenta
password=Contraseña
security=Seguridad
avatar=Avatar
ssh_gpg_keys=SSH / claves GPG
social=Redes Sociales
applications=Aplicaciones
orgs=Administrar organizaciones
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_fa-IR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ account=حساب کاربری
password=گذرواژه
security=امنیت
avatar=آواتار
ssh_gpg_keys=کلید‌های SSH / GPG
social=حساب های اجتماعی
applications=برنامه‌ها
orgs=مدیریت سازمان‌ها
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_fi-FI.ini
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,6 @@ account=Tili
password=Salasana
security=Turvallisuus
avatar=Profiilikuva
ssh_gpg_keys=SSH / GPG-avaimet
social=Sosiaaliset tilit
applications=Sovellukset
orgs=Hallitse organisaatioita
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_fr-FR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ account=Compte
password=Mot de passe
security=Sécurité
avatar=Avatar
ssh_gpg_keys=Clés SSH / GPG
social=Réseaux Sociaux
applications=Applications
orgs=Gérer les organisations
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_hu-HU.ini
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,6 @@ account=Fiók
password=Jelszó
security=Biztonság
avatar=Profilkép
ssh_gpg_keys=SSH / GPG kulcsok
social=Közösségi fiókok
applications=Alkalmazások
orgs=Szervezetek kezelése
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_id-ID.ini
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,6 @@ account=Akun
password=Kata Sandi
security=Keamanan
avatar=Avatar
ssh_gpg_keys=Kunci SSH / GPG
social=Akun Sosial
applications=Aplikasi
orgs=Kelola organisasi
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_it-IT.ini
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ account=Account
password=Password
security=Sicurezza
avatar=Avatar
ssh_gpg_keys=Chiavi SSH / GPG
social=Account Sociali
applications=Applicazioni
orgs=Gestisci le organizzazioni
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_ja-JP.ini
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ account=アカウント
password=パスワード
security=セキュリティ
avatar=アバター
ssh_gpg_keys=SSH / GPGキー
social=ソーシャルアカウント
applications=アプリケーション
orgs=組織の管理
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_ko-KR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,6 @@ account=계정
password=비밀번호
security=보안
avatar=아바타
ssh_gpg_keys=SSH / GPG 키
social=소셜 계정
applications=어플리케이션
orgs=조직 관리
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_lv-LV.ini
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ account=Konts
password=Parole
security=Drošība
avatar=Profila attēls
ssh_gpg_keys=SSH / GPG atslēgas
social=Sociālie konti
applications=Lietotnes
orgs=Pārvaldīt organizācijas
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_ml-IN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@ account=അക്കൗണ്ട്
password=രഹസ്യവാക്കു്
security=സുരക്ഷ
avatar=അവതാര്‍
ssh_gpg_keys=SSH / GPG കീകള്‍
social=സോഷ്യൽ അക്കൗണ്ടുകൾ
applications=അപ്ലിക്കേഷനുകൾ
orgs=സംഘടനകളെ നിയന്ത്രിക്കുക
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_nl-NL.ini
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ account=Account
password=Wachtwoord
security=Beveiliging
avatar=Profielfoto
ssh_gpg_keys=SSH / GPG sleutels
social=Sociale netwerk-accounts
applications=Applicaties
orgs=Beheer organisaties
Expand Down
2 changes: 1 addition & 1 deletion options/locale/locale_pl-PL.ini
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ account=Konto
password=Hasło
security=Bezpieczeństwo
avatar=Awatar
ssh_gpg_keys=Klucze SSH / GPG
keys=Klucze
social=Konta społecznościowe
applications=Aplikacje
orgs=Zarządzaj organizacjami
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_pt-BR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,6 @@ account=Conta
password=Senha
security=Segurança
avatar=Avatar
ssh_gpg_keys=Chaves SSH / GPG
social=Contas sociais
applications=Aplicativos
orgs=Gerenciar organizações
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_pt-PT.ini
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ account=Conta
password=Senha
security=Segurança
avatar=Avatar
ssh_gpg_keys=Chaves SSH / GPG
social=Contas sociais
applications=Aplicações
orgs=Gerir organizações
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_ru-RU.ini
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ account=Аккаунт
password=Пароль
security=Безопасность
avatar=Аватар
ssh_gpg_keys=SSH / GPG ключи
social=Учетные записи в соцсетях
applications=Приложения
orgs=Управление организациями
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_sv-SE.ini
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,6 @@ account=Konto
password=Lösenord
security=Säkerhet
avatar=Visningsbild
ssh_gpg_keys=SSH / GPG-nycklar
social=Sociala konton
applications=Applikationer
orgs=Hantera Organisationer
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_tr-TR.ini
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ account=Hesap
password=Parola
security=Güvenlik
avatar=Avatar
ssh_gpg_keys=SSH / GPG Anahtarları
social=Sosyal Medya Hesapları
applications=Uygulamalar
orgs=Organizasyonları Yönet
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_uk-UA.ini
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ account=Обліковий запис
password=Пароль
security=Безпека
avatar=Аватар
ssh_gpg_keys=SSH / GPG ключі
social=Соціальні облікові записи
applications=Додатки
orgs=Керування організаціями
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_zh-CN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,6 @@ account=账号
password=修改密码
security=安全
avatar=头像设置
ssh_gpg_keys=SSH / GPG 密钥
social=社交帐号绑定
applications=应用
orgs=管理组织
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_zh-HK.ini
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ form.name_reserved=這個使用者名稱已被系統保留,請改用其他名
profile=個人訊息
password=修改密碼
avatar=頭像
ssh_gpg_keys=SSH / GPG 金鑰
social=社交帳號綁定
delete=刪除帳戶
twofa=兩步驟驗證
Expand Down
1 change: 0 additions & 1 deletion options/locale/locale_zh-TW.ini
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ account=帳戶
password=修改密碼
security=安全性
avatar=大頭貼
ssh_gpg_keys=SSH / GPG 金鑰
social=社群帳戶
applications=應用程式
orgs=管理組織
Expand Down
20 changes: 16 additions & 4 deletions routers/routes/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,18 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("/:provider", user.SignInOAuth)
m.Get("/:provider/callback", user.SignInOAuthCallback)
})
m.Get("/link_account", user.LinkAccount)
m.Post("/link_account_signin", bindIgnErr(auth.SignInForm{}), user.LinkAccountPostSignIn)
m.Post("/link_account_signup", bindIgnErr(auth.RegisterForm{}), user.LinkAccountPostRegister)
m.Group("/link_account", func() {
m.Get("", user.LinkAccount)
}, openIDSignInEnabled)

m.Group("/link_account_signin", func() {
m.Post("", bindIgnErr(auth.SignInForm{}), user.LinkAccountPostSignIn)
}, openIDSignInEnabled)

m.Group("/link_account_signup", func() {
m.Post("", bindIgnErr(auth.RegisterForm{}), user.LinkAccountPostRegister)
}, openIDSignUpEnabled)

m.Group("/two_factor", func() {
m.Get("", user.TwoFactor)
m.Post("", bindIgnErr(auth.TwoFactorAuthForm{}), user.TwoFactorPost)
Expand Down Expand Up @@ -429,7 +438,10 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Post("/delete", userSetting.DeleteOpenID)
m.Post("/toggle_visibility", userSetting.ToggleOpenIDVisibility)
}, openIDSignInEnabled)
m.Post("/account_link", userSetting.DeleteAccountLink)

m.Group("/account_link", func() {
m.Post("", userSetting.DeleteAccountLink)
}, openIDSignInEnabled)
})
m.Group("/applications/oauth2", func() {
m.Get("/:id", userSetting.OAuth2ApplicationShow)
Expand Down
25 changes: 20 additions & 5 deletions routers/user/setting/applications.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
package setting

import (
"fmt"

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/base"
Expand Down Expand Up @@ -39,6 +41,11 @@ func ApplicationsPost(ctx *context.Context, form auth.NewAccessTokenForm) {
return
}

if !setting.API.EnableSwagger {
ctx.ServerError("AccessToken", fmt.Errorf("cannot modify access tokens; swagger disabled"))
return
}

t := &models.AccessToken{
UID: ctx.User.ID,
Name: form.Name,
Expand Down Expand Up @@ -68,6 +75,11 @@ func ApplicationsPost(ctx *context.Context, form auth.NewAccessTokenForm) {

// DeleteApplication response for delete user access token
func DeleteApplication(ctx *context.Context) {
if !setting.API.EnableSwagger {
ctx.ServerError("DeleteAccessToken", fmt.Errorf("cannot delete access token; swagger disabled"))
return
}

if err := models.DeleteAccessTokenByID(ctx.QueryInt64("id"), ctx.User.ID); err != nil {
ctx.Flash.Error("DeleteAccessTokenByID: " + err.Error())
} else {
Expand All @@ -80,14 +92,17 @@ func DeleteApplication(ctx *context.Context) {
}

func loadApplicationsData(ctx *context.Context) {
tokens, err := models.ListAccessTokens(models.ListAccessTokensOptions{UserID: ctx.User.ID})
if err != nil {
ctx.ServerError("ListAccessTokens", err)
return
if setting.API.EnableSwagger {
tokens, err := models.ListAccessTokens(models.ListAccessTokensOptions{UserID: ctx.User.ID})
if err != nil {
ctx.ServerError("ListAccessTokens", err)
return
}
ctx.Data["Tokens"] = tokens
}
ctx.Data["Tokens"] = tokens
ctx.Data["EnableOAuth2"] = setting.OAuth2.Enable
if setting.OAuth2.Enable {
var err error
ctx.Data["Applications"], err = models.GetOAuth2ApplicationsByUserID(ctx.User.ID)
if err != nil {
ctx.ServerError("GetOAuth2ApplicationsByUserID", err)
Expand Down
6 changes: 5 additions & 1 deletion templates/admin/dashboard.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -35,22 +35,26 @@
<td>{{.i18n.Tr "admin.dashboard.git_gc_repos"}}</td>
<td><button type="submit" class="ui green button" name="op" value="git_gc_repos">{{svg "octicon-play"}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
{{if and (not .SSH.Disabled) (not .SSH.StartBuiltinServer)}}
{{if and (not .SSH.Disabled) (not .SSH.StartBuiltinServer) (.SSH.CreateAuthorizedKeysFile) }}
<tr>
<td>{{.i18n.Tr "admin.dashboard.resync_all_sshkeys"}}<br/>
{{.i18n.Tr "admin.dashboard.resync_all_sshkeys.desc"}}</td>
<td><button type="submit" class="ui green button" name="op" value="resync_all_sshkeys">{{svg "octicon-play"}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
{{end}}
{{if and (not .SSH.Disabled) (not .SSH.StartBuiltinServer) (.SSH.CreateAuthorizedPrincipalsFile) }}
<tr>
<td>{{.i18n.Tr "admin.dashboard.resync_all_sshprincipals"}}<br/>
{{.i18n.Tr "admin.dashboard.resync_all_sshprincipals.desc"}}</td>
<td><button type="submit" class="ui green button" name="op" value="resync_all_sshprincipals">{{svg "octicon-play" 16}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
{{end}}
{{if not DisableGitHooks}}
<tr>
<td>{{.i18n.Tr "admin.dashboard.resync_all_hooks"}}</td>
<td><button type="submit" class="ui green button" name="op" value="resync_all_hooks">{{svg "octicon-play"}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
</tr>
{{end}}
<tr>
<td>{{.i18n.Tr "admin.dashboard.reinit_missing_repos"}}</td>
<td><button type="submit" class="ui green button" name="op" value="reinit_missing_repos">{{svg "octicon-play"}} {{.i18n.Tr "admin.dashboard.operation_run"}}</button></td>
Expand Down
Loading