options.go 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package authority
  2. import (
  3. "context"
  4. "crypto/x509"
  5. "github.com/smallstep/certificates/authority/provisioner"
  6. "github.com/smallstep/certificates/db"
  7. "github.com/smallstep/certificates/sshutil"
  8. )
  9. // Option sets options to the Authority.
  10. type Option func(*Authority)
  11. // WithDatabase sets an already initialized authority database to a new
  12. // authority. This option is intended to be use on graceful reloads.
  13. func WithDatabase(db db.AuthDB) Option {
  14. return func(a *Authority) {
  15. a.db = db
  16. }
  17. }
  18. // WithGetIdentityFunc sets a custom function to retrieve the identity from
  19. // an external resource.
  20. func WithGetIdentityFunc(fn func(p provisioner.Interface, email string) (*provisioner.Identity, error)) Option {
  21. return func(a *Authority) {
  22. a.getIdentityFunc = fn
  23. }
  24. }
  25. // WithSSHBastionFunc sets a custom function to get the bastion for a
  26. // given user-host pair.
  27. func WithSSHBastionFunc(fn func(user, host string) (*Bastion, error)) Option {
  28. return func(a *Authority) {
  29. a.sshBastionFunc = fn
  30. }
  31. }
  32. // WithSSHGetHosts sets a custom function to get the bastion for a
  33. // given user-host pair.
  34. func WithSSHGetHosts(fn func(cert *x509.Certificate) ([]sshutil.Host, error)) Option {
  35. return func(a *Authority) {
  36. a.sshGetHostsFunc = fn
  37. }
  38. }
  39. // WithSSHCheckHost sets a custom function to check whether a given host is
  40. // step ssh enabled. The token is used to validate the request, while the roots
  41. // are used to validate the token.
  42. func WithSSHCheckHost(fn func(ctx context.Context, principal string, tok string, roots []*x509.Certificate) (bool, error)) Option {
  43. return func(a *Authority) {
  44. a.sshCheckHostFunc = fn
  45. }
  46. }