| Abhay Kumar | 40252eb | 2025-10-13 13:25:53 +0000 | [diff] [blame^] | 1 | package sarama |
| 2 | |
| 3 | import ( |
| 4 | krb5client "github.com/jcmturner/gokrb5/v8/client" |
| 5 | krb5config "github.com/jcmturner/gokrb5/v8/config" |
| 6 | "github.com/jcmturner/gokrb5/v8/credentials" |
| 7 | "github.com/jcmturner/gokrb5/v8/keytab" |
| 8 | "github.com/jcmturner/gokrb5/v8/types" |
| 9 | ) |
| 10 | |
| 11 | type KerberosGoKrb5Client struct { |
| 12 | krb5client.Client |
| 13 | } |
| 14 | |
| 15 | func (c *KerberosGoKrb5Client) Domain() string { |
| 16 | return c.Credentials.Domain() |
| 17 | } |
| 18 | |
| 19 | func (c *KerberosGoKrb5Client) CName() types.PrincipalName { |
| 20 | return c.Credentials.CName() |
| 21 | } |
| 22 | |
| 23 | // NewKerberosClient creates kerberos client used to obtain TGT and TGS tokens. |
| 24 | // It uses pure go Kerberos 5 solution (RFC-4121 and RFC-4120). |
| 25 | // uses gokrb5 library underlying which is a pure go kerberos client with some GSS-API capabilities. |
| 26 | func NewKerberosClient(config *GSSAPIConfig) (KerberosClient, error) { |
| 27 | cfg, err := krb5config.Load(config.KerberosConfigPath) |
| 28 | if err != nil { |
| 29 | return nil, err |
| 30 | } |
| 31 | return createClient(config, cfg) |
| 32 | } |
| 33 | |
| 34 | func createClient(config *GSSAPIConfig, cfg *krb5config.Config) (KerberosClient, error) { |
| 35 | var client *krb5client.Client |
| 36 | switch config.AuthType { |
| 37 | case KRB5_KEYTAB_AUTH: |
| 38 | kt, err := keytab.Load(config.KeyTabPath) |
| 39 | if err != nil { |
| 40 | return nil, err |
| 41 | } |
| 42 | client = krb5client.NewWithKeytab(config.Username, config.Realm, kt, cfg, krb5client.DisablePAFXFAST(config.DisablePAFXFAST)) |
| 43 | case KRB5_CCACHE_AUTH: |
| 44 | cc, err := credentials.LoadCCache(config.CCachePath) |
| 45 | if err != nil { |
| 46 | return nil, err |
| 47 | } |
| 48 | client, err = krb5client.NewFromCCache(cc, cfg, krb5client.DisablePAFXFAST(config.DisablePAFXFAST)) |
| 49 | if err != nil { |
| 50 | return nil, err |
| 51 | } |
| 52 | default: |
| 53 | client = krb5client.NewWithPassword(config.Username, |
| 54 | config.Realm, config.Password, cfg, krb5client.DisablePAFXFAST(config.DisablePAFXFAST)) |
| 55 | } |
| 56 | return &KerberosGoKrb5Client{*client}, nil |
| 57 | } |