From 99d14f6051854fe0e6dfc7fb6f4eb0a839179977 Mon Sep 17 00:00:00 2001 From: Clar Fon Date: Mon, 7 Feb 2022 16:56:45 -0500 Subject: [PATCH] Add separate SSH_USER config option (#17584) Co-authored-by: zeripath --- custom/conf/app.example.ini | 7 +++++-- docs/content/doc/advanced/config-cheat-sheet.en-us.md | 1 + integrations/repo_test.go | 2 +- models/repo/repo.go | 5 +---- models/repo/wiki_test.go | 2 +- models/unittest/testdb.go | 2 ++ modules/setting/setting.go | 2 ++ 7 files changed, 13 insertions(+), 8 deletions(-) diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index bc98f4ca17..8dac6ab3ab 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -82,12 +82,15 @@ RUN_MODE = ; prod ;; Whether to use the builtin SSH server or not. ;START_SSH_SERVER = false ;; -;; Username to use for the builtin SSH server. If blank, then it is the value of RUN_USER. -;BUILTIN_SSH_SERVER_USER = +;; Username to use for the builtin SSH server. +;BUILTIN_SSH_SERVER_USER = %(RUN_USER)s ;; ;; Domain name to be exposed in clone URL ;SSH_DOMAIN = %(DOMAIN)s ;; +;; SSH username displayed in clone URLs. +;SSH_USER = %(BUILTIN_SSH_SERVER_USER)s +;; ;; The network interface the builtin SSH server should listen on ;SSH_LISTEN_HOST = ;; diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index d8a3b897cc..a3999595ab 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -265,6 +265,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a - `DISABLE_SSH`: **false**: Disable SSH feature when it's not available. - `START_SSH_SERVER`: **false**: When enabled, use the built-in SSH server. - `BUILTIN_SSH_SERVER_USER`: **%(RUN_USER)s**: Username to use for the built-in SSH Server. +- `SSH_USER`: **%(BUILTIN_SSH_SERVER_USER)**: SSH username displayed in clone URLs. This is only for people who configure the SSH server themselves; in most cases, you want to leave this blank and modify the `BUILTIN_SSH_SERVER_USER`. - `SSH_DOMAIN`: **%(DOMAIN)s**: Domain name of this server, used for displayed clone URL. - `SSH_PORT`: **22**: SSH port displayed in clone URL. - `SSH_LISTEN_HOST`: **0.0.0.0**: Listen address for the built-in SSH server. diff --git a/integrations/repo_test.go b/integrations/repo_test.go index 8c4cdf5a96..677ba57f80 100644 --- a/integrations/repo_test.go +++ b/integrations/repo_test.go @@ -135,7 +135,7 @@ func TestViewRepo1CloneLinkAuthorized(t *testing.T) { assert.Equal(t, setting.AppURL+"user2/repo1.git", link) link, exists = htmlDoc.doc.Find("#repo-clone-ssh").Attr("data-link") assert.True(t, exists, "The template has changed") - sshURL := fmt.Sprintf("ssh://%s@%s:%d/user2/repo1.git", setting.SSH.BuiltinServerUser, setting.SSH.Domain, setting.SSH.Port) + sshURL := fmt.Sprintf("ssh://%s@%s:%d/user2/repo1.git", setting.SSH.User, setting.SSH.Domain, setting.SSH.Port) assert.Equal(t, sshURL, link) } diff --git a/models/repo/repo.go b/models/repo/repo.go index 353d707e60..28d976773d 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -540,10 +540,7 @@ func (repo *Repository) cloneLink(isWiki bool) *CloneLink { repoName += ".wiki" } - sshUser := setting.RunUser - if setting.SSH.StartBuiltinServer { - sshUser = setting.SSH.BuiltinServerUser - } + sshUser := setting.SSH.User cl := new(CloneLink) diff --git a/models/repo/wiki_test.go b/models/repo/wiki_test.go index 72f5280ce5..f5e61e5ae3 100644 --- a/models/repo/wiki_test.go +++ b/models/repo/wiki_test.go @@ -19,7 +19,7 @@ func TestRepository_WikiCloneLink(t *testing.T) { repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository) cloneLink := repo.WikiCloneLink() - assert.Equal(t, "ssh://runuser@try.gitea.io:3000/user2/repo1.wiki.git", cloneLink.SSH) + assert.Equal(t, "ssh://sshuser@try.gitea.io:3000/user2/repo1.wiki.git", cloneLink.SSH) assert.Equal(t, "https://try.gitea.io/user2/repo1.wiki.git", cloneLink.HTTPS) } diff --git a/models/unittest/testdb.go b/models/unittest/testdb.go index c904646d28..80dcb428df 100644 --- a/models/unittest/testdb.go +++ b/models/unittest/testdb.go @@ -64,6 +64,8 @@ func MainTest(m *testing.M, pathToGiteaRoot string, fixtureFiles ...string) { setting.AppURL = "https://try.gitea.io/" setting.RunUser = "runuser" + setting.SSH.User = "sshuser" + setting.SSH.BuiltinServerUser = "builtinuser" setting.SSH.Port = 3000 setting.SSH.Domain = "try.gitea.io" setting.Database.UseSQLite3 = true diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 5b8683f578..7841fbcdc3 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -131,6 +131,7 @@ var ( BuiltinServerUser string `ini:"BUILTIN_SSH_SERVER_USER"` Domain string `ini:"SSH_DOMAIN"` Port int `ini:"SSH_PORT"` + User string `ini:"SSH_USER"` ListenHost string `ini:"SSH_LISTEN_HOST"` ListenPort int `ini:"SSH_LISTEN_PORT"` RootPath string `ini:"SSH_ROOT_PATH"` @@ -970,6 +971,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) { } SSH.BuiltinServerUser = Cfg.Section("server").Key("BUILTIN_SSH_SERVER_USER").MustString(RunUser) + SSH.User = Cfg.Section("server").Key("SSH_USER").MustString(SSH.BuiltinServerUser) newRepository()