Skip to content

Commit 38f2d15

Browse files
authored
feat: add BuildSpnFunc to GSSAPIConfig for allow custom spn (#2807)
Signed-off-by: fooofei <aihujianfei@qq.com>
1 parent 3e385a6 commit 38f2d15

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

gssapi_kerberos.go

+10-2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type GSSAPIConfig struct {
3939
Password string
4040
Realm string
4141
DisablePAFXFAST bool
42+
BuildSpn BuildSpnFunc
4243
}
4344

4445
type GSSAPIKerberosAuth struct {
@@ -57,6 +58,8 @@ type KerberosClient interface {
5758
Destroy()
5859
}
5960

61+
type BuildSpnFunc func(serviceName, host string) string
62+
6063
// writePackage appends length in big endian before the payload, and sends it to kafka
6164
func (krbAuth *GSSAPIKerberosAuth) writePackage(broker *Broker, payload []byte) (int, error) {
6265
length := uint64(len(payload))
@@ -211,10 +214,15 @@ func (krbAuth *GSSAPIKerberosAuth) Authorize(broker *Broker) error {
211214
return err
212215
}
213216
// Construct SPN using serviceName and host
214-
// SPN format: <SERVICE>/<FQDN>
217+
// default SPN format: <SERVICE>/<FQDN>
215218

216219
host := strings.SplitN(broker.addr, ":", 2)[0] // Strip port part
217-
spn := fmt.Sprintf("%s/%s", broker.conf.Net.SASL.GSSAPI.ServiceName, host)
220+
var spn string
221+
if krbAuth.Config.BuildSpn != nil {
222+
spn = krbAuth.Config.BuildSpn(broker.conf.Net.SASL.GSSAPI.ServiceName, host)
223+
} else {
224+
spn = fmt.Sprintf("%s/%s", broker.conf.Net.SASL.GSSAPI.ServiceName, host)
225+
}
218226

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

0 commit comments

Comments
 (0)