@@ -11,77 +11,13 @@ import (
11
11
"github.com/smallstep/cli/utils"
12
12
)
13
13
14
- // SSHTemplates contains the configuration of default templates used on ssh.
15
- // Relative paths are relative to the StepPath.
16
- var SSHTemplates = & templates.SSHTemplates {
17
- User : []templates.Template {
18
- {Name : "include.tpl" , Type : templates .Snippet , TemplatePath : "templates/ssh/include.tpl" , Path : "~/.ssh/config" , Comment : "#" },
19
- {Name : "config.tpl" , Type : templates .File , TemplatePath : "templates/ssh/config.tpl" , Path : "ssh/config" , Comment : "#" },
20
- {Name : "known_hosts.tpl" , Type : templates .File , TemplatePath : "templates/ssh/known_hosts.tpl" , Path : "ssh/known_hosts" , Comment : "#" },
21
- },
22
- Host : []templates.Template {
23
- {Name : "sshd_config.tpl" , Type : templates .Snippet , TemplatePath : "templates/ssh/sshd_config.tpl" , Path : "/etc/ssh/sshd_config" , Comment : "#" },
24
- {Name : "ca.tpl" , Type : templates .Snippet , TemplatePath : "templates/ssh/ca.tpl" , Path : "/etc/ssh/ca.pub" , Comment : "#" },
25
- },
26
- }
27
-
28
- // SSHTemplateData contains the data of the default templates used on ssh.
29
- var SSHTemplateData = map [string ]string {
30
- // include.tpl adds the step ssh config file.
31
- //
32
- // Note: on windows `Include C:\...` is treated as a relative path.
33
- "include.tpl" : `Host *
34
- {{- if or .User.GOOS "none" | eq "windows" }}
35
- Include "{{ .User.StepPath | replace "\\" "/" | trimPrefix "C:" }}/ssh/config"
36
- {{- else }}
37
- Include "{{.User.StepPath}}/ssh/config"
38
- {{- end }}` ,
39
-
40
- // config.tpl is the step ssh config file, it includes the Match rule and
41
- // references the step known_hosts file.
42
- //
43
- // Note: on windows ProxyCommand requires the full path
44
- "config.tpl" : `Match exec "step ssh check-host %h"
45
- {{- if .User.User }}
46
- User {{.User.User}}
47
- {{- end }}
48
- {{- if or .User.GOOS "none" | eq "windows" }}
49
- UserKnownHostsFile "{{.User.StepPath}}\ssh\known_hosts"
50
- ProxyCommand C:\Windows\System32\cmd.exe /c step ssh proxycommand %r %h %p
51
- {{- else }}
52
- UserKnownHostsFile "{{.User.StepPath}}/ssh/known_hosts"
53
- ProxyCommand step ssh proxycommand %r %h %p
54
- {{- end }}
55
- ` ,
56
-
57
- // known_hosts.tpl authorizes the ssh hosts key
58
- "known_hosts.tpl" : `@cert-authority * {{.Step.SSH.HostKey.Type}} {{.Step.SSH.HostKey.Marshal | toString | b64enc}}
59
- {{- range .Step.SSH.HostFederatedKeys}}
60
- @cert-authority * {{.Type}} {{.Marshal | toString | b64enc}}
61
- {{- end }}
62
- ` ,
63
-
64
- // sshd_config.tpl adds the configuration to support certificates
65
- "sshd_config.tpl" : `TrustedUserCAKeys /etc/ssh/ca.pub
66
- HostCertificate /etc/ssh/{{.User.Certificate}}
67
- HostKey /etc/ssh/{{.User.Key}}` ,
68
-
69
- // ca.tpl contains the public key used to authorized clients
70
- "ca.tpl" : `{{.Step.SSH.UserKey.Type}} {{.Step.SSH.UserKey.Marshal | toString | b64enc}}
71
- {{- range .Step.SSH.UserFederatedKeys}}
72
- {{.Type}} {{.Marshal | toString | b64enc}}
73
- {{- end }}
74
- ` ,
75
- }
76
-
77
14
// getTemplates returns all the templates enabled
78
15
func (p * PKI ) getTemplates () * templates.Templates {
79
16
if ! p .enableSSH {
80
17
return nil
81
18
}
82
-
83
19
return & templates.Templates {
84
- SSH : SSHTemplates ,
20
+ SSH : & templates . DefaultSSHTemplates ,
85
21
Data : map [string ]interface {}{},
86
22
}
87
23
}
@@ -104,7 +40,7 @@ func generateTemplates(t *templates.Templates) error {
104
40
}
105
41
// Create all templates
106
42
for _ , t := range t .SSH .User {
107
- data , ok := SSHTemplateData [t .Name ]
43
+ data , ok := templates . DefaultSSHTemplateData [t .Name ]
108
44
if ! ok {
109
45
return errors .Errorf ("template %s does not exists" , t .Name )
110
46
}
@@ -113,7 +49,7 @@ func generateTemplates(t *templates.Templates) error {
113
49
}
114
50
}
115
51
for _ , t := range t .SSH .Host {
116
- data , ok := SSHTemplateData [t .Name ]
52
+ data , ok := templates . DefaultSSHTemplateData [t .Name ]
117
53
if ! ok {
118
54
return errors .Errorf ("template %s does not exists" , t .Name )
119
55
}
0 commit comments