aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-06-15 02:15:12 +0100
committerGitHub <noreply@github.com>2021-06-14 21:15:12 -0400
commit95352e6bd55428bed947dbe2e6427ee93240bbe8 (patch)
treee5ce3345b5f386ec51b2b511e85400a65c733de5 /models
parentebf253b841d56c5cb1e57cb1e5e50c06d315bdee (diff)
downloadgitea-95352e6bd55428bed947dbe2e6427ee93240bbe8.tar.gz
gitea-95352e6bd55428bed947dbe2e6427ee93240bbe8.zip
Make command in authorized keys a template (#16003)
Fix #15595 Replaces #15978 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'models')
-rw-r--r--models/ssh_key.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/models/ssh_key.go b/models/ssh_key.go
index 9f9c33e848..e35fc12e08 100644
--- a/models/ssh_key.go
+++ b/models/ssh_key.go
@@ -38,7 +38,6 @@ import (
const (
tplCommentPrefix = `# gitea public key`
- tplCommand = "%s --config=%s serv key-%d"
tplPublicKey = tplCommentPrefix + "\n" + `command=%s,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty %s` + "\n"
authorizedPrincipalsFile = "authorized_principals"
@@ -88,7 +87,16 @@ func (key *PublicKey) OmitEmail() string {
// AuthorizedString returns formatted public key string for authorized_keys file.
func (key *PublicKey) AuthorizedString() string {
- return fmt.Sprintf(tplPublicKey, util.ShellEscape(fmt.Sprintf(tplCommand, util.ShellEscape(setting.AppPath), util.ShellEscape(setting.CustomConf), key.ID)), key.Content)
+ sb := &strings.Builder{}
+ _ = setting.SSH.AuthorizedKeysCommandTemplateTemplate.Execute(sb, map[string]interface{}{
+ "AppPath": util.ShellEscape(setting.AppPath),
+ "AppWorkPath": util.ShellEscape(setting.AppWorkPath),
+ "CustomConf": util.ShellEscape(setting.CustomConf),
+ "CustomPath": util.ShellEscape(setting.CustomPath),
+ "Key": key,
+ })
+
+ return fmt.Sprintf(tplPublicKey, util.ShellEscape(sb.String()), key.Content)
}
func extractTypeFromBase64Key(key string) (string, error) {