ssh.go 19 KB

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