ssh.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603
  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. "go.step.sm/crypto/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. certTpl := 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(certTpl); 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(certTpl, 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 certTpl.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", certTpl.CertType)
  274. }
  275. // Sign certificate.
  276. cert, err := sshutil.CreateCertificate(certTpl, 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. certTpl := &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 certTpl.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", certTpl.CertType)
  328. }
  329. // Sign certificate.
  330. cert, err := sshutil.CreateCertificate(certTpl, signer)
  331. if err != nil {
  332. return nil, errs.Wrap(http.StatusInternalServerError, err, "signSSH: error signing certificate")
  333. }
  334. if err = a.db.StoreSSHCertificate(cert); err != nil && err != db.ErrNotImplemented {
  335. return nil, errs.Wrap(http.StatusInternalServerError, err, "renewSSH: error storing certificate in db")
  336. }
  337. return cert, nil
  338. }
  339. // RekeySSH creates a signed SSH certificate using the old SSH certificate as a template.
  340. func (a *Authority) RekeySSH(ctx context.Context, oldCert *ssh.Certificate, pub ssh.PublicKey, signOpts ...provisioner.SignOption) (*ssh.Certificate, error) {
  341. var validators []provisioner.SSHCertValidator
  342. for _, op := range signOpts {
  343. switch o := op.(type) {
  344. // validate the ssh.Certificate
  345. case provisioner.SSHCertValidator:
  346. validators = append(validators, o)
  347. default:
  348. return nil, errs.InternalServer("rekeySSH; invalid extra option type %T", o)
  349. }
  350. }
  351. if oldCert.ValidAfter == 0 || oldCert.ValidBefore == 0 {
  352. return nil, errs.BadRequest("rekeySSH; cannot rekey certificate without validity period")
  353. }
  354. backdate := a.config.AuthorityConfig.Backdate.Duration
  355. duration := time.Duration(oldCert.ValidBefore-oldCert.ValidAfter) * time.Second
  356. now := time.Now()
  357. va := now.Add(-1 * backdate)
  358. vb := now.Add(duration - backdate)
  359. // Build base certificate with the new key.
  360. // Nonce and serial will be automatically generated on signing.
  361. cert := &ssh.Certificate{
  362. Key: pub,
  363. CertType: oldCert.CertType,
  364. KeyId: oldCert.KeyId,
  365. ValidPrincipals: oldCert.ValidPrincipals,
  366. Permissions: oldCert.Permissions,
  367. Reserved: oldCert.Reserved,
  368. ValidAfter: uint64(va.Unix()),
  369. ValidBefore: uint64(vb.Unix()),
  370. }
  371. // Get signer from authority keys
  372. var signer ssh.Signer
  373. switch cert.CertType {
  374. case ssh.UserCert:
  375. if a.sshCAUserCertSignKey == nil {
  376. return nil, errs.NotImplemented("rekeySSH; user certificate signing is not enabled")
  377. }
  378. signer = a.sshCAUserCertSignKey
  379. case ssh.HostCert:
  380. if a.sshCAHostCertSignKey == nil {
  381. return nil, errs.NotImplemented("rekeySSH; host certificate signing is not enabled")
  382. }
  383. signer = a.sshCAHostCertSignKey
  384. default:
  385. return nil, errs.BadRequest("rekeySSH; unexpected ssh certificate type: %d", cert.CertType)
  386. }
  387. var err error
  388. // Sign certificate.
  389. cert, err = sshutil.CreateCertificate(cert, signer)
  390. if err != nil {
  391. return nil, errs.Wrap(http.StatusInternalServerError, err, "signSSH: error signing certificate")
  392. }
  393. // Apply validators from provisioner.
  394. for _, v := range validators {
  395. if err := v.Valid(cert, provisioner.SignSSHOptions{Backdate: backdate}); err != nil {
  396. return nil, errs.Wrap(http.StatusForbidden, err, "rekeySSH")
  397. }
  398. }
  399. if err = a.db.StoreSSHCertificate(cert); err != nil && err != db.ErrNotImplemented {
  400. return nil, errs.Wrap(http.StatusInternalServerError, err, "rekeySSH; error storing certificate in db")
  401. }
  402. return cert, nil
  403. }
  404. // IsValidForAddUser checks if a user provisioner certificate can be issued to
  405. // the given certificate.
  406. func IsValidForAddUser(cert *ssh.Certificate) error {
  407. if cert.CertType != ssh.UserCert {
  408. return errors.New("certificate is not a user certificate")
  409. }
  410. switch len(cert.ValidPrincipals) {
  411. case 0:
  412. return errors.New("certificate does not have any principals")
  413. case 1:
  414. return nil
  415. case 2:
  416. // OIDC provisioners adds a second principal with the email address.
  417. // @ cannot be the first character.
  418. if strings.Index(cert.ValidPrincipals[1], "@") > 0 {
  419. return nil
  420. }
  421. return errors.New("certificate does not have only one principal")
  422. default:
  423. return errors.New("certificate does not have only one principal")
  424. }
  425. }
  426. // SignSSHAddUser signs a certificate that provisions a new user in a server.
  427. func (a *Authority) SignSSHAddUser(ctx context.Context, key ssh.PublicKey, subject *ssh.Certificate) (*ssh.Certificate, error) {
  428. if a.sshCAUserCertSignKey == nil {
  429. return nil, errs.NotImplemented("signSSHAddUser: user certificate signing is not enabled")
  430. }
  431. if err := IsValidForAddUser(subject); err != nil {
  432. return nil, errs.Wrap(http.StatusForbidden, err, "signSSHAddUser")
  433. }
  434. nonce, err := randutil.ASCII(32)
  435. if err != nil {
  436. return nil, errs.Wrap(http.StatusInternalServerError, err, "signSSHAddUser")
  437. }
  438. var serial uint64
  439. if err := binary.Read(rand.Reader, binary.BigEndian, &serial); err != nil {
  440. return nil, errs.Wrap(http.StatusInternalServerError, err, "signSSHAddUser: error reading random number")
  441. }
  442. signer := a.sshCAUserCertSignKey
  443. principal := subject.ValidPrincipals[0]
  444. addUserPrincipal := a.getAddUserPrincipal()
  445. cert := &ssh.Certificate{
  446. Nonce: []byte(nonce),
  447. Key: key,
  448. Serial: serial,
  449. CertType: ssh.UserCert,
  450. KeyId: principal + "-" + addUserPrincipal,
  451. ValidPrincipals: []string{addUserPrincipal},
  452. ValidAfter: subject.ValidAfter,
  453. ValidBefore: subject.ValidBefore,
  454. Permissions: ssh.Permissions{
  455. CriticalOptions: map[string]string{
  456. "force-command": a.getAddUserCommand(principal),
  457. },
  458. },
  459. SignatureKey: signer.PublicKey(),
  460. }
  461. // Get bytes for signing trailing the signature length.
  462. data := cert.Marshal()
  463. data = data[:len(data)-4]
  464. // Sign the certificate
  465. sig, err := signer.Sign(rand.Reader, data)
  466. if err != nil {
  467. return nil, err
  468. }
  469. cert.Signature = sig
  470. if err = a.db.StoreSSHCertificate(cert); err != nil && err != db.ErrNotImplemented {
  471. return nil, errs.Wrap(http.StatusInternalServerError, err, "signSSHAddUser: error storing certificate in db")
  472. }
  473. return cert, nil
  474. }
  475. // CheckSSHHost checks the given principal has been registered before.
  476. func (a *Authority) CheckSSHHost(ctx context.Context, principal string, token string) (bool, error) {
  477. if a.sshCheckHostFunc != nil {
  478. exists, err := a.sshCheckHostFunc(ctx, principal, token, a.GetRootCertificates())
  479. if err != nil {
  480. return false, errs.Wrap(http.StatusInternalServerError, err,
  481. "checkSSHHost: error from injected checkSSHHost func")
  482. }
  483. return exists, nil
  484. }
  485. exists, err := a.db.IsSSHHost(principal)
  486. if err != nil {
  487. if err == db.ErrNotImplemented {
  488. return false, errs.Wrap(http.StatusNotImplemented, err,
  489. "checkSSHHost: isSSHHost is not implemented")
  490. }
  491. return false, errs.Wrap(http.StatusInternalServerError, err,
  492. "checkSSHHost: error checking if hosts exists")
  493. }
  494. return exists, nil
  495. }
  496. // GetSSHHosts returns a list of valid host principals.
  497. func (a *Authority) GetSSHHosts(ctx context.Context, cert *x509.Certificate) ([]Host, error) {
  498. if a.sshGetHostsFunc != nil {
  499. hosts, err := a.sshGetHostsFunc(ctx, cert)
  500. return hosts, errs.Wrap(http.StatusInternalServerError, err, "getSSHHosts")
  501. }
  502. hostnames, err := a.db.GetSSHHostPrincipals()
  503. if err != nil {
  504. return nil, errs.Wrap(http.StatusInternalServerError, err, "getSSHHosts")
  505. }
  506. hosts := make([]Host, len(hostnames))
  507. for i, hn := range hostnames {
  508. hosts[i] = Host{Hostname: hn}
  509. }
  510. return hosts, nil
  511. }
  512. func (a *Authority) getAddUserPrincipal() (cmd string) {
  513. if a.config.SSH.AddUserPrincipal == "" {
  514. return SSHAddUserPrincipal
  515. }
  516. return a.config.SSH.AddUserPrincipal
  517. }
  518. func (a *Authority) getAddUserCommand(principal string) string {
  519. var cmd string
  520. if a.config.SSH.AddUserCommand == "" {
  521. cmd = SSHAddUserCommand
  522. } else {
  523. cmd = a.config.SSH.AddUserCommand
  524. }
  525. return strings.Replace(cmd, "<principal>", principal, -1)
  526. }