forgejo-federation/services/cron/tasks_extended.go

244 lines
7.7 KiB
Go
Raw Normal View History

// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package cron
import (
"context"
"time"
activities_model "code.gitea.io/gitea/models/activities"
asymkey_model "code.gitea.io/gitea/models/asymkey"
"code.gitea.io/gitea/models/system"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/git"
issue_indexer "code.gitea.io/gitea/modules/indexer/issues"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/updatechecker"
repo_service "code.gitea.io/gitea/services/repository"
archiver_service "code.gitea.io/gitea/services/repository/archiver"
user_service "code.gitea.io/gitea/services/user"
)
func registerDeleteInactiveUsers() {
RegisterTaskFatal("delete_inactive_accounts", &OlderThanConfig{
BaseConfig: BaseConfig{
Enabled: false,
RunAtStart: false,
Schedule: "@annually",
},
OlderThan: time.Minute * time.Duration(setting.Service.ActiveCodeLives),
}, func(ctx context.Context, _ *user_model.User, config Config) error {
olderThanConfig := config.(*OlderThanConfig)
return user_service.DeleteInactiveUsers(ctx, olderThanConfig.OlderThan)
})
}
func registerDeleteRepositoryArchives() {
RegisterTaskFatal("delete_repo_archives", &BaseConfig{
Enabled: false,
RunAtStart: false,
Schedule: "@annually",
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
return archiver_service.DeleteRepositoryArchives(ctx)
})
}
func registerGarbageCollectRepositories() {
type RepoHealthCheckConfig struct {
BaseConfig
Timeout time.Duration
Args []string `delim:" "`
}
RegisterTaskFatal("git_gc_repos", &RepoHealthCheckConfig{
BaseConfig: BaseConfig{
Enabled: false,
RunAtStart: false,
Schedule: "@every 72h",
},
Timeout: time.Duration(setting.Git.Timeout.GC) * time.Second,
Args: setting.Git.GCArgs,
}, func(ctx context.Context, _ *user_model.User, config Config) error {
rhcConfig := config.(*RepoHealthCheckConfig)
// the git args are set by config, they can be safe to be trusted
Refactor git command package to improve security and maintainability (#22678) This PR follows #21535 (and replace #22592) ## Review without space diff https://github.com/go-gitea/gitea/pull/22678/files?diff=split&w=1 ## Purpose of this PR 1. Make git module command completely safe (risky user inputs won't be passed as argument option anymore) 2. Avoid low-level mistakes like https://github.com/go-gitea/gitea/pull/22098#discussion_r1045234918 3. Remove deprecated and dirty `CmdArgCheck` function, hide the `CmdArg` type 4. Simplify code when using git command ## The main idea of this PR * Move the `git.CmdArg` to the `internal` package, then no other package except `git` could use it. Then developers could never do `AddArguments(git.CmdArg(userInput))` any more. * Introduce `git.ToTrustedCmdArgs`, it's for user-provided and already trusted arguments. It's only used in a few cases, for example: use git arguments from config file, help unit test with some arguments. * Introduce `AddOptionValues` and `AddOptionFormat`, they make code more clear and simple: * Before: `AddArguments("-m").AddDynamicArguments(message)` * After: `AddOptionValues("-m", message)` * - * Before: `AddArguments(git.CmdArg(fmt.Sprintf("--author='%s <%s>'", sig.Name, sig.Email)))` * After: `AddOptionFormat("--author='%s <%s>'", sig.Name, sig.Email)` ## FAQ ### Why these changes were not done in #21535 ? #21535 is mainly a search&replace, it did its best to not change too much logic. Making the framework better needs a lot of changes, so this separate PR is needed as the second step. ### The naming of `AddOptionXxx` According to git's manual, the `--xxx` part is called `option`. ### How can it guarantee that `internal.CmdArg` won't be not misused? Go's specification guarantees that. Trying to access other package's internal package causes compilation error. And, `golangci-lint` also denies the git/internal package. Only the `git/command.go` can use it carefully. ### There is still a `ToTrustedCmdArgs`, will it still allow developers to make mistakes and pass untrusted arguments? Generally speaking, no. Because when using `ToTrustedCmdArgs`, the code will be very complex (see the changes for examples). Then developers and reviewers can know that something might be unreasonable. ### Why there was a `CmdArgCheck` and why it's removed? At the moment of #21535, to reduce unnecessary changes, `CmdArgCheck` was introduced as a hacky patch. Now, almost all code could be written as `cmd := NewCommand(); cmd.AddXxx(...)`, then there is no need for `CmdArgCheck` anymore. ### Why many codes for `signArg == ""` is deleted? Because in the old code, `signArg` could never be empty string, it's either `-S[key-id]` or `--no-gpg-sign`. So the `signArg == ""` is just dead code. --------- Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
2023-02-04 08:00:43 +05:30
return repo_service.GitGcRepos(ctx, rhcConfig.Timeout, git.ToTrustedCmdArgs(rhcConfig.Args))
})
}
func registerRewriteAllPublicKeys() {
RegisterTaskFatal("resync_all_sshkeys", &BaseConfig{
Enabled: false,
RunAtStart: false,
Schedule: "@every 72h",
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
return asymkey_model.RewriteAllPublicKeys(ctx)
})
}
Add ssh certificate support (#12281) * Add ssh certificate support * Add ssh certificate support to builtin ssh * Write trusted-user-ca-keys.pem based on configuration * Update app.example.ini * Update templates/user/settings/keys_principal.tmpl Co-authored-by: silverwind <me@silverwind.io> * Remove unused locale string * Update options/locale/locale_en-US.ini Co-authored-by: silverwind <me@silverwind.io> * Update options/locale/locale_en-US.ini Co-authored-by: silverwind <me@silverwind.io> * Update models/ssh_key.go Co-authored-by: silverwind <me@silverwind.io> * Add missing creation of SSH.Rootpath * Update cheatsheet, example and locale strings * Update models/ssh_key.go Co-authored-by: zeripath <art27@cantab.net> * Update models/ssh_key.go Co-authored-by: zeripath <art27@cantab.net> * Update models/ssh_key.go Co-authored-by: zeripath <art27@cantab.net> * Update models/ssh_key.go Co-authored-by: zeripath <art27@cantab.net> * Update models/ssh_key.go * Optimizations based on feedback * Validate CA keys for external sshd * Add filename option and change default filename Add a SSH_TRUSTED_USER_CA_KEYS_FILENAME option which default is RUN_USER/.ssh/gitea-trusted-user-ca-keys.pem Do not write a file when SSH_TRUSTED_USER_CA_KEYS is empty. Add some more documentation. * Remove unneeded principalkey functions * Add blank line * Apply suggestions from code review Co-authored-by: zeripath <art27@cantab.net> * Add SSH_AUTHORIZED_PRINCIPALS_ALLOW option This adds a SSH_AUTHORIZED_PRINCIPALS_ALLOW which is default email,username this means that users only can add the principals that match their email or username. To allow anything the admin need to set the option anything. This allows for a safe default in gitea which protects against malicious users using other user's prinicipals. (before that user could set it). This commit also has some small other fixes from the last code review. * Rewrite principal keys file on user deletion * Use correct rewrite method * Set correct AuthorizedPrincipalsBackup default setting * Rewrite principalsfile when adding principals * Add update authorized_principals option to admin dashboard * Handle non-primary emails Signed-off-by: Andrew Thornton <art27@cantab.net> * Add the command actually to the dashboard template * Update models/ssh_key.go Co-authored-by: silverwind <me@silverwind.io> * By default do not show principal options unless there are CA keys set or they are explicitly set Signed-off-by: Andrew Thornton <art27@cantab.net> * allow settings when enabled * Fix typos in TrustedUserCAKeys path * Allow every CASignatureAlgorithms algorithm As this depends on the content of TrustedUserCAKeys we should allow all signature algorithms as admins can choose the specific algorithm on their signing CA * Update models/ssh_key.go Co-authored-by: Lauris BH <lauris@nix.lv> * Fix linting issue Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2020-10-11 06:08:09 +05:30
func registerRewriteAllPrincipalKeys() {
RegisterTaskFatal("resync_all_sshprincipals", &BaseConfig{
Enabled: false,
RunAtStart: false,
Schedule: "@every 72h",
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
return asymkey_model.RewriteAllPrincipalKeys(ctx)
Add ssh certificate support (#12281) * Add ssh certificate support * Add ssh certificate support to builtin ssh * Write trusted-user-ca-keys.pem based on configuration * Update app.example.ini * Update templates/user/settings/keys_principal.tmpl Co-authored-by: silverwind <me@silverwind.io> * Remove unused locale string * Update options/locale/locale_en-US.ini Co-authored-by: silverwind <me@silverwind.io> * Update options/locale/locale_en-US.ini Co-authored-by: silverwind <me@silverwind.io> * Update models/ssh_key.go Co-authored-by: silverwind <me@silverwind.io> * Add missing creation of SSH.Rootpath * Update cheatsheet, example and locale strings * Update models/ssh_key.go Co-authored-by: zeripath <art27@cantab.net> * Update models/ssh_key.go Co-authored-by: zeripath <art27@cantab.net> * Update models/ssh_key.go Co-authored-by: zeripath <art27@cantab.net> * Update models/ssh_key.go Co-authored-by: zeripath <art27@cantab.net> * Update models/ssh_key.go * Optimizations based on feedback * Validate CA keys for external sshd * Add filename option and change default filename Add a SSH_TRUSTED_USER_CA_KEYS_FILENAME option which default is RUN_USER/.ssh/gitea-trusted-user-ca-keys.pem Do not write a file when SSH_TRUSTED_USER_CA_KEYS is empty. Add some more documentation. * Remove unneeded principalkey functions * Add blank line * Apply suggestions from code review Co-authored-by: zeripath <art27@cantab.net> * Add SSH_AUTHORIZED_PRINCIPALS_ALLOW option This adds a SSH_AUTHORIZED_PRINCIPALS_ALLOW which is default email,username this means that users only can add the principals that match their email or username. To allow anything the admin need to set the option anything. This allows for a safe default in gitea which protects against malicious users using other user's prinicipals. (before that user could set it). This commit also has some small other fixes from the last code review. * Rewrite principal keys file on user deletion * Use correct rewrite method * Set correct AuthorizedPrincipalsBackup default setting * Rewrite principalsfile when adding principals * Add update authorized_principals option to admin dashboard * Handle non-primary emails Signed-off-by: Andrew Thornton <art27@cantab.net> * Add the command actually to the dashboard template * Update models/ssh_key.go Co-authored-by: silverwind <me@silverwind.io> * By default do not show principal options unless there are CA keys set or they are explicitly set Signed-off-by: Andrew Thornton <art27@cantab.net> * allow settings when enabled * Fix typos in TrustedUserCAKeys path * Allow every CASignatureAlgorithms algorithm As this depends on the content of TrustedUserCAKeys we should allow all signature algorithms as admins can choose the specific algorithm on their signing CA * Update models/ssh_key.go Co-authored-by: Lauris BH <lauris@nix.lv> * Fix linting issue Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2020-10-11 06:08:09 +05:30
})
}
func registerRepositoryUpdateHook() {
RegisterTaskFatal("resync_all_hooks", &BaseConfig{
Enabled: false,
RunAtStart: false,
Schedule: "@every 72h",
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
return repo_service.SyncRepositoryHooks(ctx)
})
}
func registerReinitMissingRepositories() {
RegisterTaskFatal("reinit_missing_repos", &BaseConfig{
Enabled: false,
RunAtStart: false,
Schedule: "@every 72h",
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
return repo_service.ReinitMissingRepositories(ctx)
})
}
func registerDeleteMissingRepositories() {
RegisterTaskFatal("delete_missing_repos", &BaseConfig{
Enabled: false,
RunAtStart: false,
Schedule: "@every 72h",
}, func(ctx context.Context, user *user_model.User, _ Config) error {
return repo_service.DeleteMissingRepositories(ctx, user)
})
}
func registerRemoveRandomAvatars() {
RegisterTaskFatal("delete_generated_repository_avatars", &BaseConfig{
Enabled: false,
RunAtStart: false,
Schedule: "@every 72h",
}, func(ctx context.Context, _ *user_model.User, _ Config) error {
return repo_service.RemoveRandomAvatars(ctx)
})
}
func registerDeleteOldActions() {
RegisterTaskFatal("delete_old_actions", &OlderThanConfig{
BaseConfig: BaseConfig{
Enabled: false,
RunAtStart: false,
Schedule: "@every 168h",
},
OlderThan: 365 * 24 * time.Hour,
}, func(ctx context.Context, _ *user_model.User, config Config) error {
olderThanConfig := config.(*OlderThanConfig)
return activities_model.DeleteOldActions(ctx, olderThanConfig.OlderThan)
})
}
func registerUpdateGiteaChecker() {
type UpdateCheckerConfig struct {
BaseConfig
[PRIVACY] Add a DNS method to fetch new updates - Use TXT records in order to determine the latest available version. - This addresses a valid privacy issue, as with HTTP requests the server can keep track(estimated) of how many instances are using Forgejo, with DNS that's basically not possible as the server will never receive any data, as the only ones receiving data are DNS resolvers. (cherry picked from commit 0baefb546ab96bc3c06d90feffdb14873c2c2a3a) (cherry picked from commit e8ee41880b775532e6a68bd2052ed96d369dee78) (cherry picked from commit 7eca4f3bf1faa3f063c9668d1bb354b842361007) (cherry picked from commit 6dde3992dc504f105f2285c34fa6445fa24da0b1) (cherry picked from commit fb3a37fbfc73d35e3ba8d793b6051aeddcbb0634) (cherry picked from commit 8304af1e9d94b89ee700b0d454d74d0dc5cfac64) (cherry picked from commit 0543a7d12a4bac012db8b9e683e879e6f265a9dc) (cherry picked from commit c3a22933b7ca8201c96267d360281848fb2a1c7e) (cherry picked from commit e24370769413aebe96ba6cfb230da3c2c33e39f4) (cherry picked from commit 7eb6d1bcf7a0bdae0cbbf06136854d0b29c54899) (cherry picked from commit 1d7b9535cd73bffda5defd143c25e514cc55dee8) (cherry picked from commit 05920dce67808ae346c4e9cd9a41c9942e857bc6) (cherry picked from commit f173f27d7c3bf36c54b7e715a61b2308d1b0d277) (cherry picked from commit 90e1c9340e72f08e67293647cf5f19b3e3571909) (cherry picked from commit de68610ea70b81146f6412e42d72b97aad0428ae) (cherry picked from commit 8d5757ea0459cffeb885462b7a9d1e1c630e1f16) (cherry picked from commit c7a7fff316c1a88ba9b0984114a25cecfac56bce) (cherry picked from commit 39ac8b8fc164090eacd5870bf78ea863d2add5fa) (cherry picked from commit 98892033012ccc4f4bef30e10932fa22bf12ebcd) [PRIVACY]: Adjust update checker description - Resolves #323 - Adjust the description of the update check function on the installation page to describe the privacy method instead of the HTTP method by checking gitea.io (cherry picked from commit 61eae5b105e374169fe23fbb150ce080f8f340ec) (cherry picked from commit 091def20a1180af718209f2bd520cb249b1943ae) (cherry picked from commit d5d11bf45a77cad6be2194620c4d865231cfbe67) (cherry picked from commit 71863d470739c743335931f1563e5b63cf3194eb) (cherry picked from commit 11ece4aab1ba7a154e985a6732c6839d8a688315) (cherry picked from commit afdd7e714f9e735811dc909a854cfac964e474e7) (cherry picked from commit 39170e2f1d64d79bb05940b72d7db602bcff1bce) (cherry picked from commit 4b3a52aab82e8b9f59f247983a4aa7de65c6c747) (cherry picked from commit 9d763c5fc8cd0ff7898855e1ef088edb264388d5) (cherry picked from commit 638db15482f6907fa21e27aaccf6795226ae60c0) (cherry picked from commit a52bfdd8e76466aa293855a35c6ac9e18a228e90) (cherry picked from commit dc93d00e85dfdd9c090294f5504b8d885a602c60) (cherry picked from commit 0bc4b3508c8d2e49b57d47b4c5b36a9365580a1b) (cherry picked from commit 3f760d85a45520d3340bf27efe667fc689b6b8ce) (cherry picked from commit ecc2716785036b5538c8022d1c4dd6156796acef) (cherry picked from commit 6334d5677eb3e1848ab16630a22ae59ab716a732) Conflicts: modules/updatechecker/update_checker.go UpdateRemoteVersion now has a context argument. However, in the updated code from Gitea the context comes from the HTTP request and does not actually provide any useful context. Replace that with context.Background() (cherry picked from commit ca2200767edb9c30b655b942824957577b1f6fe7) (cherry picked from commit f46feca224d388e92875a76c8d2428c2681ad0c5) (cherry picked from commit a800a66ca89c03a8e08f26f633bea8634cffe629) (cherry picked from commit 21f017454e90db7c1ce47627785e4781396300b9) (cherry picked from commit 762d18e09a5cc04f7c2ff374e1202324244999df) (cherry picked from commit 6d28e120c131b2547a87691a6195205cedfac052) (cherry picked from commit 4fcd7e7cbf55d7b69568a931fc86b3aef8346adc) (cherry picked from commit 95162851128ef1d03435bd5e011748dc3d0f26f8) (cherry picked from commit 0dd752a2624693fb1c9c4dd0efa8e343ae1ad3c7) (cherry picked from commit b1f1af7fe03878c333966b2f4c6581ab0e6c2593) (cherry picked from commit 71937deaa575015fb5e9073a014b4fba74ed92a8) (cherry picked from commit 93e41a782334b7b53198da89e1c8a92bb9e6b6be) (cherry picked from commit f497ed30cfaafb2c801ad6bfccc7788a128c4435) (cherry picked from commit bff3346f7df2cf28b1f1fdd637a87bbe6940326c) (cherry picked from commit 906ae19c0f61d808decf4fab0abc2086abf9d4e2)
2023-01-27 05:37:33 +05:30
HTTPEndpoint string
DomainEndpoint string
}
RegisterTaskFatal("update_checker", &UpdateCheckerConfig{
BaseConfig: BaseConfig{
[PRIVACY] Disable `update_checker` cron tasks - This is being disabled as it will weekly connect to a domain. - This only affects existing installations, as new installations will have a explicit value being written into app.ini due to https://github.com/go-gitea/gitea/pull/21655 (cherry picked from commit cd0b8b6852563118ab8530c01a48bc612efcf58a) (cherry picked from commit 58d43867cab15a4b93fab6f4b467756e8030fb2d) (cherry picked from commit f290b91e504933be83d5b9540a195173280ab38d) (cherry picked from commit 5bd6d7555478713c91a3c00980060041ed34ba22) (cherry picked from commit e5d0abb59244809f5181dfbadfbee47531246a18) (cherry picked from commit 4b381ce77e699ce9f0f8af8ac3488bd8e3562b15) (cherry picked from commit b6a9b1390d9ee3aa70d50b1fae1346aff69cab08) (cherry picked from commit 367436287118b0fc4030ee6527d6c366db919594) (cherry picked from commit af0f606fc1f42be49dcbedd04055f0f9a0b7d3df) (cherry picked from commit 49560da6fb01cd6ee1a69840f48ed9269330c37a) (cherry picked from commit ca06e27c5b7b8b20e34935885c4ab0ca905b9157) (cherry picked from commit 163df86df5abdda11b6d337af32e0f0f3837119b) (cherry picked from commit 0391c6ae42eb364a6db1156af93304aa73c69b2d) (cherry picked from commit f282f2d42fd850c29b489d02133698e14b21f411) (cherry picked from commit 68d31cf2478626730324eaa56ad4264580b7030c) (cherry picked from commit cfd4a479e95597f315d9d75e2b7d22c8f6941ce2) (cherry picked from commit add969bdf624df9eed3047d60a1bae979e9bfd80) (cherry picked from commit c0f3f1f1e733b6df0f028a1393549adf7f8936f4) (cherry picked from commit f11dca9090a77dbd58ff980e97cff07a5b2d27b5) (cherry picked from commit 283810387ff26fbbf1ac795d56350a7bfb87b874) (cherry picked from commit 08af1f0ea882bbe3fada3e61988baa9f0d290d1a) (cherry picked from commit 1c1a6da319f9218cc05693e0b8461f3defe1d891) (cherry picked from commit c1444bae65daa29497209a0bcc0758b1af9828a0) (cherry picked from commit 6361df634bd8fda81793e35820f0a42c56e5e55a) (cherry picked from commit cc8bb3f94605858c3ff9412644d90d80150c3f23) (cherry picked from commit c7ae4411fd041dde1c73a5fdc64679317b6daef7) (cherry picked from commit f73f4eef02c41430cc6a7375fc3b73aab8b75de7) (cherry picked from commit 2122896e8529db6b6158bb9029492f8f5e12efb7) (cherry picked from commit d469c99671cf6a5a8087b1ad106a04b43f4edc85) (cherry picked from commit 41dbbd731edf52c1c78d34cba1dfd7e03029e5f7) (cherry picked from commit e8e742b4376ab2437097a94a5f541576f9da3c81) (cherry picked from commit 0fa9f87b5fbb81b9205650da918bab02c7f86916) (cherry picked from commit a92c724a563e0260425cfe8569dec893740b8c71) (cherry picked from commit 6a18d153e1f60bdac04a568eaa2d74cb2c1d5cb1) (cherry picked from commit 0dd35a13fdcf34f88b9cc554646402b1bb40da57) (cherry picked from commit 5ae0cbe0ae98c7e12666f185aa5da21160ab83e8) (cherry picked from commit 13bd3cf37bed863491f1284572fa0bfa470b8ec0) (cherry picked from commit a163efa6cf5746a2ac3cfec78ff8c5d70158e3f2) (cherry picked from commit 422a6e8329abf9a961222a50ce136af84f4f2975) (cherry picked from commit 125fb33e1baad8bf88d71db5bffaa898c38565e9) (cherry picked from commit fd39d15a921c726f593a55ba0c4eae6f8f78a4a0) (cherry picked from commit b58147451372d354a499f6b38d2662ff6c74c132) (cherry picked from commit 987d19852364fe258b4eaddd9df51245a082522e) (cherry picked from commit f06eed025fb73ca1ebe7eb65cbd5ab5c3276d981) (cherry picked from commit 6f9f4156448e7b9eb9d7c7776eb20b0ab5de692c) (cherry picked from commit eb2c878debf07ad46e272ff8e2adfa414657f4c3) (cherry picked from commit 70daffa9fe3a4007d199ea346f0d14f37917ac5b) (cherry picked from commit 3a6ae6fa49d238bed04c1fd1342b054dab7b6f58) (cherry picked from commit 682a564b04a62aeea15e08a833ae2b158d1bfe67)
2022-12-19 00:26:08 +05:30
Enabled: false,
RunAtStart: false,
Schedule: "@every 168h",
},
[PRIVACY] Add a DNS method to fetch new updates - Use TXT records in order to determine the latest available version. - This addresses a valid privacy issue, as with HTTP requests the server can keep track(estimated) of how many instances are using Forgejo, with DNS that's basically not possible as the server will never receive any data, as the only ones receiving data are DNS resolvers. (cherry picked from commit 0baefb546ab96bc3c06d90feffdb14873c2c2a3a) (cherry picked from commit e8ee41880b775532e6a68bd2052ed96d369dee78) (cherry picked from commit 7eca4f3bf1faa3f063c9668d1bb354b842361007) (cherry picked from commit 6dde3992dc504f105f2285c34fa6445fa24da0b1) (cherry picked from commit fb3a37fbfc73d35e3ba8d793b6051aeddcbb0634) (cherry picked from commit 8304af1e9d94b89ee700b0d454d74d0dc5cfac64) (cherry picked from commit 0543a7d12a4bac012db8b9e683e879e6f265a9dc) (cherry picked from commit c3a22933b7ca8201c96267d360281848fb2a1c7e) (cherry picked from commit e24370769413aebe96ba6cfb230da3c2c33e39f4) (cherry picked from commit 7eb6d1bcf7a0bdae0cbbf06136854d0b29c54899) (cherry picked from commit 1d7b9535cd73bffda5defd143c25e514cc55dee8) (cherry picked from commit 05920dce67808ae346c4e9cd9a41c9942e857bc6) (cherry picked from commit f173f27d7c3bf36c54b7e715a61b2308d1b0d277) (cherry picked from commit 90e1c9340e72f08e67293647cf5f19b3e3571909) (cherry picked from commit de68610ea70b81146f6412e42d72b97aad0428ae) (cherry picked from commit 8d5757ea0459cffeb885462b7a9d1e1c630e1f16) (cherry picked from commit c7a7fff316c1a88ba9b0984114a25cecfac56bce) (cherry picked from commit 39ac8b8fc164090eacd5870bf78ea863d2add5fa) (cherry picked from commit 98892033012ccc4f4bef30e10932fa22bf12ebcd) [PRIVACY]: Adjust update checker description - Resolves #323 - Adjust the description of the update check function on the installation page to describe the privacy method instead of the HTTP method by checking gitea.io (cherry picked from commit 61eae5b105e374169fe23fbb150ce080f8f340ec) (cherry picked from commit 091def20a1180af718209f2bd520cb249b1943ae) (cherry picked from commit d5d11bf45a77cad6be2194620c4d865231cfbe67) (cherry picked from commit 71863d470739c743335931f1563e5b63cf3194eb) (cherry picked from commit 11ece4aab1ba7a154e985a6732c6839d8a688315) (cherry picked from commit afdd7e714f9e735811dc909a854cfac964e474e7) (cherry picked from commit 39170e2f1d64d79bb05940b72d7db602bcff1bce) (cherry picked from commit 4b3a52aab82e8b9f59f247983a4aa7de65c6c747) (cherry picked from commit 9d763c5fc8cd0ff7898855e1ef088edb264388d5) (cherry picked from commit 638db15482f6907fa21e27aaccf6795226ae60c0) (cherry picked from commit a52bfdd8e76466aa293855a35c6ac9e18a228e90) (cherry picked from commit dc93d00e85dfdd9c090294f5504b8d885a602c60) (cherry picked from commit 0bc4b3508c8d2e49b57d47b4c5b36a9365580a1b) (cherry picked from commit 3f760d85a45520d3340bf27efe667fc689b6b8ce) (cherry picked from commit ecc2716785036b5538c8022d1c4dd6156796acef) (cherry picked from commit 6334d5677eb3e1848ab16630a22ae59ab716a732) Conflicts: modules/updatechecker/update_checker.go UpdateRemoteVersion now has a context argument. However, in the updated code from Gitea the context comes from the HTTP request and does not actually provide any useful context. Replace that with context.Background() (cherry picked from commit ca2200767edb9c30b655b942824957577b1f6fe7) (cherry picked from commit f46feca224d388e92875a76c8d2428c2681ad0c5) (cherry picked from commit a800a66ca89c03a8e08f26f633bea8634cffe629) (cherry picked from commit 21f017454e90db7c1ce47627785e4781396300b9) (cherry picked from commit 762d18e09a5cc04f7c2ff374e1202324244999df) (cherry picked from commit 6d28e120c131b2547a87691a6195205cedfac052) (cherry picked from commit 4fcd7e7cbf55d7b69568a931fc86b3aef8346adc) (cherry picked from commit 95162851128ef1d03435bd5e011748dc3d0f26f8) (cherry picked from commit 0dd752a2624693fb1c9c4dd0efa8e343ae1ad3c7) (cherry picked from commit b1f1af7fe03878c333966b2f4c6581ab0e6c2593) (cherry picked from commit 71937deaa575015fb5e9073a014b4fba74ed92a8) (cherry picked from commit 93e41a782334b7b53198da89e1c8a92bb9e6b6be) (cherry picked from commit f497ed30cfaafb2c801ad6bfccc7788a128c4435) (cherry picked from commit bff3346f7df2cf28b1f1fdd637a87bbe6940326c) (cherry picked from commit 906ae19c0f61d808decf4fab0abc2086abf9d4e2)
2023-01-27 05:37:33 +05:30
HTTPEndpoint: "https://dl.gitea.com/gitea/version.json",
DomainEndpoint: "release.forgejo.org",
}, func(ctx context.Context, _ *user_model.User, config Config) error {
updateCheckerConfig := config.(*UpdateCheckerConfig)
[PRIVACY] Add a DNS method to fetch new updates - Use TXT records in order to determine the latest available version. - This addresses a valid privacy issue, as with HTTP requests the server can keep track(estimated) of how many instances are using Forgejo, with DNS that's basically not possible as the server will never receive any data, as the only ones receiving data are DNS resolvers. (cherry picked from commit 0baefb546ab96bc3c06d90feffdb14873c2c2a3a) (cherry picked from commit e8ee41880b775532e6a68bd2052ed96d369dee78) (cherry picked from commit 7eca4f3bf1faa3f063c9668d1bb354b842361007) (cherry picked from commit 6dde3992dc504f105f2285c34fa6445fa24da0b1) (cherry picked from commit fb3a37fbfc73d35e3ba8d793b6051aeddcbb0634) (cherry picked from commit 8304af1e9d94b89ee700b0d454d74d0dc5cfac64) (cherry picked from commit 0543a7d12a4bac012db8b9e683e879e6f265a9dc) (cherry picked from commit c3a22933b7ca8201c96267d360281848fb2a1c7e) (cherry picked from commit e24370769413aebe96ba6cfb230da3c2c33e39f4) (cherry picked from commit 7eb6d1bcf7a0bdae0cbbf06136854d0b29c54899) (cherry picked from commit 1d7b9535cd73bffda5defd143c25e514cc55dee8) (cherry picked from commit 05920dce67808ae346c4e9cd9a41c9942e857bc6) (cherry picked from commit f173f27d7c3bf36c54b7e715a61b2308d1b0d277) (cherry picked from commit 90e1c9340e72f08e67293647cf5f19b3e3571909) (cherry picked from commit de68610ea70b81146f6412e42d72b97aad0428ae) (cherry picked from commit 8d5757ea0459cffeb885462b7a9d1e1c630e1f16) (cherry picked from commit c7a7fff316c1a88ba9b0984114a25cecfac56bce) (cherry picked from commit 39ac8b8fc164090eacd5870bf78ea863d2add5fa) (cherry picked from commit 98892033012ccc4f4bef30e10932fa22bf12ebcd) [PRIVACY]: Adjust update checker description - Resolves #323 - Adjust the description of the update check function on the installation page to describe the privacy method instead of the HTTP method by checking gitea.io (cherry picked from commit 61eae5b105e374169fe23fbb150ce080f8f340ec) (cherry picked from commit 091def20a1180af718209f2bd520cb249b1943ae) (cherry picked from commit d5d11bf45a77cad6be2194620c4d865231cfbe67) (cherry picked from commit 71863d470739c743335931f1563e5b63cf3194eb) (cherry picked from commit 11ece4aab1ba7a154e985a6732c6839d8a688315) (cherry picked from commit afdd7e714f9e735811dc909a854cfac964e474e7) (cherry picked from commit 39170e2f1d64d79bb05940b72d7db602bcff1bce) (cherry picked from commit 4b3a52aab82e8b9f59f247983a4aa7de65c6c747) (cherry picked from commit 9d763c5fc8cd0ff7898855e1ef088edb264388d5) (cherry picked from commit 638db15482f6907fa21e27aaccf6795226ae60c0) (cherry picked from commit a52bfdd8e76466aa293855a35c6ac9e18a228e90) (cherry picked from commit dc93d00e85dfdd9c090294f5504b8d885a602c60) (cherry picked from commit 0bc4b3508c8d2e49b57d47b4c5b36a9365580a1b) (cherry picked from commit 3f760d85a45520d3340bf27efe667fc689b6b8ce) (cherry picked from commit ecc2716785036b5538c8022d1c4dd6156796acef) (cherry picked from commit 6334d5677eb3e1848ab16630a22ae59ab716a732) Conflicts: modules/updatechecker/update_checker.go UpdateRemoteVersion now has a context argument. However, in the updated code from Gitea the context comes from the HTTP request and does not actually provide any useful context. Replace that with context.Background() (cherry picked from commit ca2200767edb9c30b655b942824957577b1f6fe7) (cherry picked from commit f46feca224d388e92875a76c8d2428c2681ad0c5) (cherry picked from commit a800a66ca89c03a8e08f26f633bea8634cffe629) (cherry picked from commit 21f017454e90db7c1ce47627785e4781396300b9) (cherry picked from commit 762d18e09a5cc04f7c2ff374e1202324244999df) (cherry picked from commit 6d28e120c131b2547a87691a6195205cedfac052) (cherry picked from commit 4fcd7e7cbf55d7b69568a931fc86b3aef8346adc) (cherry picked from commit 95162851128ef1d03435bd5e011748dc3d0f26f8) (cherry picked from commit 0dd752a2624693fb1c9c4dd0efa8e343ae1ad3c7) (cherry picked from commit b1f1af7fe03878c333966b2f4c6581ab0e6c2593) (cherry picked from commit 71937deaa575015fb5e9073a014b4fba74ed92a8) (cherry picked from commit 93e41a782334b7b53198da89e1c8a92bb9e6b6be) (cherry picked from commit f497ed30cfaafb2c801ad6bfccc7788a128c4435) (cherry picked from commit bff3346f7df2cf28b1f1fdd637a87bbe6940326c) (cherry picked from commit 906ae19c0f61d808decf4fab0abc2086abf9d4e2)
2023-01-27 05:37:33 +05:30
return updatechecker.GiteaUpdateChecker(updateCheckerConfig.HTTPEndpoint, updateCheckerConfig.DomainEndpoint)
})
}
func registerDeleteOldSystemNotices() {
RegisterTaskFatal("delete_old_system_notices", &OlderThanConfig{
BaseConfig: BaseConfig{
Enabled: false,
RunAtStart: false,
Schedule: "@every 168h",
},
OlderThan: 365 * 24 * time.Hour,
}, func(ctx context.Context, _ *user_model.User, config Config) error {
olderThanConfig := config.(*OlderThanConfig)
return system.DeleteOldSystemNotices(ctx, olderThanConfig.OlderThan)
})
}
func registerGCLFS() {
if !setting.LFS.StartServer {
return
}
type GCLFSConfig struct {
OlderThanConfig
LastUpdatedMoreThanAgo time.Duration
NumberToCheckPerRepo int64
ProportionToCheckPerRepo float64
}
RegisterTaskFatal("gc_lfs", &GCLFSConfig{
OlderThanConfig: OlderThanConfig{
BaseConfig: BaseConfig{
Enabled: false,
RunAtStart: false,
Schedule: "@every 24h",
},
// Only attempt to garbage collect lfs meta objects older than a week as the order of git lfs upload
// and git object upload is not necessarily guaranteed. It's possible to imagine a situation whereby
// an LFS object is uploaded but the git branch is not uploaded immediately, or there are some rapid
// changes in new branches that might lead to lfs objects becoming temporarily unassociated with git
// objects.
//
// It is likely that a week is potentially excessive but it should definitely be enough that any
// unassociated LFS object is genuinely unassociated.
OlderThan: 24 * time.Hour * 7,
},
// Only GC things that haven't been looked at in the past 3 days
LastUpdatedMoreThanAgo: 24 * time.Hour * 3,
NumberToCheckPerRepo: 100,
ProportionToCheckPerRepo: 0.6,
}, func(ctx context.Context, _ *user_model.User, config Config) error {
gcLFSConfig := config.(*GCLFSConfig)
return repo_service.GarbageCollectLFSMetaObjects(ctx, repo_service.GarbageCollectLFSMetaObjectsOptions{
AutoFix: true,
OlderThan: time.Now().Add(-gcLFSConfig.OlderThan),
UpdatedLessRecentlyThan: time.Now().Add(-gcLFSConfig.LastUpdatedMoreThanAgo),
})
})
}
func registerRebuildIssueIndexer() {
RegisterTaskFatal("rebuild_issue_indexer", &BaseConfig{
Enabled: false,
RunAtStart: false,
Schedule: "@annually",
}, func(ctx context.Context, _ *user_model.User, config Config) error {
return issue_indexer.PopulateIssueIndexer(ctx)
})
}
func initExtendedTasks() {
registerDeleteInactiveUsers()
registerDeleteRepositoryArchives()
registerGarbageCollectRepositories()
registerRewriteAllPublicKeys()
Add ssh certificate support (#12281) * Add ssh certificate support * Add ssh certificate support to builtin ssh * Write trusted-user-ca-keys.pem based on configuration * Update app.example.ini * Update templates/user/settings/keys_principal.tmpl Co-authored-by: silverwind <me@silverwind.io> * Remove unused locale string * Update options/locale/locale_en-US.ini Co-authored-by: silverwind <me@silverwind.io> * Update options/locale/locale_en-US.ini Co-authored-by: silverwind <me@silverwind.io> * Update models/ssh_key.go Co-authored-by: silverwind <me@silverwind.io> * Add missing creation of SSH.Rootpath * Update cheatsheet, example and locale strings * Update models/ssh_key.go Co-authored-by: zeripath <art27@cantab.net> * Update models/ssh_key.go Co-authored-by: zeripath <art27@cantab.net> * Update models/ssh_key.go Co-authored-by: zeripath <art27@cantab.net> * Update models/ssh_key.go Co-authored-by: zeripath <art27@cantab.net> * Update models/ssh_key.go * Optimizations based on feedback * Validate CA keys for external sshd * Add filename option and change default filename Add a SSH_TRUSTED_USER_CA_KEYS_FILENAME option which default is RUN_USER/.ssh/gitea-trusted-user-ca-keys.pem Do not write a file when SSH_TRUSTED_USER_CA_KEYS is empty. Add some more documentation. * Remove unneeded principalkey functions * Add blank line * Apply suggestions from code review Co-authored-by: zeripath <art27@cantab.net> * Add SSH_AUTHORIZED_PRINCIPALS_ALLOW option This adds a SSH_AUTHORIZED_PRINCIPALS_ALLOW which is default email,username this means that users only can add the principals that match their email or username. To allow anything the admin need to set the option anything. This allows for a safe default in gitea which protects against malicious users using other user's prinicipals. (before that user could set it). This commit also has some small other fixes from the last code review. * Rewrite principal keys file on user deletion * Use correct rewrite method * Set correct AuthorizedPrincipalsBackup default setting * Rewrite principalsfile when adding principals * Add update authorized_principals option to admin dashboard * Handle non-primary emails Signed-off-by: Andrew Thornton <art27@cantab.net> * Add the command actually to the dashboard template * Update models/ssh_key.go Co-authored-by: silverwind <me@silverwind.io> * By default do not show principal options unless there are CA keys set or they are explicitly set Signed-off-by: Andrew Thornton <art27@cantab.net> * allow settings when enabled * Fix typos in TrustedUserCAKeys path * Allow every CASignatureAlgorithms algorithm As this depends on the content of TrustedUserCAKeys we should allow all signature algorithms as admins can choose the specific algorithm on their signing CA * Update models/ssh_key.go Co-authored-by: Lauris BH <lauris@nix.lv> * Fix linting issue Co-authored-by: silverwind <me@silverwind.io> Co-authored-by: zeripath <art27@cantab.net> Co-authored-by: Lauris BH <lauris@nix.lv> Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2020-10-11 06:08:09 +05:30
registerRewriteAllPrincipalKeys()
registerRepositoryUpdateHook()
registerReinitMissingRepositories()
registerDeleteMissingRepositories()
registerRemoveRandomAvatars()
registerDeleteOldActions()
registerUpdateGiteaChecker()
registerDeleteOldSystemNotices()
registerGCLFS()
registerRebuildIssueIndexer()
}