Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kerberos profile to support SASL_PLAINTEXT to Kafka connection #753

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions core/internal/helpers/sarama.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,20 @@ func GetSaramaConfigFromClientProfile(profileName string) *sarama.Config {
saramaConfig.Net.SASL.Password = viper.GetString("sasl." + saslName + ".password")
}

// Configure kerberos if enabled
if viper.IsSet(configRoot + ".kerberos") {
saslName := viper.GetString(configRoot + ".kerberos")
saramaConfig.Net.SASL.Enable = true

saramaConfig.Net.SASL.Mechanism = sarama.SASLTypeGSSAPI
saramaConfig.Net.SASL.GSSAPI.AuthType = sarama.KRB5_KEYTAB_AUTH
saramaConfig.Net.SASL.GSSAPI.ServiceName = viper.GetString("kerberos." + saslName + ".servicename")
saramaConfig.Net.SASL.GSSAPI.KerberosConfigPath = viper.GetString("kerberos." + saslName + ".krb5conf")
saramaConfig.Net.SASL.GSSAPI.Realm = viper.GetString("kerberos." + saslName + ".realm")
saramaConfig.Net.SASL.GSSAPI.KeyTabPath = viper.GetString("kerberos." + saslName + ".keytab")
saramaConfig.Net.SASL.GSSAPI.Username = viper.GetString("kerberos." + saslName + ".username")
}

// Timeout for the initial connection
if viper.IsSet(configRoot + ".dial-timeout") {
saramaConfig.Net.DialTimeout = time.Duration(viper.GetInt(configRoot+".dial-timeout")) * time.Second
Expand Down
17 changes: 17 additions & 0 deletions core/internal/httpserver/kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,22 @@ func getSASLProfile(name string) *httpResponseSASLProfile {
}
}

func getKerberosProfile(name string) *httpResponseKerberosProfile {
configRoot := "kerberos." + name
if !viper.IsSet(configRoot) {
return nil
}

return &httpResponseKerberosProfile{
Name: name,
KeyTab: viper.GetString(configRoot + ".keytab"),
Krb5Conf: viper.GetString(configRoot + ".krb5conf"),
Realm: viper.GetString(configRoot + ".realm"),
ServiceName: viper.GetString(configRoot + ".servicename"),
Username: viper.GetString(configRoot + ".username"),
}
}

func getClientProfile(name string) httpResponseClientProfile {
configRoot := "client-profile." + name
return httpResponseClientProfile{
Expand All @@ -73,6 +89,7 @@ func getClientProfile(name string) httpResponseClientProfile {
KafkaVersion: viper.GetString(configRoot + ".kafka-version"),
TLS: getTLSProfile(viper.GetString(configRoot + ".tls")),
SASL: getSASLProfile(viper.GetString(configRoot + ".sasl")),
Kerberos: getKerberosProfile(viper.GetString(configRoot + ".kerberos")),
}
}

Expand Down
20 changes: 15 additions & 5 deletions core/internal/httpserver/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,22 @@ type httpResponseSASLProfile struct {
Username string `json:"username"`
}

type httpResponseKerberosProfile struct {
Name string `json:"name"`
KeyTab string `json:"keytab"`
Krb5Conf string `json:"krb5conf"`
Realm string `json:"realm"`
ServiceName string `json:"servicename"`
Username string `json:"username"`
}

type httpResponseClientProfile struct {
Name string `json:"name"`
ClientID string `json:"client-id"`
KafkaVersion string `json:"kafka-version"`
TLS *httpResponseTLSProfile `json:"tls"`
SASL *httpResponseSASLProfile `json:"sasl"`
Name string `json:"name"`
ClientID string `json:"client-id"`
KafkaVersion string `json:"kafka-version"`
TLS *httpResponseTLSProfile `json:"tls"`
SASL *httpResponseSASLProfile `json:"sasl"`
Kerberos *httpResponseKerberosProfile `json:"kerberos"`
}

type httpResponseClusterList struct {
Expand Down