Skip to content

Commit

Permalink
feat: add BuildSpnFunc to GSSAPIConfig for allow custom spn (#2807)
Browse files Browse the repository at this point in the history
Signed-off-by: fooofei <[email protected]>
  • Loading branch information
fooofei authored Feb 22, 2024
1 parent 3e385a6 commit 38f2d15
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions gssapi_kerberos.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type GSSAPIConfig struct {
Password string
Realm string
DisablePAFXFAST bool
BuildSpn BuildSpnFunc
}

type GSSAPIKerberosAuth struct {
Expand All @@ -57,6 +58,8 @@ type KerberosClient interface {
Destroy()
}

type BuildSpnFunc func(serviceName, host string) string

// writePackage appends length in big endian before the payload, and sends it to kafka
func (krbAuth *GSSAPIKerberosAuth) writePackage(broker *Broker, payload []byte) (int, error) {
length := uint64(len(payload))
Expand Down Expand Up @@ -211,10 +214,15 @@ func (krbAuth *GSSAPIKerberosAuth) Authorize(broker *Broker) error {
return err
}
// Construct SPN using serviceName and host
// SPN format: <SERVICE>/<FQDN>
// default SPN format: <SERVICE>/<FQDN>

host := strings.SplitN(broker.addr, ":", 2)[0] // Strip port part
spn := fmt.Sprintf("%s/%s", broker.conf.Net.SASL.GSSAPI.ServiceName, host)
var spn string
if krbAuth.Config.BuildSpn != nil {
spn = krbAuth.Config.BuildSpn(broker.conf.Net.SASL.GSSAPI.ServiceName, host)
} else {
spn = fmt.Sprintf("%s/%s", broker.conf.Net.SASL.GSSAPI.ServiceName, host)
}

ticket, encKey, err := kerberosClient.GetServiceTicket(spn)
if err != nil {
Expand Down

0 comments on commit 38f2d15

Please sign in to comment.