Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Add a storage layer for attachments (#11387) * Add a storage layer for attachments * Fix some bug * fix test * Fix copyright head and lint * Fix bug * Add setting for minio and flags for migrate-storage * Add documents * fix lint * Add test for minio store type on attachments * fix test * fix test * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Add warning when storage migrated successfully * Fix drone * fix test * rebase * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * refactor the codes * add trace * Fix test * remove log on xorm * Fi download bug * Add a storage layer for attachments * Add setting for minio and flags for migrate-storage * fix lint * Add test for minio store type on attachments * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Fix drone * fix test * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * refactor the codes * add trace * Fix test * Add URL function to serve attachments directly from S3/Minio * Add ability to enable/disable redirection in attachment configuration * Fix typo * Add a storage layer for attachments * Add setting for minio and flags for migrate-storage * fix lint * Add test for minio store type on attachments * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Fix drone * fix test * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * don't change unrelated files * Fix lint * Fix build * update go.mod and go.sum * Use github.com/minio/minio-go/v6 * Remove unused function * Upgrade minio to v7 and some other improvements * fix lint * Fix go mod Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Tyler <tystuyfzand@gmail.com>
pirms 3 gadiem
Refactor: Move login out of models (#16199) `models` does far too much. In particular it handles all `UserSignin`. It shouldn't be responsible for calling LDAP, SMTP or PAM for signing in. Therefore we should move this code out of `models`. This code has to depend on `models` - therefore it belongs in `services`. There is a package in `services` called `auth` and clearly this functionality belongs in there. Plan: - [x] Change `auth.Auth` to `auth.Method` - as they represent methods of authentication. - [x] Move `models.UserSignIn` into `auth` - [x] Move `models.ExternalUserLogin` - [x] Move most of the `LoginVia*` methods to `auth` or subpackages - [x] Move Resynchronize functionality to `auth` - Involved some restructuring of `models/ssh_key.go` to reduce the size of this massive file and simplify its files. - [x] Move the rest of the LDAP functionality in to the ldap subpackage - [x] Re-factor the login sources to express an interfaces `auth.Source`? - I've done this through some smaller interfaces Authenticator and Synchronizable - which would allow us to extend things in future - [x] Now LDAP is out of models - need to think about modules/auth/ldap and I think all of that functionality might just be moveable - [x] Similarly a lot Oauth2 functionality need not be in models too and should be moved to services/auth/source/oauth2 - [x] modules/auth/oauth2/oauth2.go uses xorm... This is naughty - probably need to move this into models. - [x] models/oauth2.go - mostly should be in modules/auth/oauth2 or services/auth/source/oauth2 - [x] More simplifications of login_source.go may need to be done - Allow wiring in of notify registration - *this can now easily be done - but I think we should do it in another PR* - see #16178 - More refactors...? - OpenID should probably become an auth Method but I think that can be left for another PR - Methods should also probably be cleaned up - again another PR I think. - SSPI still needs more refactors.* Rename auth.Auth auth.Method * Restructure ssh_key.go - move functions from models/user.go that relate to ssh_key to ssh_key - split ssh_key.go to try create clearer function domains for allow for future refactors here. Signed-off-by: Andrew Thornton <art27@cantab.net>
pirms 2 gadiem
Add a storage layer for attachments (#11387) * Add a storage layer for attachments * Fix some bug * fix test * Fix copyright head and lint * Fix bug * Add setting for minio and flags for migrate-storage * Add documents * fix lint * Add test for minio store type on attachments * fix test * fix test * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Add warning when storage migrated successfully * Fix drone * fix test * rebase * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * refactor the codes * add trace * Fix test * remove log on xorm * Fi download bug * Add a storage layer for attachments * Add setting for minio and flags for migrate-storage * fix lint * Add test for minio store type on attachments * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Fix drone * fix test * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * refactor the codes * add trace * Fix test * Add URL function to serve attachments directly from S3/Minio * Add ability to enable/disable redirection in attachment configuration * Fix typo * Add a storage layer for attachments * Add setting for minio and flags for migrate-storage * fix lint * Add test for minio store type on attachments * Apply suggestions from code review Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> * Fix drone * fix test * Fix test * display the error on console * Move minio test to amd64 since minio docker don't support arm64 * don't change unrelated files * Fix lint * Fix build * update go.mod and go.sum * Use github.com/minio/minio-go/v6 * Remove unused function * Upgrade minio to v7 and some other improvements * fix lint * Fix go mod Co-authored-by: guillep2k <18600385+guillep2k@users.noreply.github.com> Co-authored-by: Tyler <tystuyfzand@gmail.com>
pirms 3 gadiem
Add single sign-on support via SSPI on Windows (#8463) * Add single sign-on support via SSPI on Windows * Ensure plugins implement interface * Ensure plugins implement interface * Move functions used only by the SSPI auth method to sspi_windows.go * Field SSPISeparatorReplacement of AuthenticationForm should not be required via binding, as binding will insist the field is non-empty even if another login type is selected * Fix breaking of oauth authentication on download links. Do not create new session with SSPI authentication on download links. * Update documentation for the new 'SPNEGO with SSPI' login source * Mention in documentation that ROOT_URL should contain the FQDN of the server * Make sure that Contexter is not checking for active login sources when the ORM engine is not initialized (eg. when installing) * Always initialize and free SSO methods, even if they are not enabled, as a method can be activated while the app is running (from Authentication sources) * Add option in SSPIConfig for removing of domains from logon names * Update helper text for StripDomainNames option * Make sure handleSignIn() is called after a new user object is created by SSPI auth method * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Remove default value from text of form field helper Co-Authored-By: Lauris BH <lauris@nix.lv> * Only make a query to the DB to check if SSPI is enabled on handlers that need that information for templates * Remove code duplication * Log errors in ActiveLoginSources Co-Authored-By: Lauris BH <lauris@nix.lv> * Revert suffix of randomly generated E-mails for Reverse proxy authentication Co-Authored-By: Lauris BH <lauris@nix.lv> * Revert unneeded white-space change in template Co-Authored-By: Lauris BH <lauris@nix.lv> * Add copyright comments at the top of new files * Use loopback name for randomly generated emails * Add locale tag for the SSPISeparatorReplacement field with proper casing * Revert casing of SSPISeparatorReplacement field in locale file, moving it up, next to other form fields * Update docs/content/doc/features/authentication.en-us.md Co-Authored-By: guillep2k <18600385+guillep2k@users.noreply.github.com> * Remove Priority() method and define the order in which SSO auth methods should be executed in one place * Log authenticated username only if it's not empty * Rephrase helper text for automatic creation of users * Return error if more than one active SSPI auth source is found * Change newUser() function to return error, letting caller log/handle the error * Move isPublicResource, isPublicPage and handleSignIn functions outside SSPI auth method to allow other SSO methods to reuse them if needed * Refactor initialization of the list containing SSO auth methods * Validate SSPI settings on POST * Change SSPI to only perform authentication on its own login page, API paths and download links. Leave Toggle middleware to redirect non authenticated users to login page * Make 'Default language' in SSPI config empty, unless changed by admin * Show error if admin tries to add a second authentication source of type SSPI * Simplify declaration of global variable * Rebuild gitgraph.js on Linux * Make sure config values containing only whitespace are not accepted
pirms 4 gadiem
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // Copyright 2016 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package routers
  5. import (
  6. "context"
  7. "net"
  8. "reflect"
  9. "runtime"
  10. "strconv"
  11. "strings"
  12. "code.gitea.io/gitea/models"
  13. "code.gitea.io/gitea/modules/appstate"
  14. "code.gitea.io/gitea/modules/cache"
  15. "code.gitea.io/gitea/modules/eventsource"
  16. "code.gitea.io/gitea/modules/git"
  17. "code.gitea.io/gitea/modules/highlight"
  18. code_indexer "code.gitea.io/gitea/modules/indexer/code"
  19. issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
  20. stats_indexer "code.gitea.io/gitea/modules/indexer/stats"
  21. "code.gitea.io/gitea/modules/log"
  22. "code.gitea.io/gitea/modules/markup"
  23. "code.gitea.io/gitea/modules/markup/external"
  24. "code.gitea.io/gitea/modules/notification"
  25. "code.gitea.io/gitea/modules/setting"
  26. "code.gitea.io/gitea/modules/ssh"
  27. "code.gitea.io/gitea/modules/storage"
  28. "code.gitea.io/gitea/modules/svg"
  29. "code.gitea.io/gitea/modules/translation"
  30. "code.gitea.io/gitea/modules/web"
  31. apiv1 "code.gitea.io/gitea/routers/api/v1"
  32. "code.gitea.io/gitea/routers/common"
  33. "code.gitea.io/gitea/routers/private"
  34. web_routers "code.gitea.io/gitea/routers/web"
  35. "code.gitea.io/gitea/services/archiver"
  36. "code.gitea.io/gitea/services/auth"
  37. "code.gitea.io/gitea/services/auth/source/oauth2"
  38. "code.gitea.io/gitea/services/cron"
  39. "code.gitea.io/gitea/services/mailer"
  40. repo_migrations "code.gitea.io/gitea/services/migrations"
  41. mirror_service "code.gitea.io/gitea/services/mirror"
  42. pull_service "code.gitea.io/gitea/services/pull"
  43. repo_service "code.gitea.io/gitea/services/repository"
  44. "code.gitea.io/gitea/services/task"
  45. "code.gitea.io/gitea/services/webhook"
  46. "gitea.com/go-chi/session"
  47. )
  48. func mustInit(fn func() error) {
  49. err := fn()
  50. if err != nil {
  51. ptr := reflect.ValueOf(fn).Pointer()
  52. fi := runtime.FuncForPC(ptr)
  53. log.Fatal("%s failed: %v", fi.Name(), err)
  54. }
  55. }
  56. func mustInitCtx(ctx context.Context, fn func(ctx context.Context) error) {
  57. err := fn(ctx)
  58. if err != nil {
  59. ptr := reflect.ValueOf(fn).Pointer()
  60. fi := runtime.FuncForPC(ptr)
  61. log.Fatal("%s(ctx) failed: %v", fi.Name(), err)
  62. }
  63. }
  64. // InitGitServices init new services for git, this is also called in `contrib/pr/checkout.go`
  65. func InitGitServices() {
  66. setting.NewServices()
  67. mustInit(storage.Init)
  68. mustInit(repo_service.NewContext)
  69. }
  70. func syncAppPathForGit(ctx context.Context) error {
  71. runtimeState := new(appstate.RuntimeState)
  72. if err := appstate.AppState.Get(runtimeState); err != nil {
  73. return err
  74. }
  75. if runtimeState.LastAppPath != setting.AppPath {
  76. log.Info("AppPath changed from '%s' to '%s'", runtimeState.LastAppPath, setting.AppPath)
  77. log.Info("re-sync repository hooks ...")
  78. mustInitCtx(ctx, repo_service.SyncRepositoryHooks)
  79. log.Info("re-write ssh public keys ...")
  80. mustInit(models.RewriteAllPublicKeys)
  81. runtimeState.LastAppPath = setting.AppPath
  82. return appstate.AppState.Set(runtimeState)
  83. }
  84. return nil
  85. }
  86. // GlobalInitInstalled is for global installed configuration.
  87. func GlobalInitInstalled(ctx context.Context) {
  88. if !setting.InstallLock {
  89. log.Fatal("Gitea is not installed")
  90. }
  91. mustInitCtx(ctx, git.Init)
  92. log.Info(git.VersionInfo())
  93. git.CheckLFSVersion()
  94. log.Info("AppPath: %s", setting.AppPath)
  95. log.Info("AppWorkPath: %s", setting.AppWorkPath)
  96. log.Info("Custom path: %s", setting.CustomPath)
  97. log.Info("Log path: %s", setting.LogRootPath)
  98. log.Info("Configuration file: %s", setting.CustomConf)
  99. log.Info("Run Mode: %s", strings.Title(setting.RunMode))
  100. // Setup i18n
  101. translation.InitLocales()
  102. InitGitServices()
  103. mailer.NewContext()
  104. mustInit(cache.NewContext)
  105. notification.NewContext()
  106. mustInit(archiver.Init)
  107. highlight.NewContext()
  108. external.RegisterRenderers()
  109. markup.Init()
  110. if setting.EnableSQLite3 {
  111. log.Info("SQLite3 support is enabled")
  112. } else if setting.Database.UseSQLite3 {
  113. log.Fatal("SQLite3 support is disabled, but it is used for database setting. Please get or build a Gitea release with SQLite3 support.")
  114. }
  115. mustInitCtx(ctx, common.InitDBEngine)
  116. log.Info("ORM engine initialization successful!")
  117. mustInit(appstate.Init)
  118. mustInit(oauth2.Init)
  119. models.NewRepoContext()
  120. // Booting long running goroutines.
  121. cron.NewContext()
  122. issue_indexer.InitIssueIndexer(false)
  123. code_indexer.Init()
  124. mustInit(stats_indexer.Init)
  125. mirror_service.InitSyncMirrors()
  126. webhook.InitDeliverHooks()
  127. mustInit(pull_service.Init)
  128. mustInit(task.Init)
  129. mustInit(repo_migrations.Init)
  130. eventsource.GetManager().Init()
  131. mustInitCtx(ctx, syncAppPathForGit)
  132. if setting.SSH.StartBuiltinServer {
  133. ssh.Listen(setting.SSH.ListenHost, setting.SSH.ListenPort, setting.SSH.ServerCiphers, setting.SSH.ServerKeyExchanges, setting.SSH.ServerMACs)
  134. log.Info("SSH server started on %s. Cipher list (%v), key exchange algorithms (%v), MACs (%v)",
  135. net.JoinHostPort(setting.SSH.ListenHost, strconv.Itoa(setting.SSH.ListenPort)),
  136. setting.SSH.ServerCiphers, setting.SSH.ServerKeyExchanges, setting.SSH.ServerMACs)
  137. } else {
  138. ssh.Unused()
  139. }
  140. auth.Init()
  141. svg.Init()
  142. }
  143. // NormalRoutes represents non install routes
  144. func NormalRoutes() *web.Route {
  145. r := web.NewRoute()
  146. for _, middle := range common.Middlewares() {
  147. r.Use(middle)
  148. }
  149. sessioner := session.Sessioner(session.Options{
  150. Provider: setting.SessionConfig.Provider,
  151. ProviderConfig: setting.SessionConfig.ProviderConfig,
  152. CookieName: setting.SessionConfig.CookieName,
  153. CookiePath: setting.SessionConfig.CookiePath,
  154. Gclifetime: setting.SessionConfig.Gclifetime,
  155. Maxlifetime: setting.SessionConfig.Maxlifetime,
  156. Secure: setting.SessionConfig.Secure,
  157. SameSite: setting.SessionConfig.SameSite,
  158. Domain: setting.SessionConfig.Domain,
  159. })
  160. r.Mount("/", web_routers.Routes(sessioner))
  161. r.Mount("/api/v1", apiv1.Routes(sessioner))
  162. r.Mount("/api/internal", private.Routes())
  163. return r
  164. }