kerberos_client.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package sarama
  2. import (
  3. krb5client "gopkg.in/jcmturner/gokrb5.v7/client"
  4. krb5config "gopkg.in/jcmturner/gokrb5.v7/config"
  5. "gopkg.in/jcmturner/gokrb5.v7/keytab"
  6. "gopkg.in/jcmturner/gokrb5.v7/types"
  7. )
  8. type KerberosGoKrb5Client struct {
  9. krb5client.Client
  10. }
  11. func (c *KerberosGoKrb5Client) Domain() string {
  12. return c.Credentials.Domain()
  13. }
  14. func (c *KerberosGoKrb5Client) CName() types.PrincipalName {
  15. return c.Credentials.CName()
  16. }
  17. /*
  18. *
  19. * Create kerberos client used to obtain TGT and TGS tokens
  20. * used gokrb5 library, which is a pure go kerberos client with
  21. * some GSS-API capabilities, and SPNEGO support. Kafka does not use SPNEGO
  22. * it uses pure Kerberos 5 solution (RFC-4121 and RFC-4120).
  23. *
  24. */
  25. func NewKerberosClient(config *GSSAPIConfig) (KerberosClient, error) {
  26. cfg, err := krb5config.Load(config.KerberosConfigPath)
  27. if err != nil {
  28. return nil, err
  29. }
  30. return createClient(config, cfg)
  31. }
  32. func createClient(config *GSSAPIConfig, cfg *krb5config.Config) (KerberosClient, error) {
  33. var client *krb5client.Client
  34. if config.AuthType == KRB5_KEYTAB_AUTH {
  35. kt, err := keytab.Load(config.KeyTabPath)
  36. if err != nil {
  37. return nil, err
  38. }
  39. client = krb5client.NewClientWithKeytab(config.Username, config.Realm, kt, cfg)
  40. } else {
  41. client = krb5client.NewClientWithPassword(config.Username,
  42. config.Realm, config.Password, cfg)
  43. }
  44. return &KerberosGoKrb5Client{*client}, nil
  45. }