ssh.go 19 KB

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