Skip to content

Commit 99d14f6

Browse files
Add separate SSH_USER config option (#17584)
Co-authored-by: zeripath <[email protected]>
1 parent 9911b66 commit 99d14f6

File tree

7 files changed

+13
-8
lines changed

7 files changed

+13
-8
lines changed

custom/conf/app.example.ini

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,15 @@ RUN_MODE = ; prod
8282
;; Whether to use the builtin SSH server or not.
8383
;START_SSH_SERVER = false
8484
;;
85-
;; Username to use for the builtin SSH server. If blank, then it is the value of RUN_USER.
86-
;BUILTIN_SSH_SERVER_USER =
85+
;; Username to use for the builtin SSH server.
86+
;BUILTIN_SSH_SERVER_USER = %(RUN_USER)s
8787
;;
8888
;; Domain name to be exposed in clone URL
8989
;SSH_DOMAIN = %(DOMAIN)s
9090
;;
91+
;; SSH username displayed in clone URLs.
92+
;SSH_USER = %(BUILTIN_SSH_SERVER_USER)s
93+
;;
9194
;; The network interface the builtin SSH server should listen on
9295
;SSH_LISTEN_HOST =
9396
;;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,7 @@ The following configuration set `Content-Type: application/vnd.android.package-a
265265
- `DISABLE_SSH`: **false**: Disable SSH feature when it's not available.
266266
- `START_SSH_SERVER`: **false**: When enabled, use the built-in SSH server.
267267
- `BUILTIN_SSH_SERVER_USER`: **%(RUN_USER)s**: Username to use for the built-in SSH Server.
268+
- `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`.
268269
- `SSH_DOMAIN`: **%(DOMAIN)s**: Domain name of this server, used for displayed clone URL.
269270
- `SSH_PORT`: **22**: SSH port displayed in clone URL.
270271
- `SSH_LISTEN_HOST`: **0.0.0.0**: Listen address for the built-in SSH server.

integrations/repo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ func TestViewRepo1CloneLinkAuthorized(t *testing.T) {
135135
assert.Equal(t, setting.AppURL+"user2/repo1.git", link)
136136
link, exists = htmlDoc.doc.Find("#repo-clone-ssh").Attr("data-link")
137137
assert.True(t, exists, "The template has changed")
138-
sshURL := fmt.Sprintf("ssh://%s@%s:%d/user2/repo1.git", setting.SSH.BuiltinServerUser, setting.SSH.Domain, setting.SSH.Port)
138+
sshURL := fmt.Sprintf("ssh://%s@%s:%d/user2/repo1.git", setting.SSH.User, setting.SSH.Domain, setting.SSH.Port)
139139
assert.Equal(t, sshURL, link)
140140
}
141141

models/repo/repo.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -540,10 +540,7 @@ func (repo *Repository) cloneLink(isUncyclo bool) *CloneLink {
540540
repoName += ".wiki"
541541
}
542542

543-
sshUser := setting.RunUser
544-
if setting.SSH.StartBuiltinServer {
545-
sshUser = setting.SSH.BuiltinServerUser
546-
}
543+
sshUser := setting.SSH.User
547544

548545
cl := new(CloneLink)
549546

models/repo/wiki_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestRepository_UncycloCloneLink(t *testing.T) {
1919

2020
repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 1}).(*Repository)
2121
cloneLink := repo.UncycloCloneLink()
22-
assert.Equal(t, "ssh://runuser@try.gitea.io:3000/user2/repo1.wiki.git", cloneLink.SSH)
22+
assert.Equal(t, "ssh://sshuser@try.gitea.io:3000/user2/repo1.wiki.git", cloneLink.SSH)
2323
assert.Equal(t, "https://try.gitea.io/user2/repo1.wiki.git", cloneLink.HTTPS)
2424
}
2525

models/unittest/testdb.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ func MainTest(m *testing.M, pathToGiteaRoot string, fixtureFiles ...string) {
6464

6565
setting.AppURL = "https://try.gitea.io/"
6666
setting.RunUser = "runuser"
67+
setting.SSH.User = "sshuser"
68+
setting.SSH.BuiltinServerUser = "builtinuser"
6769
setting.SSH.Port = 3000
6870
setting.SSH.Domain = "try.gitea.io"
6971
setting.Database.UseSQLite3 = true

modules/setting/setting.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ var (
131131
BuiltinServerUser string `ini:"BUILTIN_SSH_SERVER_USER"`
132132
Domain string `ini:"SSH_DOMAIN"`
133133
Port int `ini:"SSH_PORT"`
134+
User string `ini:"SSH_USER"`
134135
ListenHost string `ini:"SSH_LISTEN_HOST"`
135136
ListenPort int `ini:"SSH_LISTEN_PORT"`
136137
RootPath string `ini:"SSH_ROOT_PATH"`
@@ -970,6 +971,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
970971
}
971972

972973
SSH.BuiltinServerUser = Cfg.Section("server").Key("BUILTIN_SSH_SERVER_USER").MustString(RunUser)
974+
SSH.User = Cfg.Section("server").Key("SSH_USER").MustString(SSH.BuiltinServerUser)
973975

974976
newRepository()
975977

0 commit comments

Comments
 (0)