kerberos_client.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package sarama
  2. import (
  3. krb5client "github.com/jcmturner/gokrb5/v8/client"
  4. krb5config "github.com/jcmturner/gokrb5/v8/config"
  5. "github.com/jcmturner/gokrb5/v8/keytab"
  6. "github.com/jcmturner/gokrb5/v8/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. // NewKerberosClient creates kerberos client used to obtain TGT and TGS tokens.
  18. // It uses pure go Kerberos 5 solution (RFC-4121 and RFC-4120).
  19. // uses gokrb5 library underlying which is a pure go kerberos client with some GSS-API capabilities.
  20. func NewKerberosClient(config *GSSAPIConfig) (KerberosClient, error) {
  21. cfg, err := krb5config.Load(config.KerberosConfigPath)
  22. if err != nil {
  23. return nil, err
  24. }
  25. return createClient(config, cfg)
  26. }
  27. func createClient(config *GSSAPIConfig, cfg *krb5config.Config) (KerberosClient, error) {
  28. var client *krb5client.Client
  29. if config.AuthType == KRB5_KEYTAB_AUTH {
  30. kt, err := keytab.Load(config.KeyTabPath)
  31. if err != nil {
  32. return nil, err
  33. }
  34. client = krb5client.NewWithKeytab(config.Username, config.Realm, kt, cfg, krb5client.DisablePAFXFAST(config.DisablePAFXFAST))
  35. } else {
  36. client = krb5client.NewWithPassword(config.Username,
  37. config.Realm, config.Password, cfg, krb5client.DisablePAFXFAST(config.DisablePAFXFAST))
  38. }
  39. return &KerberosGoKrb5Client{*client}, nil
  40. }