ssh.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. package authority
  2. import (
  3. "context"
  4. "crypto/rand"
  5. "crypto/x509"
  6. "encoding/binary"
  7. "net/http"
  8. "strings"
  9. "time"
  10. "github.com/pkg/errors"
  11. "github.com/smallstep/certificates/authority/provisioner"
  12. "github.com/smallstep/certificates/db"
  13. "github.com/smallstep/certificates/errs"
  14. "github.com/smallstep/certificates/templates"
  15. "github.com/smallstep/cli/jose"
  16. "go.step.sm/crypto/randutil"
  17. "go.step.sm/crypto/sshutil"
  18. "golang.org/x/crypto/ssh"
  19. )
  20. const (
  21. // SSHAddUserPrincipal is the principal that will run the add user command.
  22. // Defaults to "provisioner" but it can be changed in the configuration.
  23. SSHAddUserPrincipal = "provisioner"
  24. // SSHAddUserCommand is the default command to run to add a new user.
  25. // Defaults to "sudo useradd -m <principal>; nc -q0 localhost 22" but it can be changed in the
  26. // configuration. The string "<principal>" will be replace by the new
  27. // principal to add.
  28. SSHAddUserCommand = "sudo useradd -m <principal>; nc -q0 localhost 22"
  29. )
  30. // SSHConfig contains the user and host keys.
  31. type SSHConfig struct {
  32. HostKey string `json:"hostKey"`
  33. UserKey string `json:"userKey"`
  34. Keys []*SSHPublicKey `json:"keys,omitempty"`
  35. AddUserPrincipal string `json:"addUserPrincipal,omitempty"`
  36. AddUserCommand string `json:"addUserCommand,omitempty"`
  37. Bastion *Bastion `json:"bastion,omitempty"`
  38. }
  39. // Bastion contains the custom properties used on bastion.
  40. type Bastion struct {
  41. Hostname string `json:"hostname"`
  42. User string `json:"user,omitempty"`
  43. Port string `json:"port,omitempty"`
  44. Command string `json:"cmd,omitempty"`
  45. Flags string `json:"flags,omitempty"`
  46. }
  47. // HostTag are tagged with k,v pairs. These tags are how a user is ultimately
  48. // associated with a host.
  49. type HostTag struct {
  50. ID string
  51. Name string
  52. Value string
  53. }
  54. // Host defines expected attributes for an ssh host.
  55. type Host struct {
  56. HostID string `json:"hid"`
  57. HostTags []HostTag `json:"host_tags"`
  58. Hostname string `json:"hostname"`
  59. }
  60. // Validate checks the fields in SSHConfig.
  61. func (c *SSHConfig) Validate() error {
  62. if c == nil {
  63. return nil
  64. }
  65. for _, k := range c.Keys {
  66. if err := k.Validate(); err != nil {
  67. return err
  68. }
  69. }
  70. return nil
  71. }
  72. // SSHPublicKey contains a public key used by federated CAs to keep old signing
  73. // keys for this ca.
  74. type SSHPublicKey struct {
  75. Type string `json:"type"`
  76. Federated bool `json:"federated"`
  77. Key jose.JSONWebKey `json:"key"`
  78. publicKey ssh.PublicKey
  79. }
  80. // Validate checks the fields in SSHPublicKey.
  81. func (k *SSHPublicKey) Validate() error {
  82. switch {
  83. case k.Type == "":
  84. return errors.New("type cannot be empty")
  85. case k.Type != provisioner.SSHHostCert && k.Type != provisioner.SSHUserCert:
  86. return errors.Errorf("invalid type %s, it must be user or host", k.Type)
  87. case !k.Key.IsPublic():
  88. return errors.New("invalid key type, it must be a public key")
  89. }
  90. key, err := ssh.NewPublicKey(k.Key.Key)
  91. if err != nil {
  92. return errors.Wrap(err, "error creating ssh key")
  93. }
  94. k.publicKey = key
  95. return nil
  96. }
  97. // PublicKey returns the ssh public key.
  98. func (k *SSHPublicKey) PublicKey() ssh.PublicKey {
  99. return k.publicKey
  100. }
  101. // SSHKeys represents the SSH User and Host public keys.
  102. type SSHKeys struct {
  103. UserKeys []ssh.PublicKey
  104. HostKeys []ssh.PublicKey
  105. }
  106. // GetSSHRoots returns the SSH User and Host public keys.
  107. func (a *Authority) GetSSHRoots(context.Context) (*SSHKeys, error) {
  108. return &SSHKeys{
  109. HostKeys: a.sshCAHostCerts,
  110. UserKeys: a.sshCAUserCerts,
  111. }, nil
  112. }
  113. // GetSSHFederation returns the public keys for federated SSH signers.
  114. func (a *Authority) GetSSHFederation(context.Context) (*SSHKeys, error) {
  115. return &SSHKeys{
  116. HostKeys: a.sshCAHostFederatedCerts,
  117. UserKeys: a.sshCAUserFederatedCerts,
  118. }, nil
  119. }
  120. // GetSSHConfig returns rendered templates for clients (user) or servers (host).
  121. func (a *Authority) GetSSHConfig(ctx context.Context, typ string, data map[string]string) ([]templates.Output, error) {
  122. if a.sshCAUserCertSignKey == nil && a.sshCAHostCertSignKey == nil {
  123. return nil, errs.NotFound("getSSHConfig: ssh is not configured")
  124. }
  125. if a.templates == nil {
  126. return nil, errs.NotFound("getSSHConfig: ssh templates are not configured")
  127. }
  128. var ts []templates.Template
  129. switch typ {
  130. case provisioner.SSHUserCert:
  131. if a.templates != nil && a.templates.SSH != nil {
  132. ts = a.templates.SSH.User
  133. }
  134. case provisioner.SSHHostCert:
  135. if a.templates != nil && a.templates.SSH != nil {
  136. ts = a.templates.SSH.Host
  137. }
  138. default:
  139. return nil, errs.BadRequest("getSSHConfig: type %s is not valid", typ)
  140. }
  141. // Merge user and default data
  142. var mergedData map[string]interface{}
  143. if len(data) == 0 {
  144. mergedData = a.templates.Data
  145. } else {
  146. mergedData = make(map[string]interface{}, len(a.templates.Data)+1)
  147. mergedData["User"] = data
  148. for k, v := range a.templates.Data {
  149. mergedData[k] = v
  150. }
  151. }
  152. // Render templates
  153. output := []templates.Output{}
  154. for _, t := range ts {
  155. if err := t.Load(); err != nil {
  156. return nil, err
  157. }
  158. // Check for required variables.
  159. if err := t.ValidateRequiredData(data); err != nil {
  160. return nil, errs.BadRequestErr(err, errs.WithMessage("%v, please use `--set <key=value>` flag", err))
  161. }
  162. o, err := t.Output(mergedData)
  163. if err != nil {
  164. return nil, err
  165. }
  166. output = append(output, o)
  167. }
  168. return output, nil
  169. }
  170. // GetSSHBastion returns the bastion configuration, for the given pair user,
  171. // hostname.
  172. func (a *Authority) GetSSHBastion(ctx context.Context, user string, hostname string) (*Bastion, error) {
  173. if a.sshBastionFunc != nil {
  174. bs, err := a.sshBastionFunc(ctx, user, hostname)
  175. return bs, errs.Wrap(http.StatusInternalServerError, err, "authority.GetSSHBastion")
  176. }
  177. if a.config.SSH != nil {
  178. if a.config.SSH.Bastion != nil && a.config.SSH.Bastion.Hostname != "" {
  179. // Do not return a bastion for a bastion host.
  180. //
  181. // This condition might fail if a different name or IP is used.
  182. // Trying to resolve hostnames to IPs and compare them won't be a
  183. // complete solution because it depends on the network
  184. // configuration, of the CA and clients and can also return false
  185. // positives. Although not perfect, this simple solution will work
  186. // in most cases.
  187. if !strings.EqualFold(hostname, a.config.SSH.Bastion.Hostname) {
  188. return a.config.SSH.Bastion, nil
  189. }
  190. }
  191. return nil, nil
  192. }
  193. return nil, errs.NotFound("authority.GetSSHBastion; ssh is not configured")
  194. }
  195. // SignSSH creates a signed SSH certificate with the given public key and options.
  196. func (a *Authority) SignSSH(ctx context.Context, key ssh.PublicKey, opts provisioner.SignSSHOptions, signOpts ...provisioner.SignOption) (*ssh.Certificate, error) {
  197. var (
  198. certOptions []sshutil.Option
  199. mods []provisioner.SSHCertModifier
  200. validators []provisioner.SSHCertValidator
  201. )
  202. // Validate given options.
  203. if err := opts.Validate(); err != nil {
  204. return nil, errs.Wrap(http.StatusBadRequest, err, "authority.SignSSH")
  205. }
  206. // Set backdate with the configured value
  207. opts.Backdate = a.config.AuthorityConfig.Backdate.Duration
  208. for _, op := range signOpts {
  209. switch o := op.(type) {
  210. // add options to NewCertificate
  211. case provisioner.SSHCertificateOptions:
  212. certOptions = append(certOptions, o.Options(opts)...)
  213. // modify the ssh.Certificate
  214. case provisioner.SSHCertModifier:
  215. mods = append(mods, o)
  216. // validate the ssh.Certificate
  217. case provisioner.SSHCertValidator:
  218. validators = append(validators, o)
  219. // validate the given SSHOptions
  220. case provisioner.SSHCertOptionsValidator:
  221. if err := o.Valid(opts); err != nil {
  222. return nil, errs.Wrap(http.StatusForbidden, err, "authority.SignSSH")
  223. }
  224. default:
  225. return nil, errs.InternalServer("authority.SignSSH: invalid extra option type %T", o)
  226. }
  227. }
  228. // Simulated certificate request with request options.
  229. cr := sshutil.CertificateRequest{
  230. Type: opts.CertType,
  231. KeyID: opts.KeyID,
  232. Principals: opts.Principals,
  233. Key: key,
  234. }
  235. // Create certificate from template.
  236. certificate, err := sshutil.NewCertificate(cr, certOptions...)
  237. if err != nil {
  238. if _, ok := err.(*sshutil.TemplateError); ok {
  239. return nil, errs.NewErr(http.StatusBadRequest, err,
  240. errs.WithMessage(err.Error()),
  241. errs.WithKeyVal("signOptions", signOpts),
  242. )
  243. }
  244. return nil, errs.Wrap(http.StatusInternalServerError, err, "authority.SignSSH")
  245. }
  246. // Get actual *ssh.Certificate and continue with provisioner modifiers.
  247. cert := certificate.GetCertificate()
  248. // Use SignSSHOptions to modify the certificate validity. It will be later
  249. // checked or set if not defined.
  250. if err := opts.ModifyValidity(cert); err != nil {
  251. return nil, errs.Wrap(http.StatusBadRequest, err, "authority.SignSSH")
  252. }
  253. // Use provisioner modifiers.
  254. for _, m := range mods {
  255. if err := m.Modify(cert, opts); err != nil {
  256. return nil, errs.Wrap(http.StatusForbidden, err, "authority.SignSSH")
  257. }
  258. }
  259. // Get signer from authority keys
  260. var signer ssh.Signer
  261. switch cert.CertType {
  262. case ssh.UserCert:
  263. if a.sshCAUserCertSignKey == nil {
  264. return nil, errs.NotImplemented("authority.SignSSH: user certificate signing is not enabled")
  265. }
  266. signer = a.sshCAUserCertSignKey
  267. case ssh.HostCert:
  268. if a.sshCAHostCertSignKey == nil {
  269. return nil, errs.NotImplemented("authority.SignSSH: host certificate signing is not enabled")
  270. }
  271. signer = a.sshCAHostCertSignKey
  272. default:
  273. return nil, errs.InternalServer("authority.SignSSH: unexpected ssh certificate type: %d", cert.CertType)
  274. }
  275. // Sign certificate.
  276. cert, err = sshutil.CreateCertificate(cert, signer)
  277. if err != nil {
  278. return nil, errs.Wrap(http.StatusInternalServerError, err, "authority.SignSSH: error signing certificate")
  279. }
  280. // User provisioners validators.
  281. for _, v := range validators {
  282. if err := v.Valid(cert, opts); err != nil {
  283. return nil, errs.Wrap(http.StatusForbidden, err, "authority.SignSSH")
  284. }
  285. }
  286. if err = a.db.StoreSSHCertificate(cert); err != nil && err != db.ErrNotImplemented {
  287. return nil, errs.Wrap(http.StatusInternalServerError, err, "authority.SignSSH: error storing certificate in db")
  288. }
  289. return cert, nil
  290. }
  291. // RenewSSH creates a signed SSH certificate using the old SSH certificate as a template.
  292. func (a *Authority) RenewSSH(ctx context.Context, oldCert *ssh.Certificate) (*ssh.Certificate, error) {
  293. if oldCert.ValidAfter == 0 || oldCert.ValidBefore == 0 {
  294. return nil, errs.BadRequest("rewnewSSH: cannot renew certificate without validity period")
  295. }
  296. backdate := a.config.AuthorityConfig.Backdate.Duration
  297. duration := time.Duration(oldCert.ValidBefore-oldCert.ValidAfter) * time.Second
  298. now := time.Now()
  299. va := now.Add(-1 * backdate)
  300. vb := now.Add(duration - backdate)
  301. // Build base certificate with the old key.
  302. // Nonce and serial will be automatically generated on signing.
  303. cert := &ssh.Certificate{
  304. Key: oldCert.Key,
  305. CertType: oldCert.CertType,
  306. KeyId: oldCert.KeyId,
  307. ValidPrincipals: oldCert.ValidPrincipals,
  308. Permissions: oldCert.Permissions,
  309. Reserved: oldCert.Reserved,
  310. ValidAfter: uint64(va.Unix()),
  311. ValidBefore: uint64(vb.Unix()),
  312. }
  313. // Get signer from authority keys
  314. var signer ssh.Signer
  315. switch cert.CertType {
  316. case ssh.UserCert:
  317. if a.sshCAUserCertSignKey == nil {
  318. return nil, errs.NotImplemented("renewSSH: user certificate signing is not enabled")
  319. }
  320. signer = a.sshCAUserCertSignKey
  321. case ssh.HostCert:
  322. if a.sshCAHostCertSignKey == nil {
  323. return nil, errs.NotImplemented("renewSSH: host certificate signing is not enabled")
  324. }
  325. signer = a.sshCAHostCertSignKey
  326. default:
  327. return nil, errs.InternalServer("renewSSH: unexpected ssh certificate type: %d", cert.CertType)
  328. }
  329. var err error
  330. // Sign certificate.
  331. cert, err = sshutil.CreateCertificate(cert, signer)
  332. if err != nil {
  333. return nil, errs.Wrap(http.StatusInternalServerError, err, "signSSH: error signing certificate")
  334. }
  335. if err = a.db.StoreSSHCertificate(cert); err != nil && err != db.ErrNotImplemented {
  336. return nil, errs.Wrap(http.StatusInternalServerError, err, "renewSSH: error storing certificate in db")
  337. }
  338. return cert, nil
  339. }
  340. // RekeySSH creates a signed SSH certificate using the old SSH certificate as a template.
  341. func (a *Authority) RekeySSH(ctx context.Context, oldCert *ssh.Certificate, pub ssh.PublicKey, signOpts ...provisioner.SignOption) (*ssh.Certificate, error) {
  342. var validators []provisioner.SSHCertValidator
  343. for _, op := range signOpts {
  344. switch o := op.(type) {
  345. // validate the ssh.Certificate
  346. case provisioner.SSHCertValidator:
  347. validators = append(validators, o)
  348. default:
  349. return nil, errs.InternalServer("rekeySSH; invalid extra option type %T", o)
  350. }
  351. }
  352. if oldCert.ValidAfter == 0 || oldCert.ValidBefore == 0 {
  353. return nil, errs.BadRequest("rekeySSH; cannot rekey certificate without validity period")
  354. }
  355. backdate := a.config.AuthorityConfig.Backdate.Duration
  356. duration := time.Duration(oldCert.ValidBefore-oldCert.ValidAfter) * time.Second
  357. now := time.Now()
  358. va := now.Add(-1 * backdate)
  359. vb := now.Add(duration - backdate)
  360. // Build base certificate with the new key.
  361. // Nonce and serial will be automatically generated on signing.
  362. cert := &ssh.Certificate{
  363. Key: pub,
  364. CertType: oldCert.CertType,
  365. KeyId: oldCert.KeyId,
  366. ValidPrincipals: oldCert.ValidPrincipals,
  367. Permissions: oldCert.Permissions,
  368. Reserved: oldCert.Reserved,
  369. ValidAfter: uint64(va.Unix()),
  370. ValidBefore: uint64(vb.Unix()),
  371. }
  372. // Get signer from authority keys
  373. var signer ssh.Signer
  374. switch cert.CertType {
  375. case ssh.UserCert:
  376. if a.sshCAUserCertSignKey == nil {
  377. return nil, errs.NotImplemented("rekeySSH; user certificate signing is not enabled")
  378. }
  379. signer = a.sshCAUserCertSignKey
  380. case ssh.HostCert:
  381. if a.sshCAHostCertSignKey == nil {
  382. return nil, errs.NotImplemented("rekeySSH; host certificate signing is not enabled")
  383. }
  384. signer = a.sshCAHostCertSignKey
  385. default:
  386. return nil, errs.BadRequest("rekeySSH; unexpected ssh certificate type: %d", cert.CertType)
  387. }
  388. var err error
  389. // Sign certificate.
  390. cert, err = sshutil.CreateCertificate(cert, signer)
  391. if err != nil {
  392. return nil, errs.Wrap(http.StatusInternalServerError, err, "signSSH: error signing certificate")
  393. }
  394. // Apply validators from provisioner.
  395. for _, v := range validators {
  396. if err := v.Valid(cert, provisioner.SignSSHOptions{Backdate: backdate}); err != nil {
  397. return nil, errs.Wrap(http.StatusForbidden, err, "rekeySSH")
  398. }
  399. }
  400. if err = a.db.StoreSSHCertificate(cert); err != nil && err != db.ErrNotImplemented {
  401. return nil, errs.Wrap(http.StatusInternalServerError, err, "rekeySSH; error storing certificate in db")
  402. }
  403. return cert, nil
  404. }
  405. // IsValidForAddUser checks if a user provisioner certificate can be issued to
  406. // the given certificate.
  407. func IsValidForAddUser(cert *ssh.Certificate) error {
  408. if cert.CertType != ssh.UserCert {
  409. return errors.New("certificate is not a user certificate")
  410. }
  411. switch len(cert.ValidPrincipals) {
  412. case 0:
  413. return errors.New("certificate does not have any principals")
  414. case 1:
  415. return nil
  416. case 2:
  417. // OIDC provisioners adds a second principal with the email address.
  418. // @ cannot be the first character.
  419. if strings.Index(cert.ValidPrincipals[1], "@") > 0 {
  420. return nil
  421. }
  422. return errors.New("certificate does not have only one principal")
  423. default:
  424. return errors.New("certificate does not have only one principal")
  425. }
  426. }
  427. // SignSSHAddUser signs a certificate that provisions a new user in a server.
  428. func (a *Authority) SignSSHAddUser(ctx context.Context, key ssh.PublicKey, subject *ssh.Certificate) (*ssh.Certificate, error) {
  429. if a.sshCAUserCertSignKey == nil {
  430. return nil, errs.NotImplemented("signSSHAddUser: user certificate signing is not enabled")
  431. }
  432. if err := IsValidForAddUser(subject); err != nil {
  433. return nil, errs.Wrap(http.StatusForbidden, err, "signSSHAddUser")
  434. }
  435. nonce, err := randutil.ASCII(32)
  436. if err != nil {
  437. return nil, errs.Wrap(http.StatusInternalServerError, err, "signSSHAddUser")
  438. }
  439. var serial uint64
  440. if err := binary.Read(rand.Reader, binary.BigEndian, &serial); err != nil {
  441. return nil, errs.Wrap(http.StatusInternalServerError, err, "signSSHAddUser: error reading random number")
  442. }
  443. signer := a.sshCAUserCertSignKey
  444. principal := subject.ValidPrincipals[0]
  445. addUserPrincipal := a.getAddUserPrincipal()
  446. cert := &ssh.Certificate{
  447. Nonce: []byte(nonce),
  448. Key: key,
  449. Serial: serial,
  450. CertType: ssh.UserCert,
  451. KeyId: principal + "-" + addUserPrincipal,
  452. ValidPrincipals: []string{addUserPrincipal},
  453. ValidAfter: subject.ValidAfter,
  454. ValidBefore: subject.ValidBefore,
  455. Permissions: ssh.Permissions{
  456. CriticalOptions: map[string]string{
  457. "force-command": a.getAddUserCommand(principal),
  458. },
  459. },
  460. SignatureKey: signer.PublicKey(),
  461. }
  462. // Get bytes for signing trailing the signature length.
  463. data := cert.Marshal()
  464. data = data[:len(data)-4]
  465. // Sign the certificate
  466. sig, err := signer.Sign(rand.Reader, data)
  467. if err != nil {
  468. return nil, err
  469. }
  470. cert.Signature = sig
  471. if err = a.db.StoreSSHCertificate(cert); err != nil && err != db.ErrNotImplemented {
  472. return nil, errs.Wrap(http.StatusInternalServerError, err, "signSSHAddUser: error storing certificate in db")
  473. }
  474. return cert, nil
  475. }
  476. // CheckSSHHost checks the given principal has been registered before.
  477. func (a *Authority) CheckSSHHost(ctx context.Context, principal string, token string) (bool, error) {
  478. if a.sshCheckHostFunc != nil {
  479. exists, err := a.sshCheckHostFunc(ctx, principal, token, a.GetRootCertificates())
  480. if err != nil {
  481. return false, errs.Wrap(http.StatusInternalServerError, err,
  482. "checkSSHHost: error from injected checkSSHHost func")
  483. }
  484. return exists, nil
  485. }
  486. exists, err := a.db.IsSSHHost(principal)
  487. if err != nil {
  488. if err == db.ErrNotImplemented {
  489. return false, errs.Wrap(http.StatusNotImplemented, err,
  490. "checkSSHHost: isSSHHost is not implemented")
  491. }
  492. return false, errs.Wrap(http.StatusInternalServerError, err,
  493. "checkSSHHost: error checking if hosts exists")
  494. }
  495. return exists, nil
  496. }
  497. // GetSSHHosts returns a list of valid host principals.
  498. func (a *Authority) GetSSHHosts(ctx context.Context, cert *x509.Certificate) ([]Host, error) {
  499. if a.sshGetHostsFunc != nil {
  500. hosts, err := a.sshGetHostsFunc(ctx, cert)
  501. return hosts, errs.Wrap(http.StatusInternalServerError, err, "getSSHHosts")
  502. }
  503. hostnames, err := a.db.GetSSHHostPrincipals()
  504. if err != nil {
  505. return nil, errs.Wrap(http.StatusInternalServerError, err, "getSSHHosts")
  506. }
  507. hosts := make([]Host, len(hostnames))
  508. for i, hn := range hostnames {
  509. hosts[i] = Host{Hostname: hn}
  510. }
  511. return hosts, nil
  512. }
  513. func (a *Authority) getAddUserPrincipal() (cmd string) {
  514. if a.config.SSH.AddUserPrincipal == "" {
  515. return SSHAddUserPrincipal
  516. }
  517. return a.config.SSH.AddUserPrincipal
  518. }
  519. func (a *Authority) getAddUserCommand(principal string) string {
  520. var cmd string
  521. if a.config.SSH.AddUserCommand == "" {
  522. cmd = SSHAddUserCommand
  523. } else {
  524. cmd = a.config.SSH.AddUserCommand
  525. }
  526. return strings.Replace(cmd, "<principal>", principal, -1)
  527. }